Class: Spriteset_Map

Inherits:
Object show all
Includes:
Hooks
Defined in:
scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb

Overview

Display everything that should be displayed during the Scene_Map

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Hooks

#exec_hooks, #force_return, included, register, remove, remove_without_name

Constructor Details

#initialize(zone = nil) ⇒ Spriteset_Map

Initialize a new Spriteset_Map object

Parameters:

  • zone (Integer, nil) (defaults to: nil)

    the id of the zone where the player is



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 9

def initialize(zone = nil)
  # Type of viewport the spriteset map uses
  viewport_type = :main
  exec_hooks(Spriteset_Map, :viewport_type, binding)
  init_viewports(viewport_type)
  Yuki::ElapsedTime.start(:spriteset_map)
  exec_hooks(Spriteset_Map, :initialize, binding)
  init_tilemap
  init_panorama_fog
  init_characters
  init_player
  init_weather_picture_timer
  finish_init(zone)
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#initialize")
end

Instance Attribute Details

#game_player_spriteSprite_Character (readonly)

Retrieve the Game Player sprite

Returns:



6
7
8
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 6

def game_player_sprite
  @game_player_sprite
end

Instance Method Details

#create_panel(zone)

create the zone panel of the current zone

Parameters:

  • zone (Integer, nil)

    the id of the zone where the player is



305
306
307
308
309
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 305

def create_panel(zone)
  return unless zone && data_zone(zone).panel_id > 0

  @map_panel = UI::MapPanel.new(@viewport2, data_zone(zone))
end

#dispose(from_warp = false) ⇒ Sprite?

Spriteset_map dispose

Parameters:

  • from_warp (Boolean) (defaults to: false)

    if true, prepare a screenshot with some conditions and cancel the sprite dispose process

Returns:

  • (Sprite, nil)

    a screenshot or nothing



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 212

def dispose(from_warp = false)
  return take_map_snapshot if $game_switches[Yuki::Sw::WRP_Transition] && $scene.class == Scene_Map && from_warp
  return nil if from_warp
  @tilemap.dispose
  @panorama.dispose
  @fog.dispose
  @character_sprites.each(&:dispose)
  @game_player_sprite = nil
  @weather.dispose
  @picture_sprites.each(&:dispose)
  @timer_sprite.dispose
  @quest_informers.clear
  @viewport1.dispose
  @viewport2.dispose
  @viewport3.dispose
  exec_hooks(Spriteset_Map, :dispose, binding)
  return nil
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#dispose")
end

#dispose_sp_map

Dispose the zone panel



313
314
315
316
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 313

def dispose_sp_map
  @map_panel&.dispose
  @map_panel = nil
end

#disposed?Boolean

Tell if the spriteset is disposed

Returns:

  • (Boolean)


205
206
207
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 205

def disposed?
  @viewport1.disposed?
end

#finish_init(zone)

Last step of the Spriteset initialization

Parameters:

  • zone (Integer, nil)

    the id of the zone where the player is



72
73
74
75
76
77
78
79
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 72

def finish_init(zone)
  exec_hooks(Spriteset_Map, :finish_init, binding)
  Yuki::ElapsedTime.show(:spriteset_map, 'End of spriteset init took')
  update
  Graphics.sort_z
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#finish_init")
end

#inform_quest(name, is_new)

Add a new quest informer

Parameters:

  • name (String)

    Name of the quest

  • is_new (Boolean)

    if the quest is new



347
348
349
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 347

def inform_quest(name, is_new)
  @quest_informers << UI::QuestInformer.new(@viewport2, name, is_new, @quest_informers.size)
end

#init_characters

Sprite_Character initialization



143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 143

def init_characters
  if (character_sprites = @character_sprites)
    return recycle_characters(character_sprites)
  end
  @character_sprites = character_sprites = []
  $game_map.events.each_value do |event|
    next unless event.can_be_shown?
    sprite = Sprite_Character.new(@viewport1, event)
    event.particle_push
    character_sprites.push(sprite)
  end
  Yuki::ElapsedTime.show(:spriteset_map, 'Slow character sprite creation took')
end

#init_panorama_fog

Panorama and fog initialization



126
127
128
129
130
131
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 126

def init_panorama_fog
  @panorama = Plane.new(@viewport1)
  @panorama.z = -1000
  @fog = Plane.new(@viewport1)
  @fog.z = 3000
end

#init_player

Player initialization



179
180
181
182
183
184
185
186
187
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 179

def init_player
  exec_hooks(Spriteset_Map, :init_player_begin, binding)
  @character_sprites.push(@game_player_sprite = Sprite_Character.new(@viewport1, $game_player))
  $game_player.particle_push
  exec_hooks(Spriteset_Map, :init_player_end, binding)
  Yuki::ElapsedTime.show(:spriteset_map, 'init_player took')
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#init_player")
end

#init_psdk_add

PSDK related thing initialization



134
135
136
137
138
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 134

def init_psdk_add
  exec_hooks(Spriteset_Map, :init_psdk_add, binding)
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#init_psdk_add")
end

#init_quest_informer

Create the quest informer array



197
198
199
200
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 197

def init_quest_informer
  # @type [Array<UI::QuestInformer>]
  @quest_informers = []
end

#init_tilemap

Tilemap initialization



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 92

def init_tilemap
  tilemap_class = self.tilemap_class
  if @tilemap.class != tilemap_class
    @tilemap&.dispose
    # @type [Yuki::Tilemap]
    @tilemap = tilemap_class.new(@viewport1)
  end
  Yuki::ElapsedTime.show(:spriteset_map, 'Creating tilemap object took')
  map_datas = Yuki::MapLinker.map_datas
  Yuki::MapLinker.spriteset = self
  map_datas.each(&:load_tileset)
  Yuki::ElapsedTime.show(:spriteset_map, 'Loading tilesets took')
  @tilemap.map_datas = map_datas
  @tilemap.reset
  Yuki::ElapsedTime.show(:spriteset_map, 'Resetting the tilemap took')
end

#init_viewports(viewport_type)

Method responsive of initializing the viewports

Parameters:

  • viewport_type (Symbol)


28
29
30
31
32
33
34
35
36
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 28

def init_viewports(viewport_type)
  @viewport1 = Viewport.create(viewport_type, 0)
  @viewport1.extend(Viewport::WithToneAndColors)
  @viewport1.shader = Shader.create(:map_shader)
  @viewport2 = Viewport.create(viewport_type, 200)
  @viewport3 = Viewport.create(viewport_type, 5000)
  @viewport3.extend(Viewport::WithToneAndColors)
  @viewport3.shader = Shader.create(:map_shader)
end

#init_weather_picture_timer

Weather, picture and timer initialization



190
191
192
193
194
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 190

def init_weather_picture_timer
  @weather = RPG::Weather.new(@viewport1)
  @picture_sprites = Array.new(50) { |i| Sprite_Picture.new(@viewport2, $game_screen.pictures[i + 1]) }
  @timer_sprite = Sprite_Timer.new(Graphics.window)
end

#load_autotile(filename) ⇒ Texture

Attempt to load an autotile

Parameters:

  • filename (String)

    name of the autotile

Returns:

  • (Texture)

    the bitmap of the autotile



112
113
114
115
116
117
118
119
120
121
122
123
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 112

def load_autotile(filename)
  target_filename = filename + '_._tiled'
  if RPG::Cache.autotile_exist?(target_filename)
    filename = target_filename
  else
    if !filename.empty? && RPG::Cache.autotile_exist?(filename)
      Converter.convert_autotile("graphics/autotiles/#{filename}.png")
      filename = target_filename
    end
  end
  return RPG::Cache.autotile(filename)
end

#map_viewportViewport

Return the map viewport

Returns:



340
341
342
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 340

def map_viewport
  return @viewport1
end

#recycle_characters(character_sprites)

Recycled Sprite_Character initialization

Parameters:



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 159

def recycle_characters(character_sprites)
  # Recycle events
  i = -1
  $game_map.events.each_value do |event|
    next unless event.can_be_shown?
    character = character_sprites[i += 1]
    event.particle_push
    if character
      character.init(event)
    else
      character_sprites[i] = Sprite_Character.new(@viewport1, event)
    end
  end
  # Overflow dispose
  i += 1
  character_sprites.pop.dispose while i < character_sprites.size
  Yuki::ElapsedTime.show(:spriteset_map, 'Fast character sprite creation took')
end

#reload(zone = nil)

Do the same as initialize but without viewport initialization (opti)

Parameters:

  • zone (Integer, nil) (defaults to: nil)

    the id of the zone where the player is



59
60
61
62
63
64
65
66
67
68
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 59

def reload(zone = nil)
  Yuki::ElapsedTime.start(:spriteset_map)
  exec_hooks(Spriteset_Map, :reload, binding)
  init_tilemap
  init_characters
  init_player
  finish_init(zone)
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#reload")
end

#snap_to_bitmapsArray<Texture>

Take a snapshot of the spriteset

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 40

def snap_to_bitmaps
  @viewport1.sort_z
  @viewport2.sort_z
  @viewport3.sort_z
  background = Texture.new(@viewport1.rect.width, @viewport2.rect.width)
  background_image = Image.new(background.width, background.height)
  background_image.fill_rect(0, 0, background.width, background.height, Color.new(0, 0, 0))
  background_image.copy_to_bitmap(background)
  background_image.dispose
  return [
    background,
    @viewport1.snap_to_bitmap,
    @viewport2.snap_to_bitmap,
    @viewport3.snap_to_bitmap
  ]
end

#tilemap_classClass

Return the prefered tilemap class

Returns:

  • (Class)


83
84
85
86
87
88
89
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 83

def tilemap_class
  tilemap_class = Configs.display.tilemap_settings.tilemap_class
  return Object.const_get(tilemap_class) if Object.const_defined?(tilemap_class)
  return Yuki::Tilemap16px if tilemap_class.match?(/16|Yuri_Tilemap/)

  return Yuki::Tilemap
end

#update

Update every sprite



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 234

def update
  update_panorama_fog
  @tilemap.ox = $game_map.display_x / 4
  @tilemap.oy = $game_map.display_y / 4
  @tilemap.update
  update_events
  update_weather_picture
  @timer_sprite.update
  @viewport1.tone = $game_screen.tone
  @viewport1.ox = $game_screen.shake
  @viewport3.color = $game_screen.flash_color
  @viewport1.update
  @viewport3.update
  exec_hooks(Spriteset_Map, :update, binding)
  Graphics::FPSBalancer.global.run { exec_hooks(Spriteset_Map, :update_fps_balanced, binding) }
  @viewport1.sort_z # unless Graphics.skipping_frame?
rescue ForceReturn => e
  log_error("Hooks tried to return #{e.data} in Spriteset_Map#update")
end

#update_events

update event sprite



255
256
257
258
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 255

def update_events
  @character_sprites.each(&:update)
  $game_map.event_erased = false if $game_map.event_erased
end

#update_panel

Update the zone panel



321
322
323
324
325
326
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 321

def update_panel
  return unless @map_panel

  @map_panel.update
  dispose_sp_map if @map_panel.done?
end

#update_panorama_fog

update panorama and fog sprites



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 271

def update_panorama_fog
  if @panorama_name != $game_map.panorama_name # or @panorama_hue != $game_map.panorama_hue
    @panorama_name = $game_map.panorama_name
    @panorama_hue = $game_map.panorama_hue
    unless @panorama.texture.nil?
      @panorama.texture.dispose
      @panorama.texture = nil
    end
    @panorama.texture = RPG::Cache.panorama(@panorama_name, @panorama_hue) unless @panorama_name.empty? # if @panorama_name != ""
    Graphics.frame_reset
  end

  if @fog_name != $game_map.fog_name # or @fog_hue != $game_map.fog_hue
    @fog_name = $game_map.fog_name
    @fog_hue = $game_map.fog_hue
    unless @fog.texture.nil?
      @fog.texture.dispose
      @fog.texture = nil
    end
    @fog.texture = RPG::Cache.fog(@fog_name, @fog_hue) unless @fog_name.empty? # if @fog_name != ""
    Graphics.frame_reset
  end

  @panorama.set_origin($game_map.display_x / 8, $game_map.display_y / 8)

  @fog.zoom = $game_map.fog_zoom / 100.0
  @fog.opacity = $game_map.fog_opacity.to_i
  @fog.blend_type = $game_map.fog_blend_type
  @fog.set_origin(($game_map.display_x / 8 + $game_map.fog_ox) / 2, ($game_map.display_y / 8 + $game_map.fog_oy) / 2)
  @fog.tone = $game_map.fog_tone
end

#update_weather_picture

update weather and picture sprites



261
262
263
264
265
266
267
268
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 261

def update_weather_picture
  @weather.type = $game_screen.weather_type
  @weather.max = $game_screen.weather_max
  @weather.ox = $game_map.display_x / 4
  @weather.oy = $game_map.display_y / 4
  @weather.update
  @picture_sprites.each(&:update)
end

#visible=(value)

Change the visible state of the Spriteset

Parameters:

  • value (Boolean)

    the new visibility state



331
332
333
334
335
336
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/03500 Spriteset_Map.rb', line 331

def visible=(value)
  @map_panel&.visible = value
  @viewport1.visible = value
  @viewport2.visible = value
  @viewport3.visible = value
end