Class: NuriGame::TsxReader
- Inherits:
-
Object
- Object
- NuriGame::TsxReader
- Defined in:
- lib/nuri_game/tsx_reader.rb,
lib/nuri_game/tsx_reader/version.rb
Overview
class that converts TSX file to Ruby object
Defined Under Namespace
Classes: Image
Constant Summary collapse
- TILESET_INFOS =
Constant holding the list of tileset information
%w[tilewidth tileheight tilecount columns spacing margin].freeze
- VERSION =
"0.1.0"
Instance Attribute Summary collapse
-
#columns ⇒ Integer
readonly
Number of columns in the tileset.
-
#image ⇒ Image
readonly
Image used in the tileset.
-
#margin ⇒ Integer
readonly
Margin around the tile of the tileset.
-
#name ⇒ String
readonly
Name of the tileset.
-
#spacing ⇒ Integer
readonly
Space in px between tiles in the tileset image.
-
#terrains ⇒ Hash{String => Integer}
readonly
Terrains of the tileset by name.
-
#tilecount ⇒ Integer
readonly
Number of tiles in the tileset.
-
#tileheight ⇒ Integer
readonly
Height of a tile on the tileset.
-
#tilewidth ⇒ Integer
readonly
Width of a tile on the tileset.
Instance Method Summary collapse
-
#initialize(filename) ⇒ TsxReader
constructor
Create a new TmxReader.
Constructor Details
#initialize(filename) ⇒ TsxReader
Create a new TmxReader
45 46 47 48 49 50 51 52 53 |
# File 'lib/nuri_game/tsx_reader.rb', line 45 def initialize(filename) contents = File.read(filename).force_encoding(Encoding::UTF_8) tileset = REXML::Document.new(contents).root @terrains = {} validate_tileset(tileset) load_tileset_infos(tileset) load_tileset_image(tileset) load_tileset_terrains(tileset) end |
Instance Attribute Details
#columns ⇒ Integer (readonly)
Returns number of columns in the tileset.
23 24 25 |
# File 'lib/nuri_game/tsx_reader.rb', line 23 def columns @columns end |
#image ⇒ Image (readonly)
Returns image used in the tileset.
41 42 43 |
# File 'lib/nuri_game/tsx_reader.rb', line 41 def image @image end |
#margin ⇒ Integer (readonly)
Returns margin around the tile of the tileset.
35 36 37 |
# File 'lib/nuri_game/tsx_reader.rb', line 35 def margin @margin end |
#name ⇒ String (readonly)
Returns name of the tileset.
17 18 19 |
# File 'lib/nuri_game/tsx_reader.rb', line 17 def name @name end |
#spacing ⇒ Integer (readonly)
Returns space in px between tiles in the tileset image.
32 33 34 |
# File 'lib/nuri_game/tsx_reader.rb', line 32 def spacing @spacing end |
#terrains ⇒ Hash{String => Integer} (readonly)
Returns terrains of the tileset by name.
38 39 40 |
# File 'lib/nuri_game/tsx_reader.rb', line 38 def terrains @terrains end |
#tilecount ⇒ Integer (readonly)
Returns number of tiles in the tileset.
20 21 22 |
# File 'lib/nuri_game/tsx_reader.rb', line 20 def tilecount @tilecount end |
#tileheight ⇒ Integer (readonly)
Returns height of a tile on the tileset.
29 30 31 |
# File 'lib/nuri_game/tsx_reader.rb', line 29 def tileheight @tileheight end |
#tilewidth ⇒ Integer (readonly)
Returns width of a tile on the tileset.
26 27 28 |
# File 'lib/nuri_game/tsx_reader.rb', line 26 def tilewidth @tilewidth end |