From 56c9b69c44a80c643bf2d6e840e882f1253b310f Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Wed, 13 Oct 2021 22:55:29 +0100 Subject: [PATCH] Added "Name" property to map_metadata.txt, fixed map names not being translated in some cases, fixed minor things from a previous commit --- .../001_Technical/003_Intl_Messages.rb | 5 -- Data/Scripts/004_Game classes/004_Game_Map.rb | 4 +- .../007_Objects and windows/011_Messages.rb | 7 +-- .../010_Data/002_PBS data/016_MapMetadata.rb | 52 +++++++++++-------- .../005_Overworld_RoamingPokemon.rb | 4 +- Data/Scripts/013_Items/004_Item_Phone.rb | 2 +- Data/Scripts/016_UI/010_UI_Phone.rb | 4 +- .../001_Editor screens/001_EditorScreens.rb | 45 ++++++++-------- Data/Scripts/020_Debug/003_Editor_Listers.rb | 1 - Data/Scripts/021_Compiler/001_Compiler.rb | 1 + .../021_Compiler/002_Compiler_CompilePBS.rb | 6 +++ 11 files changed, 71 insertions(+), 60 deletions(-) diff --git a/Data/Scripts/001_Technical/003_Intl_Messages.rb b/Data/Scripts/001_Technical/003_Intl_Messages.rb index 7f8b21799..47ed423f8 100644 --- a/Data/Scripts/001_Technical/003_Intl_Messages.rb +++ b/Data/Scripts/001_Technical/003_Intl_Messages.rb @@ -110,11 +110,6 @@ def pbSetTextMessages items.concat(choices) MessageTypes.setMapMessagesAsHash(0,items) mapinfos = pbLoadMapInfos - mapnames=[] - for id in mapinfos.keys - mapnames[id]=mapinfos[id].name - end - MessageTypes.setMessages(MessageTypes::MapNames,mapnames) for id in mapinfos.keys if Time.now.to_i - t >= 5 t = Time.now.to_i diff --git a/Data/Scripts/004_Game classes/004_Game_Map.rb b/Data/Scripts/004_Game classes/004_Game_Map.rb index ea2f41923..d6a912610 100644 --- a/Data/Scripts/004_Game classes/004_Game_Map.rb +++ b/Data/Scripts/004_Game classes/004_Game_Map.rb @@ -98,9 +98,7 @@ class Game_Map def tileset_id; return @map.tileset_id; end def name - ret = pbGetMessage(MessageTypes::MapNames,@map_id) - ret.gsub!(/\\PN/,$Trainer.name) if $Trainer - return ret + return pbGetMapNameFromId(@map_id) end def metadata diff --git a/Data/Scripts/007_Objects and windows/011_Messages.rb b/Data/Scripts/007_Objects and windows/011_Messages.rb index 20effc8e2..fc7c3b581 100644 --- a/Data/Scripts/007_Objects and windows/011_Messages.rb +++ b/Data/Scripts/007_Objects and windows/011_Messages.rb @@ -351,9 +351,10 @@ def pbGetBasicMapNameFromId(id) end def pbGetMapNameFromId(id) - map=pbGetBasicMapNameFromId(id) - map.gsub!(/\\PN/,$Trainer.name) if $Trainer - return map + name = pbGetMessage(MessageTypes::MapNames, id) + name = pbGetBasicMapNameFromId(id) if nil_or_empty?(name) + name.gsub!(/\\PN/, $Trainer.name) if $Trainer + return name end def pbCsvField!(str) diff --git a/Data/Scripts/010_Data/002_PBS data/016_MapMetadata.rb b/Data/Scripts/010_Data/002_PBS data/016_MapMetadata.rb index 1d85fa18e..7938855ac 100644 --- a/Data/Scripts/010_Data/002_PBS data/016_MapMetadata.rb +++ b/Data/Scripts/010_Data/002_PBS data/016_MapMetadata.rb @@ -1,6 +1,7 @@ module GameData class MapMetadata attr_reader :id + attr_reader :real_name attr_reader :outdoor_map attr_reader :announce_location attr_reader :can_bicycle @@ -27,27 +28,28 @@ module GameData DATA_FILENAME = "map_metadata.dat" SCHEMA = { - "Outdoor" => [1, "b"], - "ShowArea" => [2, "b"], - "Bicycle" => [3, "b"], - "BicycleAlways" => [4, "b"], - "HealingSpot" => [5, "vuu"], - "Weather" => [6, "eu", :Weather], - "MapPosition" => [7, "uuu"], - "DiveMap" => [8, "v"], - "DarkMap" => [9, "b"], - "SafariMap" => [10, "b"], - "SnapEdges" => [11, "b"], - "Dungeon" => [12, "b"], - "BattleBack" => [13, "s"], - "WildBattleBGM" => [14, "s"], - "TrainerBattleBGM" => [15, "s"], - "WildVictoryME" => [16, "s"], - "TrainerVictoryME" => [17, "s"], - "WildCaptureME" => [18, "s"], - "MapSize" => [19, "us"], - "Environment" => [20, "e", :Environment], - "Flags" => [21, "*s"] + "Name" => [1, "s"], + "Outdoor" => [2, "b"], + "ShowArea" => [3, "b"], + "Bicycle" => [4, "b"], + "BicycleAlways" => [5, "b"], + "HealingSpot" => [6, "vuu"], + "Weather" => [7, "eu", :Weather], + "MapPosition" => [8, "uuu"], + "DiveMap" => [9, "v"], + "DarkMap" => [10, "b"], + "SafariMap" => [11, "b"], + "SnapEdges" => [12, "b"], + "Dungeon" => [13, "b"], + "BattleBack" => [14, "s"], + "WildBattleBGM" => [15, "s"], + "TrainerBattleBGM" => [16, "s"], + "WildVictoryME" => [17, "s"], + "TrainerVictoryME" => [18, "s"], + "WildCaptureME" => [19, "s"], + "MapSize" => [20, "us"], + "Environment" => [21, "e", :Environment], + "Flags" => [22, "*s"] } extend ClassMethodsIDNumbers @@ -55,6 +57,7 @@ module GameData def self.editor_properties return [ + ["Name", StringProperty, _INTL("The name of the map, as seen by the player. Can be different to the map's name as seen in RMXP.")], ["Outdoor", BooleanProperty, _INTL("If true, this map is an outdoor map and will be tinted according to time of day.")], ["ShowArea", BooleanProperty, _INTL("If true, the game will display the map's name upon entry.")], ["Bicycle", BooleanProperty, _INTL("If true, the bicycle can be used on this map.")], @@ -81,6 +84,7 @@ module GameData def initialize(hash) @id = hash[:id] + @real_name = hash[:name] @outdoor_map = hash[:outdoor_map] @announce_location = hash[:announce_location] @can_bicycle = hash[:can_bicycle] @@ -106,6 +110,7 @@ module GameData def property_from_string(str) case str + when "Name" then return @real_name when "Outdoor" then return @outdoor_map when "ShowArea" then return @announce_location when "Bicycle" then return @can_bicycle @@ -131,6 +136,11 @@ module GameData return nil end + # @return [String] the translated name of this map + def name + return pbGetMapNameFromId(@id) + end + def has_flag?(flag) return @flags.any? { |f| f.downcase == flag.downcase } end diff --git a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb index de5585fb6..faad2d173 100644 --- a/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb +++ b/Data/Scripts/012_Overworld/002_Battle triggering/005_Overworld_RoamingPokemon.rb @@ -146,7 +146,7 @@ EncounterModifier.register(proc { |encounter| # Look at each roaming Pokémon in turn and decide whether it's possible to # encounter it currentRegion = pbGetCurrentRegion - currentMapName = pbGetMessage(MessageTypes::MapNames, $game_map.map_id) + currentMapName = $game_map.name possible_roamers = [] Settings::ROAMING_SPECIES.each_with_index do |data, i| # data = [species, level, Game Switch, roamer method, battle BGM, area maps hash] @@ -167,7 +167,7 @@ EncounterModifier.register(proc { |encounter| map_metadata = GameData::MapMetadata.try_get(roamerMap) next if !map_metadata || !map_metadata.town_map_position || map_metadata.town_map_position[0] != currentRegion - next if pbGetMessage(MessageTypes::MapNames, roamerMap) != currentMapName + next if pbGetMapNameFromId(roamerMap) != currentMapName end # Check whether the roamer's roamer method is currently possible next if !pbRoamingMethodAllowed(data[3]) diff --git a/Data/Scripts/013_Items/004_Item_Phone.rb b/Data/Scripts/013_Items/004_Item_Phone.rb index 2d8f9740e..e66978238 100644 --- a/Data/Scripts/013_Items/004_Item_Phone.rb +++ b/Data/Scripts/013_Items/004_Item_Phone.rb @@ -279,7 +279,7 @@ end def pbTrainerMapName(phonenum) return "" if !phonenum[6] || phonenum[6] == 0 - return pbGetMessage(MessageTypes::MapNames, phonenum[6]) + return pbGetMapNameFromId(phonenum[6]) end #=============================================================================== diff --git a/Data/Scripts/016_UI/010_UI_Phone.rb b/Data/Scripts/016_UI/010_UI_Phone.rb index 6ed6f85fa..f06856185 100644 --- a/Data/Scripts/016_UI/010_UI_Phone.rb +++ b/Data/Scripts/016_UI/010_UI_Phone.rb @@ -47,7 +47,7 @@ class PokemonPhoneScene 2,-18,128,64,@viewport) @sprites["header"].baseColor = Color.new(248,248,248) @sprites["header"].shadowColor = Color.new(0,0,0) - mapname = (@trainers[0][2]) ? pbGetMessage(MessageTypes::MapNames,@trainers[0][2]) : "" + mapname = (@trainers[0][2]) ? pbGetMapNameFromId(@trainers[0][2]) : "" @sprites["bottom"] = Window_AdvancedTextPokemon.newWithSize("", 162,Graphics.height-64,Graphics.width-158,64,@viewport) @sprites["bottom"].text = ""+mapname @@ -117,7 +117,7 @@ class PokemonPhoneScene @sprites["icon"].x = 86-charwidth/8 @sprites["icon"].y = 134-charheight/8 @sprites["icon"].src_rect = Rect.new(0,0,charwidth/4,charheight/4) - mapname=(trainer[2]) ? pbGetMessage(MessageTypes::MapNames,trainer[2]) : "" + mapname = (trainer[2]) ? pbGetMapNameFromId(trainer[2]) : "" @sprites["bottom"].text = ""+mapname for i in 0...@sprites["list"].page_item_max @sprites["rematch[#{i}]"].clearBitmaps 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 19095ba70..3fe32f392 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/001_EditorScreens.rb @@ -803,7 +803,7 @@ def pbMapMetadataScreen(map_id = 0) loop do map_id = pbListScreen(_INTL("SET METADATA"), MapLister.new(map_id)) break if map_id < 0 - (map_id == 0) ? pbEditMetadata : pbEditMetadata(map_id) + (map_id == 0) ? pbEditMetadata : pbEditMapMetadata(map_id) end end @@ -821,27 +821,28 @@ def pbEditMapMetadata(map_id) # Construct map metadata hash metadata_hash = { :id => map_id, - :outdoor_map => data[0], - :announce_location => data[1], - :can_bicycle => data[2], - :always_bicycle => data[3], - :teleport_destination => data[4], - :weather => data[5], - :town_map_position => data[6], - :dive_map_id => data[7], - :dark_map => data[8], - :safari_map => data[9], - :snap_edges => data[10], - :random_dungeon => data[11], - :battle_background => data[12], - :wild_battle_BGM => data[13], - :trainer_battle_BGM => data[14], - :wild_victory_ME => data[15], - :trainer_victory_ME => data[16], - :wild_capture_ME => data[17], - :town_map_size => data[18], - :battle_environment => data[19], - :flags => data[20] + :name => data[0], + :outdoor_map => data[1], + :announce_location => data[2], + :can_bicycle => data[3], + :always_bicycle => data[4], + :teleport_destination => data[5], + :weather => data[6], + :town_map_position => data[7], + :dive_map_id => data[8], + :dark_map => data[9], + :safari_map => data[10], + :snap_edges => data[11], + :random_dungeon => data[12], + :battle_background => data[13], + :wild_battle_BGM => data[14], + :trainer_battle_BGM => data[15], + :wild_victory_ME => data[16], + :trainer_victory_ME => data[17], + :wild_capture_ME => data[18], + :town_map_size => data[19], + :battle_environment => data[20], + :flags => data[21] } # Add map metadata's data to records GameData::MapMetadata.register(metadata_hash) diff --git a/Data/Scripts/020_Debug/003_Editor_Listers.rb b/Data/Scripts/020_Debug/003_Editor_Listers.rb index 7b530e4f7..71f0ec9dd 100644 --- a/Data/Scripts/020_Debug/003_Editor_Listers.rb +++ b/Data/Scripts/020_Debug/003_Editor_Listers.rb @@ -263,7 +263,6 @@ class MetadataLister @commands = [] @player_ids = [] GameData::PlayerMetadata.each do |player| - echoln player @index = @commands.length + 1 if sel_player_id > 0 && player.id == sel_player_id @player_ids.push(player.id) end diff --git a/Data/Scripts/021_Compiler/001_Compiler.rb b/Data/Scripts/021_Compiler/001_Compiler.rb index 59a845849..d11b10d35 100644 --- a/Data/Scripts/021_Compiler/001_Compiler.rb +++ b/Data/Scripts/021_Compiler/001_Compiler.rb @@ -787,6 +787,7 @@ module Compiler "encounters.txt", "items.txt", "map_connections.txt", + "map_metadata.txt", "metadata.txt", "moves.txt", "phone.txt", diff --git a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb index e0803c277..1508f17c7 100644 --- a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb @@ -1469,6 +1469,9 @@ module Compiler #============================================================================= def compile_map_metadata(path = "PBS/map_metadata.txt") GameData::MapMetadata::DATA.clear + map_infos = pbLoadMapInfos + map_names = [] + map_infos.keys.each { |id| map_names[id] = map_infos[id].name } # Read from PBS file File.open(path, "rb") { |f| FileLineData.file = path # For error reporting @@ -1490,6 +1493,7 @@ module Compiler # Construct map metadata hash metadata_hash = { :id => map_id, + :name => contents["Name"], :outdoor_map => contents["Outdoor"], :announce_location => contents["ShowArea"], :can_bicycle => contents["Bicycle"], @@ -1514,10 +1518,12 @@ module Compiler } # Add map metadata's data to records GameData::MapMetadata.register(metadata_hash) + map_names[map_id] = metadata_hash[:name] if !nil_or_empty?(metadata_hash[:name]) } } # Save all data GameData::MapMetadata.save + MessageTypes.setMessages(MessageTypes::MapNames, map_names) Graphics.update end