Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/
*.iml

4 changes: 2 additions & 2 deletions com/stencyl/AssetLoader.hx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.stencyl;

import haxe.xml.Fast;
import com.stencyl.models.IdType;

interface AssetLoader
{
function loadResources(resourceMap:Map<String,Dynamic>):Void;
function loadScenes(scenesXML:Map<Int,String>):Void;
function loadScenes(scenesXML:Map<IdType,String>):Void;
}
6 changes: 4 additions & 2 deletions com/stencyl/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,7 +85,7 @@ class Data
//*-----------------------------------------------

//Map of each [sceneID].xml by ID
public var scenesXML:Map<Int,String>;
public var scenesXML:Map<IdType,String>;

//Map of each [sceneID].scn by ID
//public var scenesTerrain:Map<Int,Dynamic>;
Expand Down Expand Up @@ -151,7 +153,7 @@ class Data

updatePreloader(90);

scenesXML = new Map<Int,String>();
scenesXML = new Map<IdType,String>();

loader.loadScenes(scenesXML);

Expand Down
13 changes: 8 additions & 5 deletions com/stencyl/Engine.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -209,7 +212,7 @@ class Engine

private var leave:Transition;
private var enter:Transition;
private var sceneToEnter:Int;
private var sceneToEnter:IdType;


//*-----------------------------------------------
Expand Down Expand Up @@ -625,7 +628,7 @@ class Engine
}
#end

public function begin(initSceneID:Int)
public function begin(initSceneID:IdType)
{
loadedAtlases = new Map<Int,Int>();
atlasesToLoad = new Map<Int,Int>();
Expand Down Expand Up @@ -805,7 +808,7 @@ class Engine
loadScene(initSceneID);
}

public function loadScene(sceneID:Int)
public function loadScene(sceneID:IdType)
{
collisionPairs = new IntHashTable<Map<Int,Bool>>(32);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
12 changes: 7 additions & 5 deletions com/stencyl/behavior/Script.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1177,17 +1179,17 @@ class Script
*
* @return The ID current scene
*/
public static function getCurrentScene():Int
public static function getCurrentScene():IdType
{
return getScene().ID;
}

/**
* 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)
{
Expand All @@ -1197,7 +1199,7 @@ class Script
}
}

return 0;
return IdUtils.INVALID_ID;
}

/**
Expand Down Expand Up @@ -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);
}
Expand Down
22 changes: 12 additions & 10 deletions com/stencyl/models/GameModel.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<GroupDef>;
public var groupsCollidesWith:Map<Int,Array<Int>>;
Expand All @@ -36,7 +38,7 @@ class GameModel
public var gameAttributes:Map<String,Dynamic>;
public var shapes:Map<Int,B2PolygonShape>;
public var atlases:Map<Int,Atlas>;
public var scenes:Map<Int,Scene>;
public var scenes:Map<IdType,Scene>;
public var autotileFormats:Map<Int, AutotileFormat>;

public static var INHERIT_ID:Int = -1000;
Expand Down Expand Up @@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not equivalent, but this shouldn't be an issue because if the defaultSceneID can't be read, something is really wrong anyway.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's not, but 0 is also wrong, I guess?

If I create a game, add two scenes, then delete the first one 0 is not a valid scene either...


try
{
defaultSceneID = Std.parseInt(xml.att.defaultSceneID);
defaultSceneID = IdUtils.parseId(xml.att.defaultSceneID);
}

catch(e:String)
Expand Down Expand Up @@ -164,15 +166,15 @@ class GameModel
scenes = readScenes(Data.get().sceneListXML);
}

public function readScenes(list:Fast):Map<Int,Scene>
public function readScenes(list:Fast):Map<IdType,Scene>
{
var map:Map<Int,Scene> = new Map<Int,Scene>();
var map = new Map<IdType,Scene>();

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;
Expand Down
11 changes: 11 additions & 0 deletions com/stencyl/models/IdType.hx
Original file line number Diff line number Diff line change
@@ -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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseXmlId is a little weird to me because it's not parsing from Fast or Xml, but String. Simple parseId might be better.

}
6 changes: 3 additions & 3 deletions com/stencyl/models/Scene.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,7 +78,7 @@ class Scene

public var animatedTiles:Array<Tile>;

public function new(ID:Int, name:String)
public function new(ID:IdType, name:String)
{
this.ID = ID;
this.name = name;
Expand Down Expand Up @@ -1026,7 +1026,7 @@ class Scene
return ai;
}

public function getID():Int
public function getID():IdType
{
return ID;
}
Expand Down
Empty file removed com/stencyl/utils/HashMap.hx
Empty file.
Empty file removed com/stencyl/utils/SizedIntHash.hx
Empty file.