Anim Editor: added Insert/Delete keyboard shortcuts

This commit is contained in:
Maruno17
2024-04-20 18:29:48 +01:00
parent 4480def33c
commit a80dd5adb2
16 changed files with 158 additions and 412 deletions

View File

@@ -119,7 +119,7 @@ module Compiler
next if value.nil?
case schema[1][i, 1]
when "e", "E" # Enumerable
enumer = schema[2 + i]
enumer = schema[2 + i - start]
case enumer
when Array
file.write(enumer[value])
@@ -136,7 +136,7 @@ module Compiler
end
end
when "y", "Y" # Enumerable or integer
enumer = schema[2 + i]
enumer = schema[2 + i - start]
case enumer
when Array
file.write((enumer[value].nil?) ? value : enumer[value])
@@ -146,14 +146,14 @@ module Compiler
when Module
file.write(getConstantNameOrValue(enumer, value))
when Hash
hasenum = false
has_enum = false
enumer.each_key do |key|
next if enumer[key] != value
file.write(key)
hasenum = true
has_enum = true
break
end
file.write(value) unless hasenum
file.write(value) if !has_enum
end
else
if value.is_a?(String)

View File

@@ -338,7 +338,7 @@ module GameData
new_cmd = cmd.clone
if @particles[index][:name] != "SE" && new_cmd[1] > 0
new_cmd.pop if new_cmd.last == :linear # This is the default
ret.push([@@cmd_to_pbs_name[key][1]] + new_cmd) # ["MoveXYZ", keyframe, duration, value]
ret.push([@@cmd_to_pbs_name[key][1]] + new_cmd) # ["MoveXYZ", keyframe, duration, value, interpolation]
else
case key
when :se

View File

@@ -54,17 +54,6 @@ module Compiler
f.write("\r\n")
end
# Write each particle in turn
element.particles.sort! do |a, b|
a_val = 0
a_val = -2 if a[:name] == "User"
a_val = -1 if a[:name] == "Target"
a_val = 1 if a[:name] == "SE"
b_val = 0
b_val = -2 if b[:name] == "User"
b_val = -1 if b[:name] == "Target"
b_val = 1 if b[:name] == "SE"
next a_val <=> b_val
end
element.particles.each_with_index do |particle, i|
# Write header
f.write("<" + particle[:name] + ">")

View File

@@ -744,10 +744,40 @@ class AnimationEditor
def update_input
if Input.triggerex?(:S)
# Swap battler sides
@settings[:user_opposes] = !@settings[:user_opposes]
refresh
elsif Input.triggerex?(:SPACE)
# Play animation
@ready_to_play = true
elsif Input.triggerex?(:INSERT)
# Insert empty keyframe for selected particle or all particles
this_frame = keyframe
if this_frame >= 0 && this_frame < @components[:particle_list].duration
if Input.pressex?(:LSHIFT) || Input.pressex?(:RSHIFT)
@anim[:particles].each do |particle|
AnimationEditor::ParticleDataHelper.insert_frame(particle, this_frame)
end
else
AnimationEditor::ParticleDataHelper.insert_frame(@anim[:particles][particle_index], this_frame)
end
@components[:particle_list].set_particles(@anim[:particles])
refresh
end
elsif Input.triggerex?(:DELETE)
# Delete keyframe for selected particle or all particles
this_frame = keyframe
if this_frame >= 0 && this_frame < @components[:particle_list].duration
if Input.pressex?(:LSHIFT) || Input.pressex?(:RSHIFT)
@anim[:particles].each do |particle|
AnimationEditor::ParticleDataHelper.remove_frame(particle, this_frame)
end
else
AnimationEditor::ParticleDataHelper.remove_frame(@anim[:particles][particle_index], this_frame)
end
@components[:particle_list].set_particles(@anim[:particles])
refresh
end
end
end

View File

@@ -103,9 +103,9 @@ module AnimationEditor::ParticleDataHelper
def get_particle_commands_timeline(particle)
ret = []
durations = []
particle.each_pair do |property, value|
next if !value.is_a?(Array)
value.each do |cmd|
particle.each_pair do |property, values|
next if !values.is_a?(Array) || values.empty?
values.each do |cmd|
ret[cmd[0]] = true
if cmd[1] > 0
ret[cmd[0] + cmd[1]] = true
@@ -224,7 +224,7 @@ module AnimationEditor::ParticleDataHelper
# * SetXYZ and MoveXYZ start - delete SetXYZ (leave MoveXYZ alone)
# * SetXYZ and MoveXYZ end - (unlikely) delete both
# * SetXYZ and MoveXYZ start and end - (unlikely) delete SetXYZ, merge Moves together
def delete_command(particle, property, frame)
def delete_command(particle, property, frame, full_delete = false)
# Find all relevant commands
set_now = nil
move_ending_now = nil
@@ -246,7 +246,7 @@ module AnimationEditor::ParticleDataHelper
particle[property].delete(move_starting_now)
elsif move_ending_now # Delete MoveXYZ ending now
particle[property].delete(move_ending_now)
elsif move_starting_now && !set_now # Turn into SetXYZ at its end point
elsif move_starting_now && (full_delete || !set_now) # Turn into SetXYZ at its end point
move_starting_now[0] += move_starting_now[1]
move_starting_now[1] = 0
move_starting_now[3] = nil
@@ -457,6 +457,45 @@ module AnimationEditor::ParticleDataHelper
#-----------------------------------------------------------------------------
# Inserts an empty frame at the given frame. Delays all commands at or after
# the given frame by 1, and increases the duration of all commands that
# overlap the given frame.
def insert_frame(particle, frame)
particle.each_pair do |property, values|
next if !values.is_a?(Array) || values.empty?
values.each do |cmd|
if cmd[0] >= frame
cmd[0] += 1
elsif cmd[0] < frame && cmd[0] + cmd[1] > frame
cmd[1] += 1
end
end
end
end
# Removes a frame at the given frame. Deletes all commands in that frame, then
# brings all commands after the given frame earlier by 1, and reduces the
# duration of all commands that overlap the given frame.
def remove_frame(particle, frame)
particle.keys.each do |property|
next if !particle[property].is_a?(Array) || particle[property].empty?
delete_command(particle, property, frame, true)
end
particle.delete_if { |property, values| values.is_a?(Array) && values.empty? }
particle.each_pair do |key, values|
next if !values.is_a?(Array) || values.empty?
values.each do |cmd|
if cmd[0] > frame
cmd[0] -= 1
elsif cmd[0] < frame && cmd[0] + cmd[1] > frame
cmd[1] -= 1
end
end
end
end
#-----------------------------------------------------------------------------
# Creates a new particle and inserts it at index. If there is a particle above
# the new one, the new particle will inherit its focus; otherwise it gets a
# default focus of :foreground.

View File

@@ -642,7 +642,7 @@ class AnimationEditor::Canvas < Sprite
if GameData::Animation::FOCUS_TYPES_WITH_USER.include?(particle[:focus])
relative_to_index = user_index
elsif GameData::Animation::FOCUS_TYPES_WITH_TARGET.include?(particle[:focus])
relative_to_index = target_idx
relative_to_index = first_target_index
end
end
new_pos *= -1 if relative_to_index >= 0 && relative_to_index.odd? && particle[:foe_invert_x]
@@ -679,7 +679,7 @@ class AnimationEditor::Canvas < Sprite
if GameData::Animation::FOCUS_TYPES_WITH_USER.include?(particle[:focus])
relative_to_index = user_index
elsif GameData::Animation::FOCUS_TYPES_WITH_TARGET.include?(particle[:focus])
relative_to_index = target_idx
relative_to_index = first_target_index
end
end
new_pos *= -1 if relative_to_index >= 0 && relative_to_index.odd? && particle[:foe_invert_y]