Module: Yuki::MapLinker

Defined in:
scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb

Overview

MapLinker, script that emulate the links between maps. This script also display events.

Author:

  • Nuri Yuri

Constant Summary collapse

OFFSET_X =

The offset in X until we see black borders

Configs.display.tilemap_settings.map_linker_offset.x
OFFSET_Y =

The offset in Y until we seen black borders

Configs.display.tilemap_settings.map_linker_offset.y
DELTA_MAKER =

The number of tiles the Maker has to let in common between each maps

Configs.display.tilemap_settings.uses_old_map_linker ? 3 : 0
DEFAULT_MAP =

The default Map (black borders)

RPG::Map.new(20, 15)
MAP_FORMAT =

The map filename format

'Data/Map%03d.rxdata'
%i[north east south west]

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.added_eventsHash<Integer => Array<RPG::Event>> (readonly)

Get the added events

Returns:



40
41
42
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 40

def added_events
  @added_events
end

.map_datasArray<Yuki::Tilemap::MapData> (readonly)

Return the map datas

Returns:



34
35
36
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 34

def map_datas
  @map_datas
end

.spritesetSpriteset_Map

Return the SpritesetMap object used to load the map

Returns:



37
38
39
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 37

def spriteset
  @spriteset
end

Class Method Details

.from_center_map?(event) ⇒ Boolean?

Test if the given event is from the center map or not

Parameters:

Returns:

  • (Boolean, nil)


45
46
47
48
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 45

def from_center_map?(event)
  return !@added_events.key?(event.original_map)
  # return !(@added_events[event.original_map].select { |e| e.id == event.original_id }).empty?
end

.load_map(map_id) ⇒ RPG::Map

Load a map and its linked map

Parameters:

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 66

def load_map(map_id)
  Yuki::ElapsedTime.start(:maplinker)
  map_datas.first&.map&.events = @last_events if @last_events
  # @type [Array<Yuki::Tilemap::MapData>]
  map_datas = [@map_datas.find { |map| map.map_id == map_id } || Tilemap::MapData.new(load_map_data(map_id), map_id)]
  current_map = map_datas.first.map
  map_datas.first.load_position(current_map, :self, 0)

  if $game_switches[Sw::MapLinkerDisabled]
    reset
  elsif (link_data = $game_data_maplinks[map_id])
    (link_data.size / 2).times do |i|
      sub_map_id = link_data[i * 2]
      next if sub_map_id == 0

      map_data = @map_datas.find { |map| map.map_id == sub_map_id } || Tilemap::MapData.new(load_map_data(sub_map_id), sub_map_id)
      map_data.load_position(current_map, LINK_TYPES[i % 4], link_data[i * 2 + 1])
      map_datas << map_data
    end
  end

  @map_datas = map_datas
  @added_events.delete(map_id)
  load_events

  Yuki::ElapsedTime.show(:maplinker, 'Loading the tileset & priority took')
  return current_map
end

.load_map_data(map_id) ⇒ RPG::Map

Load the data of a map (with some optimizations)

Parameters:

  • map_id (Integer)

    the id of the Map

Returns:



98
99
100
101
102
103
104
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 98

def load_map_data(map_id)
  return DEFAULT_MAP if map_id == 0

  return load_data(format(MAP_FORMAT, map_id))
rescue StandardError
  return RPG::Map.new(20, 15)
end

.passable?(x, y, d = 0, event = $game_player) ⇒ Boolean

Test if a tile is passable

Parameters:

  • x (Integer)

    x coordinate of the tile on the map

  • y (Integer)

    y coordinate of the tile on the map

  • d (Integer) (defaults to: 0)

    direction to check

  • event (Game_Character) (defaults to: $game_player)

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 160

def passable?(x, y, d = 0, event = $game_player)
  return false unless !event || event.passage_surf_check?(system_tag(x, y))
  # @type [Yuki::Tilemap::MapData]
  return false unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })

  tileset = $data_tilesets[target_map.map.tileset_id]
  passages = tileset.passages
  priorities = tileset.priorities
  bit = (1 << (d / 2 - 1)) & 0x0f
  data = target_map.map.data
  x += target_map.offset_x
  y += target_map.offset_y
  2.downto(0) do |i|
    tile_id = data[x, y, i]
    return false if tile_id.nil?
    return false if passages[tile_id] & bit != 0
    return false if passages[tile_id] & 0x0f == 0x0f
    return true if priorities[tile_id] == 0
  end

  return true
end

.reset

Reset the module when the RGSS resets itself



51
52
53
54
55
56
57
58
59
60
61
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 51

def reset
  # [n_id, n_addx, e_id, e_addy, s_id, s_addx, o_id, o_addy, ...repeating]
  @link_data = nil
  # All the map_data_shown
  # @type [Array<Yuki::Tilemap::MapData>]
  @map_datas = []
  @last_events = nil
  @last_event_id = 0
  # Event added in the map to ensure proper link
  @added_events = {}
end

.system_tag(x, y) ⇒ Integer

Retrieve the ID of the SystemTag on a specific tile

Parameters:

  • x (Integer)

    x position of the tile

  • y (Integer)

    y position of the tile

Returns:

Author:

  • Nuri Yuri



188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 188

def system_tag(x, y)
  # @type [Yuki::Tilemap::MapData]
  return 0 unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })
  return 0 unless (system_tags = $data_system_tags[target_map.map.tileset_id])

  tiles = target_map.map.data
  x += target_map.offset_x
  y += target_map.offset_y
  2.downto(0) do |i|
    tile_id = tiles[x, y, i]
    return 0 unless tile_id

    tag_id = system_tags[tile_id]
    return tag_id if tag_id && tag_id > 0
  end
  return 0
end

.system_tag_here?(x, y, tag) ⇒ Boolean

Check if a specific SystemTag is present on a specific tile

Parameters:

  • x (Integer)

    x position of the tile

  • y (Integer)

    y position of the tile

  • tag (Integer)

    ID of the SystemTag

Returns:

  • (Boolean)

Author:

  • Nuri Yuri



212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 212

def system_tag_here?(x, y, tag)
  # @type [Yuki::Tilemap::MapData]
  return false unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })
  return false unless (system_tags = $data_system_tags[target_map.map.tileset_id])

  tiles = target_map.map.data
  x += target_map.offset_x
  y += target_map.offset_y

  return 2.downto(0).any? do |i|
    (tile_id = tiles[x, y, i]) && system_tags[tile_id] == tag
  end
end

.tileset_nameString

Return the current tileset name

Returns:



108
109
110
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 108

def tileset_name
  @map_datas.first.tileset_name
end

Instance Method Details

#test_warp

Test if the player can warp between maps and warp him



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'scripts/01450 Systems/00003 Map Engine/00002 Logic/00400 Yuki__MapLinker.rb', line 114

def test_warp
  x = $game_player.x
  y = $game_player.y
  # North
  if y <= 1
    y -= DELTA_MAKER
    return unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })

    warp(target_map.map_id, x + target_map.offset_x, target_map.map.height - $game_player.y - 1)
  # East
  elsif x >= (@map_datas.first.map.width - 1)
    x += DELTA_MAKER
    return unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })

    warp(target_map.map_id, 2, y + target_map.offset_y)
  # South
  elsif y >= (@map_datas.first.map.height - 1)
    y += DELTA_MAKER
    return unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })

    warp(target_map.map_id, x + target_map.offset_x, 2)
  # West
  elsif x <= 1
    x -= DELTA_MAKER
    return unless (target_map = @map_datas.find { |map| map.x_range.include?(x) && map.y_range.include?(y) })

    warp(target_map.map_id, target_map.map.width - $game_player.x - 1, y + target_map.offset_y)
  end
end