mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-01-22 14:26:01 +00:00
Merge branch 'dev' into ai
This commit is contained in:
@@ -127,6 +127,16 @@ module Enumerable
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Collision testing
|
||||
#===============================================================================
|
||||
class Rect < Object
|
||||
def contains?(cx, cy)
|
||||
return cx >= self.x && cx < self.x + self.width &&
|
||||
cy >= self.y && cy < self.y + self.height
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# class File
|
||||
#===============================================================================
|
||||
|
||||
@@ -364,11 +364,12 @@ SaveData.register_conversion(:v21_replace_phone_data) do
|
||||
@phoneNumbers.each do |contact|
|
||||
if contact.length > 4
|
||||
# Trainer
|
||||
# TODO: Is there any way to ensure the versions count is accurate?
|
||||
Phone.add_silent(contact[6], contact[7], contact[1], contact[2], 0, [contact[5], 3].max)
|
||||
# TODO: Is there any way to ensure the versions count (contact[5]
|
||||
# is the next version to be battled) is accurate?
|
||||
Phone.add_silent(contact[6], contact[7], contact[1], contact[2], contact[5], 0)
|
||||
new_contact = Phone.get(contact[1], contact[2], 0)
|
||||
new_contact.visible = contact[0]
|
||||
new_contact.version = contact[5]
|
||||
new_contact.version = [contact[5] - 1, 0].max
|
||||
new_contact.rematch_flag = [contact[4] - 1, 0].max
|
||||
else
|
||||
# Non-trainer
|
||||
|
||||
@@ -165,7 +165,7 @@ class GameStats
|
||||
end
|
||||
|
||||
def set_time_to_hall_of_fame
|
||||
@time_to_enter_hall_of_fame = @play_time
|
||||
@time_to_enter_hall_of_fame = @play_time if @time_to_enter_hall_of_fame == 0
|
||||
end
|
||||
|
||||
def play_time_per_session
|
||||
|
||||
@@ -53,7 +53,7 @@ module GameData
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
# @param other [Symbol, String, self]
|
||||
# @param area [Symbol, String, self]
|
||||
# @param version [Integer]
|
||||
# @return [self]
|
||||
def self.try_get(area, version = 0)
|
||||
|
||||
@@ -256,8 +256,6 @@ class Battle::Battler
|
||||
@battle.pbShowAbilitySplash(self, true)
|
||||
@battle.pbHideAbilitySplash(self)
|
||||
pbChangeForm(newForm, _INTL("{1} deactivated!", abilityName))
|
||||
elsif !endOfRound
|
||||
@battle.pbDisplay(_INTL("{1} deactivated!", abilityName))
|
||||
end
|
||||
elsif @form < 7 # Turn into Core form
|
||||
@battle.pbShowAbilitySplash(self, true)
|
||||
|
||||
@@ -692,7 +692,10 @@ class Battle::Battler
|
||||
end
|
||||
# HP-healing held items (checks all battlers rather than just targets
|
||||
# because Flame Burst's splash damage affects non-targets)
|
||||
@battle.pbPriority(true).each { |b| b.pbItemHPHealCheck }
|
||||
@battle.pbPriority(true).each do |b|
|
||||
next if move.preventsBattlerConsumingHealingBerry?(b, targets)
|
||||
b.pbItemHPHealCheck
|
||||
end
|
||||
# Animate battlers fainting (checks all battlers rather than just targets
|
||||
# because Flame Burst's splash damage affects non-targets)
|
||||
@battle.pbPriority(true).each { |b| b.pbFaint if b&.fainted? }
|
||||
|
||||
@@ -144,6 +144,7 @@ class Battle::Move
|
||||
def tramplesMinimize?; return @flags.any? { |f| f[/^TramplesMinimize$/i] }; end
|
||||
|
||||
def nonLethal?(_user, _target); return false; end # For False Swipe
|
||||
def preventsBattlerConsumingHealingBerry?(battler, targets); return false; end # For Bug Bite/Pluck
|
||||
|
||||
def ignoresSubstitute?(user) # user is the Pokémon using this move
|
||||
if Settings::MECHANICS_GENERATION >= 6
|
||||
|
||||
@@ -378,6 +378,11 @@ end
|
||||
# User consumes target's berry and gains its effect. (Bug Bite, Pluck)
|
||||
#===============================================================================
|
||||
class Battle::Move::UserConsumeTargetBerry < Battle::Move
|
||||
def preventsBattlerConsumingHealingBerry?(battler, targets)
|
||||
return targets.any? { |b| b.index == battler.index } &&
|
||||
battler.item&.is_berry? && Battle::ItemEffects::HPHeal[battler.item]
|
||||
end
|
||||
|
||||
def pbEffectAfterAllHits(user, target)
|
||||
return if user.fainted? || target.fainted?
|
||||
return if target.damageState.unaffected || target.damageState.substitute
|
||||
|
||||
@@ -471,6 +471,49 @@ class PBAnimation < Array
|
||||
end
|
||||
|
||||
def playTiming(frame, bgGraphic, bgColor, foGraphic, foColor, oldbg = [], oldfo = [], user = nil)
|
||||
@timing.each do |i|
|
||||
next if !i.duration || i.duration <= 0
|
||||
next if i.frame + i.duration < frame || i.frame >= frame
|
||||
fraction = (frame - i.frame).to_f / i.duration
|
||||
case i.timingType
|
||||
when 2
|
||||
if bgGraphic.bitmap.nil?
|
||||
bgColor.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red
|
||||
cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green
|
||||
cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue
|
||||
ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha
|
||||
bgColor.color = Color.new(cr, cg, cb, ca)
|
||||
else
|
||||
bgGraphic.ox = oldbg[0] - ((i.bgX - oldbg[0]) * fraction) if i.bgX
|
||||
bgGraphic.oy = oldbg[1] - ((i.bgY - oldbg[1]) * fraction) if i.bgY
|
||||
bgGraphic.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red
|
||||
cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green
|
||||
cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue
|
||||
ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha
|
||||
bgGraphic.color = Color.new(cr, cg, cb, ca)
|
||||
end
|
||||
when 4
|
||||
if foGraphic.bitmap.nil?
|
||||
foColor.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red
|
||||
cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green
|
||||
cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue
|
||||
ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha
|
||||
foColor.color = Color.new(cr, cg, cb, ca)
|
||||
else
|
||||
foGraphic.ox = oldfo[0] - ((i.bgX - oldfo[0]) * fraction) if i.bgX
|
||||
foGraphic.oy = oldfo[1] - ((i.bgY - oldfo[1]) * fraction) if i.bgY
|
||||
foGraphic.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red
|
||||
cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green
|
||||
cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue
|
||||
ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha
|
||||
foGraphic.color = Color.new(cr, cg, cb, ca)
|
||||
end
|
||||
end
|
||||
end
|
||||
@timing.each do |i|
|
||||
next if i.frame != frame
|
||||
case i.timingType
|
||||
@@ -539,52 +582,6 @@ class PBAnimation < Array
|
||||
end
|
||||
end
|
||||
end
|
||||
@timing.each do |i|
|
||||
case i.timingType
|
||||
when 2
|
||||
next if !i.duration || i.duration <= 0
|
||||
next if frame < i.frame || frame > i.frame + i.duration
|
||||
fraction = (frame - i.frame).to_f / i.duration
|
||||
if bgGraphic.bitmap.nil?
|
||||
bgColor.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red
|
||||
cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green
|
||||
cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue
|
||||
ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha
|
||||
bgColor.color = Color.new(cr, cg, cb, ca)
|
||||
else
|
||||
bgGraphic.ox = oldbg[0] - ((i.bgX - oldbg[0]) * fraction) if i.bgX
|
||||
bgGraphic.oy = oldbg[1] - ((i.bgY - oldbg[1]) * fraction) if i.bgY
|
||||
bgGraphic.opacity = oldbg[2] + ((i.opacity - oldbg[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldbg[3].red + ((i.colorRed - oldbg[3].red) * fraction) : oldbg[3].red
|
||||
cg = (i.colorGreen) ? oldbg[3].green + ((i.colorGreen - oldbg[3].green) * fraction) : oldbg[3].green
|
||||
cb = (i.colorBlue) ? oldbg[3].blue + ((i.colorBlue - oldbg[3].blue) * fraction) : oldbg[3].blue
|
||||
ca = (i.colorAlpha) ? oldbg[3].alpha + ((i.colorAlpha - oldbg[3].alpha) * fraction) : oldbg[3].alpha
|
||||
bgGraphic.color = Color.new(cr, cg, cb, ca)
|
||||
end
|
||||
when 4
|
||||
next if !i.duration || i.duration <= 0
|
||||
next if frame < i.frame || frame > i.frame + i.duration
|
||||
fraction = (frame - i.frame).to_f / i.duration
|
||||
if foGraphic.bitmap.nil?
|
||||
foColor.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red
|
||||
cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green
|
||||
cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue
|
||||
ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha
|
||||
foColor.color = Color.new(cr, cg, cb, ca)
|
||||
else
|
||||
foGraphic.ox = oldfo[0] - ((i.bgX - oldfo[0]) * fraction) if i.bgX
|
||||
foGraphic.oy = oldfo[1] - ((i.bgY - oldfo[1]) * fraction) if i.bgY
|
||||
foGraphic.opacity = oldfo[2] + ((i.opacity - oldfo[2]) * fraction) if i.opacity
|
||||
cr = (i.colorRed) ? oldfo[3].red + ((i.colorRed - oldfo[3].red) * fraction) : oldfo[3].red
|
||||
cg = (i.colorGreen) ? oldfo[3].green + ((i.colorGreen - oldfo[3].green) * fraction) : oldfo[3].green
|
||||
cb = (i.colorBlue) ? oldfo[3].blue + ((i.colorBlue - oldfo[3].blue) * fraction) : oldfo[3].blue
|
||||
ca = (i.colorAlpha) ? oldfo[3].alpha + ((i.colorAlpha - oldfo[3].alpha) * fraction) : oldfo[3].alpha
|
||||
foGraphic.color = Color.new(cr, cg, cb, ca)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1708,10 +1708,10 @@ Battle::AbilityEffects::OnBeingHit.add(:ANGERPOINT,
|
||||
|
||||
Battle::AbilityEffects::OnBeingHit.add(:COTTONDOWN,
|
||||
proc { |ability, user, target, move, battle|
|
||||
next if battle.allBattlers.none? { |b| b.pbCanLowerStatStage?(:DEFENSE, target) }
|
||||
next if battle.allBattlers.none? { |b| b.index != target.index && b.pbCanLowerStatStage?(:SPEED, target) }
|
||||
battle.pbShowAbilitySplash(target)
|
||||
battle.allBattlers.each do |b|
|
||||
b.pbLowerStatStageByAbility(:SPEED, 1, target, false)
|
||||
b.pbLowerStatStageByAbility(:SPEED, 1, target, false) if b.index != target.index
|
||||
end
|
||||
battle.pbHideAbilitySplash(target)
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class Phone
|
||||
|
||||
def initialize
|
||||
@contacts = []
|
||||
@rematch_variant = 0 # Original variant is 0, first rematch variant is 1, etc.
|
||||
@rematch_variant = 0 # Original battle is 0, first rematch is 1, etc.
|
||||
@rematches_enabled = Settings::PHONE_REMATCHES_POSSIBLE_FROM_BEGINNING
|
||||
@time_to_next_call = 0.0
|
||||
@last_refresh_time = 0
|
||||
@@ -91,7 +91,6 @@ class Phone
|
||||
else
|
||||
contact = Contact.new(true, args[0].map_id, args[0].id,
|
||||
trainer_type, name, args[3], args[4], args[5])
|
||||
contact.increment_version
|
||||
end
|
||||
elsif args[1].is_a?(Numeric)
|
||||
# Trainer
|
||||
@@ -105,7 +104,6 @@ class Phone
|
||||
else
|
||||
contact = Contact.new(true, args[0], args[1],
|
||||
trainer_type, name, args[4], args[5], args[6])
|
||||
contact.increment_version
|
||||
end
|
||||
else
|
||||
# Non-trainer
|
||||
@@ -162,10 +160,9 @@ class Phone
|
||||
trainer_type = GameData::TrainerType.get(trainer_type).id
|
||||
contact = get(true, trainer_type, name, start_version)
|
||||
return if !contact
|
||||
contact.variant_beaten = contact.version - contact.start_version
|
||||
contact.increment_version
|
||||
contact.rematch_flag = 0
|
||||
contact.time_to_ready = 0.0
|
||||
contact.time_to_ready = 0
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
@@ -213,34 +210,25 @@ class Phone
|
||||
return $PokemonGlobal.phone.add(*args)
|
||||
end
|
||||
|
||||
def self.variant(trainer_type, name, start_version = 0)
|
||||
contact = $PokemonGlobal.phone.get(trainer_type, name, start_version)
|
||||
return (contact) ? contact.variant : 0
|
||||
end
|
||||
|
||||
def self.increment_version(trainer_type, name, start_version = 0)
|
||||
contact = $PokemonGlobal.phone.get(trainer_type, name, start_version)
|
||||
contact.increment_version if contact
|
||||
end
|
||||
|
||||
# TODO: Rename this.
|
||||
def self.variant(trainer_type, name, start_version = 0)
|
||||
contact = $PokemonGlobal.phone.get(trainer_type, name, start_version)
|
||||
return contact.version - contact.start_version if contact
|
||||
return start_version
|
||||
end
|
||||
|
||||
def self.battle(trainer_type, name, start_version = 0)
|
||||
contact = $PokemonGlobal.phone.get(true, trainer_type, name, start_version)
|
||||
return false if !contact
|
||||
contact.increment_version if contact.version == contact.start_version + contact.variant_beaten
|
||||
return TrainerBattle.start(trainer_type, name, contact.version)
|
||||
return TrainerBattle.start(trainer_type, name, contact.next_version)
|
||||
end
|
||||
|
||||
def self.reset_after_win(trainer_type, name, start_version = 0)
|
||||
$PokemonGlobal.phone.reset_after_win(trainer_type, name, start_version)
|
||||
end
|
||||
|
||||
def self.variant_beaten(trainer_type, name, start_version = 0)
|
||||
contact = $PokemonGlobal.phone.get(true, trainer_type, name, start_version)
|
||||
return 0 if !contact
|
||||
return contact.variant_beaten
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
@@ -250,8 +238,9 @@ class Phone
|
||||
class Contact
|
||||
attr_accessor :map_id, :event_id
|
||||
attr_accessor :name
|
||||
attr_accessor :trainer_type, :start_version, :versions_count, :version
|
||||
attr_accessor :time_to_ready, :rematch_flag, :variant_beaten
|
||||
attr_accessor :trainer_type
|
||||
attr_accessor :start_version, :versions_count, :version # :version is the last trainer version that was beaten
|
||||
attr_accessor :time_to_ready, :rematch_flag
|
||||
attr_accessor :common_event_id
|
||||
attr_reader :visible
|
||||
|
||||
@@ -268,7 +257,6 @@ class Phone
|
||||
@versions_count = [args[4] || 1, 1].max # Includes the original version
|
||||
@start_version = args[5] || 0
|
||||
@version = @start_version
|
||||
@variant_beaten = 0
|
||||
@time_to_ready = 0
|
||||
@rematch_flag = 0 # 0=counting down, 1=ready for rematch, 2=ready and told player
|
||||
@common_event_id = args[6] || 0
|
||||
@@ -319,13 +307,22 @@ class Phone
|
||||
return _INTL(@name)
|
||||
end
|
||||
|
||||
# Original battle is 0, first rematch is 1, etc.
|
||||
def variant
|
||||
return 0 if !trainer?
|
||||
return @version - @start_version
|
||||
end
|
||||
|
||||
# Returns the version of this trainer to be battled next.
|
||||
def next_version
|
||||
var = variant + 1
|
||||
var = [var, $PokemonGlobal.phone.rematch_variant, @versions_count - 1].min
|
||||
return @start_version + var
|
||||
end
|
||||
|
||||
def increment_version
|
||||
return if !trainer?
|
||||
max_variant = [$PokemonGlobal.phone.rematch_variant, @versions_count - 1].min
|
||||
return if @version - @start_version >= max_variant
|
||||
@version += 1
|
||||
@time_to_ready = 0
|
||||
@rematch_flag = 0
|
||||
@version = next_version
|
||||
end
|
||||
|
||||
def set_trainer_event_ready_for_rematch
|
||||
@@ -530,7 +527,7 @@ class Phone
|
||||
|
||||
def get_random_contact_pokemon_species(contact)
|
||||
return "" if !contact.trainer?
|
||||
version = [contact.version - 1, contact.start_version].max
|
||||
version = [contact.version, contact.start_version].max
|
||||
trainer_data = GameData::Trainer.try_get(contact.trainer_type, contact.name, version)
|
||||
return "" if !trainer_data
|
||||
pkmn = trainer_data.pokemon.sample[:species]
|
||||
|
||||
@@ -275,13 +275,21 @@ class HallOfFame_Scene
|
||||
end
|
||||
|
||||
def writeTrainerData
|
||||
totalsec = Graphics.frame_count / Graphics.frame_rate
|
||||
if $PokemonGlobal.hallOfFameLastNumber == 1
|
||||
totalsec = $stats.time_to_enter_hall_of_fame.to_i
|
||||
else
|
||||
totalsec = $stats.play_time.to_i
|
||||
end
|
||||
hour = totalsec / 60 / 60
|
||||
min = totalsec / 60 % 60
|
||||
pubid = sprintf("%05d", $player.public_ID)
|
||||
lefttext = _INTL("Name<r>{1}<br>", $player.name)
|
||||
lefttext += _INTL("IDNo.<r>{1}<br>", pubid)
|
||||
lefttext += _ISPRINTF("Time<r>{1:02d}:{2:02d}<br>", hour, min)
|
||||
lefttext += _INTL("ID No.<r>{1}<br>", pubid)
|
||||
if hour > 0
|
||||
lefttext += _INTL("Time<r>{1}h {2}m<br>", hour, min)
|
||||
else
|
||||
lefttext += _INTL("Time<r>{1}m<br>", min)
|
||||
end
|
||||
lefttext += _INTL("Pokédex<r>{1}/{2}<br>",
|
||||
$player.pokedex.owned_count, $player.pokedex.seen_count)
|
||||
@sprites["messagebox"] = Window_AdvancedTextPokemon.new(lefttext)
|
||||
@@ -315,7 +323,7 @@ class HallOfFame_Scene
|
||||
[pokename, Graphics.width - 192, Graphics.height - 74, 2, BASECOLOR, SHADOWCOLOR],
|
||||
[_INTL("Lv. {1}", pokemon.egg? ? "?" : pokemon.level),
|
||||
64, Graphics.height - 42, 0, BASECOLOR, SHADOWCOLOR],
|
||||
[_INTL("IDNo.{1}", pokemon.egg? ? "?????" : idno),
|
||||
[_INTL("ID No. {1}", pokemon.egg? ? "?????" : idno),
|
||||
Graphics.width - 192, Graphics.height - 42, 2, BASECOLOR, SHADOWCOLOR]
|
||||
]
|
||||
if hallNumber > -1
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,432 +1,436 @@
|
||||
#===============================================================================
|
||||
# Paths and interpolation
|
||||
#===============================================================================
|
||||
class ControlPointSprite < Sprite
|
||||
attr_accessor :dragging
|
||||
module BattleAnimationEditor
|
||||
module_function
|
||||
|
||||
def initialize(red, viewport = nil)
|
||||
super(viewport)
|
||||
self.bitmap = Bitmap.new(6, 6)
|
||||
self.bitmap.fill_rect(0, 0, 6, 1, Color.black)
|
||||
self.bitmap.fill_rect(0, 0, 1, 6, Color.black)
|
||||
self.bitmap.fill_rect(0, 5, 6, 1, Color.black)
|
||||
self.bitmap.fill_rect(5, 0, 1, 6, Color.black)
|
||||
color = (red) ? Color.new(255, 0, 0) : Color.black
|
||||
self.bitmap.fill_rect(2, 2, 2, 2, color)
|
||||
self.x = -6
|
||||
self.y = -6
|
||||
self.visible = false
|
||||
@dragging = false
|
||||
end
|
||||
#===============================================================================
|
||||
# Paths and interpolation
|
||||
#===============================================================================
|
||||
class ControlPointSprite < Sprite
|
||||
attr_accessor :dragging
|
||||
|
||||
def mouseover
|
||||
if Input.time?(Input::MOUSELEFT) == 0 || !@dragging
|
||||
def initialize(red, viewport = nil)
|
||||
super(viewport)
|
||||
self.bitmap = Bitmap.new(6, 6)
|
||||
self.bitmap.fill_rect(0, 0, 6, 1, Color.black)
|
||||
self.bitmap.fill_rect(0, 0, 1, 6, Color.black)
|
||||
self.bitmap.fill_rect(0, 5, 6, 1, Color.black)
|
||||
self.bitmap.fill_rect(5, 0, 1, 6, Color.black)
|
||||
color = (red) ? Color.new(255, 0, 0) : Color.black
|
||||
self.bitmap.fill_rect(2, 2, 2, 2, color)
|
||||
self.x = -6
|
||||
self.y = -6
|
||||
self.visible = false
|
||||
@dragging = false
|
||||
return
|
||||
end
|
||||
mouse = Mouse.getMousePos(true)
|
||||
return if !mouse
|
||||
self.x = [[mouse[0], 0].max, 512].min
|
||||
self.y = [[mouse[1], 0].max, 384].min
|
||||
end
|
||||
|
||||
def hittest?
|
||||
return true if !self.visible
|
||||
mouse = Mouse.getMousePos(true)
|
||||
return false if !mouse
|
||||
return mouse[0] >= self.x && mouse[0] < self.x + 6 &&
|
||||
mouse[1] >= self.y && mouse[1] < self.y + 6
|
||||
end
|
||||
|
||||
def inspect
|
||||
return "[#{self.x},#{self.y}]"
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PointSprite < Sprite
|
||||
def initialize(x, y, viewport = nil)
|
||||
super(viewport)
|
||||
self.bitmap = Bitmap.new(2, 2)
|
||||
self.bitmap.fill_rect(0, 0, 2, 2, Color.black)
|
||||
self.x = x
|
||||
self.y = y
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PointPath
|
||||
include Enumerable
|
||||
|
||||
def initialize
|
||||
@points = []
|
||||
@distances = []
|
||||
@totaldist = 0
|
||||
end
|
||||
|
||||
def [](x)
|
||||
return @points[x].clone
|
||||
end
|
||||
|
||||
def each
|
||||
@points.each { |o| yield o.clone }
|
||||
end
|
||||
|
||||
def size
|
||||
return @points.size
|
||||
end
|
||||
|
||||
def length
|
||||
return @points.length
|
||||
end
|
||||
|
||||
def totalDistance
|
||||
return @totaldist
|
||||
end
|
||||
|
||||
def inspect
|
||||
p = []
|
||||
@points.each do |point|
|
||||
p.push([point[0].to_i, point[1].to_i])
|
||||
end
|
||||
return p.inspect
|
||||
end
|
||||
|
||||
def isEndPoint?(x, y)
|
||||
return false if @points.length == 0
|
||||
index = @points.length - 1
|
||||
return @points[index][0] == x &&
|
||||
@points[index][1] == y
|
||||
end
|
||||
|
||||
def addPoint(x, y)
|
||||
@points.push([x, y])
|
||||
if @points.length > 1
|
||||
len = @points.length
|
||||
dx = @points[len - 2][0] - @points[len - 1][0]
|
||||
dy = @points[len - 2][1] - @points[len - 1][1]
|
||||
dist = Math.sqrt((dx * dx) + (dy * dy))
|
||||
@distances.push(dist)
|
||||
@totaldist += dist
|
||||
end
|
||||
end
|
||||
|
||||
def clear
|
||||
@points.clear
|
||||
@distances.clear
|
||||
@totaldist = 0
|
||||
end
|
||||
|
||||
def smoothPointPath(frames, roundValues = false)
|
||||
raise ArgumentError.new("frames out of range: #{frames}") if frames < 0
|
||||
ret = PointPath.new
|
||||
return ret if @points.length == 0
|
||||
step = 1.0 / frames
|
||||
t = 0.0
|
||||
(frames + 2).times do
|
||||
point = pointOnPath(t)
|
||||
if roundValues
|
||||
ret.addPoint(point[0].round, point[1].round)
|
||||
else
|
||||
ret.addPoint(point[0], point[1])
|
||||
def mouseover
|
||||
if Input.time?(Input::MOUSELEFT) == 0 || !@dragging
|
||||
@dragging = false
|
||||
return
|
||||
end
|
||||
t += step
|
||||
t = [1.0, t].min
|
||||
mouse = Mouse.getMousePos(true)
|
||||
return if !mouse
|
||||
self.x = [[mouse[0], 0].max, 512].min
|
||||
self.y = [[mouse[1], 0].max, 384].min
|
||||
end
|
||||
|
||||
def hittest?
|
||||
return true if !self.visible
|
||||
mouse = Mouse.getMousePos(true)
|
||||
return false if !mouse
|
||||
return mouse[0] >= self.x && mouse[0] < self.x + 6 &&
|
||||
mouse[1] >= self.y && mouse[1] < self.y + 6
|
||||
end
|
||||
|
||||
def inspect
|
||||
return "[#{self.x},#{self.y}]"
|
||||
end
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose
|
||||
super
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def pointOnPath(t)
|
||||
if t < 0 || t > 1
|
||||
raise ArgumentError.new("t out of range for pointOnPath: #{t}")
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PointSprite < Sprite
|
||||
def initialize(x, y, viewport = nil)
|
||||
super(viewport)
|
||||
self.bitmap = Bitmap.new(2, 2)
|
||||
self.bitmap.fill_rect(0, 0, 2, 2, Color.black)
|
||||
self.x = x
|
||||
self.y = y
|
||||
end
|
||||
return nil if @points.length == 0
|
||||
ret = @points[@points.length - 1].clone
|
||||
return ret if @points.length == 1
|
||||
curdist = 0
|
||||
distForT = @totaldist * t
|
||||
i = 0
|
||||
@distances.each do |dist|
|
||||
curdist += dist
|
||||
if dist > 0.0 && curdist >= distForT
|
||||
distT = 1.0 - ((curdist - distForT) / dist)
|
||||
dx = @points[i + 1][0] - @points[i][0]
|
||||
dy = @points[i + 1][1] - @points[i][1]
|
||||
ret = [@points[i][0] + (dx * distT),
|
||||
@points[i][1] + (dy * distT)]
|
||||
break
|
||||
|
||||
def dispose
|
||||
self.bitmap.dispose
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class PointPath
|
||||
include Enumerable
|
||||
|
||||
def initialize
|
||||
@points = []
|
||||
@distances = []
|
||||
@totaldist = 0
|
||||
end
|
||||
|
||||
def [](x)
|
||||
return @points[x].clone
|
||||
end
|
||||
|
||||
def each
|
||||
@points.each { |o| yield o.clone }
|
||||
end
|
||||
|
||||
def size
|
||||
return @points.size
|
||||
end
|
||||
|
||||
def length
|
||||
return @points.length
|
||||
end
|
||||
|
||||
def totalDistance
|
||||
return @totaldist
|
||||
end
|
||||
|
||||
def inspect
|
||||
p = []
|
||||
@points.each do |point|
|
||||
p.push([point[0].to_i, point[1].to_i])
|
||||
end
|
||||
i += 1
|
||||
return p.inspect
|
||||
end
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def catmullRom(p1, p2, p3, p4, t)
|
||||
# p1=prevPoint, p2=startPoint, p3=endPoint, p4=nextPoint, t is from 0 through 1
|
||||
t2 = t * t
|
||||
t3 = t2 * t
|
||||
return 0.5 * ((2 * p2) + (t * (p3 - p1)) +
|
||||
(t2 * ((2 * p1) - (5 * p2) + (4 * p3) - p4)) +
|
||||
(t3 * (p4 - (3 * p3) + (3 * p2) - p1)))
|
||||
end
|
||||
def isEndPoint?(x, y)
|
||||
return false if @points.length == 0
|
||||
index = @points.length - 1
|
||||
return @points[index][0] == x &&
|
||||
@points[index][1] == y
|
||||
end
|
||||
|
||||
def getCatmullRomPoint(src, t)
|
||||
x = 0, y = 0
|
||||
t *= 3.0
|
||||
if t < 1.0
|
||||
x = catmullRom(src[0].x, src[0].x, src[1].x, src[2].x, t)
|
||||
y = catmullRom(src[0].y, src[0].y, src[1].y, src[2].y, t)
|
||||
elsif t < 2.0
|
||||
t -= 1.0
|
||||
x = catmullRom(src[0].x, src[1].x, src[2].x, src[3].x, t)
|
||||
y = catmullRom(src[0].y, src[1].y, src[2].y, src[3].y, t)
|
||||
else
|
||||
t -= 2.0
|
||||
x = catmullRom(src[1].x, src[2].x, src[3].x, src[3].x, t)
|
||||
y = catmullRom(src[1].y, src[2].y, src[3].y, src[3].y, t)
|
||||
end
|
||||
return [x, y]
|
||||
end
|
||||
def addPoint(x, y)
|
||||
@points.push([x, y])
|
||||
if @points.length > 1
|
||||
len = @points.length
|
||||
dx = @points[len - 2][0] - @points[len - 1][0]
|
||||
dy = @points[len - 2][1] - @points[len - 1][1]
|
||||
dist = Math.sqrt((dx * dx) + (dy * dy))
|
||||
@distances.push(dist)
|
||||
@totaldist += dist
|
||||
end
|
||||
end
|
||||
|
||||
def getCurvePoint(src, t)
|
||||
return getCatmullRomPoint(src, t)
|
||||
end
|
||||
def clear
|
||||
@points.clear
|
||||
@distances.clear
|
||||
@totaldist = 0
|
||||
end
|
||||
|
||||
def curveToPointPath(curve, numpoints)
|
||||
return nil if numpoints < 2
|
||||
path = PointPath.new
|
||||
step = 1.0 / (numpoints - 1)
|
||||
t = 0.0
|
||||
numpoints.times do
|
||||
point = getCurvePoint(curve, t)
|
||||
path.addPoint(point[0], point[1])
|
||||
t += step
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
def pbDefinePath(canvas)
|
||||
sliderwin2 = ControlWindow.new(0, 0, 320, 320)
|
||||
sliderwin2.viewport = canvas.viewport
|
||||
sliderwin2.addSlider(_INTL("Number of frames:"), 2, 500, 20)
|
||||
sliderwin2.opacity = 200
|
||||
defcurvebutton = sliderwin2.addButton(_INTL("Define Smooth Curve"))
|
||||
defpathbutton = sliderwin2.addButton(_INTL("Define Freehand Path"))
|
||||
okbutton = sliderwin2.addButton(_INTL("OK"))
|
||||
cancelbutton = sliderwin2.addButton(_INTL("Cancel"))
|
||||
points = []
|
||||
path = nil
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
sliderwin2.update
|
||||
if sliderwin2.changed?(0) # Number of frames
|
||||
if path
|
||||
path = path.smoothPointPath(sliderwin2.value(0), false)
|
||||
i = 0
|
||||
path.each do |point|
|
||||
if i < points.length
|
||||
points[i].x = point[0]
|
||||
points[i].y = point[1]
|
||||
else
|
||||
points.push(PointSprite.new(point[0], point[1], canvas.viewport))
|
||||
end
|
||||
i += 1
|
||||
def smoothPointPath(frames, roundValues = false)
|
||||
raise ArgumentError.new("frames out of range: #{frames}") if frames < 0
|
||||
ret = PointPath.new
|
||||
return ret if @points.length == 0
|
||||
step = 1.0 / frames
|
||||
t = 0.0
|
||||
(frames + 2).times do
|
||||
point = pointOnPath(t)
|
||||
if roundValues
|
||||
ret.addPoint(point[0].round, point[1].round)
|
||||
else
|
||||
ret.addPoint(point[0], point[1])
|
||||
end
|
||||
(i...points.length).each do |j|
|
||||
points[j].dispose
|
||||
points[j] = nil
|
||||
end
|
||||
points.compact!
|
||||
t += step
|
||||
t = [1.0, t].min
|
||||
end
|
||||
elsif sliderwin2.changed?(defcurvebutton)
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
return ret
|
||||
end
|
||||
|
||||
def pointOnPath(t)
|
||||
if t < 0 || t > 1
|
||||
raise ArgumentError.new("t out of range for pointOnPath: #{t}")
|
||||
end
|
||||
points.clear
|
||||
30.times do
|
||||
point = PointSprite.new(0, 0, canvas.viewport)
|
||||
point.visible = false
|
||||
points.push(point)
|
||||
end
|
||||
curve = [
|
||||
ControlPointSprite.new(true, canvas.viewport),
|
||||
ControlPointSprite.new(false, canvas.viewport),
|
||||
ControlPointSprite.new(false, canvas.viewport),
|
||||
ControlPointSprite.new(true, canvas.viewport)
|
||||
]
|
||||
showline = false
|
||||
sliderwin2.visible = false
|
||||
# This window displays the mouse's current position
|
||||
window = Window_UnformattedTextPokemon.newWithSize(
|
||||
"", 0, 320 - 64, 128, 64, canvas.viewport
|
||||
)
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.trigger?(Input::BACK)
|
||||
return nil if @points.length == 0
|
||||
ret = @points[@points.length - 1].clone
|
||||
return ret if @points.length == 1
|
||||
curdist = 0
|
||||
distForT = @totaldist * t
|
||||
i = 0
|
||||
@distances.each do |dist|
|
||||
curdist += dist
|
||||
if dist > 0.0 && curdist >= distForT
|
||||
distT = 1.0 - ((curdist - distForT) / dist)
|
||||
dx = @points[i + 1][0] - @points[i][0]
|
||||
dy = @points[i + 1][1] - @points[i][1]
|
||||
ret = [@points[i][0] + (dx * distT),
|
||||
@points[i][1] + (dy * distT)]
|
||||
break
|
||||
end
|
||||
if Input.trigger?(Input::MOUSELEFT)
|
||||
i += 1
|
||||
end
|
||||
return ret
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
def catmullRom(p1, p2, p3, p4, t)
|
||||
# p1=prevPoint, p2=startPoint, p3=endPoint, p4=nextPoint, t is from 0 through 1
|
||||
t2 = t * t
|
||||
t3 = t2 * t
|
||||
return 0.5 * ((2 * p2) + (t * (p3 - p1)) +
|
||||
(t2 * ((2 * p1) - (5 * p2) + (4 * p3) - p4)) +
|
||||
(t3 * (p4 - (3 * p3) + (3 * p2) - p1)))
|
||||
end
|
||||
|
||||
def getCatmullRomPoint(src, t)
|
||||
x = 0, y = 0
|
||||
t *= 3.0
|
||||
if t < 1.0
|
||||
x = catmullRom(src[0].x, src[0].x, src[1].x, src[2].x, t)
|
||||
y = catmullRom(src[0].y, src[0].y, src[1].y, src[2].y, t)
|
||||
elsif t < 2.0
|
||||
t -= 1.0
|
||||
x = catmullRom(src[0].x, src[1].x, src[2].x, src[3].x, t)
|
||||
y = catmullRom(src[0].y, src[1].y, src[2].y, src[3].y, t)
|
||||
else
|
||||
t -= 2.0
|
||||
x = catmullRom(src[1].x, src[2].x, src[3].x, src[3].x, t)
|
||||
y = catmullRom(src[1].y, src[2].y, src[3].y, src[3].y, t)
|
||||
end
|
||||
return [x, y]
|
||||
end
|
||||
|
||||
def getCurvePoint(src, t)
|
||||
return getCatmullRomPoint(src, t)
|
||||
end
|
||||
|
||||
def curveToPointPath(curve, numpoints)
|
||||
return nil if numpoints < 2
|
||||
path = PointPath.new
|
||||
step = 1.0 / (numpoints - 1)
|
||||
t = 0.0
|
||||
numpoints.times do
|
||||
point = getCurvePoint(curve, t)
|
||||
path.addPoint(point[0], point[1])
|
||||
t += step
|
||||
end
|
||||
return path
|
||||
end
|
||||
|
||||
def pbDefinePath(canvas)
|
||||
sliderwin2 = ControlWindow.new(0, 0, 320, 320)
|
||||
sliderwin2.viewport = canvas.viewport
|
||||
sliderwin2.addSlider(_INTL("Number of frames:"), 2, 500, 20)
|
||||
sliderwin2.opacity = 200
|
||||
defcurvebutton = sliderwin2.addButton(_INTL("Define Smooth Curve"))
|
||||
defpathbutton = sliderwin2.addButton(_INTL("Define Freehand Path"))
|
||||
okbutton = sliderwin2.addButton(_INTL("OK"))
|
||||
cancelbutton = sliderwin2.addButton(_INTL("Cancel"))
|
||||
points = []
|
||||
path = nil
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
sliderwin2.update
|
||||
if sliderwin2.changed?(0) # Number of frames
|
||||
if path
|
||||
path = path.smoothPointPath(sliderwin2.value(0), false)
|
||||
i = 0
|
||||
path.each do |point|
|
||||
if i < points.length
|
||||
points[i].x = point[0]
|
||||
points[i].y = point[1]
|
||||
else
|
||||
points.push(PointSprite.new(point[0], point[1], canvas.viewport))
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
(i...points.length).each do |j|
|
||||
points[j].dispose
|
||||
points[j] = nil
|
||||
end
|
||||
points.compact!
|
||||
end
|
||||
elsif sliderwin2.changed?(defcurvebutton)
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
30.times do
|
||||
point = PointSprite.new(0, 0, canvas.viewport)
|
||||
point.visible = false
|
||||
points.push(point)
|
||||
end
|
||||
curve = [
|
||||
ControlPointSprite.new(true, canvas.viewport),
|
||||
ControlPointSprite.new(false, canvas.viewport),
|
||||
ControlPointSprite.new(false, canvas.viewport),
|
||||
ControlPointSprite.new(true, canvas.viewport)
|
||||
]
|
||||
showline = false
|
||||
sliderwin2.visible = false
|
||||
# This window displays the mouse's current position
|
||||
window = Window_UnformattedTextPokemon.newWithSize(
|
||||
"", 0, 320 - 64, 128, 64, canvas.viewport
|
||||
)
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
if Input.trigger?(Input::MOUSELEFT)
|
||||
4.times do |j|
|
||||
next if !curve[j].hittest?
|
||||
if [1, 2].include?(j) && (!curve[0].visible || !curve[3].visible)
|
||||
next
|
||||
end
|
||||
curve[j].visible = true
|
||||
4.times do |k|
|
||||
curve[k].dragging = (k == j)
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
4.times do |j|
|
||||
next if !curve[j].hittest?
|
||||
if [1, 2].include?(j) && (!curve[0].visible || !curve[3].visible)
|
||||
next
|
||||
curve[j].mouseover
|
||||
end
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
newtext = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
window.text = newtext if window.text != newtext
|
||||
if curve[0].visible && curve[3].visible &&
|
||||
!curve[0].dragging && !curve[3].dragging
|
||||
points.each do |point|
|
||||
point.visible = true
|
||||
end
|
||||
curve[j].visible = true
|
||||
4.times do |k|
|
||||
curve[k].dragging = (k == j)
|
||||
if !showline
|
||||
curve[1].visible = true
|
||||
curve[2].visible = true
|
||||
curve[1].x = curve[0].x + (0.3333 * (curve[3].x - curve[0].x))
|
||||
curve[1].y = curve[0].y + (0.3333 * (curve[3].y - curve[0].y))
|
||||
curve[2].x = curve[0].x + (0.6666 * (curve[3].x - curve[0].x))
|
||||
curve[2].y = curve[0].y + (0.6666 * (curve[3].y - curve[0].y))
|
||||
end
|
||||
showline = true
|
||||
end
|
||||
if showline
|
||||
step = 1.0 / (points.length - 1)
|
||||
t = 0.0
|
||||
points.length.times do |j|
|
||||
point = getCurvePoint(curve, t)
|
||||
points[j].x = point[0]
|
||||
points[j].y = point[1]
|
||||
t += step
|
||||
end
|
||||
end
|
||||
end
|
||||
window.dispose
|
||||
# dispose temporary path
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
if showline
|
||||
path = curveToPointPath(curve, sliderwin2.value(0))
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
path.each do |point|
|
||||
points.push(PointSprite.new(point[0], point[1], canvas.viewport))
|
||||
end
|
||||
end
|
||||
curve.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
sliderwin2.visible = true
|
||||
next
|
||||
elsif sliderwin2.changed?(defpathbutton)
|
||||
canceled = false
|
||||
pointpath = PointPath.new
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
window = Window_UnformattedTextPokemon.newWithSize(
|
||||
"", 0, 320 - 64, 128, 64, canvas.viewport
|
||||
)
|
||||
sliderwin2.visible = false
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.triggerex?(:ESCAPE)
|
||||
canceled = true
|
||||
break
|
||||
end
|
||||
if Input.trigger?(Input::MOUSELEFT)
|
||||
break
|
||||
end
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
window.text = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
end
|
||||
until canceled
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
if mousepos && !pointpath.isEndPoint?(mousepos[0], mousepos[1])
|
||||
pointpath.addPoint(mousepos[0], mousepos[1])
|
||||
points.push(PointSprite.new(mousepos[0], mousepos[1], canvas.viewport))
|
||||
end
|
||||
window.text = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.triggerex?(:ESCAPE) || Input.time?(Input::MOUSELEFT) == 0
|
||||
break
|
||||
end
|
||||
end
|
||||
4.times do |j|
|
||||
curve[j].mouseover
|
||||
window.dispose
|
||||
# dispose temporary path
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
newtext = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
window.text = newtext if window.text != newtext
|
||||
if curve[0].visible && curve[3].visible &&
|
||||
!curve[0].dragging && !curve[3].dragging
|
||||
points.each do |point|
|
||||
point.visible = true
|
||||
end
|
||||
if !showline
|
||||
curve[1].visible = true
|
||||
curve[2].visible = true
|
||||
curve[1].x = curve[0].x + (0.3333 * (curve[3].x - curve[0].x))
|
||||
curve[1].y = curve[0].y + (0.3333 * (curve[3].y - curve[0].y))
|
||||
curve[2].x = curve[0].x + (0.6666 * (curve[3].x - curve[0].x))
|
||||
curve[2].y = curve[0].y + (0.6666 * (curve[3].y - curve[0].y))
|
||||
end
|
||||
showline = true
|
||||
end
|
||||
if showline
|
||||
step = 1.0 / (points.length - 1)
|
||||
t = 0.0
|
||||
points.length.times do |j|
|
||||
point = getCurvePoint(curve, t)
|
||||
points[j].x = point[0]
|
||||
points[j].y = point[1]
|
||||
t += step
|
||||
end
|
||||
end
|
||||
end
|
||||
window.dispose
|
||||
# dispose temporary path
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
if showline
|
||||
path = curveToPointPath(curve, sliderwin2.value(0))
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
points.clear
|
||||
# generate smooth path from temporary path
|
||||
path = pointpath.smoothPointPath(sliderwin2.value(0), true)
|
||||
# redraw path from smooth path
|
||||
path.each do |point|
|
||||
points.push(PointSprite.new(point[0], point[1], canvas.viewport))
|
||||
end
|
||||
end
|
||||
curve.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
sliderwin2.visible = true
|
||||
next
|
||||
elsif sliderwin2.changed?(defpathbutton)
|
||||
canceled = false
|
||||
pointpath = PointPath.new
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
window = Window_UnformattedTextPokemon.newWithSize(
|
||||
"", 0, 320 - 64, 128, 64, canvas.viewport
|
||||
)
|
||||
sliderwin2.visible = false
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.triggerex?(:ESCAPE)
|
||||
canceled = true
|
||||
break
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
sliderwin2.visible = true
|
||||
next
|
||||
elsif sliderwin2.changed?(okbutton) && path
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
neededsize = canvas.currentframe + sliderwin2.value(0)
|
||||
if neededsize > canvas.animation.length
|
||||
canvas.animation.resize(neededsize)
|
||||
end
|
||||
if Input.trigger?(Input::MOUSELEFT)
|
||||
break
|
||||
thiscel = canvas.currentCel
|
||||
celnumber = canvas.currentcel
|
||||
(canvas.currentframe...neededsize).each do |j|
|
||||
cel = canvas.animation[j][celnumber]
|
||||
if !canvas.animation[j][celnumber]
|
||||
cel = pbCreateCel(0, 0, thiscel[AnimFrame::PATTERN], canvas.animation.position)
|
||||
canvas.animation[j][celnumber] = cel
|
||||
end
|
||||
cel[AnimFrame::X] = path[j - canvas.currentframe][0]
|
||||
cel[AnimFrame::Y] = path[j - canvas.currentframe][1]
|
||||
end
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
window.text = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
break
|
||||
elsif sliderwin2.changed?(cancelbutton) || Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
until canceled
|
||||
mousepos = Mouse.getMousePos(true)
|
||||
if mousepos && !pointpath.isEndPoint?(mousepos[0], mousepos[1])
|
||||
pointpath.addPoint(mousepos[0], mousepos[1])
|
||||
points.push(PointSprite.new(mousepos[0], mousepos[1], canvas.viewport))
|
||||
end
|
||||
window.text = (mousepos) ? sprintf("(%d,%d)", mousepos[0], mousepos[1]) : "(??,??)"
|
||||
Graphics.update
|
||||
Input.update
|
||||
if Input.triggerex?(:ESCAPE) || Input.time?(Input::MOUSELEFT) == 0
|
||||
break
|
||||
end
|
||||
end
|
||||
window.dispose
|
||||
# dispose temporary path
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
# generate smooth path from temporary path
|
||||
path = pointpath.smoothPointPath(sliderwin2.value(0), true)
|
||||
# redraw path from smooth path
|
||||
path.each do |point|
|
||||
points.push(PointSprite.new(point[0], point[1], canvas.viewport))
|
||||
end
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
sliderwin2.visible = true
|
||||
next
|
||||
elsif sliderwin2.changed?(okbutton) && path
|
||||
# File.open("pointpath.txt","wb") { |f| f.write(path.inspect) }
|
||||
neededsize = canvas.currentframe + sliderwin2.value(0)
|
||||
if neededsize > canvas.animation.length
|
||||
canvas.animation.resize(neededsize)
|
||||
end
|
||||
thiscel = canvas.currentCel
|
||||
celnumber = canvas.currentcel
|
||||
(canvas.currentframe...neededsize).each do |j|
|
||||
cel = canvas.animation[j][celnumber]
|
||||
if !canvas.animation[j][celnumber]
|
||||
cel = pbCreateCel(0, 0, thiscel[AnimFrame::PATTERN], canvas.animation.position)
|
||||
canvas.animation[j][celnumber] = cel
|
||||
end
|
||||
cel[AnimFrame::X] = path[j - canvas.currentframe][0]
|
||||
cel[AnimFrame::Y] = path[j - canvas.currentframe][1]
|
||||
end
|
||||
break
|
||||
elsif sliderwin2.changed?(cancelbutton) || Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
# dispose all points
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
sliderwin2.dispose
|
||||
return
|
||||
end
|
||||
# dispose all points
|
||||
points.each do |point|
|
||||
point.dispose
|
||||
end
|
||||
points.clear
|
||||
sliderwin2.dispose
|
||||
return
|
||||
end
|
||||
|
||||
@@ -1,143 +1,147 @@
|
||||
################################################################################
|
||||
# Importing and exporting
|
||||
################################################################################
|
||||
def pbRgssChdir(dir)
|
||||
RTP.eachPathFor(dir) { |path| Dir.chdir(path) { yield } }
|
||||
end
|
||||
module BattleAnimationEditor
|
||||
module_function
|
||||
|
||||
def tryLoadData(file)
|
||||
begin
|
||||
return load_data(file)
|
||||
rescue
|
||||
return nil
|
||||
################################################################################
|
||||
# Importing and exporting
|
||||
################################################################################
|
||||
def pbRgssChdir(dir)
|
||||
RTP.eachPathFor(dir) { |path| Dir.chdir(path) { yield } }
|
||||
end
|
||||
end
|
||||
|
||||
def dumpBase64Anim(s)
|
||||
return [Zlib::Deflate.deflate(Marshal.dump(s))].pack("m").gsub(/\n/, "\r\n")
|
||||
end
|
||||
|
||||
def loadBase64Anim(s)
|
||||
return Marshal.restore(Zlib::Inflate.inflate(s.unpack("m")[0]))
|
||||
end
|
||||
|
||||
def pbExportAnim(animations)
|
||||
filename = pbMessageFreeText(_INTL("Enter a filename."), "", false, 32)
|
||||
if filename != ""
|
||||
def tryLoadData(file)
|
||||
begin
|
||||
filename += ".anm"
|
||||
File.open(filename, "wb") do |f|
|
||||
f.write(dumpBase64Anim(animations[animations.selected]))
|
||||
end
|
||||
failed = false
|
||||
return load_data(file)
|
||||
rescue
|
||||
pbMessage(_INTL("Couldn't save the animation to {1}.", filename))
|
||||
failed = true
|
||||
end
|
||||
if !failed
|
||||
pbMessage(_INTL("Animation was saved to {1} in the game folder.", filename))
|
||||
pbMessage(_INTL("It's a text file, so it can be transferred to others easily."))
|
||||
return nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pbImportAnim(animations, canvas, animwin)
|
||||
animfiles = []
|
||||
pbRgssChdir(".") { animfiles.concat(Dir.glob("*.anm")) }
|
||||
cmdwin = pbListWindow(animfiles, 320)
|
||||
cmdwin.opacity = 200
|
||||
cmdwin.height = 480
|
||||
cmdwin.viewport = canvas.viewport
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
cmdwin.update
|
||||
if Input.trigger?(Input::USE) && animfiles.length > 0
|
||||
def dumpBase64Anim(s)
|
||||
return [Zlib::Deflate.deflate(Marshal.dump(s))].pack("m").gsub(/\n/, "\r\n")
|
||||
end
|
||||
|
||||
def loadBase64Anim(s)
|
||||
return Marshal.restore(Zlib::Inflate.inflate(s.unpack("m")[0]))
|
||||
end
|
||||
|
||||
def pbExportAnim(animations)
|
||||
filename = pbMessageFreeText(_INTL("Enter a filename."), "", false, 32)
|
||||
if filename != ""
|
||||
begin
|
||||
textdata = loadBase64Anim(IO.read(animfiles[cmdwin.index]))
|
||||
throw "Bad data" if !textdata.is_a?(PBAnimation)
|
||||
textdata.id = -1 # this is not an RPG Maker XP animation
|
||||
pbConvertAnimToNewFormat(textdata)
|
||||
animations[animations.selected] = textdata
|
||||
filename += ".anm"
|
||||
File.open(filename, "wb") do |f|
|
||||
f.write(dumpBase64Anim(animations[animations.selected]))
|
||||
end
|
||||
failed = false
|
||||
rescue
|
||||
pbMessage(_INTL("The animation is invalid or could not be loaded."))
|
||||
next
|
||||
pbMessage(_INTL("Couldn't save the animation to {1}.", filename))
|
||||
failed = true
|
||||
end
|
||||
graphic = animations[animations.selected].graphic
|
||||
graphic = "Graphics/Animations/#{graphic}"
|
||||
if graphic && graphic != "" && !FileTest.image_exist?(graphic)
|
||||
pbMessage(_INTL("The animation file {1} was not found. The animation will load anyway.", graphic))
|
||||
if !failed
|
||||
pbMessage(_INTL("Animation was saved to {1} in the game folder.", filename))
|
||||
pbMessage(_INTL("It's a text file, so it can be transferred to others easily."))
|
||||
end
|
||||
canvas.loadAnimation(animations[animations.selected])
|
||||
animwin.animbitmap = canvas.animbitmap
|
||||
break
|
||||
end
|
||||
if Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
end
|
||||
cmdwin.dispose
|
||||
return
|
||||
end
|
||||
|
||||
################################################################################
|
||||
# Format conversion
|
||||
################################################################################
|
||||
def pbConvertAnimToNewFormat(textdata)
|
||||
needconverting = false
|
||||
textdata.length.times do |i|
|
||||
next if !textdata[i]
|
||||
PBAnimation::MAX_SPRITES.times do |j|
|
||||
next if !textdata[i][j]
|
||||
needconverting = true if textdata[i][j][AnimFrame::FOCUS].nil?
|
||||
break if needconverting
|
||||
def pbImportAnim(animations, canvas, animwin)
|
||||
animfiles = []
|
||||
pbRgssChdir(".") { animfiles.concat(Dir.glob("*.anm")) }
|
||||
cmdwin = pbListWindow(animfiles, 320)
|
||||
cmdwin.opacity = 200
|
||||
cmdwin.height = 480
|
||||
cmdwin.viewport = canvas.viewport
|
||||
loop do
|
||||
Graphics.update
|
||||
Input.update
|
||||
cmdwin.update
|
||||
if Input.trigger?(Input::USE) && animfiles.length > 0
|
||||
begin
|
||||
textdata = loadBase64Anim(IO.read(animfiles[cmdwin.index]))
|
||||
throw "Bad data" if !textdata.is_a?(PBAnimation)
|
||||
textdata.id = -1 # this is not an RPG Maker XP animation
|
||||
pbConvertAnimToNewFormat(textdata)
|
||||
animations[animations.selected] = textdata
|
||||
rescue
|
||||
pbMessage(_INTL("The animation is invalid or could not be loaded."))
|
||||
next
|
||||
end
|
||||
graphic = animations[animations.selected].graphic
|
||||
graphic = "Graphics/Animations/#{graphic}"
|
||||
if graphic && graphic != "" && !FileTest.image_exist?(graphic)
|
||||
pbMessage(_INTL("The animation file {1} was not found. The animation will load anyway.", graphic))
|
||||
end
|
||||
canvas.loadAnimation(animations[animations.selected])
|
||||
animwin.animbitmap = canvas.animbitmap
|
||||
break
|
||||
end
|
||||
if Input.trigger?(Input::BACK)
|
||||
break
|
||||
end
|
||||
end
|
||||
break if needconverting
|
||||
cmdwin.dispose
|
||||
return
|
||||
end
|
||||
if needconverting
|
||||
|
||||
################################################################################
|
||||
# Format conversion
|
||||
################################################################################
|
||||
def pbConvertAnimToNewFormat(textdata)
|
||||
needconverting = false
|
||||
textdata.length.times do |i|
|
||||
next if !textdata[i]
|
||||
PBAnimation::MAX_SPRITES.times do |j|
|
||||
next if !textdata[i][j]
|
||||
textdata[i][j][AnimFrame::PRIORITY] = 1 if textdata[i][j][AnimFrame::PRIORITY].nil?
|
||||
case j
|
||||
when 0 # User battler
|
||||
textdata[i][j][AnimFrame::FOCUS] = 2
|
||||
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSUSER_X
|
||||
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSUSER_Y
|
||||
when 1 # Target battler
|
||||
textdata[i][j][AnimFrame::FOCUS] = 1
|
||||
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSTARGET_X
|
||||
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSTARGET_Y
|
||||
else
|
||||
textdata[i][j][AnimFrame::FOCUS] = (textdata.position || 4)
|
||||
if textdata.position == 1
|
||||
textdata[i][j][AnimFrame::X] += Battle::Scene::FOCUSTARGET_X
|
||||
textdata[i][j][AnimFrame::Y] += Battle::Scene::FOCUSTARGET_Y - 2
|
||||
needconverting = true if textdata[i][j][AnimFrame::FOCUS].nil?
|
||||
break if needconverting
|
||||
end
|
||||
break if needconverting
|
||||
end
|
||||
if needconverting
|
||||
textdata.length.times do |i|
|
||||
next if !textdata[i]
|
||||
PBAnimation::MAX_SPRITES.times do |j|
|
||||
next if !textdata[i][j]
|
||||
textdata[i][j][AnimFrame::PRIORITY] = 1 if textdata[i][j][AnimFrame::PRIORITY].nil?
|
||||
case j
|
||||
when 0 # User battler
|
||||
textdata[i][j][AnimFrame::FOCUS] = 2
|
||||
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSUSER_X
|
||||
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSUSER_Y
|
||||
when 1 # Target battler
|
||||
textdata[i][j][AnimFrame::FOCUS] = 1
|
||||
textdata[i][j][AnimFrame::X] = Battle::Scene::FOCUSTARGET_X
|
||||
textdata[i][j][AnimFrame::Y] = Battle::Scene::FOCUSTARGET_Y
|
||||
else
|
||||
textdata[i][j][AnimFrame::FOCUS] = (textdata.position || 4)
|
||||
if textdata.position == 1
|
||||
textdata[i][j][AnimFrame::X] += Battle::Scene::FOCUSTARGET_X
|
||||
textdata[i][j][AnimFrame::Y] += Battle::Scene::FOCUSTARGET_Y - 2
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return needconverting
|
||||
end
|
||||
return needconverting
|
||||
end
|
||||
|
||||
def pbConvertAnimsToNewFormat
|
||||
pbMessage(_INTL("Will convert animations now."))
|
||||
count = 0
|
||||
animations = pbLoadBattleAnimations
|
||||
if !animations || !animations[0]
|
||||
pbMessage(_INTL("No animations exist."))
|
||||
return
|
||||
def pbConvertAnimsToNewFormat
|
||||
pbMessage(_INTL("Will convert animations now."))
|
||||
count = 0
|
||||
animations = pbLoadBattleAnimations
|
||||
if !animations || !animations[0]
|
||||
pbMessage(_INTL("No animations exist."))
|
||||
return
|
||||
end
|
||||
animations.length.times do |k|
|
||||
next if !animations[k]
|
||||
ret = pbConvertAnimToNewFormat(animations[k])
|
||||
count += 1 if ret
|
||||
end
|
||||
if count > 0
|
||||
save_data(animations, "Data/PkmnAnimations.rxdata")
|
||||
$game_temp.battle_animations_data = nil
|
||||
end
|
||||
pbMessage(_INTL("{1} animations converted to new format.", count))
|
||||
end
|
||||
animations.length.times do |k|
|
||||
next if !animations[k]
|
||||
ret = pbConvertAnimToNewFormat(animations[k])
|
||||
count += 1 if ret
|
||||
end
|
||||
if count > 0
|
||||
save_data(animations, "Data/PkmnAnimations.rxdata")
|
||||
$game_temp.battle_animations_data = nil
|
||||
end
|
||||
pbMessage(_INTL("{1} animations converted to new format.", count))
|
||||
end
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -558,7 +558,7 @@ def pbExportAllAnimations
|
||||
safename = anim.name.gsub(/\W/, "_")
|
||||
Dir.mkdir("Animations/#{safename}") rescue nil
|
||||
File.open("Animations/#{safename}/#{safename}.anm", "wb") do |f|
|
||||
f.write(dumpBase64Anim(anim))
|
||||
f.write(BattleAnimationEditor.dumpBase64Anim(anim))
|
||||
end
|
||||
if anim.graphic && anim.graphic != ""
|
||||
graphicname = RTP.getImagePath("Graphics/Animations/" + anim.graphic)
|
||||
@@ -626,13 +626,13 @@ def pbImportAllAnimations
|
||||
pbSafeCopyFile(image, RTP.getImagePath("Graphics/Animations/" + File.basename(image)), "Graphics/Animations/" + File.basename(image))
|
||||
end
|
||||
Dir.glob(folder + "/*.anm") do |f|
|
||||
textdata = loadBase64Anim(IO.read(f)) rescue nil
|
||||
textdata = BattleAnimationEditor.loadBase64Anim(IO.read(f)) rescue nil
|
||||
if textdata.is_a?(PBAnimation)
|
||||
index = pbAllocateAnimation(animations, textdata.name)
|
||||
missingFiles = []
|
||||
textdata.name = File.basename(folder) if textdata.name == ""
|
||||
textdata.id = -1 # This is not an RPG Maker XP animation
|
||||
pbConvertAnimToNewFormat(textdata)
|
||||
BattleAnimationEditor.pbConvertAnimToNewFormat(textdata)
|
||||
if textdata.graphic && textdata.graphic != "" &&
|
||||
!safeExists?(folder + "/" + textdata.graphic) &&
|
||||
!FileTest.image_exist?("Graphics/Animations/" + textdata.graphic)
|
||||
|
||||
@@ -769,7 +769,7 @@ MenuHandlers.add(:pokemon_debug_menu, :species_and_form, {
|
||||
form_name = sprintf("%d: %s", sp.form, form_name)
|
||||
formcmds[0].push(sp.form)
|
||||
formcmds[1].push(form_name)
|
||||
cmd2 = sp.form if pkmn.form == sp.form
|
||||
cmd2 = formcmds[0].length - 1 if pkmn.form == sp.form
|
||||
end
|
||||
if formcmds[0].length <= 1
|
||||
screen.pbDisplay(_INTL("Species {1} only has one form.", pkmn.speciesName))
|
||||
|
||||
@@ -677,9 +677,9 @@ module Compiler
|
||||
else
|
||||
(0...battles.length).each do |i|
|
||||
if i == battles.length - 1
|
||||
push_branch(lastpage.list, sprintf("Phone.variant_beaten(%s) >= %d", safetrcombo, i))
|
||||
push_branch(lastpage.list, sprintf("Phone.variant(%s) >= %d", safetrcombo, i))
|
||||
else
|
||||
push_branch(lastpage.list, sprintf("Phone.variant_beaten(%s) == %d", safetrcombo, i))
|
||||
push_branch(lastpage.list, sprintf("Phone.variant(%s) == %d", safetrcombo, i))
|
||||
end
|
||||
ebattle = (endbattles[i]) ? endbattles[i] : endbattles[endbattles.length - 1]
|
||||
push_text(lastpage.list, ebattle, 1)
|
||||
|
||||
Reference in New Issue
Block a user