mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-06 06:01:46 +00:00
Tidied, fixed some bugs
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#==============================================================================#
|
||||
# Pokémon Essentials #
|
||||
# Version 18.1.dev #
|
||||
# Version 19 #
|
||||
# https://github.com/Maruno17/pokemon-essentials #
|
||||
#==============================================================================#
|
||||
|
||||
module Settings
|
||||
# The version of the game. It has to adhere to the MAJOR.MINOR.PATCH format.
|
||||
# The version of your game. It has to adhere to the MAJOR.MINOR.PATCH format.
|
||||
GAME_VERSION = '1.0.0'
|
||||
|
||||
# The generation that the battle system follows. Used throughout the battle
|
||||
@@ -397,7 +397,8 @@ module Settings
|
||||
]
|
||||
end
|
||||
|
||||
# DO NOT EDIT THESE!
|
||||
module Essentials
|
||||
VERSION = "18.1.dev"
|
||||
VERSION = "19"
|
||||
ERROR_TEXT = ""
|
||||
end
|
||||
end
|
||||
|
||||
@@ -162,7 +162,7 @@ class Bitmap
|
||||
end
|
||||
end
|
||||
# Zlib deflation
|
||||
smoldata = Zlib::Deflate.deflate(data.pack("C*")).bytes.map
|
||||
smoldata = Zlib::Deflate.deflate(data.pack("C*")).bytes.map { |e| e.to_i }
|
||||
# data chunk length
|
||||
f.write_int smoldata.size
|
||||
# IDAT
|
||||
|
||||
@@ -11,44 +11,11 @@ module SaveData
|
||||
'./Game.rxdata'
|
||||
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
|
||||
|
||||
File.open(file_path, 'wb') { |file| Marshal.dump(save_data, file) }
|
||||
end
|
||||
|
||||
# Fetches save data from the given file.
|
||||
# @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)
|
||||
|
||||
return save_data
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the save file exists
|
||||
def self.exists?
|
||||
return File.file?(FILE_PATH)
|
||||
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
|
||||
|
||||
# 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
|
||||
@@ -57,35 +24,59 @@ module SaveData
|
||||
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
|
||||
|
||||
@@ -7,6 +7,7 @@ module SaveData
|
||||
# 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
|
||||
@@ -24,15 +25,11 @@ module SaveData
|
||||
raise "No load_value defined for save value #{id.inspect}" if @load_proc.nil?
|
||||
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
|
||||
# @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.
|
||||
@@ -40,16 +37,22 @@ module SaveData
|
||||
# @raise [InvalidValueError] if an invalid value is being loaded
|
||||
def load(value)
|
||||
validate_value(value)
|
||||
|
||||
@load_proc.call(value)
|
||||
@loaded = true
|
||||
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))
|
||||
# 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
|
||||
@@ -59,15 +62,9 @@ module SaveData
|
||||
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 has a new game value proc defined
|
||||
def has_new_game_proc?
|
||||
return @new_game_value_proc.is_a?(Proc)
|
||||
end
|
||||
|
||||
# @return [Boolean] whether the value should be loaded during bootup
|
||||
def load_in_bootup?
|
||||
return @load_in_bootup
|
||||
@@ -90,13 +87,22 @@ module SaveData
|
||||
|
||||
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
|
||||
|
||||
# Defines what is saved into save data. Requires a block.
|
||||
# If present, ensures that the value is of the given class.
|
||||
# @param class_name [Symbol] class to enforce
|
||||
# @see SaveData.register
|
||||
def save_value(&block)
|
||||
raise ArgumentError, 'No block given to save_value' unless block_given?
|
||||
@save_proc = block
|
||||
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.
|
||||
@@ -107,10 +113,11 @@ module SaveData
|
||||
@load_proc = block
|
||||
end
|
||||
|
||||
# If present, sets the value to be loaded during bootup.
|
||||
# Defines what is saved into save data. Requires a block.
|
||||
# @see SaveData.register
|
||||
def load_in_bootup
|
||||
@load_in_bootup = true
|
||||
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.
|
||||
@@ -120,12 +127,10 @@ module SaveData
|
||||
@new_game_value_proc = block
|
||||
end
|
||||
|
||||
# If present, ensures that the value is of the given class.
|
||||
# @param class_name [Symbol] class to enforce
|
||||
# If present, sets the value to be loaded during bootup.
|
||||
# @see SaveData.register
|
||||
def ensure_class(class_name)
|
||||
validate class_name => Symbol
|
||||
@ensured_class = class_name
|
||||
def load_in_bootup
|
||||
@load_in_bootup = true
|
||||
end
|
||||
|
||||
# If present, defines how the value should be fetched from the pre-v19
|
||||
@@ -137,18 +142,9 @@ module SaveData
|
||||
end
|
||||
|
||||
# @!endgroup
|
||||
|
||||
# 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
|
||||
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.
|
||||
@@ -183,11 +179,9 @@ module SaveData
|
||||
# @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
|
||||
|
||||
@@ -198,38 +192,6 @@ module SaveData
|
||||
return @values.all? { |value| value.valid?(save_data[value.id]) }
|
||||
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_data = {}
|
||||
@values.each { |value| save_data[value.id] = value.save }
|
||||
return save_data
|
||||
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
|
||||
|
||||
# Loads each value from the given save data that has
|
||||
# been set to be loaded during bootup.
|
||||
# @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
|
||||
|
||||
# Loads values from the given save data.
|
||||
# An optional condition can be passed.
|
||||
# @param save_data [Hash] save data to load from
|
||||
@@ -246,19 +208,50 @@ module SaveData
|
||||
end
|
||||
end
|
||||
|
||||
# Loads each {Value}'s new game value, if one is defined.
|
||||
def self.load_new_game_values
|
||||
@values.each do |value|
|
||||
value.load_new_game_value if value.has_new_game_proc? && !value.loaded?
|
||||
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
|
||||
|
||||
# Goes through each value with {Value#load_in_bootup} enabled and
|
||||
# loads their new game value, if one is defined.
|
||||
# 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
|
||||
@@ -18,6 +18,7 @@ module SaveData
|
||||
game: {}
|
||||
}
|
||||
|
||||
#=============================================================================
|
||||
# Represents a conversion made to save data.
|
||||
# New conversions are added using {SaveData.register_conversion}.
|
||||
class Conversion
|
||||
@@ -44,6 +45,13 @@ module SaveData
|
||||
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)
|
||||
@@ -56,13 +64,6 @@ module SaveData
|
||||
@all_proc.call(save_data) if @all_proc.is_a?(Proc)
|
||||
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
|
||||
|
||||
private
|
||||
|
||||
# @!group Configuration
|
||||
@@ -83,9 +84,7 @@ module SaveData
|
||||
# @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
|
||||
@@ -96,9 +95,7 @@ module SaveData
|
||||
# @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
|
||||
@@ -108,13 +105,10 @@ module SaveData
|
||||
# @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
|
||||
|
||||
@@ -122,17 +116,16 @@ module SaveData
|
||||
# @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
|
||||
@@ -152,20 +145,40 @@ module SaveData
|
||||
# save_data[:new_value] = Foo.new
|
||||
# end
|
||||
# end
|
||||
# @yieldself [Conversion]
|
||||
# @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
|
||||
@@ -173,46 +186,16 @@ module SaveData
|
||||
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
|
||||
|
||||
save_data[:essentials_version] = Essentials::VERSION
|
||||
save_data[:game_version] = Settings::GAME_VERSION
|
||||
return true
|
||||
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
|
||||
end
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
SaveData.register_conversion(:v19_define_versions) do
|
||||
essentials_version 19
|
||||
display_title 'Defining versions in save data'
|
||||
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
|
||||
@@ -15,7 +15,7 @@ end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_player) do
|
||||
essentials_version 19
|
||||
display_title 'Converting player trainer'
|
||||
display_title 'Converting player trainer class'
|
||||
to_all do |save_data|
|
||||
next if save_data[:player].is_a?(PlayerTrainer)
|
||||
# Conversion of the party is handled in PokeBattle_Trainer.copy
|
||||
@@ -25,7 +25,7 @@ end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_storage) do
|
||||
essentials_version 19
|
||||
display_title 'Converting Pokémon in storage'
|
||||
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
|
||||
@@ -39,9 +39,25 @@ SaveData.register_conversion(:v19_convert_storage) do
|
||||
end # to_value
|
||||
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
|
||||
for item in pocket
|
||||
next if !item || !item[0] || item[0] == 0
|
||||
item_data = GameData::Item.try_get(item[0])
|
||||
item[0] = item_data.id if item_data
|
||||
end
|
||||
end
|
||||
end # bag.instance_eval
|
||||
end # to_value
|
||||
end
|
||||
|
||||
SaveData.register_conversion(:v19_convert_global_metadata) do
|
||||
essentials_version 19
|
||||
display_title 'Converting global metadata'
|
||||
display_title 'Adding encounter version variable to global metadata'
|
||||
to_value :global_metadata do |global|
|
||||
global.encounter_version ||= 0
|
||||
end
|
||||
@@ -11,62 +11,46 @@ module Game
|
||||
$data_system = load_data('Data/System.rxdata')
|
||||
pbLoadBattleAnimations
|
||||
GameData.load_all
|
||||
|
||||
map_file = format('Data/Map%03d.rxdata', $data_system.start_map_id)
|
||||
|
||||
if $data_system.start_map_id == 0 || !pbRgssExists?(map_file)
|
||||
raise _INTL('No starting position was set in the map editor.')
|
||||
end
|
||||
end
|
||||
|
||||
# Loads values from the save file and runs any necessary
|
||||
# conversions on it.
|
||||
# Loads bootup data from save file (if it exists) or creates bootup data (if
|
||||
# it doesn't).
|
||||
def self.set_up_system
|
||||
SaveData.move_old_windows_save if System.platform[/Windows/]
|
||||
|
||||
if SaveData.exists?
|
||||
save_data = SaveData.read_from_file(SaveData::FILE_PATH)
|
||||
else
|
||||
save_data = {}
|
||||
end
|
||||
|
||||
if !save_data.empty? && SaveData.run_conversions(save_data)
|
||||
File.open(SaveData::FILE_PATH, 'wb') { |f| Marshal.dump(save_data, f) }
|
||||
end
|
||||
|
||||
save_data = (SaveData.exists?) ? SaveData.read_from_file(SaveData::FILE_PATH) : {}
|
||||
if save_data.empty?
|
||||
SaveData.initialize_bootup_values
|
||||
else
|
||||
SaveData.load_bootup_values(save_data)
|
||||
end
|
||||
|
||||
# Set resize factor
|
||||
pbSetResizeFactor([$PokemonSystem.screensize, 4].min)
|
||||
# Set language (and choose language if there is no save file)
|
||||
if Settings::LANGUAGES.length >= 2
|
||||
$PokemonSystem.language = pbChooseLanguage if save_data.empty?
|
||||
pbLoadMessages('Data/' + Settings::LANGUAGES[$PokemonSystem.language][1])
|
||||
end
|
||||
end
|
||||
|
||||
# Saves the game. Returns whether the operation was successful.
|
||||
# @param save_file [String] the save file path
|
||||
# @param safe [Boolean] whether $PokemonGlobal.safesave should be set to true
|
||||
# @return [Boolean] whether the operation was successful
|
||||
# @raise [SaveData::InvalidValueError] if an invalid value is being saved
|
||||
def self.save(save_file = SaveData::FILE_PATH, safe: false)
|
||||
validate save_file => String, safe => [TrueClass, FalseClass]
|
||||
|
||||
$PokemonGlobal.safesave = safe
|
||||
$game_system.save_count += 1
|
||||
$game_system.magic_number = $data_system.magic_number
|
||||
begin
|
||||
SaveData.save_to_file(save_file)
|
||||
Graphics.frame_reset
|
||||
rescue IOError, SystemCallError
|
||||
$game_system.save_count -= 1
|
||||
return false
|
||||
# Called when starting a new game. Initializes global variables
|
||||
# and transfers the player into the map scene.
|
||||
def self.start_new
|
||||
if $game_map && $game_map.events
|
||||
$game_map.events.each_value { |event| event.clear_starting }
|
||||
end
|
||||
|
||||
return true
|
||||
$game_temp.common_event_id = 0 if $game_temp
|
||||
$PokemonTemp.begunNewGame = true
|
||||
$scene = Scene_Map.new
|
||||
SaveData.load_new_game_values
|
||||
$MapFactory = PokemonMapFactory.new($data_system.start_map_id)
|
||||
$game_player.moveto($data_system.start_x, $data_system.start_y)
|
||||
$game_player.refresh
|
||||
$game_map.autoplay
|
||||
$game_map.update
|
||||
end
|
||||
|
||||
# Loads the game from the given save data and starts the map scene.
|
||||
@@ -74,11 +58,8 @@ module Game
|
||||
# @raise [SaveData::InvalidValueError] if an invalid value is being loaded
|
||||
def self.load(save_data)
|
||||
validate save_data => Hash
|
||||
|
||||
SaveData.load_all_values(save_data)
|
||||
|
||||
self.load_map
|
||||
|
||||
pbAutoplayOnSave
|
||||
$game_map.update
|
||||
$PokemonMap.updateMap
|
||||
@@ -117,20 +98,23 @@ module Game
|
||||
$PokemonEncounters.setup($game_map.map_id)
|
||||
end
|
||||
|
||||
# Called when starting a new game. Initializes global variables
|
||||
# and transfers the player into the map scene.
|
||||
def self.start_new
|
||||
if $game_map && $game_map.events
|
||||
$game_map.events.each_value { |event| event.clear_starting }
|
||||
# Saves the game. Returns whether the operation was successful.
|
||||
# @param save_file [String] the save file path
|
||||
# @param safe [Boolean] whether $PokemonGlobal.safesave should be set to true
|
||||
# @return [Boolean] whether the operation was successful
|
||||
# @raise [SaveData::InvalidValueError] if an invalid value is being saved
|
||||
def self.save(save_file = SaveData::FILE_PATH, safe: false)
|
||||
validate save_file => String, safe => [TrueClass, FalseClass]
|
||||
$PokemonGlobal.safesave = safe
|
||||
$game_system.save_count += 1
|
||||
$game_system.magic_number = $data_system.magic_number
|
||||
begin
|
||||
SaveData.save_to_file(save_file)
|
||||
Graphics.frame_reset
|
||||
rescue IOError, SystemCallError
|
||||
$game_system.save_count -= 1
|
||||
return false
|
||||
end
|
||||
$game_temp.common_event_id = 0 if $game_temp
|
||||
$PokemonTemp.begunNewGame = true
|
||||
$scene = Scene_Map.new
|
||||
SaveData.load_new_game_values
|
||||
$MapFactory = PokemonMapFactory.new($data_system.start_map_id)
|
||||
$game_player.moveto($data_system.start_x, $data_system.start_y)
|
||||
$game_player.refresh
|
||||
$game_map.autoplay
|
||||
$game_map.update
|
||||
return true
|
||||
end
|
||||
end
|
||||
@@ -56,7 +56,7 @@ class PokeBattle_Trainer
|
||||
ret.money = trainer.money
|
||||
trainer.seen.each_with_index { |value, i| ret.set_seen(i) if value }
|
||||
trainer.owned.each_with_index { |value, i| ret.set_owned(i) if value }
|
||||
ret.formseen.each_with_index do |value, i|
|
||||
trainer.formseen.each_with_index do |value, i|
|
||||
ret.seen_forms[GameData::Species.get(i).species] = [value[0].clone, value[1].clone] if value
|
||||
end
|
||||
trainer.formlastseen.each_with_index do |value, i|
|
||||
|
||||
@@ -263,7 +263,7 @@ MultipleForms.register(:ROTOM,{
|
||||
MultipleForms.register(:GIRATINA,{
|
||||
"getForm" => proc { |pkmn|
|
||||
maps = [49,50,51,72,73] # Map IDs for Origin Forme
|
||||
if pkmn.hasItem?(:GRISEOUSORB) || maps.include?($game_map.map_id)
|
||||
if pkmn.hasItem?(:GRISEOUSORB) || ($game_map && maps.include?($game_map.map_id))
|
||||
next 1
|
||||
end
|
||||
next 0
|
||||
@@ -597,9 +597,11 @@ MultipleForms.register(:NECROZMA,{
|
||||
MultipleForms.register(:PIKACHU, {
|
||||
"getForm" => proc { |pkmn|
|
||||
next if pkmn.form_simple >= 2
|
||||
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
|
||||
next 1 if map_metadata && map_metadata.town_map_position &&
|
||||
map_metadata.town_map_position[0] == 1 # Tiall region
|
||||
if $game_map
|
||||
map_metadata = GameData::MapMetadata.try_get($game_map.map_id)
|
||||
next 1 if map_metadata && map_metadata.town_map_position &&
|
||||
map_metadata.town_map_position[0] == 1 # Tiall region
|
||||
end
|
||||
next 0
|
||||
}
|
||||
})
|
||||
|
||||
@@ -970,8 +970,9 @@ class Pokemon
|
||||
# @param species [Symbol, String, Integer] Pokémon species
|
||||
# @param level [Integer] Pokémon level
|
||||
# @param owner [Owner, PlayerTrainer, NPCTrainer] Pokémon owner (the player by default)
|
||||
# @param withMoves [Boolean] whether the Pokémon should have moves
|
||||
def initialize(species, level, owner = $Trainer, withMoves = true)
|
||||
# @param withMoves [TrueClass, FalseClass] whether the Pokémon should have moves
|
||||
# @param rechech_form [TrueClass, FalseClass] whether to auto-check the form
|
||||
def initialize(species, level, owner = $Trainer, withMoves = true, recheck_form = true)
|
||||
species_data = GameData::Species.get(species)
|
||||
@species = species_data.species
|
||||
@form = species_data.form
|
||||
@@ -1030,7 +1031,7 @@ class Pokemon
|
||||
@hp = 1
|
||||
@totalhp = 1
|
||||
calcStats
|
||||
if @form == 0
|
||||
if @form == 0 && recheck_form
|
||||
f = MultipleForms.call("getFormOnCreation", self)
|
||||
if f
|
||||
self.form = f
|
||||
|
||||
@@ -28,7 +28,7 @@ class PokeBattle_Pokemon
|
||||
return pkmn if pkmn.is_a?(Pokemon)
|
||||
owner = Pokemon::Owner.new(pkmn.trainerID, pkmn.ot, pkmn.otgender, pkmn.language)
|
||||
# Set level to 1 initially, as it will be recalculated later
|
||||
ret = Pokemon.new(pkmn.species, 1, owner, false)
|
||||
ret = Pokemon.new(pkmn.species, 1, owner, false, false)
|
||||
ret.forced_form = pkmn.forcedForm if pkmn.forcedForm
|
||||
ret.time_form_set = pkmn.formTime
|
||||
ret.exp = pkmn.exp
|
||||
@@ -43,7 +43,9 @@ class PokeBattle_Pokemon
|
||||
ret.item = pkmn.item
|
||||
ret.mail = PokemonMail.copy(pkmn.mail) if pkmn.mail
|
||||
pkmn.moves.each { |m| ret.moves.push(PBMove.copy(m)) if m && m.id > 0 }
|
||||
pkmn.firstmoves.each { |m| ret.add_first_move(m) }
|
||||
if pkmn.firstmoves
|
||||
pkmn.firstmoves.each { |m| ret.add_first_move(m) }
|
||||
end
|
||||
if pkmn.ribbons
|
||||
pkmn.ribbons.each { |r| ret.giveRibbon(r) }
|
||||
end
|
||||
|
||||
@@ -300,7 +300,7 @@ class PokemonPokedexInfo_Scene
|
||||
mapwidth = 1+PokemonRegionMap_Scene::RIGHT-PokemonRegionMap_Scene::LEFT
|
||||
GameData::Encounter.each_of_version($PokemonGlobal.encounter_version) do |enc_data|
|
||||
next if !pbFindEncounter(enc_data.types, @species)
|
||||
map_metadata = GameData::MapMetadata.try_get(enc_data.id)
|
||||
map_metadata = GameData::MapMetadata.try_get(enc_data.map)
|
||||
mappos = (map_metadata) ? map_metadata.town_map_position : nil
|
||||
next if !mappos || mappos[0] != @region
|
||||
showpoint = true
|
||||
|
||||
@@ -819,7 +819,7 @@ class PokemonSummary_Scene
|
||||
if selected_move.accuracy == 0
|
||||
textpos.push(["---", 216, 186, 1, base, shadow])
|
||||
else
|
||||
textpos.push([sprintf("%d%", selected_move.accuracy), 216 + overlay.text_size("%").width, 186, 1, base, shadow])
|
||||
textpos.push(["#{selected_move.accuracy}%", 216 + overlay.text_size("%").width, 186, 1, base, shadow])
|
||||
end
|
||||
# Draw all text
|
||||
pbDrawTextPositions(overlay, textpos)
|
||||
|
||||
@@ -223,7 +223,6 @@ class PokemonLoadScreen
|
||||
# @return [Hash] save data
|
||||
def load_save_file(file_path)
|
||||
save_data = SaveData.read_from_file(file_path)
|
||||
|
||||
unless SaveData.valid?(save_data)
|
||||
if File.file?(file_path + '.bak')
|
||||
pbMessage(_INTL('The save file is corrupt. A backup will be loaded.'))
|
||||
@@ -233,7 +232,6 @@ class PokemonLoadScreen
|
||||
return {}
|
||||
end
|
||||
end
|
||||
|
||||
return save_data
|
||||
end
|
||||
|
||||
@@ -315,9 +313,7 @@ class PokemonLoadScreen
|
||||
Game.start_new
|
||||
return
|
||||
when cmd_mystery_gift
|
||||
pbFadeOutIn do
|
||||
@save_data[:player] = pbDownloadMysteryGift(@save_data[:player])
|
||||
end
|
||||
pbFadeOutIn { pbDownloadMysteryGift(@save_data[:player]) }
|
||||
when cmd_options
|
||||
pbFadeOutIn do
|
||||
scene = PokemonOption_Scene.new
|
||||
|
||||
@@ -97,7 +97,7 @@ class MoveRelearner_Scene
|
||||
textpos.push([basedamage<=1 ? basedamage==1 ? "???" : "---" : sprintf("%d",basedamage),
|
||||
468,146,2,Color.new(64,64,64),Color.new(176,176,176)])
|
||||
textpos.push([_INTL("ACCURACY"),272,178,0,Color.new(248,248,248),Color.new(0,0,0)])
|
||||
textpos.push([accuracy==0 ? "---" : sprintf("%d%",accuracy),
|
||||
textpos.push([accuracy==0 ? "---" : "#{accuracy}%",
|
||||
468,178,2,Color.new(64,64,64),Color.new(176,176,176)])
|
||||
pbDrawTextPositions(overlay,textpos)
|
||||
imagepos.push(["Graphics/Pictures/category",436,116,0,category*28,64,28])
|
||||
|
||||
@@ -324,7 +324,6 @@ def pbDownloadMysteryGift(trainer)
|
||||
pbDisposeMessageWindow(sprites["msgwindow"])
|
||||
pbDisposeSpriteHash(sprites)
|
||||
viewport.dispose
|
||||
return trainer
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
|
||||
@@ -1,13 +1,3 @@
|
||||
# Loads data from a file "safely", similar to load_data. If an encrypted archive
|
||||
# exists, the real file is deleted to ensure that the file is loaded from the
|
||||
# encrypted archive.
|
||||
def pbSafeLoad(file)
|
||||
if safeExists?("./Game.rgssad") && safeExists?(file)
|
||||
File.delete(file) rescue nil
|
||||
end
|
||||
return load_data(file)
|
||||
end
|
||||
|
||||
def pbChooseLanguage
|
||||
commands=[]
|
||||
for lang in Settings::LANGUAGES
|
||||
|
||||
Reference in New Issue
Block a user