Removed deprecated methods

This commit is contained in:
Maruno17
2024-06-27 21:37:00 +01:00
parent 509a414f37
commit 6cc07d1c7a
12 changed files with 1 additions and 866 deletions

View File

@@ -73,19 +73,6 @@ end
#=============================================================================== #===============================================================================
# Checking for files and directories # Checking for files and directories
#=============================================================================== #===============================================================================
# Works around a problem with FileTest.directory if directory contains accent marks
# @deprecated This method is slated to be removed in v22.
def safeIsDirectory?(f)
Deprecation.warn_method("safeIsDirectory?(f)", "v22", "FileTest.directory?(f)")
return FileTest.directory?(f)
end
# @deprecated This method is slated to be removed in v22.
def safeExists?(f)
Deprecation.warn_method("safeExists?(f)", "v22", "FileTest.exist?(f)")
return FileTest.exist?(f)
end
# Similar to "Dir.glob", but designed to work around a problem with accessing # Similar to "Dir.glob", but designed to work around a problem with accessing
# files if a path contains accent marks. # files if a path contains accent marks.
# "dir" is the directory path, "wildcard" is the filename pattern to match. # "dir" is the directory path, "wildcard" is the filename pattern to match.

View File

@@ -9,15 +9,6 @@ SaveData.register(:player) do
new_game_value { Player.new("Unnamed", GameData::TrainerType.keys.first) } new_game_value { Player.new("Unnamed", GameData::TrainerType.keys.first) }
end end
# @deprecated This save data is slated to be removed in v22, as its use is
# replaced by $stats.play_time.
SaveData.register(:frame_count) do
ensure_class :Integer
save_value { Graphics.frame_count }
load_value { |value| Graphics.frame_count = value }
new_game_value { 0 }
end
SaveData.register(:game_system) do SaveData.register(:game_system) do
load_in_bootup load_in_bootup
ensure_class :Game_System ensure_class :Game_System

View File

@@ -3,355 +3,6 @@
# (within reason). # (within reason).
#=============================================================================== #===============================================================================
# Planted berries accidentally weren't converted in v19 to change their
# numerical IDs to symbolic IDs (for the berry planted and for mulch laid down).
# Since item numerical IDs no longer exist, this conversion needs to have a list
# of them in order to convert planted berry data properly.
SaveData.register_conversion(:v20_fix_planted_berry_numerical_ids) do
essentials_version 20
display_title "Fixing berry plant IDs data"
to_value :global_metadata do |global|
berry_conversion = {
389 => :CHERIBERRY,
390 => :CHESTOBERRY,
391 => :PECHABERRY,
392 => :RAWSTBERRY,
393 => :ASPEARBERRY,
394 => :LEPPABERRY,
395 => :ORANBERRY,
396 => :PERSIMBERRY,
397 => :LUMBERRY,
398 => :SITRUSBERRY,
399 => :FIGYBERRY,
400 => :WIKIBERRY,
401 => :MAGOBERRY,
402 => :AGUAVBERRY,
403 => :IAPAPABERRY,
404 => :RAZZBERRY,
405 => :BLUKBERRY,
406 => :NANABBERRY,
407 => :WEPEARBERRY,
408 => :PINAPBERRY,
409 => :POMEGBERRY,
410 => :KELPSYBERRY,
411 => :QUALOTBERRY,
412 => :HONDEWBERRY,
413 => :GREPABERRY,
414 => :TAMATOBERRY,
415 => :CORNNBERRY,
416 => :MAGOSTBERRY,
417 => :RABUTABERRY,
418 => :NOMELBERRY,
419 => :SPELONBERRY,
420 => :PAMTREBERRY,
421 => :WATMELBERRY,
422 => :DURINBERRY,
423 => :BELUEBERRY,
424 => :OCCABERRY,
425 => :PASSHOBERRY,
426 => :WACANBERRY,
427 => :RINDOBERRY,
428 => :YACHEBERRY,
429 => :CHOPLEBERRY,
430 => :KEBIABERRY,
431 => :SHUCABERRY,
432 => :COBABERRY,
433 => :PAYAPABERRY,
434 => :TANGABERRY,
435 => :CHARTIBERRY,
436 => :KASIBBERRY,
437 => :HABANBERRY,
438 => :COLBURBERRY,
439 => :BABIRIBERRY,
440 => :CHILANBERRY,
441 => :LIECHIBERRY,
442 => :GANLONBERRY,
443 => :SALACBERRY,
444 => :PETAYABERRY,
445 => :APICOTBERRY,
446 => :LANSATBERRY,
447 => :STARFBERRY,
448 => :ENIGMABERRY,
449 => :MICLEBERRY,
450 => :CUSTAPBERRY,
451 => :JABOCABERRY,
452 => :ROWAPBERRY
}
mulch_conversion = {
59 => :GROWTHMULCH,
60 => :DAMPMULCH,
61 => :STABLEMULCH,
62 => :GOOEYMULCH
}
global.eventvars.each_value do |var|
next if !var || !var.is_a?(Array)
next if var.length < 6 || var.length > 8 # Neither old nor new berry plant
if !var[1].is_a?(Symbol) # Planted berry item
var[1] = berry_conversion[var[1]] || :ORANBERRY
end
if var[7] && !var[7].is_a?(Symbol) # Mulch
var[7] = mulch_conversion[var[7]]
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_refactor_planted_berries_data) do
essentials_version 20
display_title "Updating berry plant data format"
to_value :global_metadata do |global|
if global.eventvars
global.eventvars.each_pair do |key, value|
next if !value || !value.is_a?(Array)
case value.length
when 6 # Old berry plant data
data = BerryPlantData.new
if value[1].is_a?(Symbol)
plant_data = GameData::BerryPlant.get(value[1])
data.new_mechanics = false
data.berry_id = value[1]
data.time_alive = value[0] * plant_data.hours_per_stage * 3600
data.time_last_updated = value[3]
data.growth_stage = value[0]
data.replant_count = value[5]
data.watered_this_stage = value[2]
data.watering_count = value[4]
end
global.eventvars[key] = data
when 7, 8 # New berry plant data
data = BerryPlantData.new
if value[1].is_a?(Symbol)
data.new_mechanics = true
data.berry_id = value[1]
data.mulch_id = value[7] if value[7].is_a?(Symbol)
data.time_alive = value[2]
data.time_last_updated = value[3]
data.growth_stage = value[0]
data.replant_count = value[5]
data.moisture_level = value[4]
data.yield_penalty = value[6]
end
global.eventvars[key] = data
end
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_refactor_follower_data) do
essentials_version 20
display_title "Updating follower data format"
to_value :global_metadata do |global|
# NOTE: dependentEvents is still defined in class PokemonGlobalMetadata just
# for the sake of this conversion. It is deprecated and will be
# removed in v22.
if global.dependentEvents && global.dependentEvents.length > 0
global.followers = []
global.dependentEvents.each do |follower|
data = FollowerData.new(follower[0], follower[1], "reflection",
follower[2], follower[3], follower[4],
follower[5], follower[6], follower[7])
data.name = follower[8]
data.common_event_id = follower[9]
global.followers.push(data)
end
end
global.dependentEvents = nil
end
end
#===============================================================================
SaveData.register_conversion(:v20_refactor_day_care_variables) do
essentials_version 20
display_title "Refactoring Day Care variables"
to_value :global_metadata do |global|
global.instance_eval do
@day_care = DayCare.new if @day_care.nil?
if !@daycare.nil?
@daycare.each do |old_slot|
if !old_slot[0]
old_slot[0] = Pokemon.new(:MANAPHY, 50)
old_slot[1] = 4
end
next if !old_slot[0]
@day_care.slots.each do |slot|
next if slot.filled?
slot.instance_eval do
@pokemon = old_slot[0]
@initial_level = old_slot[1]
if @pokemon && @pokemon.markings.is_a?(Integer)
markings = []
6.times { |i| markings[i] = ((@pokemon.markings & (1 << i)) == 0) ? 0 : 1 }
@pokemon.markings = markings
end
end
end
end
@day_care.egg_generated = ((@daycareEgg.is_a?(Numeric) && @daycareEgg > 0) || @daycareEgg == true)
@day_care.step_counter = @daycareEggSteps
@daycare = nil
@daycareEgg = nil
@daycareEggSteps = nil
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_rename_bag_variables) do
essentials_version 20
display_title "Renaming Bag variables"
to_value :bag do |bag|
bag.instance_eval do
if !@lastpocket.nil?
@last_viewed_pocket = @lastpocket
@lastPocket = nil
end
if !@choices.nil?
@last_pocket_selections = @choices.clone
@choices = nil
end
if !@registeredItems.nil?
@registered_items = @registeredItems || []
@registeredItems = nil
end
if !@registeredIndex.nil?
@ready_menu_selection = @registeredIndex || [0, 0, 1]
@registeredIndex = nil
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_increment_player_character_id) do
essentials_version 20
display_title "Incrementing player character ID"
to_value :player do |player|
player.character_ID += 1
end
end
#===============================================================================
SaveData.register_conversion(:v20_add_pokedex_records) do
essentials_version 20
display_title "Adding more Pokédex records"
to_value :player do |player|
player.pokedex.instance_eval do
@caught_counts = {} if @caught_counts.nil?
@defeated_counts = {} if @defeated_counts.nil?
@seen_eggs = {} if @seen_eggs.nil?
@seen_forms.each_value do |sp|
next if !sp || sp[0][0].is_a?(Array) # Already converted to include shininess
sp[0] = [sp[0], []]
sp[1] = [sp[1], []]
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_add_new_default_options) do
essentials_version 20
display_title "Updating Options to include new settings"
to_value :pokemon_system do |option|
option.givenicknames = 0 if option.givenicknames.nil?
option.sendtoboxes = 0 if option.sendtoboxes.nil?
end
end
#===============================================================================
SaveData.register_conversion(:v20_fix_default_weather_type) do
essentials_version 20
display_title "Fixing weather type 0 in effect"
to_value :game_screen do |game_screen|
game_screen.instance_eval do
@weather_type = :None if @weather_type == 0
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_add_stats) do
essentials_version 20
display_title "Adding stats to save data"
to_all do |save_data|
unless save_data.has_key?(:stats)
save_data[:stats] = GameStats.new
save_data[:stats].play_time = (save_data[:frame_count] || 0).to_f / Graphics.frame_rate
save_data[:stats].play_sessions = 1
save_data[:stats].time_last_saved = save_data[:stats].play_time
end
end
end
#===============================================================================
SaveData.register_conversion(:v20_convert_pokemon_markings) do
essentials_version 20
display_title "Updating format of Pokémon markings"
to_all do |save_data|
# Create a lambda function that updates a Pokémon's markings
update_markings = lambda do |pkmn|
return if !pkmn || !pkmn.markings.is_a?(Integer)
markings = []
6.times { |i| markings[i] = ((pkmn.markings & (1 << i)) == 0) ? 0 : 1 }
pkmn.markings = markings
end
# Party Pokémon
save_data[:player].party.each { |pkmn| update_markings.call(pkmn) }
# Pokémon storage
save_data[:storage_system].boxes.each do |box|
box.pokemon.each { |pkmn| update_markings.call(pkmn) if pkmn }
end
# NOTE: Pokémon in the Day Care have their markings converted above.
# Partner trainer
if save_data[:global_metadata].partner
save_data[:global_metadata].partner[3].each { |pkmn| update_markings.call(pkmn) }
end
# Roaming Pokémon
if save_data[:global_metadata].roamPokemon
save_data[:global_metadata].roamPokemon.each { |pkmn| update_markings.call(pkmn) }
end
# Purify Chamber
save_data[:global_metadata].purifyChamber.sets.each do |set|
set.list.each { |pkmn| update_markings.call(pkmn) }
update_markings.call(set.shadow) if set.shadow
end
# Hall of Fame records
if save_data[:global_metadata].hallOfFame
save_data[:global_metadata].hallOfFame.each do |team|
next if !team
team.each { |pkmn| update_markings.call(pkmn) }
end
end
# Pokémon stored in Game Variables for some reason
variables = save_data[:variables]
(0..5000).each do |i|
value = variables[i]
case value
when Array
value.each { |value2| update_markings.call(value2) if value2.is_a?(Pokemon) }
when Pokemon
update_markings.call(value)
end
end
end
end
#===============================================================================
SaveData.register_conversion(:v21_replace_phone_data) do SaveData.register_conversion(:v21_replace_phone_data) do
essentials_version 21 essentials_version 21
display_title "Updating Phone data format" display_title "Updating Phone data format"

View File

@@ -49,8 +49,7 @@ end
# Permanently stores data of follower events (i.e. in save files). # Permanently stores data of follower events (i.e. in save files).
#=============================================================================== #===============================================================================
class PokemonGlobalMetadata class PokemonGlobalMetadata
attr_accessor :dependentEvents # Deprecated - to be removed in v22 attr_writer :followers
attr_writer :followers
def followers def followers
@followers = [] if !@followers @followers = [] if !@followers

View File

@@ -39,36 +39,6 @@ def shadowctagFromRgb(param)
return shadowctagFromColor(Color.new_from_rgb(param)) return shadowctagFromColor(Color.new_from_rgb(param))
end end
# @deprecated This method is slated to be removed in v22.
def colorToRgb32(color)
Deprecation.warn_method("colorToRgb32", "v22", "color.to_rgb32")
return color.to_rgb32
end
# @deprecated This method is slated to be removed in v22.
def colorToRgb16(color)
Deprecation.warn_method("colorToRgb16", "v22", "color.to_rgb15")
return color.to_rgb15
end
# @deprecated This method is slated to be removed in v22.
def rgbToColor(param)
Deprecation.warn_method("rgbToColor", "v22", "Color.new_from_rgb(param)")
return Color.new_from_rgb(param)
end
# @deprecated This method is slated to be removed in v22.
def rgb15ToColor(param)
Deprecation.warn_method("rgb15ToColor", "v22", "Color.new_from_rgb(param)")
return Color.new_from_rgb(param)
end
# @deprecated This method is slated to be removed in v22.
def getContrastColor(color)
Deprecation.warn_method("getContrastColor", "v22", "color.get_contrast_color")
return color.get_contrast_color
end
#=============================================================================== #===============================================================================
# Format text. # Format text.
#=============================================================================== #===============================================================================

View File

@@ -61,12 +61,6 @@ module GameData
@pbs_file_suffix = hash[:pbs_file_suffix] || "" @pbs_file_suffix = hash[:pbs_file_suffix] || ""
end end
# @deprecated This method is slated to be removed in v22.
def base_damage
Deprecation.warn_method("base_damage", "v22", "power")
return @power
end
# @return [String] the translated name of this move # @return [String] the translated name of this move
def name def name
return pbGetMessageFromHash(MessageTypes::MOVE_NAMES, @real_name) return pbGetMessageFromHash(MessageTypes::MOVE_NAMES, @real_name)

View File

@@ -23,14 +23,6 @@ class Battle::Move
CRITICAL_HIT_RATIOS = (Settings::NEW_CRITICAL_HIT_RATE_MECHANICS) ? [24, 8, 2, 1] : [16, 8, 4, 3, 2] CRITICAL_HIT_RATIOS = (Settings::NEW_CRITICAL_HIT_RATE_MECHANICS) ? [24, 8, 2, 1] : [16, 8, 4, 3, 2]
def to_int; return @id; end
# @deprecated This method is slated to be removed in v22.
def baseDamage
Deprecation.warn_method("baseDamage", "v22", "power")
return @power
end
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Creating a move. # Creating a move.
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------

View File

@@ -16,8 +16,6 @@ class PokemonGlobalMetadata
attr_accessor :stepcount attr_accessor :stepcount
attr_accessor :pcItemStorage attr_accessor :pcItemStorage
attr_accessor :mailbox attr_accessor :mailbox
attr_accessor :phoneNumbers # Deprecated - to be removed in v22
attr_accessor :phoneTime # Deprecated - to be removed in v22
attr_accessor :phone attr_accessor :phone
attr_accessor :partner attr_accessor :partner
attr_accessor :creditsPlayed attr_accessor :creditsPlayed

View File

@@ -558,149 +558,3 @@ EventHandlers.add(:on_frame_update, :phone_call_counter,
Phone::Call.make_incoming Phone::Call.make_incoming
} }
) )
#===============================================================================
# Deprecated.
#===============================================================================
# Called by events. Make your event look like this instead:
#
# @>Conditional Branch: Phone.can_add?(trainer_type, name, start_version)
# @>Text: Let me register you.
# @>Show Choices: Yes, No
# : When [Yes]
# @>Conditional Branch: Phone.add(get_self, trainer_type, name, start_version, versions_count)
# @>Text: Thanks! (optional)
# @>
# : Branch End
# : When [No]
# @>Text: Oh, okay then. (optional)
# @>
# : Branch End
# : Branch End
# @>
#
# @deprecated This method is slated to be removed in v22.
def pbPhoneRegisterBattle(message, event, trainer_type, name, versions_count)
Deprecation.warn_method("pbPhoneRegisterBattle", "v22", "several scripts and event commands; see def pbPhoneRegisterBattle")
return false if !Phone.can_add?(trainer_type, name, 0)
message = _INTL("Let me register you.") if !message
return false if !pbConfirmMessage(message)
return Phone.add(event, trainer_type, name, 0, versions_count)
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneRegister(event, trainer_type, name)
Deprecation.warn_method("pbPhoneRegister", "v22", "Phone.add_silent(event, trainer_type, name)")
Phone.add_silent(event, trainer_type, name)
end
# Called by events.
# @deprecated This method is slated to be removed in v22.
def pbPhoneRegisterNPC(common_event_id, name, map_id, show_message = true)
Deprecation.warn_method("pbPhoneRegisterNPC", "v22", "Phone.add(map_id, name, common_event_id) or Phone.add_silent(map_id, name, common_event_id)")
if show_message
Phone.add(map_id, name, common_event_id)
else
Phone.add_silent(map_id, name, common_event_id)
end
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneDeleteContact(index)
Deprecation.warn_method("pbPhoneDeleteContact", "v22", "$PokemonGlobal.phone.contacts[index].visible = false")
$PokemonGlobal.phone.contacts[index].visible = false
end
# @deprecated This method is slated to be removed in v22.
def pbFindPhoneTrainer(trainer_type, name)
Deprecation.warn_method("pbFindPhoneTrainer", "v22", "Phone.get(trainer_type, name)")
return Phone.get(trainer_type, name)
end
# @deprecated This method is slated to be removed in v22.
def pbHasPhoneTrainer?(trainer_type, name)
Deprecation.warn_method("pbHasPhoneTrainer", "v22", "Phone.get(trainer_type, name) != nil")
return Phone.get(trainer_type, name) != nil
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneReadyToBattle?(trainer_type, name)
Deprecation.warn_method("pbPhoneReadyToBattle", "v22", "Phone.get(trainer_type, name).can_rematch?")
contact = Phone.get(trainer_type, name)
return contact && contact.can_rematch?
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneReset(tr_type, tr_name)
Deprecation.warn_method("pbPhoneReadyToBattle", "v22", "Phone.get(trainer_type, name) and other things")
contact = Phone.get(trainer_type, name)
return false if !contact
contact.time_to_ready = 0
contact.rematch_flag = 0
$game_self_switches[[contact.map_id, contact.event_id, "A"]] = true
$game_map.need_refresh = true
return true
end
# Called by events.
# @deprecated This method is slated to be removed in v22.
def pbPhoneBattleCount(trainer_type, name)
Deprecation.warn_method("pbPhoneBattleCount", "v22", "Phone.variant(trainer_type, name)")
return Phone.variant(trainer_type, name)
end
# Called by events.
# @deprecated This method is slated to be removed in v22.
def pbPhoneIncrement(trainer_type, name, versions_count)
Deprecation.warn_method("pbPhoneIncrement", "v22", "Phone.increment_version(trainer_type, name, start_version)")
Phone.increment_version(trainer_type, name, 0)
end
# Used in phone calls that say they're ready for a rematch, used in Debug function.
# @deprecated This method is slated to be removed in v22.
def pbSetReadyToBattle(contact)
Deprecation.warn_method("pbSetReadyToBattle", "v22", "contact.set_trainer_event_ready_for_rematch")
contact.set_trainer_event_ready_for_rematch
end
# @deprecated This method is slated to be removed in v22.
def pbRandomPhoneTrainer
Deprecation.warn_method("pbRandomPhoneTrainer", "v22", "Phone::Call.get_random_trainer_for_incoming_call")
return Phone::Call.get_random_trainer_for_incoming_call
end
# @deprecated This method is slated to be removed in v22.
def pbCallTrainer(trainer_type, name)
Deprecation.warn_method("pbCallTrainer", "v22", "Phone::Call.make_outgoing(trainer_type, name)")
Phone::Call.make_outgoing(trainer_type, name)
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneGenerateCall(contact)
Deprecation.warn_method("pbPhoneGenerateCall", "v22", "Phone::Call.generate_trainer_dialogue(contact)")
return Phone::Call.generate_trainer_dialogue(contact)
end
# @deprecated This method is slated to be removed in v22.
def pbPhoneCall(dialogue, contact)
Deprecation.warn_method("pbPhoneCall", "v22", "Phone::Call.play(dialogue, contact)")
Phone::Call.play(dialogue, contact)
end
# @deprecated This method is slated to be removed in v22.
def pbEncounterSpecies(contact)
Deprecation.warn_method("pbEncounterSpecies", "v22", "Phone::Call.get_random_encounter_species(contact)")
return Phone::Call.get_random_encounter_species(contact)
end
# @deprecated This method is slated to be removed in v22.
def pbTrainerSpecies(contact)
Deprecation.warn_method("pbTrainerSpecies", "v22", "Phone::Call.get_random_contact_pokemon_species(contact)")
return Phone::Call.get_random_contact_pokemon_species(contact)
end
# @deprecated This method is slated to be removed in v22.
def pbTrainerMapName(contact)
Deprecation.warn_method("pbTrainerMapName", "v22", "Phone::Call.get_map_name(contact)")
return Phone::Call.get_map_name(contact)
end

View File

@@ -323,18 +323,6 @@ class Pokemon
return species_data.types.clone return species_data.types.clone
end end
# @deprecated This method is slated to be removed in v22.
def type1
Deprecation.warn_method("type1", "v22", "pkmn.types")
return types[0]
end
# @deprecated This method is slated to be removed in v22.
def type2
Deprecation.warn_method("type2", "v22", "pkmn.types")
return types[1] || types[0]
end
# @param type [Symbol, String, GameData::Type] type to check # @param type [Symbol, String, GameData::Type] type to check
# @return [Boolean] whether this Pokémon has the specified type # @return [Boolean] whether this Pokémon has the specified type
def hasType?(type) def hasType?(type)

View File

@@ -63,12 +63,6 @@ class Pokemon
def description; return GameData::Move.get(@id).description; end def description; return GameData::Move.get(@id).description; end
def hidden_move?; return GameData::Move.get(@id).hidden_move?; end def hidden_move?; return GameData::Move.get(@id).hidden_move?; end
# @deprecated This method is slated to be removed in v22.
def base_damage
Deprecation.warn_method("base_damage", "v22", "power")
return @power
end
def display_type(pkmn); return GameData::Move.get(@id).display_type(pkmn, self); end def display_type(pkmn); return GameData::Move.get(@id).display_type(pkmn, self); end
def display_category(pkmn); return GameData::Move.get(@id).display_category(pkmn, self); end def display_category(pkmn); return GameData::Move.get(@id).display_category(pkmn, self); end
def display_damage(pkmn); return GameData::Move.get(@id).display_damage(pkmn, self); end def display_damage(pkmn); return GameData::Move.get(@id).display_damage(pkmn, self); end

View File

@@ -297,88 +297,6 @@ module Compiler
# Convert a string to certain kinds of values. # Convert a string to certain kinds of values.
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Unused.
# NOTE: This method is about 10 times slower than split_csv_line.
def csvfield!(str)
ret = ""
str.sub!(/^\s*/, "")
if str[0, 1] == "\""
str[0, 1] = ""
escaped = false
fieldbytes = 0
str.scan(/./) do |s|
fieldbytes += s.length
break if s == "\"" && !escaped
if s == "\\" && !escaped
escaped = true
else
ret += s
escaped = false
end
end
str[0, fieldbytes] = ""
if !str[/^\s*,/] && !str[/^\s*$/]
raise _INTL("Invalid quoted field (in: {1}).", str) + "\n" + FileLineData.linereport
end
str[0, str.length] = $~.post_match
else
if str[/,/]
str[0, str.length] = $~.post_match
ret = $~.pre_match
else
ret = str.clone
str[0, str.length] = ""
end
ret.gsub!(/\s+$/, "")
end
return ret
end
# Unused.
def csvBoolean!(str, _line = -1)
field = csvfield!(str)
return true if field[/^(?:1|TRUE|YES|Y)$/i]
return false if field[/^(?:0|FALSE|NO|N)$/i]
raise _INTL("Field '{1}' is not a Boolean value (true, false, 1, 0).", field) + "\n" + FileLineData.linereport
end
# Unused.
def csvInt!(str, _line = -1)
ret = csvfield!(str)
if !ret[/^\-?\d+$/]
raise _INTL("Field '{1}' is not an integer.", ret) + "\n" + FileLineData.linereport
end
return ret.to_i
end
# Unused.
def csvPosInt!(str, _line = -1)
ret = csvfield!(str)
if !ret[/^\d+$/]
raise _INTL("Field '{1}' is not a positive integer.", ret) + "\n" + FileLineData.linereport
end
return ret.to_i
end
# Unused.
def csvFloat!(str, _line = -1)
ret = csvfield!(str)
return Float(ret) rescue raise _INTL("Field '{1}' is not a number.", ret) + "\n" + FileLineData.linereport
end
# Unused.
def csvEnumField!(value, enumer, _key, _section)
ret = csvfield!(value)
return checkEnumField(ret, enumer)
end
# Unused.
def csvEnumFieldOrInt!(value, enumer, _key, _section)
ret = csvfield!(value)
return ret.to_i if ret[/\-?\d+/]
return checkEnumField(ret, enumer)
end
# Turns a value (a string) into another data type as determined by the given # Turns a value (a string) into another data type as determined by the given
# schema. # schema.
# @param value [String] # @param value [String]
@@ -485,207 +403,6 @@ module Compiler
raise _INTL("Enumeration not defined.") + "\n" + FileLineData.linereport raise _INTL("Enumeration not defined.") + "\n" + FileLineData.linereport
end end
# Unused.
def checkEnumFieldOrNil(ret, enumer)
case enumer
when Module
return nil if nil_or_empty?(ret) || !(enumer.const_defined?(ret) rescue false)
return enumer.const_get(ret.to_sym)
when Symbol, String
if GameData.const_defined?(enumer.to_sym)
enumer = GameData.const_get(enumer.to_sym)
return nil if nil_or_empty?(ret) || !enumer.exists?(ret.to_sym)
return ret.to_sym
end
enumer = Object.const_get(enumer.to_sym)
return nil if nil_or_empty?(ret) || !(enumer.const_defined?(ret) rescue false)
return enumer.const_get(ret.to_sym)
when Array
idx = findIndex(enumer) { |item| ret == item }
return nil if idx < 0
return idx
when Hash
return enumer[ret]
end
return nil
end
#-----------------------------------------------------------------------------
# Convert a string to values using a schema.
# Unused.
# @deprecated This method is slated to be removed in v22.
def pbGetCsvRecord(rec, lineno, schema)
Deprecation.warn_method("pbGetCsvRecord", "v22", "get_csv_record")
record = []
repeat = false
schema_length = schema[1].length
start = 0
case schema[1][0, 1]
when "*"
repeat = true
start = 1
when "^"
start = 1
schema_length -= 1
end
subarrays = repeat && schema[1].length > 2
loop do
subrecord = []
(start...schema[1].length).each do |i|
chr = schema[1][i, 1]
case chr
when "i" # Integer
subrecord.push(csvInt!(rec, lineno))
when "I" # Optional integer
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^\-?\d+$/]
raise _INTL("Field '{1}' is not an integer.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.to_i)
end
when "u" # Positive integer or zero
subrecord.push(csvPosInt!(rec, lineno))
when "U" # Optional positive integer or zero
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^\d+$/]
raise _INTL("Field '{1}' must be 0 or greater.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.to_i)
end
when "v" # Positive integer
field = csvPosInt!(rec, lineno)
raise _INTL("Field '{1}' must be greater than 0.", field) + "\n" + FileLineData.linereport if field == 0
subrecord.push(field)
when "V" # Optional positive integer
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^\d+$/]
raise _INTL("Field '{1}' must be greater than 0.", field) + "\n" + FileLineData.linereport
elsif field.to_i == 0
raise _INTL("Field '{1}' must be greater than 0.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.to_i)
end
when "x" # Hexadecimal number
field = csvfield!(rec)
if !field[/^[A-Fa-f0-9]+$/]
raise _INTL("Field '{1}' is not a hexadecimal number.", field) + "\n" + FileLineData.linereport
end
subrecord.push(field.hex)
when "X" # Optional hexadecimal number
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^[A-Fa-f0-9]+$/]
raise _INTL("Field '{1}' is not a hexadecimal number.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.hex)
end
when "f" # Floating point number
subrecord.push(csvFloat!(rec, lineno))
when "F" # Optional floating point number
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^\-?^\d*\.?\d*$/]
raise _INTL("Field '{1}' is not a floating point number.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.to_f)
end
when "b" # Boolean
subrecord.push(csvBoolean!(rec, lineno))
when "B" # Optional Boolean
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif field[/^1|[Tt][Rr][Uu][Ee]|[Yy][Ee][Ss]|[Tt]|[Yy]$/]
subrecord.push(true)
else
subrecord.push(false)
end
when "n" # Name
field = csvfield!(rec)
if !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\nunderscores and can't begin with a number.", field) + "\n" + FileLineData.linereport
end
subrecord.push(field)
when "N" # Optional name
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\nunderscores and can't begin with a number.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field)
end
when "s" # String
subrecord.push(csvfield!(rec))
when "S" # Optional string
field = csvfield!(rec)
subrecord.push((nil_or_empty?(field)) ? nil : field)
when "q" # Unformatted text
subrecord.push(rec)
rec = ""
when "Q" # Optional unformatted text
if nil_or_empty?(rec)
subrecord.push(nil)
else
subrecord.push(rec)
rec = ""
end
when "m" # Symbol
field = csvfield!(rec)
if !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\nunderscores and can't begin with a number.", field) + "\n" + FileLineData.linereport
end
subrecord.push(field.to_sym)
when "M" # Optional symbol
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\nunderscores and can't begin with a number.", field) + "\n" + FileLineData.linereport
else
subrecord.push(field.to_sym)
end
when "e" # Enumerable
subrecord.push(csvEnumField!(rec, schema[2 + i - start], "", FileLineData.linereport))
when "E" # Optional enumerable
field = csvfield!(rec)
subrecord.push(checkEnumFieldOrNil(field, schema[2 + i - start]))
when "y" # Enumerable or integer
field = csvfield!(rec)
subrecord.push(csvEnumFieldOrInt!(field, schema[2 + i - start], "", FileLineData.linereport))
when "Y" # Optional enumerable or integer
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif field[/^\-?\d+$/]
subrecord.push(field.to_i)
else
subrecord.push(checkEnumFieldOrNil(field, schema[2 + i - start]))
end
end
end
if !subrecord.empty?
if subarrays
record.push(subrecord)
else
record.concat(subrecord)
end
end
break if repeat && nil_or_empty?(rec)
break unless repeat
end
return (!repeat && schema_length == 1) ? record[0] : record
end
#----------------------------------------------------------------------------- #-----------------------------------------------------------------------------
# Convert a string to values using a schema. # Convert a string to values using a schema.