diff options
| author | realtradam <[email protected]> | 2021-05-19 05:42:53 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2021-05-19 05:42:53 -0400 |
| commit | fee80f42f0889f2d484e25f4366f14b68c65ba70 (patch) | |
| tree | fa1e728e3d9d91eb5946177f347781cdfea45b47 /app/helpers | |
| parent | 490b20123c75cf8eb5de7039993cb704e3d7a0c8 (diff) | |
| download | typemon-code-fee80f42f0889f2d484e25f4366f14b68c65ba70.tar.gz typemon-code-fee80f42f0889f2d484e25f4366f14b68c65ba70.zip | |
fully working map import
Diffstat (limited to 'app/helpers')
| -rw-r--r-- | app/helpers/00_tileset.rb | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/app/helpers/00_tileset.rb b/app/helpers/00_tileset.rb index d6e6cf3..d64006d 100644 --- a/app/helpers/00_tileset.rb +++ b/app/helpers/00_tileset.rb @@ -7,12 +7,12 @@ class Helper attr_accessor :json_data def get_json_tiles(json_name) + return nil if json_name == 'hitbox' && !Components::DebugSingleton.data + if self.json_data[json_name].nil? self.json_data[json_name] = $gtk.parse_json_file "assets/json/#{json_name}.json" raise Exception.new "#{json_name} is null and not loaded. Cannot get json tile" if self.json_data[json_name].nil? - #puts self.json_data[json_name].inspect - #puts json_name if self.json_data[json_name]['type'] == 'map' #json_name.split("_").first == 'map' self.json_data[json_name]['tilesets'].each do |tileset| tileset = Helper.get_json_tiles(tileset['source'].split('/').last.delete_suffix('.tsx')) @@ -25,16 +25,21 @@ class Helper end def get_tile(json_name:, tile_index:) + if json_name == 'hitbox' && !Components::DebugSingleton.data + return tile_index - 1 if tile_index > 1 + return {} + end + json_tiles = self.get_json_tiles(json_name) - return puts "Error, json file not a tileset" unless json_tiles['type'] == 'tileset' + raise Exception.new "Error, json file not a tileset" unless json_tiles['type'] == 'tileset' return tile_index - json_tiles['tilecount'] if tile_index > json_tiles['tilecount'] source_height_tiles = (tile_index.to_i / json_tiles['columns'].to_i).to_i# * json_tiles['tileheight'] { w: json_tiles['tilewidth'], h: json_tiles['tileheight'], path: json_tiles['image'].split('mygame/').last.delete('\\'), - source_x: ((tile_index % json_tiles['columns']) - 1) * json_tiles['tilewidth'], + source_x: [((tile_index % json_tiles['columns']) - 1) * json_tiles['tilewidth'], 0].max, # source_y gets special treatment - source_y: json_tiles['imageheight'] - ((source_height_tiles + 1) * json_tiles['tileheight']), + source_y: [json_tiles['imageheight'] - ((source_height_tiles + 1) * json_tiles['tileheight']), 0].max, source_w: json_tiles['tilewidth'], source_h: json_tiles['tileheight'] } end |
