summaryrefslogtreecommitdiffhomepage
path: root/app/lib/helpers
diff options
context:
space:
mode:
author_Tradam <[email protected]>2021-05-26 02:12:54 -0400
committerGitHub <[email protected]>2021-05-26 02:12:54 -0400
commit41f574c04c70e6327cb1861fac01664bd3f3f7ba (patch)
tree34a184ff4fd182a8823f416fd87b4d546e1e250f /app/lib/helpers
parentf97a9ca95e464e728bba9337b579bc380c33bc7d (diff)
parenta5bbcbf5d78005746fb64c51a779f830d7667a57 (diff)
downloadtypemon-code-master.tar.gz
typemon-code-master.zip
Merge pull request #1 from realtradam/reworkHEADmaster
split off FelFlame
Diffstat (limited to 'app/lib/helpers')
-rw-r--r--app/lib/helpers/00_tileset.rb49
-rw-r--r--app/lib/helpers/01_component.rb76
2 files changed, 0 insertions, 125 deletions
diff --git a/app/lib/helpers/00_tileset.rb b/app/lib/helpers/00_tileset.rb
deleted file mode 100644
index 3890550..0000000
--- a/app/lib/helpers/00_tileset.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-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
diff --git a/app/lib/helpers/01_component.rb b/app/lib/helpers/01_component.rb
deleted file mode 100644
index 4937ec9..0000000
--- a/app/lib/helpers/01_component.rb
+++ /dev/null
@@ -1,76 +0,0 @@
-class Helper
- class BaseComponent
- class <<self
- def id
- @id ||= ID.send(Helper::ComponentHelper.underscore(ancestors[0].name.split('::').last))
- end
-
- def data
- @data ||= {}
- end
-
- def add(entity_id)
- data[entity_id] = new
- end
-
- def delete(entity_id)
- data.delete entity_id
- end
- end
- end
-
- class Level < Helper::BaseComponent
- class <<self
- def data
- @data ||= { add: [], remove: [], grid: Helper::Array2D.new }
- end
-
- def add(entity_id)
- super
- data[:add].push entity_id
- end
-
- def remove(entity_id)
- data[:remove].push entity_id
- super
- end
- end
- end
-
- class Array2D < Array
- def [](val)
- unless val.nil?
- return self[val] = [] if super.nil?
- end
- super
- end
- end
-
-
- module ComponentHelper
- class <<self
- def up? char
- char == char.upcase
- end
-
- def down? char
- char == char.downcase
- end
-
- def underscore(input)
- output = input[0].downcase
- (1...(input.length - 1)).each do |iter|
- if down?(input[iter]) && up?(input[iter + 1])
- output += "#{input[iter].downcase}_"
- elsif up?(input[iter - 1]) && up?(input[iter]) && down?(input[iter + 1])
- output += "_#{input[iter].downcase}"
- else
- output += input[iter].downcase
- end
- end
- output += input[-1].downcase unless input.length == 1
- output
- end
- end
- end
-end