@@ -2,8 +2,9 @@ package zero.flxutil.editors;
22
33import flixel .tile .FlxTilemap ;
44import flixel .tile .FlxBaseTilemap ;
5- import flixel .tile .FlxTilemapExt ;
5+ import flixel .addons . tile .FlxTilemapExt ;
66import flixel .system .FlxAssets ;
7+ import haxe .Json ;
78
89/**
910 * A class for loading json levels created with ZOME (01010111/itch.io/zome)
@@ -21,7 +22,7 @@ class ZomeLoader
2122 */
2223 public function new (json_path : String , tileset_folder : String = ' assets/images/' )
2324 {
24- this .level = openfl. Assets .getText (json_path );
25+ this .level = Json . parse ( openfl. Assets .getText (json_path ) );
2526 this .tileset_folder = tileset_folder ;
2627 }
2728
@@ -45,7 +46,7 @@ class ZomeLoader
4546 public function get_tilemap (? options : TilemapOptions ): FlxTilemap
4647 {
4748 var tilemap = new FlxTilemap ();
48- tilemap . load_tilemap (tilemap , options );
49+ load_tilemap (tilemap , options );
4950 return tilemap ;
5051 }
5152
@@ -57,12 +58,12 @@ class ZomeLoader
5758 public function get_tilemap_ext (? options : TilemapExtOptions ): FlxTilemapExt
5859 {
5960 var tilemap = new FlxTilemapExt ();
60- tilemap . load_tilemap (tilemap , options .tilemap_options );
61+ load_tilemap (tilemap , options .tilemap_options );
6162 tilemap .setSlopes (options .northwest_slopes , options .northeast_slopes , options .southwest_slopes , options .southeast_slopes );
6263 return tilemap ;
6364 }
6465
65- function load_tilemap (tilemap : FlxBaseTilemap , options : TilemapOptions )
66+ function load_tilemap (tilemap : FlxTilemap , options : TilemapOptions )
6667 {
6768 options = prep_tilemap_options (options );
6869 tilemap .loadMapFrom2DArray (
@@ -76,6 +77,7 @@ class ZomeLoader
7677 options .collide_index
7778 );
7879 if (options .collision_array != null ) set_tile_properties (tilemap , options .collision_array );
80+ if (options .follow ) tilemap .follow ();
7981 }
8082
8183 function prep_tilemap_options (options : TilemapOptions ): TilemapOptions
@@ -87,10 +89,14 @@ class ZomeLoader
8789 if (options .starting_index == null ) options .starting_index = 0 ;
8890 if (options .draw_index == null ) options .draw_index = 0 ;
8991 if (options .collide_index == null ) options .collide_index = 1 ;
92+ if (options .follow == null ) options .follow = true ;
9093 return options ;
9194 }
9295
93- function set_tile_properties (tilemap : FlxBaseTilemap , collision_array : Array <Int >) for (tile in collision_array ) tilemap .setTileProperties (tile , collision_array [tile ]);
96+ function set_tile_properties (tilemap : FlxTilemap , collision_array : Array <Int >)
97+ {
98+ for (i in 0 ... collision_array .length ) tilemap .setTileProperties (i , collision_array [i ]);
99+ }
94100
95101}
96102
@@ -109,14 +115,15 @@ typedef TilemapOptions =
109115 ? starting_index : Int ,
110116 ? draw_index : Int ,
111117 ? collide_index : Int ,
112- ? collision_array : Array <Int >
118+ ? collision_array : Array <Int >,
119+ ? follow : Bool
113120}
114121
115122typedef TilemapExtOptions =
116123{
117- tilemap_options : TilemapOptions ,
118- northeast_slopes : Array <Int >,
119- northwest_slopes : Array <Int >,
120- southeast_slopes : Array <Int >,
121- southwest_slopes : Array <Int >
124+ ? tilemap_options : TilemapOptions ,
125+ ? northeast_slopes : Array <Int >,
126+ ? northwest_slopes : Array <Int >,
127+ ? southeast_slopes : Array <Int >,
128+ ? southwest_slopes : Array <Int >
122129}
0 commit comments