Class: Yuki::Tilemap::MapData
- Defined in:
- scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb
Overview
Class containing the map Data and its resources
Constant Summary collapse
- POSITION_LOADERS =
List of method that help to load the position
{ north: :load_position_north, south: :load_position_south, east: :load_position_east, west: :load_position_west, self: :load_position_self }
Class Attribute Summary collapse
-
.tileset_chunks ⇒ Hash{filename => Array<Texture>}
readonly
Get tileset chunks.
Instance Attribute Summary collapse
-
#map ⇒ RPG::Map
readonly
Get access to the original map data.
-
#map_id ⇒ Integer
readonly
Get the map id.
-
#offset_x ⇒ Integer
readonly
Get the map offset_x.
-
#offset_y ⇒ Integer
readonly
Get the map offset_y.
-
#side ⇒ Symbol
readonly
Get the side of the map.
-
#tileset_name ⇒ String
readonly
Get the tileset filename (to prevent unwanted dispose in the future).
-
#x_range ⇒ Range
readonly
Get the map X coordinate range.
-
#y_range ⇒ Range
readonly
Get the map Y coordinate range.
Instance Method Summary collapse
-
#[](x, y, z)
Get a tile from the map.
-
#assign_tile_to_sprite(sprite, tile_id)
Set tile sprite to sprite.
-
#draw(x, y, tx, ty, tz, layer)
Draw the tile on the right layer.
-
#draw_map(x, y, rx, ry, layers)
Draw the visible part of the map.
-
#initialize(map, map_id) ⇒ MapData
constructor
Create a new MapData.
-
#load_position(map, side, offset)
Sets the position of the map in the 2D Space.
-
#load_tileset
Load the tileset.
-
#update_counters
Update the autotiles counter (for tilemap).
Constructor Details
Class Attribute Details
.tileset_chunks ⇒ Hash{filename => Array<Texture>} (readonly)
Get tileset chunks
254 255 256 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 254 def tileset_chunks @tileset_chunks end |
Instance Attribute Details
#map ⇒ RPG::Map (readonly)
Get access to the original map data
15 16 17 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 15 def map @map end |
#map_id ⇒ Integer (readonly)
Get the map id
18 19 20 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 18 def map_id @map_id end |
#offset_x ⇒ Integer (readonly)
Get the map offset_x
27 28 29 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 27 def offset_x @offset_x end |
#offset_y ⇒ Integer (readonly)
Get the map offset_y
30 31 32 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 30 def offset_y @offset_y end |
#side ⇒ Symbol (readonly)
Get the side of the map
36 37 38 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 36 def side @side end |
#tileset_name ⇒ String (readonly)
Get the tileset filename (to prevent unwanted dispose in the future)
33 34 35 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 33 def tileset_name @tileset_name end |
#x_range ⇒ Range (readonly)
Get the map X coordinate range
21 22 23 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 21 def x_range @x_range end |
#y_range ⇒ Range (readonly)
Get the map Y coordinate range
24 25 26 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 24 def y_range @y_range end |
Instance Method Details
#[](x, y, z)
Get a tile from the map
64 65 66 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 64 def [](x, y, z) @data[x + @offset_x, y + @offset_y, z] end |
#assign_tile_to_sprite(sprite, tile_id)
Set tile sprite to sprite
71 72 73 74 75 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 71 def assign_tile_to_sprite(sprite, tile_id) tile_id -= 384 sprite.bitmap = @tilesets[tile_id / 256] sprite.src_rect.set(tile_id % 8 * 32, (tile_id % 256) / 8 * 32, 32, 32) end |
#draw(x, y, tx, ty, tz, layer)
Draw the tile on the right layer
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 84 def draw(x, y, tx, ty, tz, layer) tile_id = self[x + tx, y + ty, tz] return unless tile_id && tile_id != 0 priority = @priorities[tile_id] || 0 if tile_id < 384 # Autotile tileset = @autotiles[tile_id / 48 - 1] tileset && layer.dig(priority, ty).set(tx, tileset, @rect.set((tile_id % 48) * 32, @autotile_counter[tile_id / 48] * 32)) else tile_id -= 384 tileset = @tilesets[tile_id / 256] tileset && layer.dig(priority, ty).set(tx, tileset, @rect.set(tile_id % 8 * 32, (tile_id % 256) / 8 * 32)) end end |
#draw_map(x, y, rx, ry, layers)
Draw the visible part of the map
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 105 def draw_map(x, y, rx, ry, layers) lx = x_range.min mx = x_range.max ly = y_range.min my = y_range.max bx = lx > x ? lx : x ex = mx > rx ? rx : mx by = ly > y ? ly : y ey = my > ry ? ry : my return unless bx <= ex && by <= ey bx.upto(ex) do |ax| by.upto(ey) do |ay| layers.each_with_index do |layer, tz| draw(x, y, ax - x, ay - y, tz, layer) end end end end |
#load_position(map, side, offset)
Sets the position of the map in the 2D Space
54 55 56 57 58 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 54 def load_position(map, side, offset) maker_offset = MapLinker::DELTA_MAKER send(POSITION_LOADERS[side], map, offset, maker_offset) @side = side end |
#load_tileset
Load the tileset
127 128 129 130 131 132 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 127 def load_tileset # @type [RPG::Tileset] @tileset = $data_tilesets[@map.tileset_id] @priorities = @tileset.priorities load_tileset_graphics end |
#update_counters
Update the autotiles counter (for tilemap)
135 136 137 138 139 140 141 142 143 |
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00300 Tilemap/00010 MapData.rb', line 135 def update_counters @autotiles.each_with_index do |autotile, index| next unless autotile next if autotile.height <= 32 frame_count = autotile.height / 32 @autotile_counter[index + 1] = (@autotile_counter[index + 1] + 1) % frame_count end end |