From 8a3353973b90452bb61490d6523f34e3f27ce799 Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Wed, 8 Feb 2023 23:51:42 +0000 Subject: [PATCH] =?UTF-8?q?Fixed=20minor=20bug=20in=20sprite=20position=20?= =?UTF-8?q?editor,=20made=20trainers'=20Pok=C3=A9mon=20nicknames=20transla?= =?UTF-8?q?table,=20generalised=20code=20for=20optional=20PBS=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../001_Technical/003_Intl_Messages.rb | 1 + Data/Scripts/010_Data/001_GameData.rb | 6 +++- .../Scripts/010_Data/002_PBS data/006_Item.rb | 28 ++++++++++--------- .../002_PBS data/011_ShadowPokemon.rb | 3 +- .../010_Data/002_PBS data/015_Trainer.rb | 4 ++- .../002_Trainer_LoadAndNew.rb | 4 +-- .../001_Editor screens/001_EditorScreens.rb | 14 +++++----- .../004_EditorScreens_SpritePositioning.rb | 1 + Data/Scripts/021_Compiler/001_Compiler.rb | 2 +- .../021_Compiler/002_Compiler_CompilePBS.rb | 17 +++++++---- 10 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Data/Scripts/001_Technical/003_Intl_Messages.rb b/Data/Scripts/001_Technical/003_Intl_Messages.rb index f5e552b36..3a8d01416 100644 --- a/Data/Scripts/001_Technical/003_Intl_Messages.rb +++ b/Data/Scripts/001_Technical/003_Intl_Messages.rb @@ -702,6 +702,7 @@ module MessageTypes STORAGE_CREATOR_NAME = 27 ITEM_PORTION_NAMES = 28 ITEM_PORTION_NAME_PLURALS = 29 + POKEMON_NICKNAMES = 30 @@messages = Translation.new def self.load_default_messages diff --git a/Data/Scripts/010_Data/001_GameData.rb b/Data/Scripts/010_Data/001_GameData.rb index 83263509c..8a278726c 100644 --- a/Data/Scripts/010_Data/001_GameData.rb +++ b/Data/Scripts/010_Data/001_GameData.rb @@ -256,7 +256,11 @@ module GameData ret = [] self.constants.each do |c| next if !self.const_get(c).is_a?(Class) - ret.push(self.const_get(c)::DATA_FILENAME) if self.const_get(c).const_defined?(:DATA_FILENAME) + next if !self.const_get(c).const_defined?(:DATA_FILENAME) + if self.const_get(c).const_defined?(:OPTIONAL) && self.const_get(c)::OPTIONAL + next if !safeExists?(self.const_get(c)::DATA_FILENAME) + end + ret.push(self.const_get(c)::DATA_FILENAME) end return ret end diff --git a/Data/Scripts/010_Data/002_PBS data/006_Item.rb b/Data/Scripts/010_Data/002_PBS data/006_Item.rb index dff99bfdc..24083dcc6 100644 --- a/Data/Scripts/010_Data/002_PBS data/006_Item.rb +++ b/Data/Scripts/010_Data/002_PBS data/006_Item.rb @@ -50,19 +50,21 @@ module GameData battle_use_array = [_INTL("Can't use in battle")] self.schema["BattleUse"][2].each { |key, value| battle_use_array[value] = key if !battle_use_array[value] } return [ - ["ID", ReadOnlyProperty, _INTL("ID of this item (used as a symbol like :XXX).")], - ["Name", ItemNameProperty, _INTL("Name of this item as displayed by the game.")], - ["NamePlural", ItemNameProperty, _INTL("Plural name of this item as displayed by the game.")], - ["Pocket", PocketProperty, _INTL("Pocket in the Bag where this item is stored.")], - ["Price", LimitProperty.new(Settings::MAX_MONEY), _INTL("Purchase price of this item.")], - ["SellPrice", LimitProperty2.new(Settings::MAX_MONEY), _INTL("Sell price of this item. If blank, is half the purchase price.")], - ["BPPrice", LimitProperty.new(Settings::MAX_BATTLE_POINTS), _INTL("Purchase price of this item in Battle Points (BP).")], - ["FieldUse", EnumProperty.new(field_use_array), _INTL("How this item can be used outside of battle.")], - ["BattleUse", EnumProperty.new(battle_use_array), _INTL("How this item can be used within a battle.")], - ["Flags", StringListProperty, _INTL("Words/phrases that can be used to group certain kinds of items.")], - ["Consumable", BooleanProperty, _INTL("Whether this item is consumed after use.")], - ["Move", MoveProperty, _INTL("Move taught by this HM, TM or TR.")], - ["Description", StringProperty, _INTL("Description of this item.")] + ["ID", ReadOnlyProperty, _INTL("ID of this item (used as a symbol like :XXX).")], + ["Name", ItemNameProperty, _INTL("Name of this item as displayed by the game.")], + ["NamePlural", ItemNameProperty, _INTL("Plural name of this item as displayed by the game.")], + ["PortionName", ItemNameProperty, _INTL("Name of a portion of this item as displayed by the game.")], + ["PortionNamePlural", ItemNameProperty, _INTL("Name of 2 or more portions of this item as displayed by the game.")], + ["Pocket", PocketProperty, _INTL("Pocket in the Bag where this item is stored.")], + ["Price", LimitProperty.new(Settings::MAX_MONEY), _INTL("Purchase price of this item.")], + ["SellPrice", LimitProperty2.new(Settings::MAX_MONEY), _INTL("Sell price of this item. If blank, is half the purchase price.")], + ["BPPrice", LimitProperty.new(Settings::MAX_BATTLE_POINTS), _INTL("Purchase price of this item in Battle Points (BP).")], + ["FieldUse", EnumProperty.new(field_use_array), _INTL("How this item can be used outside of battle.")], + ["BattleUse", EnumProperty.new(battle_use_array), _INTL("How this item can be used within a battle.")], + ["Flags", StringListProperty, _INTL("Words/phrases that can be used to group certain kinds of items.")], + ["Consumable", BooleanProperty, _INTL("Whether this item is consumed after use.")], + ["Move", MoveProperty, _INTL("Move taught by this HM, TM or TR.")], + ["Description", StringProperty, _INTL("Description of this item.")] ] end diff --git a/Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb b/Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb index 5ef06ab74..dca905398 100644 --- a/Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb +++ b/Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb @@ -9,6 +9,7 @@ module GameData DATA = {} DATA_FILENAME = "shadow_pokemon.dat" PBS_BASE_FILENAME = "shadow_pokemon" + OPTIONAL = true SCHEMA = { "SectionName" => [:id, "e", :Species], @@ -21,7 +22,7 @@ module GameData extend ClassMethodsSymbols include InstanceMethods - alias __orig__load load unless private_method_defined?(:__orig__load) + singleton_class.alias_method(:__orig__load, :load) unless singleton_class.method_defined?(:__orig__load) def self.load __orig__load if safeExists?("Data/#{self::DATA_FILENAME}") end diff --git a/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb b/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb index df301b5de..10a51c3d7 100644 --- a/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb +++ b/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb @@ -167,7 +167,9 @@ module GameData end end pkmn.happiness = pkmn_data[:happiness] if pkmn_data[:happiness] - pkmn.name = pkmn_data[:real_name] if !nil_or_empty?(pkmn_data[:real_name]) + if !nil_or_empty?(pkmn_data[:real_name]) + pkmn.name = pbGetMessageFromHash(MessageTypes::POKEMON_NICKNAMES, pkmn_data[:real_name]) + end if pkmn_data[:shadowness] pkmn.makeShadow pkmn.shiny = false diff --git a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb index c41df0829..d9212f01d 100644 --- a/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb +++ b/Data/Scripts/015_Trainers and player/002_Trainer_LoadAndNew.rb @@ -37,7 +37,7 @@ def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true) if save_changes trainer_hash = { :trainer_type => tr_type, - :name => tr_name, + :real_name => tr_name, :version => tr_version, :pokemon => [] } @@ -50,7 +50,7 @@ def pbNewTrainer(tr_type, tr_name, tr_version, save_changes = true) ) end # Add trainer's data to records - trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]] + trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:real_name], trainer_hash[:version]] GameData::Trainer.register(trainer_hash) GameData::Trainer.save pbConvertTrainerData diff --git a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb index 44672a015..748504570 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb @@ -525,7 +525,7 @@ def pbTrainerBattleEditor else trainer_hash = { :trainer_type => data[0], - :name => data[1], + :real_name => data[1], :version => data[2], :lose_text => data[3], :pokemon => party, @@ -533,7 +533,7 @@ def pbTrainerBattleEditor :pbs_file_suffix => tr_data.pbs_file_suffix } # Add trainer type's data to records - trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]] + trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:real_name], trainer_hash[:version]] GameData::Trainer.register(trainer_hash) if data[0] != old_type || data[1] != old_name || data[2] != old_version GameData::Trainer::DATA.delete([old_type, old_name, old_version]) @@ -568,7 +568,7 @@ def pbTrainerBattleEditor if t trainer_hash = { :trainer_type => tr_type, - :name => tr_name, + :real_name => tr_name, :version => tr_version, :pokemon => [] } @@ -581,7 +581,7 @@ def pbTrainerBattleEditor ) end # Add trainer's data to records - trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:name], trainer_hash[:version]] + trainer_hash[:id] = [trainer_hash[:trainer_type], trainer_hash[:real_name], trainer_hash[:version]] GameData::Trainer.register(trainer_hash) pbMessage(_INTL("The Trainer battle was added.")) modified = true @@ -607,7 +607,7 @@ module TrainerPokemonProperty oldsetting = [ initsetting[:species], initsetting[:level], - initsetting[:name], + initsetting[:real_name], initsetting[:form], initsetting[:gender], initsetting[:shininess], @@ -629,7 +629,7 @@ module TrainerPokemonProperty pkmn_properties = [ [_INTL("Species"), SpeciesProperty, _INTL("Species of the Pokémon.")], [_INTL("Level"), NonzeroLimitProperty.new(max_level), _INTL("Level of the Pokémon (1-{1}).", max_level)], - [_INTL("Name"), StringProperty, _INTL("Name of the Pokémon.")], + [_INTL("Name"), StringProperty, _INTL("Nickname of the Pokémon.")], [_INTL("Form"), LimitProperty2.new(999), _INTL("Form of the Pokémon.")], [_INTL("Gender"), GenderProperty, _INTL("Gender of the Pokémon.")], [_INTL("Shiny"), BooleanProperty2, _INTL("If set to true, the Pokémon is a different-colored Pokémon.")], @@ -655,7 +655,7 @@ module TrainerPokemonProperty ret = { :species => oldsetting[0], :level => oldsetting[1], - :name => oldsetting[2], + :real_name => oldsetting[2], :form => oldsetting[3], :gender => oldsetting[4], :shininess => oldsetting[5], diff --git a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb index 110d64a5e..4673ffb94 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/004_EditorScreens_SpritePositioning.rb @@ -213,6 +213,7 @@ class SpritePositioner break elsif Input.trigger?(Input::USE) pbPlayDecisionSE + @metricsChanged = true if metrics_data.shadow_size != oldval break end end diff --git a/Data/Scripts/021_Compiler/001_Compiler.rb b/Data/Scripts/021_Compiler/001_Compiler.rb index 096dcb591..4b9756948 100644 --- a/Data/Scripts/021_Compiler/001_Compiler.rb +++ b/Data/Scripts/021_Compiler/001_Compiler.rb @@ -889,7 +889,7 @@ module Compiler rescue SystemCallError mustCompile = true end - elsif filename != "shadow_pokemon.dat" + else mustCompile = true break end diff --git a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb index 8d4ff7200..1aec8db6f 100644 --- a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb @@ -2,6 +2,9 @@ module Compiler module_function def compile_PBS_file_generic(game_data, *paths) + if game_data.const_defined?(:OPTIONAL) && game_data::OPTIONAL + return if paths.none? { |p| safeExists?(p) } + end game_data::DATA.clear schema = game_data.schema # Read from PBS file(s) @@ -214,10 +217,10 @@ module Compiler def validate_compiled_move(hash) if (hash[:category] || 2) == 2 && (hash[:base_damage] || 0) != 0 raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", - hash[:name], FileLineData.linereport) + hash[:real_name], FileLineData.linereport) elsif (hash[:category] || 2) != 2 && (hash[:base_damage] || 0) == 0 print _INTL("Warning: Move {1} is defined as Physical or Special but has a base damage of 0. Changing it to a Status move.\r\n{2}", - hash[:name], FileLineData.linereport) + hash[:real_name], FileLineData.linereport) hash[:category] = 2 end end @@ -542,7 +545,6 @@ module Compiler # Compile Shadow Pokémon data #============================================================================= def compile_shadow_pokemon(*paths) - return if !safeExists?("PBS/shadow_pokemon.txt") compile_PBS_file_generic(GameData::ShadowPokemon, *paths) do |final_validate, hash| (final_validate) ? validate_all_compiled_shadow_pokemon : validate_compiled_shadow_pokemon(hash) end @@ -847,9 +849,9 @@ module Compiler pkmn[:level], max_level, FileLineData.linereport) end # Ensure valid name length - if pkmn[:name] && pkmn[:name].length > Pokemon::MAX_NAME_SIZE + if pkmn[:real_name] && pkmn[:real_name].length > Pokemon::MAX_NAME_SIZE raise _INTL("Invalid Pokémon nickname: {1} (must be 1-{2} characters).\r\n{3}", - pkmn[:name], Pokemon::MAX_NAME_SIZE, FileLineData.linereport) + pkmn[:real_name], Pokemon::MAX_NAME_SIZE, FileLineData.linereport) end # Ensure no duplicate moves pkmn[:moves].uniq! if pkmn[:moves] @@ -904,12 +906,17 @@ module Compiler # Get trainer names and lose texts for translating trainer_names = [] lose_texts = [] + pokemon_nicknames = [] GameData::Trainer.each do |trainer| trainer_names.push(trainer.real_name) lose_texts.push(trainer.real_lose_text) + trainer.pokemon.each do |pkmn| + pokemon_nicknames.push(pkmn[:real_name]) if !nil_or_empty?(pkmn[:real_name]) + end end MessageTypes.setMessagesAsHash(MessageTypes::TRAINER_NAMES, trainer_names) MessageTypes.setMessagesAsHash(MessageTypes::TRAINER_SPEECHES_LOSE, lose_texts) + MessageTypes.setMessagesAsHash(MessageTypes::POKEMON_NICKNAMES, pokemon_nicknames) end #=============================================================================