Remove Scripts folder to convert to submodule

This commit is contained in:
chardub
2025-04-19 15:43:57 -04:00
parent 0807a7ea79
commit 58da1023c1
429 changed files with 0 additions and 165507 deletions

View File

@@ -1,96 +0,0 @@
# The SaveData module is used to manipulate save data. It contains the {Value}s
# that make up the save data and {Conversion}s for resolving incompatibilities
# between Essentials and game versions.
# @see SaveData.register
# @see SaveData.register_conversion
module SaveData
# Contains the file path of the save file.
FILE_PATH = if File.directory?(System.data_directory)
System.data_directory + '/Game.rxdata'
else
'./Game.rxdata'
end
# @return [Boolean] whether the save file exists
def self.exists?
return File.file?(FILE_PATH)
end
# Fetches the save data from the given file.
# Returns an Array in the case of a pre-v19 save file.
# @param file_path [String] path of the file to load from
# @return [Hash, Array] loaded save data
# @raise [IOError, SystemCallError] if file opening fails
def self.get_data_from_file(file_path) validate file_path => String
save_data = nil
File.open(file_path) do |file|
data = Marshal.load(file)
if data.is_a?(Hash)
save_data = data
next
end
save_data = [data]
save_data << Marshal.load(file) until file.eof?
end
return save_data
end
# Fetches save data from the given file. If it needed converting, resaves it.
# @param file_path [String] path of the file to read from
# @return [Hash] save data in Hash format
# @raise (see .get_data_from_file)
def self.read_from_file(file_path)
validate file_path => String
save_data = get_data_from_file(file_path)
save_data = to_hash_format(save_data) if save_data.is_a?(Array)
if !save_data.empty? && run_conversions(save_data)
File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) }
end
return save_data
end
# Compiles the save data and saves a marshaled version of it into
# the given file.
# @param file_path [String] path of the file to save into
# @raise [InvalidValueError] if an invalid value is being saved
def self.save_to_file(file_path)
validate file_path => String
save_data = self.compile_save_hash
File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) }
end
# Deletes the save file (and a possible .bak backup file if one exists)
# @raise [Error::ENOENT]
def self.delete_file
File.delete(FILE_PATH)
File.delete(FILE_PATH + '.bak') if File.file?(FILE_PATH + '.bak')
end
# Converts the pre-v19 format data to the new format.
# @param old_format [Array] pre-v19 format save data
# @return [Hash] save data in new format
def self.to_hash_format(old_format)
validate old_format => Array
hash = {}
@values.each do |value|
data = value.get_from_old_format(old_format)
hash[value.id] = data unless data.nil?
end
return hash
end
# Moves a save file from the old Saved Games folder to the new
# location specified by {FILE_PATH}. Does nothing if a save file
# already exists in {FILE_PATH}.
def self.move_old_windows_save
return if File.file?(FILE_PATH)
game_title = System.game_title.gsub(/[^\w ]/, '_')
home = ENV['HOME'] || ENV['HOMEPATH']
return if home.nil?
old_location = File.join(home, 'Saved Games', game_title)
return unless File.directory?(old_location)
old_file = File.join(old_location, 'Game.rxdata')
return unless File.file?(old_file)
File.move(old_file, FILE_PATH)
end
end

View File

@@ -1,269 +0,0 @@
module SaveData
# Contains Value objects for each save element.
# Populated during runtime by SaveData.register calls.
# @type [Array<Value>]
@values = []
# An error raised if an invalid save value is being saved or loaded.
class InvalidValueError < RuntimeError; end
#=============================================================================
# Represents a single value in save data.
# New values are added using {SaveData.register}.
class Value
# @return [Symbol] the value id
attr_reader :id
# @param id [Symbol] value id
def initialize(id, &block)
validate id => Symbol, block => Proc
@id = id
@loaded = false
@load_in_bootup = false
instance_eval(&block)
raise "No save_value defined for save value #{id.inspect}" if @save_proc.nil?
raise "No load_value defined for save value #{id.inspect}" if @load_proc.nil?
end
# @param value [Object] value to check
# @return [Boolean] whether the given value is valid
def valid?(value)
return true if @ensured_class.nil?
return value.is_a?(Object.const_get(@ensured_class))
end
# Calls the value's load proc with the given argument passed into it.
# @param value [Object] load proc argument
# @raise [InvalidValueError] if an invalid value is being loaded
def load(value)
validate_value(value)
@load_proc.call(value)
@loaded = true
end
# Calls the value's save proc and returns its value.
# @return [Object] save proc value
# @raise [InvalidValueError] if an invalid value is being saved
def save
value = @save_proc.call
validate_value(value)
return value
end
# @return [Boolean] whether the value has a new game value proc defined
def has_new_game_proc?
return @new_game_value_proc.is_a?(Proc)
end
# Calls the save value's load proc with the value fetched
# from the defined new game value proc.
# @raise (see #load)
def load_new_game_value
unless self.has_new_game_proc?
raise "Save value #{@id.inspect} has no new_game_value defined"
end
self.load(@new_game_value_proc.call)
end
# @return [Boolean] whether the value should be loaded during bootup
def load_in_bootup?
return @load_in_bootup
end
# @return [Boolean] whether the value has been loaded
def loaded?
return @loaded
end
# Marks value as unloaded.
def mark_as_unloaded
@loaded = false
end
# Uses the {#from_old_format} proc to select the correct data from
# +old_format+ and return it.
# Returns nil if the proc is undefined.
# @param old_format [Array] old format to load value from
# @return [Object] data from the old format
def get_from_old_format(old_format)
return nil if @old_format_get_proc.nil?
return @old_format_get_proc.call(old_format)
end
private
# Raises an {InvalidValueError} if the given value is invalid.
# @param value [Object] value to check
# @raise [InvalidValueError] if the value is invalid
def validate_value(value)
return if self.valid?(value)
raise InvalidValueError, "Save value #{@id.inspect} is not a #{@ensured_class} (#{value.class.name} given)"
end
# @!group Configuration
# If present, ensures that the value is of the given class.
# @param class_name [Symbol] class to enforce
# @see SaveData.register
def ensure_class(class_name)
validate class_name => Symbol
@ensured_class = class_name
end
# Defines how the loaded value is placed into a global variable.
# Requires a block with the loaded value as its parameter.
# @see SaveData.register
def load_value(&block)
raise ArgumentError, 'No block given to load_value' unless block_given?
@load_proc = block
end
# Defines what is saved into save data. Requires a block.
# @see SaveData.register
def save_value(&block)
raise ArgumentError, 'No block given to save_value' unless block_given?
@save_proc = block
end
# If present, defines what the value is set to at the start of a new game.
# @see SaveData.register
def new_game_value(&block)
raise ArgumentError, 'No block given to new_game_value' unless block_given?
@new_game_value_proc = block
end
# If present, sets the value to be loaded during bootup.
# @see SaveData.register
def load_in_bootup
@load_in_bootup = true
end
# If present, defines how the value should be fetched from the pre-v19
# save format. Requires a block with the old format array as its parameter.
# @see SaveData.register
def from_old_format(&block)
raise ArgumentError, 'No block given to from_old_format' unless block_given?
@old_format_get_proc = block
end
# @!endgroup
end
#=============================================================================
# Registers a {Value} to be saved into save data.
# Takes a block which defines the value's saving ({Value#save_value})
# and loading ({Value#load_value}) procedures.
#
# It is also possible to provide a proc for fetching the value
# from the pre-v19 format ({Value#from_old_format}), define
# a value to be set upon starting a new game with {Value#new_game_value}
# and ensure that the saved and loaded value is of the correct
# class with {Value#ensure_class}.
#
# Values can be registered to be loaded on bootup with
# {Value#load_in_bootup}. If a new_game_value proc is defined, it
# will be called when the game is launched for the first time,
# or if the save data does not contain the value in question.
#
# @example Registering a new value
# SaveData.register(:foo) do
# ensure_class :Foo
# save_value { $foo }
# load_value { |value| $foo = value }
# new_game_value { Foo.new }
# from_old_format { |old_format| old_format[16] if old_format[16].is_a?(Foo) }
# end
# @example Registering a value to be loaded on bootup
# SaveData.register(:bar) do
# load_in_bootup
# save_value { $bar }
# load_value { |value| $bar = value }
# new_game_value { Bar.new }
# end
# @param id [Symbol] value id
# @yieldself [Value]
def self.register(id, &block)
validate id => Symbol
unless block_given?
raise ArgumentError, 'No block given to SaveData.register'
end
@values << Value.new(id, &block)
end
# @param save_data [Hash] save data to validate
# @return [Boolean] whether the given save data is valid
def self.valid?(save_data)
validate save_data => Hash
return @values.all? { |value| value.valid?(save_data[value.id]) }
end
# Loads values from the given save data.
# An optional condition can be passed.
# @param save_data [Hash] save data to load from
# @param condition_block [Proc] optional condition
# @api private
def self.load_values(save_data, &condition_block)
@values.each do |value|
next if block_given? && !condition_block.call(value)
if save_data.has_key?(value.id)
value.load(save_data[value.id])
elsif value.has_new_game_proc?
value.load_new_game_value
end
end
end
# Loads the values from the given save data by
# calling each {Value} object's {Value#load_value} proc.
# Values that are already loaded are skipped.
# If a value does not exist in the save data and has
# a {Value#new_game_value} proc defined, that value
# is loaded instead.
# @param save_data [Hash] save data to load
# @raise [InvalidValueError] if an invalid value is being loaded
def self.load_all_values(save_data)
validate save_data => Hash
load_values(save_data) { |value| !value.loaded? }
end
# Marks all values that aren't loaded on bootup as unloaded.
def self.mark_values_as_unloaded
@values.each do |value|
value.mark_as_unloaded unless value.load_in_bootup?
end
end
# Loads each value from the given save data that has
# been set to be loaded during bootup. Done when a save file exists.
# @param save_data [Hash] save data to load
# @raise [InvalidValueError] if an invalid value is being loaded
def self.load_bootup_values(save_data)
validate save_data => Hash
load_values(save_data) { |value| !value.loaded? && value.load_in_bootup? }
end
# Goes through each value with {Value#load_in_bootup} enabled and loads their
# new game value, if one is defined. Done when no save file exists.
def self.initialize_bootup_values
@values.each do |value|
next unless value.load_in_bootup?
value.load_new_game_value if value.has_new_game_proc? && !value.loaded?
end
end
# Loads each {Value}'s new game value, if one is defined. Done when starting a
# new game.
def self.load_new_game_values
@values.each do |value|
value.load_new_game_value if value.has_new_game_proc? && !value.loaded?
end
end
# @return [Hash{Symbol => Object}] a hash representation of the save data
# @raise [InvalidValueError] if an invalid value is being saved
def self.compile_save_hash
save_data = {}
@values.each { |value| save_data[value.id] = value.save }
return save_data
end
end

View File

@@ -1,221 +0,0 @@
module SaveData
# Contains Conversion objects for each defined conversion:
# {
# :essentials => {
# '19' => [<Conversion>, ...],
# '19.1' => [<Conversion>, ...],
# ...
# },
# :game => {
# '1.1.0' => [<Conversion>, ...],
# '1.2.0' => [<Conversion>, ...],
# ...
# }
# }
# Populated during runtime by SaveData.register_conversion calls.
@conversions = {
essentials: {},
game: {}
}
#=============================================================================
# Represents a conversion made to save data.
# New conversions are added using {SaveData.register_conversion}.
class Conversion
# @return [Symbol] conversion ID
attr_reader :id
# @return [String] conversion title
attr_reader :title
# @return [Symbol] trigger type of the conversion (+:essentials+ or +:game+)
attr_reader :trigger_type
# @return [String] trigger version of the conversion
attr_reader :version
# @param id [String] conversion ID
def initialize(id, &block)
@id = id
@value_procs = {}
@all_proc = nil
@title = "Running conversion #{@id}"
@trigger_type = nil
@version = nil
instance_eval(&block)
if @trigger_type.nil? || @version.nil?
raise "Conversion #{@id} is missing a condition"
end
end
# Returns whether the conversion should be run with the given version.
# @param version [String] version to check
# @return [Boolean] whether the conversion should be run
def should_run?(version)
return PluginManager.compare_versions(version, @version) < 0
end
# Runs the conversion on the given save data.
# @param save_data [Hash]
def run(save_data)
@value_procs.each do |value_id, proc|
unless save_data.has_key?(value_id)
raise "Save data does not have value #{value_id.inspect}"
end
proc.call(save_data[value_id])
end
@all_proc.call(save_data) if @all_proc.is_a?(Proc)
end
# Runs the conversion on the given object.
# @param object
# @param key [Symbol]
def run_single(object, key)
@value_procs[key].call(object) if @value_procs[key].is_a?(Proc)
end
private
# @!group Configuration
# Sets the conversion's title.
# @param new_title [String] conversion title
# @note Since conversions are run before loading the player's chosen language,
# conversion titles can not be localized.
# @see SaveData.register_conversion
def display_title(new_title)
validate new_title => String
@title = new_title
end
# Sets the conversion to trigger for save files created below
# the given Essentials version.
# @param version [Numeric, String]
# @see SaveData.register_conversion
def essentials_version(version)
validate version => [Numeric, String]
raise "Multiple conditions in conversion #{@id}" unless @version.nil?
@trigger_type = :essentials
@version = version.to_s
end
# Sets the conversion to trigger for save files created below
# the given game version.
# @param version [Numeric, String]
# @see SaveData.register_conversion
def game_version(version)
validate version => [Numeric, String]
raise "Multiple conditions in conversion #{@id}" unless @version.nil?
@trigger_type = :game
@version = version.to_s
end
# Defines a conversion to the given save value.
# @param value_id [Symbol] save value ID
# @see SaveData.register_conversion
def to_value(value_id, &block)
validate value_id => Symbol
raise ArgumentError, 'No block given to to_value' unless block_given?
if @value_procs[value_id].is_a?(Proc)
raise "Multiple to_value definitions in conversion #{@id} for #{value_id}"
end
@value_procs[value_id] = block
end
# Defines a conversion to the entire save data.
# @see SaveData.register_conversion
def to_all(&block)
raise ArgumentError, 'No block given to to_all' unless block_given?
if @all_proc.is_a?(Proc)
raise "Multiple to_all definitions in conversion #{@id}"
end
@all_proc = block
end
# @!endgroup
end
#=============================================================================
# Registers a {Conversion} to occur for save data that meets the given criteria.
# Two types of criteria can be defined: {Conversion#essentials_version} and
# {Conversion#game_version}. The conversion is automatically run on save data
# that contains an older version number.
#
# A single value can be modified with {Conversion#to_value}. The entire save data
# is accessed with {Conversion#to_all}, and a conversion title can be specified
# with {Conversion#display_title}.
# @example Registering a new conversion
# SaveData.register_conversion(:my_conversion) do
# game_version '1.1.0'
# display_title 'Converting some stuff'
# to_value :player do |player|
# # code that modifies the :player value
# end
# to_all do |save_data|
# save_data[:new_value] = Foo.new
# end
# end
# @yield self [Conversion]
def self.register_conversion(id, &block)
validate id => Symbol
unless block_given?
raise ArgumentError, 'No block given to SaveData.register_conversion'
end
conversion = Conversion.new(id, &block)
@conversions[conversion.trigger_type][conversion.version] ||= []
@conversions[conversion.trigger_type][conversion.version] << conversion
end
# @param save_data [Hash] save data to get conversions for
# @return [Array<Conversion>] all conversions that should be run on the data
def self.get_conversions(save_data)
conversions_to_run = []
versions = {
essentials: save_data[:essentials_version] || '18.1',
game: save_data[:game_version] || '0.0.0'
}
[:essentials, :game].each do |trigger_type|
# Ensure the versions are sorted from lowest to highest
sorted_versions = @conversions[trigger_type].keys.sort do |v1, v2|
PluginManager.compare_versions(v1, v2)
end
sorted_versions.each do |version|
@conversions[trigger_type][version].each do |conversion|
next unless conversion.should_run?(versions[trigger_type])
conversions_to_run << conversion
end
end
end
return conversions_to_run
end
# Runs all possible conversions on the given save data.
# Saves a backup before running conversions.
# @param save_data [Hash] save data to run conversions on
# @return [Boolean] whether conversions were run
def self.run_conversions(save_data)
validate save_data => Hash
conversions_to_run = self.get_conversions(save_data)
return false if conversions_to_run.none?
File.open(SaveData::FILE_PATH + '.bak', 'wb') { |f| Marshal.dump(save_data, f) }
echoln "Running #{conversions_to_run.length} conversions..."
conversions_to_run.each do |conversion|
echo "#{conversion.title}..."
conversion.run(save_data)
echoln ' done.'
end
echoln '' if conversions_to_run.length > 0
save_data[:essentials_version] = Essentials::VERSION
save_data[:game_version] = Settings::GAME_VERSION
return true
end
# Runs all possible conversions on the given object.
# @param object [Hash] object to run conversions on
# @param key [Hash] object's key in save data
# @param save_data [Hash] save data to run conversions on
def self.run_single_conversions(object, key, save_data)
validate key => Symbol
conversions_to_run = self.get_conversions(save_data)
conversions_to_run.each do |conversion|
conversion.run_single(object, key)
end
end
end

View File

@@ -1,135 +0,0 @@
# Contains the save values defined in Essentials by default.
SaveData.register(:player) do
ensure_class :Player
save_value { $Trainer }
load_value { |value| $Trainer = value }
new_game_value {
trainer_type = nil # Get the first defined trainer type as a placeholder
GameData::TrainerType.each { |t| trainer_type = t.id; break }
Player.new("Unnamed", trainer_type)
}
from_old_format { |old_format| old_format[0] }
end
SaveData.register(:frame_count) do
ensure_class :Integer
save_value { Graphics.frame_count }
load_value { |value| Graphics.frame_count = value }
new_game_value { 0 }
from_old_format { |old_format| old_format[1] }
end
SaveData.register(:game_system) do
load_in_bootup
ensure_class :Game_System
save_value { $game_system }
load_value { |value| $game_system = value }
new_game_value { Game_System.new }
from_old_format { |old_format| old_format[2] }
end
SaveData.register(:pokemon_system) do
load_in_bootup
ensure_class :PokemonSystem
save_value { $PokemonSystem }
load_value { |value| $PokemonSystem = value }
new_game_value { PokemonSystem.new }
from_old_format { |old_format| old_format[3] }
end
SaveData.register(:switches) do
ensure_class :Game_Switches
save_value { $game_switches }
load_value { |value| $game_switches = value }
new_game_value { Game_Switches.new }
from_old_format { |old_format| old_format[5] }
end
SaveData.register(:variables) do
ensure_class :Game_Variables
save_value { $game_variables }
load_value { |value| $game_variables = value }
new_game_value { Game_Variables.new }
from_old_format { |old_format| old_format[6] }
end
SaveData.register(:self_switches) do
ensure_class :Game_SelfSwitches
save_value { $game_self_switches }
load_value { |value| $game_self_switches = value }
new_game_value { Game_SelfSwitches.new }
from_old_format { |old_format| old_format[7] }
end
SaveData.register(:game_screen) do
ensure_class :Game_Screen
save_value { $game_screen }
load_value { |value| $game_screen = value }
new_game_value { Game_Screen.new }
from_old_format { |old_format| old_format[8] }
end
SaveData.register(:map_factory) do
ensure_class :PokemonMapFactory
save_value { $MapFactory }
load_value { |value| $MapFactory = value }
from_old_format { |old_format| old_format[9] }
end
SaveData.register(:game_player) do
ensure_class :Game_Player
save_value { $game_player }
load_value { |value| $game_player = value }
new_game_value { Game_Player.new }
from_old_format { |old_format| old_format[10] }
end
SaveData.register(:global_metadata) do
ensure_class :PokemonGlobalMetadata
save_value { $PokemonGlobal }
load_value { |value| $PokemonGlobal = value }
new_game_value { PokemonGlobalMetadata.new }
from_old_format { |old_format| old_format[11] }
end
SaveData.register(:map_metadata) do
ensure_class :PokemonMapMetadata
save_value { $PokemonMap }
load_value { |value| $PokemonMap = value }
new_game_value { PokemonMapMetadata.new }
from_old_format { |old_format| old_format[12] }
end
SaveData.register(:bag) do
ensure_class :PokemonBag
save_value { $PokemonBag }
load_value { |value| $PokemonBag = value }
new_game_value { PokemonBag.new }
from_old_format { |old_format| old_format[13] }
end
SaveData.register(:storage_system) do
ensure_class :PokemonStorage
save_value { $PokemonStorage }
load_value { |value| $PokemonStorage = value }
new_game_value { PokemonStorage.new }
from_old_format { |old_format| old_format[14] }
end
SaveData.register(:essentials_version) do
load_in_bootup
ensure_class :String
save_value { Essentials::VERSION }
load_value { |value| $SaveVersion = value }
new_game_value { Essentials::VERSION }
from_old_format { |old_format| old_format[15] }
end
SaveData.register(:game_version) do
load_in_bootup
ensure_class :String
save_value { Settings::GAME_VERSION }
load_value { |value| $game_version = value }
new_game_value { Settings::GAME_VERSION }
end

View File

@@ -1,242 +0,0 @@
# Contains conversions defined in Essentials by default.
SaveData.register_conversion(:v19_define_versions) do
essentials_version 19
display_title 'Adding game version and Essentials version to save data'
to_all do |save_data|
unless save_data.has_key?(:essentials_version)
save_data[:essentials_version] = Essentials::VERSION
end
unless save_data.has_key?(:game_version)
save_data[:game_version] = Settings::GAME_VERSION
end
end
end
SaveData.register_conversion(:v19_convert_PokemonSystem) do
essentials_version 19
display_title 'Updating PokemonSystem class'
to_all do |save_data|
new_system = PokemonSystem.new
new_system.textspeed = save_data[:pokemon_system].textspeed || new_system.textspeed
new_system.battlescene = save_data[:pokemon_system].battlescene || new_system.battlescene
new_system.battlestyle = save_data[:pokemon_system].battlestyle || new_system.battlestyle
new_system.frame = save_data[:pokemon_system].frame || new_system.frame
new_system.textskin = save_data[:pokemon_system].textskin || new_system.textskin
new_system.screensize = save_data[:pokemon_system].screensize || new_system.screensize
new_system.language = save_data[:pokemon_system].language || new_system.language
new_system.runstyle = save_data[:pokemon_system].runstyle || new_system.runstyle
new_system.bgmvolume = save_data[:pokemon_system].bgmvolume || new_system.bgmvolume
new_system.sevolume = save_data[:pokemon_system].sevolume || new_system.sevolume
new_system.textinput = save_data[:pokemon_system].textinput || new_system.textinput
save_data[:pokemon_system] = new_system
end
end
SaveData.register_conversion(:v19_convert_player) do
essentials_version 19
display_title 'Converting player trainer class'
to_all do |save_data|
next if save_data[:player].is_a?(Player)
# Conversion of the party is handled in PokeBattle_Trainer.convert
save_data[:player] = PokeBattle_Trainer.convert(save_data[:player])
end
end
SaveData.register_conversion(:v19_move_global_data_to_player) do
essentials_version 19
display_title 'Moving some global metadata data to player'
to_all do |save_data|
global = save_data[:global_metadata]
player = save_data[:player]
player.character_ID = global.playerID
global.playerID = nil
global.pokedexUnlocked.each_with_index do |value, i|
if value
player.pokedex.unlock(i)
else
player.pokedex.lock(i)
end
end
player.coins = global.coins
global.coins = nil
player.soot = global.sootsack
global.sootsack = nil
player.has_running_shoes = global.runningShoes
global.runningShoes = nil
player.seen_storage_creator = global.seenStorageCreator
global.seenStorageCreator = nil
player.has_snag_machine = global.snagMachine
global.snagMachine = nil
player.seen_purify_chamber = global.seenPurifyChamber
global.seenPurifyChamber = nil
end
end
SaveData.register_conversion(:v19_convert_global_metadata) do
essentials_version 19
display_title 'Adding encounter version variable to global metadata'
to_value :global_metadata do |global|
global.bridge ||= 0
global.encounter_version ||= 0
if global.pcItemStorage
global.pcItemStorage.items.each_with_index do |slot, i|
item_data = GameData::Item.try_get(slot[0])
if item_data
slot[0] = item_data.id
else
global.pcItemStorage.items[i] = nil
end
end
global.pcItemStorage.items.compact!
end
if global.mailbox
global.mailbox.each_with_index do |mail, i|
global.mailbox[i] = PokemonMail.convert(mail) if mail
end
end
global.phoneNumbers.each do |contact|
contact[1] = GameData::TrainerType.get(contact[1]).id if contact && contact.length == 8
end
if global.partner
global.partner[0] = GameData::TrainerType.get(global.partner[0]).id
global.partner[3].each_with_index do |pkmn, i|
global.partner[3][i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
end
end
if global.daycare
global.daycare.each do |slot|
slot[0] = PokeBattle_Pokemon.convert(slot[0]) if slot && slot[0]
end
end
if global.roamPokemon
global.roamPokemon.each_with_index do |pkmn, i|
global.roamPokemon[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn && pkmn != true
end
end
global.purifyChamber.sets.each do |set|
set.shadow = PokeBattle_Pokemon.convert(set.shadow) if set.shadow
set.list.each_with_index do |pkmn, i|
set.list[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
end
end
if global.hallOfFame
global.hallOfFame.each do |team|
next if !team
team.each_with_index do |pkmn, i|
team[i] = PokeBattle_Pokemon.convert(pkmn) if pkmn
end
end
end
if global.triads
global.triads.items.each do |card|
card[0] = GameData::Species.get(card[0]).id if card && card[0] && card[0] != 0
end
end
end
end
SaveData.register_conversion(:v19_1_fix_phone_contacts) do
essentials_version 19.1
display_title 'Fixing phone contacts data'
to_value :global_metadata do |global|
global.phoneNumbers.each do |contact|
contact[1] = GameData::TrainerType.get(contact[1]).id if contact && contact.length == 8
end
end
end
SaveData.register_conversion(:v19_convert_bag) do
essentials_version 19
display_title 'Converting item IDs in Bag'
to_value :bag do |bag|
bag.instance_eval do
for pocket in self.pockets
pocket.each_with_index do |item, i|
next if !item || !item[0] || item[0] == 0
item_data = GameData::Item.try_get(item[0])
if item_data
item[0] = item_data.id
else
pocket[i] = nil
end
end
pocket.compact!
end
self.registeredIndex # Just to ensure this data exists
self.registeredItems.each_with_index do |item, i|
next if !item
if item == 0
self.registeredItems[i] = nil
else
item_data = GameData::Item.try_get(item)
if item_data
self.registeredItems[i] = item_data.id
else
self.registeredItems[i] = nil
end
end
end
self.registeredItems.compact!
end # bag.instance_eval
end # to_value
end
SaveData.register_conversion(:v19_convert_game_variables) do
essentials_version 19
display_title 'Converting classes of things in Game Variables'
to_all do |save_data|
variables = save_data[:variables]
for i in 0..5000
value = variables[i]
next if value.nil?
if value.is_a?(Array)
value.each_with_index do |value2, j|
if value2.is_a?(PokeBattle_Pokemon)
value[j] = PokeBattle_Pokemon.convert(value2)
end
end
elsif value.is_a?(PokeBattle_Pokemon)
variables[i] = PokeBattle_Pokemon.convert(value)
elsif value.is_a?(PokemonBag)
SaveData.run_single_conversions(value, :bag, save_data)
end
end
end
end
SaveData.register_conversion(:v19_convert_storage) do
essentials_version 19
display_title 'Converting classes of Pokémon in storage'
to_value :storage_system do |storage|
storage.instance_eval do
for box in 0...self.maxBoxes
for i in 0...self.maxPokemon(box)
self[box, i] = PokeBattle_Pokemon.convert(self[box, i]) if self[box, i]
end
end
self.unlockedWallpapers # Just to ensure this data exists
end # storage.instance_eval
end # to_value
end
SaveData.register_conversion(:v19_convert_game_player) do
essentials_version 19
display_title 'Converting game player character'
to_value :game_player do |game_player|
game_player.width = 1
game_player.height = 1
game_player.sprite_size = [Game_Map::TILE_WIDTH, Game_Map::TILE_HEIGHT]
game_player.pattern_surf ||= 0
game_player.lock_pattern ||= false
game_player.move_speed = game_player.move_speed
end
end
SaveData.register_conversion(:v19_convert_game_screen) do
essentials_version 19
display_title 'Converting game screen'
to_value :game_screen do |game_screen|
game_screen.weather(game_screen.weather_type, game_screen.weather_max, 0)
end
end