Module: Yuki::Particles

Defined in:
scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb,
scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00501 Particles_Def.rb

Overview

Module that manage the particle display

Author:

  • Nuri Yuri

Constant Summary collapse

Data =

The particle data

[]
EMPTY =

The empty actions

{ max_counter: 1, loop: false, data: [] }

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.namedHash{ Symbol => Particle_Object } (readonly)

Return the list of named particles

Returns:



125
126
127
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 125

def named
  @named
end

Class Method Details

.add_building(image, x, y, oy = 0, visible_from1 = false, visible_from2 = false) ⇒ Building_Object

Add a building

Parameters:

  • image (String)

    name of the image in Graphics/Autotiles/

  • x (Integer)

    x coordinate of the building

  • y (Integer)

    y coordinate of the building

  • oy (Integer) (defaults to: 0)

    offset y coordinate of the building in native resolution pixel

  • visible_from1 (Symbol, false) (defaults to: false)

    data parameter (unused there)

  • visible_from2 (Symbol, false) (defaults to: false)

    data parameter (unused there)

Returns:



88
89
90
91
92
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 88

def add_building(image, x, y, oy = 0, visible_from1 = false, visible_from2 = false)
  object = Building_Object.new(image, x, y, oy)
  @stack << object
  return object
end

.add_named_particle(name, character, particle_tag, params = {})

Add a named particle (particle that has a specific flow)

Parameters:

  • name (Symbol)

    name of the particle to prevent collision

  • character (Game_Character)

    the character on which the particle displays

  • particle_tag (Integer, Symbol)

    identifier of the particle in the hash

  • params (Hash) (defaults to: {})

    additional params for the particle



58
59
60
61
62
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 58

def add_named_particle(name, character, particle_tag, params = {})
  return if @named[name] && !@named[name].disposed

  @named[name] = add_particle(character, particle_tag, params)
end

.add_parallax(image, x, y, z, zoom_x = 1, zoom_y = 1, opacity = 255, blend_type = 0) ⇒ Parallax_Object

Add a parallax

Parameters:

  • image (String)

    name of the image in Graphics/Pictures/

  • x (Integer)

    x coordinate of the parallax from the first pixel of the Map (16x16 tiles /!)

  • y (Integer)

    y coordinate of the parallax from the first pixel of the Map (16x16 tiles /!)

  • z (Integer)

    z superiority in the tile viewport

  • zoom_x (Numeric) (defaults to: 1)

    zoom_x of the parallax

  • zoom_y (Numeric) (defaults to: 1)

    zoom_y of the parallax

  • opacity (Integer) (defaults to: 255)

    opacity of the parallax (0~255)

  • blend_type (Integer) (defaults to: 0)

    blend_type of the parallax (0, 1, 2)

Returns:



74
75
76
77
78
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 74

def add_parallax(image, x, y, z, zoom_x = 1, zoom_y = 1, opacity = 255, blend_type = 0)
  object = Parallax_Object.new(image, x, y, z, zoom_x, zoom_y, opacity, blend_type)
  @stack << object
  return object
end

.add_particle(character, particle_tag, params = {}) ⇒ Particle_Object

Add a particle to the stack

Parameters:

  • character (Game_Character)

    the character on which the particle displays

  • particle_tag (Integer, Symbol)

    identifier of the particle in the hash

  • params (Hash) (defaults to: {})

    additional params for the particle

Returns:



42
43
44
45
46
47
48
49
50
51
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 42

def add_particle(character, particle_tag, params = {})
  return unless ready?
  return if character.character_name.empty?

  particle_data = find_particle(character.terrain_tag, particle_tag)
  return unless particle_data

  @stack.push(particle = Particle_Object.new(character, particle_data, @on_teleportation, params))
  return particle
end

.clean_stack

Request to clean the stack



33
34
35
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 33

def clean_stack
  @clean_stack = true
end

.dispose

Dispose each particle



112
113
114
115
116
117
118
119
120
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 112

def dispose
  return unless ready?

  @stack.each do |i|
    i.dispose if i && !i.disposed
  end
ensure
  @stack = nil
end

.find_particle(terrain_tag, particle_tag)

Note:

This function will try $game_variables & 0 as terrain_tag if the particle_tag wasn't found

Function that find the data for a particle according to the terrain_tag & the particle tag

Parameters:

  • terrain_tag (Integer)

    terrain_tag in which the event is

  • particle_tag (Integer, Symbol)

    identifier of the particle in the hash



14
15
16
17
18
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00501 Particles_Def.rb', line 14

def find_particle(terrain_tag, particle_tag)
  Data.dig(terrain_tag, particle_tag) ||
    Data.dig($game_variables[Var::PAR_DatID], particle_tag) ||
    Data.dig(0, particle_tag)
end

.init(viewport)

Init the particle display on a new viewport

Parameters:



9
10
11
12
13
14
15
16
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 9

def init(viewport)
  dispose if @stack && viewport != @viewport
  @clean_stack = false
  @stack ||= []
  @named = {}
  @viewport = viewport
  @on_teleportation = false
end

.ready?Boolean

Tell if the system is ready to work

Returns:

  • (Boolean)


101
102
103
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 101

def ready?
  return @stack && !viewport.disposed?
end

.set_on_teleportation(v)

Tell the particle manager the game is warping the player. Particle will skip the :enter phase.

Parameters:

  • v (Boolean)


107
108
109
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 107

def set_on_teleportation(v)
  @on_teleportation = v
end

.update

Update of the particles & stack cleaning if requested



19
20
21
22
23
24
25
26
27
28
29
30
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 19

def update
  return unless ready?

  @stack.each do |i|
    i.update if i && !i.disposed
  end
  # Clean stack part
  return unless @clean_stack

  @clean_stack = false
  @stack.delete_if(&:disposed)
end

.viewport

Return the viewport of in which the Particles are shown



95
96
97
# File 'scripts/01450 Systems/00003 Map Engine/00001 Graphics/00400 Particles/00500 Yuki__Particles.rb', line 95

def viewport
  @viewport
end