diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..6ef72f83 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.idea/ +*.iml + diff --git a/com/stencyl/AssetLoader.hx b/com/stencyl/AssetLoader.hx index 0fb5dd42..6025a5c6 100644 --- a/com/stencyl/AssetLoader.hx +++ b/com/stencyl/AssetLoader.hx @@ -1,9 +1,9 @@ package com.stencyl; -import haxe.xml.Fast; +import com.stencyl.models.IdType; interface AssetLoader { function loadResources(resourceMap:Map):Void; - function loadScenes(scenesXML:Map):Void; + function loadScenes(scenesXML:Map):Void; } \ No newline at end of file diff --git a/com/stencyl/Data.hx b/com/stencyl/Data.hx index 6a307e9c..507c2b3b 100644 --- a/com/stencyl/Data.hx +++ b/com/stencyl/Data.hx @@ -9,6 +9,8 @@ import com.stencyl.io.SoundReader; import com.stencyl.io.SpriteReader; import com.stencyl.io.TilesetReader; +import com.stencyl.models.IdType; + import openfl.Assets; import openfl.Lib; import haxe.xml.Fast; @@ -83,7 +85,7 @@ class Data //*----------------------------------------------- //Map of each [sceneID].xml by ID - public var scenesXML:Map; + public var scenesXML:Map; //Map of each [sceneID].scn by ID //public var scenesTerrain:Map; @@ -151,7 +153,7 @@ class Data updatePreloader(90); - scenesXML = new Map(); + scenesXML = new Map(); loader.loadScenes(scenesXML); diff --git a/com/stencyl/Engine.hx b/com/stencyl/Engine.hx index 5dcb132c..cbd94b97 100644 --- a/com/stencyl/Engine.hx +++ b/com/stencyl/Engine.hx @@ -15,6 +15,9 @@ import com.stencyl.behavior.BehaviorManager; import com.stencyl.behavior.BehaviorInstance; import com.stencyl.behavior.Script; +import com.stencyl.models.IdType; +import com.stencyl.models.IdType.IdUtils; + import openfl.geom.Point; import openfl.geom.Rectangle; import openfl.display.DisplayObject; @@ -209,7 +212,7 @@ class Engine private var leave:Transition; private var enter:Transition; - private var sceneToEnter:Int; + private var sceneToEnter:IdType; //*----------------------------------------------- @@ -625,7 +628,7 @@ class Engine } #end - public function begin(initSceneID:Int) + public function begin(initSceneID:IdType) { loadedAtlases = new Map(); atlasesToLoad = new Map(); @@ -805,7 +808,7 @@ class Engine loadScene(initSceneID); } - public function loadScene(sceneID:Int) + public function loadScene(sceneID:IdType) { collisionPairs = new IntHashTable>(32); @@ -817,7 +820,7 @@ class Engine scene = GameModel.get().scenes.get(sceneID); - if(sceneID == -1 || scene == null) + if(sceneID == IdUtils.INVALID_ID || scene == null) { scene = GameModel.get().scenes.get(GameModel.get().defaultSceneID); @@ -1719,7 +1722,7 @@ class Engine world = null; } - public function switchScene(sceneID:Int, leave:Transition=null, enter:Transition=null) + public function switchScene(sceneID:IdType, leave:Transition=null, enter:Transition=null) { // trace("Request to switch to Scene " + sceneID); diff --git a/com/stencyl/behavior/Script.hx b/com/stencyl/behavior/Script.hx index 71cc9447..0d4b7479 100644 --- a/com/stencyl/behavior/Script.hx +++ b/com/stencyl/behavior/Script.hx @@ -64,6 +64,8 @@ import com.stencyl.event.EventMaster; import com.stencyl.event.NativeListener; import com.stencyl.io.SpriteReader; +import com.stencyl.models.IdType; + import motion.Actuate; import motion.easing.Linear; @@ -1177,7 +1179,7 @@ class Script * * @return The ID current scene */ - public static function getCurrentScene():Int + public static function getCurrentScene():IdType { return getScene().ID; } @@ -1185,9 +1187,9 @@ class Script /** * Get the ID of a scene by name. * - * @return The ID current scene or 0 if it doesn't exist. + * @return The ID current scene or IdUtils.INVALID_ID if it doesn't exist. */ - public static function getIDForScene(sceneName:String):Int + public static function getIDForScene(sceneName:String):IdType { for(s in GameModel.get().scenes) { @@ -1197,7 +1199,7 @@ class Script } } - return 0; + return IdUtils.INVALID_ID; } /** @@ -1272,7 +1274,7 @@ class Script * @param leave exit transition * @param enter enter transition */ - public static function switchScene(sceneID:Int, leave:Transition=null, enter:Transition=null) + public static function switchScene(sceneID:IdType, leave:Transition=null, enter:Transition=null) { engine.switchScene(sceneID, leave, enter); } diff --git a/com/stencyl/models/GameModel.hx b/com/stencyl/models/GameModel.hx index 35a84642..fc1564fc 100644 --- a/com/stencyl/models/GameModel.hx +++ b/com/stencyl/models/GameModel.hx @@ -7,6 +7,8 @@ import com.stencyl.utils.Utils; import com.stencyl.models.scene.Autotile; import com.stencyl.models.scene.AutotileFormat; +import com.stencyl.models.IdType.IdUtils; + import box2D.common.math.B2Vec2; import box2D.collision.shapes.B2Shape; import box2D.collision.shapes.B2PolygonShape; @@ -26,7 +28,7 @@ class GameModel public var actualHeight:Int; public var scale:Int; - public var defaultSceneID:Int; + public var defaultSceneID:IdType; public var groups:Array; public var groupsCollidesWith:Map>; @@ -36,7 +38,7 @@ class GameModel public var gameAttributes:Map; public var shapes:Map; public var atlases:Map; - public var scenes:Map; + public var scenes:Map; public var autotileFormats:Map; public static var INHERIT_ID:Int = -1000; @@ -65,11 +67,11 @@ class GameModel actualWidth = Std.parseInt(xml.att.awidth); actualHeight = Std.parseInt(xml.att.aheight); scale = Std.parseInt(xml.att.scale); - defaultSceneID = 0; - + defaultSceneID = IdUtils.INVALID_ID; + try { - defaultSceneID = Std.parseInt(xml.att.defaultSceneID); + defaultSceneID = IdUtils.parseId(xml.att.defaultSceneID); } catch(e:String) @@ -164,15 +166,15 @@ class GameModel scenes = readScenes(Data.get().sceneListXML); } - public function readScenes(list:Fast):Map + public function readScenes(list:Fast):Map { - var map:Map = new Map(); + var map = new Map(); for(e in list.elements) { - var sceneID = Std.parseInt(e.att.id); - - map.set(Std.parseInt(e.att.id), new Scene(sceneID, e.att.name)); + var sceneID = IdUtils.parseId(e.att.id); + + map.set(sceneID, new Scene(sceneID, e.att.name)); } Data.get().scenesXML = null; diff --git a/com/stencyl/models/IdType.hx b/com/stencyl/models/IdType.hx new file mode 100644 index 00000000..20232a0c --- /dev/null +++ b/com/stencyl/models/IdType.hx @@ -0,0 +1,11 @@ +package com.stencyl.models; + +typedef IdType = Int + +class IdUtils { + public static var INVALID_ID = -1; + + public static function parseId(id: String): IdType { + return Std.parseInt(id); + } +} \ No newline at end of file diff --git a/com/stencyl/models/Scene.hx b/com/stencyl/models/Scene.hx index fe361c56..a5ed5fa9 100644 --- a/com/stencyl/models/Scene.hx +++ b/com/stencyl/models/Scene.hx @@ -47,7 +47,7 @@ import com.stencyl.utils.PolyDecompBayazit; class Scene { - public var ID:Int; + public var ID:IdType; public var name:String; public var sceneWidth:Int; @@ -78,7 +78,7 @@ class Scene public var animatedTiles:Array; - public function new(ID:Int, name:String) + public function new(ID:IdType, name:String) { this.ID = ID; this.name = name; @@ -1026,7 +1026,7 @@ class Scene return ai; } - public function getID():Int + public function getID():IdType { return ID; } diff --git a/com/stencyl/utils/HashMap.hx b/com/stencyl/utils/HashMap.hx deleted file mode 100644 index e69de29b..00000000 diff --git a/com/stencyl/utils/SizedIntHash.hx b/com/stencyl/utils/SizedIntHash.hx deleted file mode 100644 index e69de29b..00000000