summaryrefslogtreecommitdiffhomepage
path: root/deprecated/helpers/00_tileset.rb
diff options
context:
space:
mode:
authorrealtradam <[email protected]>2021-06-12 03:15:59 -0400
committerrealtradam <[email protected]>2021-06-12 03:15:59 -0400
commit795cb85e284d6adc83d8a8770e1e2406322f4034 (patch)
tree1fe065f7f5ecfaf9bc34638cc5a5dd7fe848eb3e /deprecated/helpers/00_tileset.rb
parent6e9ff64fec30779eb894a617af95ce7815e3d1ca (diff)
downloadFelECS-795cb85e284d6adc83d8a8770e1e2406322f4034.tar.gz
FelECS-795cb85e284d6adc83d8a8770e1e2406322f4034.zip
file cleanup
Diffstat (limited to 'deprecated/helpers/00_tileset.rb')
-rw-r--r--deprecated/helpers/00_tileset.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/deprecated/helpers/00_tileset.rb b/deprecated/helpers/00_tileset.rb
new file mode 100644
index 0000000..c4293cb
--- /dev/null
+++ b/deprecated/helpers/00_tileset.rb
@@ -0,0 +1,56 @@
+# Coverage Ignored because the functionality of this
+# code will not be used for the core of FelFlame.
+# It will most likely be released as a seperate package
+# The code will most likely be kept here until it
+# eventually will be migrated to a new git repo
+# :nocov:
+class Helper
+ # Returns a loaded map and its dependecies(images,json)
+ # If any are missing then it will load them from files
+
+ @json_data = {}
+ class <<self
+ attr_accessor :json_data
+
+ def get_json_tiles(json_name, hitbox: false)
+ unless hitbox
+ return nil if json_name == 'hitbox' && !Components::DebugSingleton.data
+ end
+
+ 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?
+
+ 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'))
+ # download tileset here
+ # $gtk.args.gtk.http_get 'https://mysite.net/#{tileset['name']}.png'
+ end
+ end
+ end
+ self.json_data[json_name]
+ 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)
+ 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'], 0].max,
+ # source_y gets special treatment
+ 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
+ end
+end
+# :nocov: