Class: NuriGame::TsxReader

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ TsxReader

Create a new TmxReader

Parameters:

  • filename (String)

    name of the tmx file to read



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

#columnsInteger (readonly)

Returns number of columns in the tileset.

Returns:

  • (Integer)

    number of columns in the tileset



23
24
25
# File 'lib/nuri_game/tsx_reader.rb', line 23

def columns
  @columns
end

#imageImage (readonly)

Returns image used in the tileset.

Returns:

  • (Image)

    image used in the tileset



41
42
43
# File 'lib/nuri_game/tsx_reader.rb', line 41

def image
  @image
end

#marginInteger (readonly)

Returns margin around the tile of the tileset.

Returns:

  • (Integer)

    margin around the tile of the tileset



35
36
37
# File 'lib/nuri_game/tsx_reader.rb', line 35

def margin
  @margin
end

#nameString (readonly)

Returns name of the tileset.

Returns:

  • (String)

    name of the tileset



17
18
19
# File 'lib/nuri_game/tsx_reader.rb', line 17

def name
  @name
end

#spacingInteger (readonly)

Returns space in px between tiles in the tileset image.

Returns:

  • (Integer)

    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

#terrainsHash{String => Integer} (readonly)

Returns terrains of the tileset by name.

Returns:

  • (Hash{String => Integer})

    terrains of the tileset by name



38
39
40
# File 'lib/nuri_game/tsx_reader.rb', line 38

def terrains
  @terrains
end

#tilecountInteger (readonly)

Returns number of tiles in the tileset.

Returns:

  • (Integer)

    number of tiles in the tileset



20
21
22
# File 'lib/nuri_game/tsx_reader.rb', line 20

def tilecount
  @tilecount
end

#tileheightInteger (readonly)

Returns height of a tile on the tileset.

Returns:

  • (Integer)

    height of a tile on the tileset



29
30
31
# File 'lib/nuri_game/tsx_reader.rb', line 29

def tileheight
  @tileheight
end

#tilewidthInteger (readonly)

Returns width of a tile on the tileset.

Returns:

  • (Integer)

    width of a tile on the tileset



26
27
28
# File 'lib/nuri_game/tsx_reader.rb', line 26

def tilewidth
  @tilewidth
end