Anim Editor: Particle spawner tweaks

This commit is contained in:
Maruno17
2024-05-04 22:20:05 +01:00
parent dba28332f2
commit 8aacfe491f
10 changed files with 119 additions and 551 deletions

View File

@@ -45,9 +45,10 @@ module GameData
}
USER_AND_TARGET_SEPARATION = [200, -200, -100] # x, y, z (from user to target)
SPAWNER_TYPES = {
"None" => :none,
"RandomDirection" => :random_direction,
"RandomDirectionGravity" => :random_direction_gravity
"None" => :none,
"RandomDirection" => :random_direction,
"RandomDirectionGravity" => :random_direction_gravity,
"RandomUpDirectionGravity" => :random_up_direction_gravity
}
# Properties that apply to the animation in general, not to individual

View File

@@ -533,9 +533,10 @@ AnimationEditor::SidePanes.add_property(:particle_pane, :random_frame_max, {
AnimationEditor::SidePanes.add_property(:particle_pane, :spawner, {
:new => proc { |pane, editor|
values = {
:none => _INTL("None"),
:random_direction => _INTL("Random direction"),
:random_direction_gravity => _INTL("Random direction gravity")
:none => _INTL("None"),
:random_direction => _INTL("Random direction"),
:random_direction_gravity => _INTL("Random dir. with gravity"),
:random_up_direction_gravity => _INTL("Random up dir. gravity")
}
pane.add_labelled_dropdown_list(:spawner, _INTL("Spawner"), values, :none)
}
@@ -552,6 +553,12 @@ AnimationEditor::SidePanes.add_property(:particle_pane, :spawn_quantity, {
else
control.enable
end
},
:apply_value => proc { |value, editor|
AnimationEditor::SidePanes.get_pane(:particle_pane)[:apply_value].call(:spawn_quantity, value, editor)
editor.components[:particle_list].change_particle_commands(editor.particle_index)
editor.components[:play_controls].duration = editor.components[:particle_list].duration
editor.refresh
}
})

View File

@@ -64,7 +64,8 @@ module AnimationEditor::ParticleDataHelper
end
# Used to determine which keyframes the particle is visible in, which is
# indicated in the timeline by a coloured bar.
# indicated in the timeline by a coloured bar. 0=not visible, 1=visible,
# 2=visible because of spawner delay.
# NOTE: Particles are assumed to be not visible at the start of the
# animation, and automatically become visible when the particle has
# its first command. This does not apply to the "User" and "Target"
@@ -75,8 +76,8 @@ module AnimationEditor::ParticleDataHelper
raise _INTL("Couldn't get default value for property {1} for particle {2}.",
property, particle[:name])
end
value = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[:visible]
value = true if ["User", "Target", "SE"].include?(particle[:name])
value = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[:visible] ? 1 : 0
value = 1 if ["User", "Target", "SE"].include?(particle[:name])
ret = []
if !["User", "Target", "SE"].include?(particle[:name])
earliest = duration
@@ -84,15 +85,31 @@ module AnimationEditor::ParticleDataHelper
next if !value.is_a?(Array) || value.empty?
earliest = value[0][0] if earliest > value[0][0]
end
ret[earliest] = true
ret[earliest] = 1
end
if particle[:visible]
particle[:visible].each { |cmd| ret[cmd[0]] = cmd[2] }
particle[:visible].each { |cmd| ret[cmd[0]] = (cmd[2]) ? 1 : 0 }
end
duration.times do |i|
value = ret[i] if !ret[i].nil?
ret[i] = value
end
qty = particle[:spawn_quantity] || 1 if particle[:spawner] && particle[:spawner] != :none
if (particle[:spawner] || :none) != :none
qty = particle[:spawn_quantity] || 1
delay = AnimationPlayer::Helper.get_particle_delay(particle, qty - 1)
if delay > 0
count = -1
duration.times do |i|
if ret[i] == 1 # Visible
count = 0
elsif ret[i] == 0 && count >= 0 && count < delay # Not visible and within delay
ret[i] = 2
count += 1
end
end
end
end
return ret
end

View File

@@ -518,7 +518,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
sprites_need_changing = ensure_sprites
if @duration != old_duration || sprites_need_changing
@keyframe = @keyframe.clamp(0, @duration - 1)
@keyframe = @keyframe.clamp(-1, @duration - 1)
@row_index = @row_index.clamp(0, @particle_list.length - 1)
create_sprites
end
@@ -737,7 +737,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
each_visible_keyframe do |i|
draw_x = TIMELINE_LEFT_BUFFER + (i * KEYFRAME_SPACING) - @left_pos
# Draw bg
if i < @duration - DURATION_BUFFER && visible_cmds[i]
if i < @duration - DURATION_BUFFER && visible_cmds[i] == 1
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, ROW_HEIGHT - ROW_SPACING, bg_color)
end
# Draw hover highlight
@@ -772,19 +772,39 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
end
next if i >= @duration - DURATION_BUFFER
next if !visible_cmds[i]
# Draw outline
outline_color = Color.black
if is_property
outline_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, outline_color) # Bottom
if i <= 0 || !visible_cmds[i - 1]
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && !visible_cmds[i + 1])
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Right
case visible_cmds[i]
when 1 # Particle is visible
# Draw outline
if is_property
outline_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, outline_color) # Bottom
if i <= 0 || visible_cmds[i - 1] != 1
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && visible_cmds[i + 1] != 1)
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Right
end
when 2 # Particle is a spawner and delays its particles into this frame
if !is_property
# Draw dotted outline
KEYFRAME_SPACING.times do |j|
next if j.odd?
bg_spr.bitmap.fill_rect(draw_x + j, ROW_SPACING, 1, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x + j, ROW_HEIGHT - 1, 1, 1, outline_color) # Bottom
end
(ROW_HEIGHT - ROW_SPACING).times do |j|
next if j.odd?
if i <= 0 || visible_cmds[i - 1] != 2
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING + j, 1, 1, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && visible_cmds[i + 1] != 2)
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING + j, 1, 1, outline_color) # Right
end
end
end
end
end
end
@@ -1027,7 +1047,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
def update_input
# Left/right to change current keyframe
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
if @keyframe > 0
if @keyframe >= 0
@keyframe -= 1
scroll_to_keyframe(@keyframe)
set_changed

View File

@@ -21,6 +21,7 @@ class AnimationPlayer
@slowdown = 1
@timer_start = nil
@anim_sprites = [] # Each is a ParticleSprite
@spawner_sprites = []
@duration = total_duration
end
@@ -168,41 +169,49 @@ class AnimationPlayer
end
end
end
# Add spawner commands
add_spawner_commands(particle_sprite, particle, instance, delay)
# Finish up
@anim_sprites.push(particle_sprite)
@spawner_sprites.push([particle_sprite, particle, target_idx, instance, delay]) if spawner_type != :none
end
def add_spawner_commands(particle_sprite, particle, instance, delay)
def add_spawner_commands(particle_sprite, particle, target_idx, instance, delay, add_as_spawner = true)
spawner_type = particle[:spawner] || :none
return if spawner_type == :none
@spawner_sprites.push([particle_sprite, particle, target_idx, instance, delay]) if add_as_spawner
life_start = AnimationPlayer::Helper.get_first_command_frame(particle)
life_end = AnimationPlayer::Helper.get_last_command_frame(particle)
life_end = AnimationPlayer::Helper.get_duration(particles) if life_end < 0
lifetime = life_end - life_start
spawner_type = particle[:spawner] || :none
case spawner_type
when :random_direction, :random_direction_gravity
angle = rand(360)
angle = rand(360) if angle >= 180 && spawner_type == :random_direction_gravity # Prefer upwards angles
speed = rand(150, 250)
when :random_direction, :random_direction_gravity, :random_up_direction_gravity
if spawner_type == :random_up_direction_gravity
angle = 30 + rand(120)
else
angle = rand(360)
angle = rand(360) if angle >= 180 && spawner_type == :random_direction_gravity # Prefer upwards angles
end
speed = rand(200, 400)
start_x_speed = speed * Math.cos(angle * Math::PI / 180)
start_y_speed = -speed * Math.sin(angle * Math::PI / 180)
start_x = (start_x_speed * 0.05) + rand(-8, 8)
start_y = (start_y_speed * 0.05) + rand(-8, 8)
# Set initial positions
[:x, :y].each do |property|
offset = (property == :x) ? start_x : start_y
particle[property].each do |cmd|
next if cmd[1] > 0
particle_sprite.add_set_process(property, (cmd[0] + delay) * slowdown, cmd[2] + offset)
break
particle_sprite.delete_processes(property)
if particle[property] && !particle[property].empty?
offset = (property == :x) ? start_x : start_y
particle[property].each do |cmd|
next if cmd[1] > 0
particle_sprite.add_set_process(property, (cmd[0] + delay) * slowdown, cmd[2] + offset)
break
end
end
end
# Set movements
particle_sprite.add_move_process(:x,
(life_start + delay) * slowdown, lifetime * slowdown,
start_x + (start_x_speed * lifetime / 20.0), :linear)
if spawner_type == :random_direction_gravity
if [:random_direction_gravity, :random_up_direction_gravity].include?(spawner_type)
particle_sprite.add_move_process(:y,
(life_start + delay) * slowdown, lifetime * slowdown,
[start_y_speed / slowdown, AnimationPlayer::Helper::GRAVITY_STRENGTH.to_f / (slowdown * slowdown)], :gravity)
@@ -241,6 +250,8 @@ class AnimationPlayer
# yet started.
def reset_anim_sprites
@anim_sprites.each { |particle| particle.reset_processes }
# Randomise spawner particle properties
@spawner_sprites.each { |spawner| add_spawner_commands(*spawner, false) }
end
#-----------------------------------------------------------------------------

View File

@@ -49,6 +49,10 @@ class AnimationPlayer::ParticleSprite
@processes.push([property, start_frame, duration, value, interpolation, nil, nil])
end
def delete_processes(property)
@processes.delete_if { |process| process[0] == property }
end
# Sets sprite's initial For looping purposes.
def reset_processes
initialize_values

View File

@@ -3,10 +3,11 @@
#===============================================================================
module AnimationPlayer::Helper
PROPERTIES_SET_BY_SPAWNER = {
:random_direction => [:x, :y],
:random_direction_gravity => [:x, :y]
:random_direction => [:x, :y],
:random_direction_gravity => [:x, :y],
:random_up_direction_gravity => [:x, :y]
}
GRAVITY_STRENGTH = 300
GRAVITY_STRENGTH = 500
BATTLE_MESSAGE_BAR_HEIGHT = 96 # NOTE: You shouldn't need to change this.
module_function
@@ -18,6 +19,10 @@ module AnimationPlayer::Helper
particle.each_pair do |property, value|
next if !value.is_a?(Array) || value.empty?
max = value.last[0] + value.last[1] # Keyframe + duration
# Particle spawners can delay their particles; account for this
if (particle[:spawner] || :none) != :none
max += get_particle_delay(particle, (particle[:spawn_quantity] || 1) - 1)
end
ret = max if ret < max
end
end
@@ -51,7 +56,7 @@ module AnimationPlayer::Helper
# For spawner particles
def get_particle_delay(particle, instance)
case particle[:spawner] || :none
when :random_direction, :random_direction_gravity
when :random_direction, :random_direction_gravity, :random_up_direction_gravity
return instance / 4
end
return 0