@@ -17,79 +17,80 @@ import openfl.utils.Assets;
1717/**
1818 * Class used for scripting.
1919 */
20- class Script extends FlxBasic implements IFlxDestroyable {
20+ class Script extends FlxBasic implements IFlxDestroyable
21+ {
2122 /**
2223 * Use "static var thing = true;" in hscript to use those!!
2324 * are reset every mod switch so once you're done with them make sure to make them null!!
2425 */
2526 public static var staticVariables : Map <String , Dynamic > = [];
2627
27- public static function getDefaultVariables (? script : Script ): Map <String , Dynamic > {
28+ public static function getDefaultVariables (? script : Script ): Map <String , Dynamic >
29+ {
2830 return [
2931 // Haxe related stuff
30- " Std" => Std ,
31- " Math" => Math ,
32- " Reflect" => Reflect ,
33- " StringTools" => StringTools ,
34- " Json" => haxe. Json ,
32+ " Std" => Std ,
33+ " Math" => Math ,
34+ " Reflect" => Reflect ,
35+ " StringTools" => StringTools ,
36+ " Json" => haxe. Json ,
3537
3638 // OpenFL & Lime related stuff
37- " Assets" => openfl.utils. Assets ,
38- " Application" => lime.app. Application ,
39- " window" => lime.app. Application .current .window ,
39+ " Assets" => openfl.utils. Assets ,
40+ " Application" => lime.app. Application ,
41+ " window" => lime.app. Application .current .window ,
4042
4143 // Flixel related stuff
42- " FlxG" => flixel. FlxG ,
43- " FlxSprite" => flixel. FlxSprite ,
44- " FlxBasic" => flixel. FlxBasic ,
45- " FlxCamera" => flixel. FlxCamera ,
46- " state" => flixel. FlxG .state ,
47- " FlxEase" => flixel.tweens. FlxEase ,
48- " FlxTween" => flixel.tweens. FlxTween ,
49- " FlxSound" => flixel.sound. FlxSound ,
50- " FlxAssets" => flixel.system. FlxAssets ,
51- " FlxMath" => flixel.math. FlxMath ,
52- " FlxGroup" => flixel.group. FlxGroup ,
53- " FlxTypedGroup" => flixel.group. FlxGroup . FlxTypedGroup ,
54- " FlxSpriteGroup" => flixel.group. FlxSpriteGroup ,
55- " FlxTypeText" => flixel.addons.text. FlxTypeText ,
56- " FlxText" => flixel.text. FlxText ,
57- " FlxTimer" => flixel.util. FlxTimer ,
58- " FlxPoint" => ScriptUtils .getMacroAbstractClass (" flixel.math.FlxPoint" ),
59- " FlxAxes" => ScriptUtils .getMacroAbstractClass (" flixel.util.FlxAxes" ),
60- " FlxColor" => ScriptUtils .getMacroAbstractClass (" flixel.util.FlxColor" ),
61-
62- " ModState" => codename.scripting. ModState ,
63- " ModSubState" => codename.scripting. ModSubState ,
64- " PlayState" => PlayState ,
65- " GameOverSubstate" => GameOverSubstate ,
66- " HealthIcon" => HealthIcon ,
67- " Note" => Note ,
68- " StrumNote" => StrumNote ,
69- " Character" => Character ,
70- " Boyfriend" => Boyfriend , // for compatibility
71- " PauseSubstate" => PauseSubState ,
72- " FreeplayState" => FreeplayState ,
73- " MainMenuState" => MainMenuState ,
74- " PauseSubState" => PauseSubState ,
75- " StoryMenuState" => StoryMenuState ,
76- " TitleState" => TitleState ,
44+ " FlxG" => flixel. FlxG ,
45+ " FlxSprite" => flixel. FlxSprite ,
46+ " FlxBasic" => flixel. FlxBasic ,
47+ " FlxCamera" => flixel. FlxCamera ,
48+ " state" => flixel. FlxG .state ,
49+ " FlxEase" => flixel.tweens. FlxEase ,
50+ " FlxTween" => flixel.tweens. FlxTween ,
51+ " FlxSound" => flixel.sound. FlxSound ,
52+ " FlxAssets" => flixel.system. FlxAssets ,
53+ " FlxMath" => flixel.math. FlxMath ,
54+ " FlxGroup" => flixel.group. FlxGroup ,
55+ " FlxTypedGroup" => flixel.group. FlxGroup . FlxTypedGroup ,
56+ " FlxSpriteGroup" => flixel.group. FlxSpriteGroup ,
57+ " FlxTypeText" => flixel.addons.text. FlxTypeText ,
58+ " FlxText" => flixel.text. FlxText ,
59+ " FlxTimer" => flixel.util. FlxTimer ,
60+ " FlxPoint" => ScriptUtils .getMacroAbstractClass (" flixel.math.FlxPoint" ),
61+ " FlxAxes" => ScriptUtils .getMacroAbstractClass (" flixel.util.FlxAxes" ),
62+ " FlxColor" => ScriptUtils .getMacroAbstractClass (" flixel.util.FlxColor" ),
63+
64+ " ModState" => codename.scripting. ModState ,
65+ " ModSubState" => codename.scripting. ModSubState ,
66+ " PlayState" => PlayState ,
67+ " GameOverSubstate" => GameOverSubstate ,
68+ " HealthIcon" => HealthIcon ,
69+ " Note" => Note ,
70+ " StrumNote" => StrumNote ,
71+ " Character" => Character ,
72+ " Boyfriend" => Boyfriend , // for compatibility
73+ " PauseSubstate" => PauseSubState ,
74+ " FreeplayState" => FreeplayState ,
75+ " MainMenuState" => MainMenuState ,
76+ " PauseSubState" => PauseSubState ,
77+ " StoryMenuState" => StoryMenuState ,
78+ " TitleState" => TitleState ,
7779 // "Options" => options.SelectThing,
78- " Paths" => Paths ,
79- " Conductor" => Conductor ,
80- " FunkinShader" => codename.backend.shaders. FunkinShader ,
81- " CustomShader" => codename.backend.shaders. CustomShader ,
82- " Alphabet" => Alphabet ,
80+ " Paths" => Paths ,
81+ " Conductor" => Conductor ,
82+ " FunkinShader" => codename.backend.shaders. FunkinShader ,
83+ " CustomShader" => codename.backend.shaders. CustomShader ,
84+ " Alphabet" => Alphabet ,
8385
84- " CoolUtil" => CoolUtil ,
86+ " CoolUtil" => CoolUtil ,
8587 ];
8688 }
89+
8790 /**
8891 * All available script extensions
8992 */
90- public static var scriptExtensions : Array <String > = [
91- " hx" , " hscript"
92- ];
93+ public static var scriptExtensions : Array <String > = [" hx" , " hscript" ];
9394
9495 /**
9596 * Currently executing script.
@@ -121,9 +122,12 @@ class Script extends FlxBasic implements IFlxDestroyable {
121122 * Creates a script from the specified asset path. The language is automatically determined.
122123 * @param path Path in assets
123124 */
124- public static function create (path : String ): Script {
125- if (Assets .exists (path )) {
126- return switch (Path .extension (path ).toLowerCase ()) {
125+ public static function create (path : String ): Script
126+ {
127+ if (Assets .exists (path ))
128+ {
129+ return switch (Path .extension (path ).toLowerCase ())
130+ {
127131 case " hx" | " hscript" :
128132 new HScript (path );
129133 default :
@@ -138,8 +142,10 @@ class Script extends FlxBasic implements IFlxDestroyable {
138142 * @param code code
139143 * @param path filename
140144 */
141- public static function fromString (code : String , path : String ): Script {
142- return switch (Path .extension (path ).toLowerCase ()) {
145+ public static function fromString (code : String , path : String ): Script
146+ {
147+ return switch (Path .extension (path ).toLowerCase ())
148+ {
143149 case " hx" | " hscript" :
144150 new HScript (path ).loadFromString (code );
145151 default :
@@ -151,7 +157,8 @@ class Script extends FlxBasic implements IFlxDestroyable {
151157 * Creates a new instance of the script class.
152158 * @param path
153159 */
154- public function new (path : String ) {
160+ public function new (path : String )
161+ {
155162 super ();
156163
157164 rawPath = path ;
@@ -161,21 +168,24 @@ class Script extends FlxBasic implements IFlxDestroyable {
161168 extension = Path .extension (path );
162169 this .path = path ;
163170 onCreate (path );
164- for (k => e in getDefaultVariables (this )) {
171+ for (k => e in getDefaultVariables (this ))
172+ {
165173 set (k , e );
166174 }
167- set (" disableScript" , () -> {
175+ set (" disableScript" , () ->
176+ {
168177 active = false ;
169178 });
170179 set (" __script__" , this );
171180 }
172181
173-
174182 /**
175183 * Loads the script
176184 */
177- public function load () {
178- if (didLoad ) return ;
185+ public function load ()
186+ {
187+ if (didLoad )
188+ return ;
179189
180190 var oldScript = curScript ;
181191 curScript = this ;
@@ -189,38 +199,36 @@ class Script extends FlxBasic implements IFlxDestroyable {
189199 * HSCRIPT ONLY FOR NOW
190200 * Sets the "public" variables map for ScriptPack
191201 */
192- public function setPublicMap (map : Map <String , Dynamic >) {
193-
202+ public function setPublicMap (map : Map <String , Dynamic >)
203+ {
194204 }
195205
196206 /**
197207 * Hot-reloads the script, if possible
198208 */
199- public function reload () {
200-
209+ public function reload ()
210+ {
201211 }
202212
203213 /**
204214 * Traces something as this script.
205215 */
206- public function trace (v : Dynamic ) {
216+ public function trace (v : Dynamic )
217+ {
207218 var fileName = this .fileName ;
208- if (remappedNames .exists (fileName ))
219+ if (remappedNames .exists (fileName ))
209220 fileName = remappedNames .get (fileName );
210- // Logs.traceColored([
211- // Logs.logText('${fileName}: ', GREEN),
212- // Logs.logText(Std.string(v))
213- // ], TRACE);
221+ Logs .traceNew (' ${fileName }: ' + Std .string (v ), MISC );
214222 }
215223
216-
217224 /**
218225 * Calls the function `func` defined in the script.
219226 * @param func Name of the function
220227 * @param parameters (Optional) Parameters of the function.
221228 * @return Result (if void, then null)
222229 */
223- public function call (func : String , ? parameters : Array <Dynamic >): Dynamic {
230+ public function call (func : String , ? parameters : Array <Dynamic >): Dynamic
231+ {
224232 var oldScript = curScript ;
225233 curScript = this ;
226234
@@ -234,38 +242,47 @@ class Script extends FlxBasic implements IFlxDestroyable {
234242 * Loads the code from a string, doesnt really work after the script has been loaded
235243 * @param code The code.
236244 */
237- public function loadFromString (code : String ) {
245+ public function loadFromString (code : String )
246+ {
238247 return this ;
239248 }
240249
241250 /**
242251 * Sets a script's parent object so that its properties can be accessed easily. Ex: Passing `PlayState.instance` will allow `boyfriend` to be typed instead of `PlayState.instance.boyfriend`.
243252 * @param variable Parent variable.
244253 */
245- public function setParent (variable : Dynamic ) {}
254+ public function setParent (variable : Dynamic )
255+ {
256+ }
246257
247258 /**
248259 * Gets the variable `variable` from the script's variables.
249260 * @param variable Name of the variable.
250261 * @return Variable (or null if it doesn't exists)
251262 */
252- public function get (variable : String ): Dynamic {return null ;}
263+ public function get (variable : String ): Dynamic
264+ {
265+ return null ;
266+ }
253267
254268 /**
255269 * Sets the variable `variable` from the script's variables.
256270 * @param variable Name of the variable.
257271 * @return Variable (or null if it doesn't exists)
258272 */
259- public function set (variable : String , value : Dynamic ): Void {}
273+ public function set (variable : String , value : Dynamic ): Void
274+ {
275+ }
260276
261277 /**
262278 * Shows an error from this script.
263279 * @param text Text of the error (ex: Null Object Reference).
264280 * @param additionalInfo Additional information you could provide.
265281 */
266- public function error (text : String , ? additionalInfo : Dynamic ): Void {
282+ public function error (text : String , ? additionalInfo : Dynamic ): Void
283+ {
267284 var fileName = this .fileName ;
268- if (remappedNames .exists (fileName ))
285+ if (remappedNames .exists (fileName ))
269286 fileName = remappedNames .get (fileName );
270287 // Logs.traceColored([
271288 // Logs.logText(fileName, RED),
@@ -287,10 +304,16 @@ class Script extends FlxBasic implements IFlxDestroyable {
287304 /**
288305 * PRIVATE HANDLERS - DO NOT TOUCH
289306 */
290- private function onCall (func : String , parameters : Array <Dynamic >): Dynamic {
307+ private function onCall (func : String , parameters : Array <Dynamic >): Dynamic
308+ {
291309 return null ;
292310 }
293- public function onCreate (path : String ) {}
294311
295- public function onLoad () {}
296- }
312+ public function onCreate (path : String )
313+ {
314+ }
315+
316+ public function onLoad ()
317+ {
318+ }
319+ }
0 commit comments