From 490b20123c75cf8eb5de7039993cb704e3d7a0c8 Mon Sep 17 00:00:00 2001 From: realtradam Date: Wed, 19 May 2021 02:23:17 -0400 Subject: working json to sprite conversion --- app/helpers/00_tileset.rb | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 app/helpers/00_tileset.rb (limited to 'app/helpers') diff --git a/app/helpers/00_tileset.rb b/app/helpers/00_tileset.rb new file mode 100644 index 0000000..d6e6cf3 --- /dev/null +++ b/app/helpers/00_tileset.rb @@ -0,0 +1,42 @@ +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 < 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_y gets special treatment + source_y: json_tiles['imageheight'] - ((source_height_tiles + 1) * json_tiles['tileheight']), + source_w: json_tiles['tilewidth'], + source_h: json_tiles['tileheight'] } + end + end +end -- cgit v1.2.3