From 4d147a7bf70af7b844e6a3ee89093410431789eb Mon Sep 17 00:00:00 2001 From: Maruno17 Date: Sun, 20 Nov 2022 21:44:53 +0000 Subject: [PATCH] Turned Town Map PBS data into a GameData class --- Data/Scripts/010_Data/001_GameData.rb | 1 + .../010_Data/002_PBS data/001_MiscPBSData.rb | 13 -- .../010_Data/002_PBS data/002_TownMap.rb | 40 +++++ .../002_PBS data/{002_Type.rb => 003_Type.rb} | 0 .../{003_Ability.rb => 004_Ability.rb} | 0 .../002_PBS data/{004_Move.rb => 005_Move.rb} | 0 .../002_PBS data/{005_Item.rb => 006_Item.rb} | 0 .../{006_BerryPlant.rb => 007_BerryPlant.rb} | 0 .../{007_Species.rb => 008_Species.rb} | 0 ..._Species_Files.rb => 009_Species_files.rb} | 0 ...peciesMetrics.rb => 010_SpeciesMetrics.rb} | 0 ..._ShadowPokemon.rb => 011_ShadowPokemon.rb} | 0 .../{011_Ribbon.rb => 012_Ribbon.rb} | 0 .../{012_Encounter.rb => 013_Encounter.rb} | 0 ...{013_TrainerType.rb => 014_TrainerType.rb} | 0 .../{014_Trainer.rb => 015_Trainer.rb} | 0 .../{015_Metadata.rb => 016_Metadata.rb} | 0 ...layerMetadata.rb => 017_PlayerMetadata.rb} | 0 ...{017_MapMetadata.rb => 018_MapMetadata.rb} | 0 ...ungeonTileset.rb => 019_DungeonTileset.rb} | 0 ...20_PhoneMessage.rb => 021_PhoneMessage.rb} | 0 Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb | 8 +- Data/Scripts/016_UI/009_UI_RegionMap.rb | 59 +++---- .../003_EditorScreens_MapConnections.rb | 5 +- .../Scripts/020_Debug/002_Editor_DataTypes.rb | 17 +-- .../021_Compiler/002_Compiler_CompilePBS.rb | 144 ++++++------------ .../021_Compiler/003_Compiler_WritePBS.rb | 45 +----- 27 files changed, 127 insertions(+), 205 deletions(-) create mode 100644 Data/Scripts/010_Data/002_PBS data/002_TownMap.rb rename Data/Scripts/010_Data/002_PBS data/{002_Type.rb => 003_Type.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{003_Ability.rb => 004_Ability.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{004_Move.rb => 005_Move.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{005_Item.rb => 006_Item.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{006_BerryPlant.rb => 007_BerryPlant.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{007_Species.rb => 008_Species.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{008_Species_Files.rb => 009_Species_files.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{009_SpeciesMetrics.rb => 010_SpeciesMetrics.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{010_ShadowPokemon.rb => 011_ShadowPokemon.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{011_Ribbon.rb => 012_Ribbon.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{012_Encounter.rb => 013_Encounter.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{013_TrainerType.rb => 014_TrainerType.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{014_Trainer.rb => 015_Trainer.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{015_Metadata.rb => 016_Metadata.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{016_PlayerMetadata.rb => 017_PlayerMetadata.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{017_MapMetadata.rb => 018_MapMetadata.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{018_DungeonTileset.rb => 019_DungeonTileset.rb} (100%) rename Data/Scripts/010_Data/002_PBS data/{020_PhoneMessage.rb => 021_PhoneMessage.rb} (100%) diff --git a/Data/Scripts/010_Data/001_GameData.rb b/Data/Scripts/010_Data/001_GameData.rb index 92d972cee..eacfaf053 100644 --- a/Data/Scripts/010_Data/001_GameData.rb +++ b/Data/Scripts/010_Data/001_GameData.rb @@ -246,6 +246,7 @@ module GameData # A bulk loader method for all data stored in .dat files in the Data folder. #============================================================================= def self.load_all + TownMap.load Type.load Ability.load Move.load diff --git a/Data/Scripts/010_Data/002_PBS data/001_MiscPBSData.rb b/Data/Scripts/010_Data/002_PBS data/001_MiscPBSData.rb index 8b5da65b0..b6bddb673 100644 --- a/Data/Scripts/010_Data/002_PBS data/001_MiscPBSData.rb +++ b/Data/Scripts/010_Data/002_PBS data/001_MiscPBSData.rb @@ -2,7 +2,6 @@ # Data caches. #=============================================================================== class Game_Temp - attr_accessor :town_map_data attr_accessor :regional_dexes_data attr_accessor :battle_animations_data attr_accessor :move_to_battle_animation_data @@ -11,7 +10,6 @@ end def pbClearData if $game_temp - $game_temp.town_map_data = nil $game_temp.regional_dexes_data = nil $game_temp.battle_animations_data = nil $game_temp.move_to_battle_animation_data = nil @@ -24,17 +22,6 @@ def pbClearData end end -#=============================================================================== -# Method to get Town Map data. -#=============================================================================== -def pbLoadTownMapData - $game_temp = Game_Temp.new if !$game_temp - if !$game_temp.town_map_data - $game_temp.town_map_data = load_data("Data/town_map.dat") - end - return $game_temp.town_map_data -end - #=============================================================================== # Method to get Regional Dexes data. #=============================================================================== diff --git a/Data/Scripts/010_Data/002_PBS data/002_TownMap.rb b/Data/Scripts/010_Data/002_PBS data/002_TownMap.rb new file mode 100644 index 000000000..a11d850a1 --- /dev/null +++ b/Data/Scripts/010_Data/002_PBS data/002_TownMap.rb @@ -0,0 +1,40 @@ +module GameData + class TownMap + attr_reader :id + attr_reader :real_name + attr_reader :filename + attr_reader :point + attr_reader :flags + + DATA = {} + DATA_FILENAME = "town_map.dat" + + SCHEMA = { + "SectionName" => [:id, "u"], + "Name" => [:real_name, "s"], + "Filename" => [:filename, "s"], + "Point" => [:point, "^uussUUUU"], + "Flags" => [:flags, "*s"] + } + + extend ClassMethodsIDNumbers + include InstanceMethods + + def initialize(hash) + @id = hash[:id] + @real_name = hash[:real_name] || "???" + @filename = hash[:filename] + @point = hash[:point] || [] + @flags = hash[:flags] || [] + end + + # @return [String] the translated name of this region + def name + return pbGetMessage(MessageTypes::RegionNames, @id) + end + + def has_flag?(flag) + return @flags.any? { |f| f.downcase == flag.downcase } + end + end +end diff --git a/Data/Scripts/010_Data/002_PBS data/002_Type.rb b/Data/Scripts/010_Data/002_PBS data/003_Type.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/002_Type.rb rename to Data/Scripts/010_Data/002_PBS data/003_Type.rb diff --git a/Data/Scripts/010_Data/002_PBS data/003_Ability.rb b/Data/Scripts/010_Data/002_PBS data/004_Ability.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/003_Ability.rb rename to Data/Scripts/010_Data/002_PBS data/004_Ability.rb diff --git a/Data/Scripts/010_Data/002_PBS data/004_Move.rb b/Data/Scripts/010_Data/002_PBS data/005_Move.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/004_Move.rb rename to Data/Scripts/010_Data/002_PBS data/005_Move.rb diff --git a/Data/Scripts/010_Data/002_PBS data/005_Item.rb b/Data/Scripts/010_Data/002_PBS data/006_Item.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/005_Item.rb rename to Data/Scripts/010_Data/002_PBS data/006_Item.rb diff --git a/Data/Scripts/010_Data/002_PBS data/006_BerryPlant.rb b/Data/Scripts/010_Data/002_PBS data/007_BerryPlant.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/006_BerryPlant.rb rename to Data/Scripts/010_Data/002_PBS data/007_BerryPlant.rb diff --git a/Data/Scripts/010_Data/002_PBS data/007_Species.rb b/Data/Scripts/010_Data/002_PBS data/008_Species.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/007_Species.rb rename to Data/Scripts/010_Data/002_PBS data/008_Species.rb diff --git a/Data/Scripts/010_Data/002_PBS data/008_Species_Files.rb b/Data/Scripts/010_Data/002_PBS data/009_Species_files.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/008_Species_Files.rb rename to Data/Scripts/010_Data/002_PBS data/009_Species_files.rb diff --git a/Data/Scripts/010_Data/002_PBS data/009_SpeciesMetrics.rb b/Data/Scripts/010_Data/002_PBS data/010_SpeciesMetrics.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/009_SpeciesMetrics.rb rename to Data/Scripts/010_Data/002_PBS data/010_SpeciesMetrics.rb diff --git a/Data/Scripts/010_Data/002_PBS data/010_ShadowPokemon.rb b/Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/010_ShadowPokemon.rb rename to Data/Scripts/010_Data/002_PBS data/011_ShadowPokemon.rb diff --git a/Data/Scripts/010_Data/002_PBS data/011_Ribbon.rb b/Data/Scripts/010_Data/002_PBS data/012_Ribbon.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/011_Ribbon.rb rename to Data/Scripts/010_Data/002_PBS data/012_Ribbon.rb diff --git a/Data/Scripts/010_Data/002_PBS data/012_Encounter.rb b/Data/Scripts/010_Data/002_PBS data/013_Encounter.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/012_Encounter.rb rename to Data/Scripts/010_Data/002_PBS data/013_Encounter.rb diff --git a/Data/Scripts/010_Data/002_PBS data/013_TrainerType.rb b/Data/Scripts/010_Data/002_PBS data/014_TrainerType.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/013_TrainerType.rb rename to Data/Scripts/010_Data/002_PBS data/014_TrainerType.rb diff --git a/Data/Scripts/010_Data/002_PBS data/014_Trainer.rb b/Data/Scripts/010_Data/002_PBS data/015_Trainer.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/014_Trainer.rb rename to Data/Scripts/010_Data/002_PBS data/015_Trainer.rb diff --git a/Data/Scripts/010_Data/002_PBS data/015_Metadata.rb b/Data/Scripts/010_Data/002_PBS data/016_Metadata.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/015_Metadata.rb rename to Data/Scripts/010_Data/002_PBS data/016_Metadata.rb diff --git a/Data/Scripts/010_Data/002_PBS data/016_PlayerMetadata.rb b/Data/Scripts/010_Data/002_PBS data/017_PlayerMetadata.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/016_PlayerMetadata.rb rename to Data/Scripts/010_Data/002_PBS data/017_PlayerMetadata.rb diff --git a/Data/Scripts/010_Data/002_PBS data/017_MapMetadata.rb b/Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/017_MapMetadata.rb rename to Data/Scripts/010_Data/002_PBS data/018_MapMetadata.rb diff --git a/Data/Scripts/010_Data/002_PBS data/018_DungeonTileset.rb b/Data/Scripts/010_Data/002_PBS data/019_DungeonTileset.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/018_DungeonTileset.rb rename to Data/Scripts/010_Data/002_PBS data/019_DungeonTileset.rb diff --git a/Data/Scripts/010_Data/002_PBS data/020_PhoneMessage.rb b/Data/Scripts/010_Data/002_PBS data/021_PhoneMessage.rb similarity index 100% rename from Data/Scripts/010_Data/002_PBS data/020_PhoneMessage.rb rename to Data/Scripts/010_Data/002_PBS data/021_PhoneMessage.rb diff --git a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb index eabdf250c..ba1a5fec4 100644 --- a/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb +++ b/Data/Scripts/016_UI/004_UI_Pokedex_Entry.rb @@ -17,13 +17,13 @@ class PokemonPokedexInfo_Scene @sprites["infosprite"].setOffset(PictureOrigin::CENTER) @sprites["infosprite"].x = 104 @sprites["infosprite"].y = 136 - @mapdata = pbLoadTownMapData mappos = $game_map.metadata&.town_map_position if @region < 0 # Use player's current region @region = (mappos) ? mappos[0] : 0 # Region 0 default end + @mapdata = GameData::TownMap.get(@region) @sprites["areamap"] = IconSprite.new(0, 0, @viewport) - @sprites["areamap"].setBitmap("Graphics/UI/Town Map/#{@mapdata[@region][1]}") + @sprites["areamap"].setBitmap("Graphics/UI/Town Map/#{@mapdata.filename}") @sprites["areamap"].x += (Graphics.width - @sprites["areamap"].bitmap.width) / 2 @sprites["areamap"].y += (Graphics.height + 32 - @sprites["areamap"].bitmap.height) / 2 Settings::REGION_MAP_EXTRAS.each do |hidden| @@ -296,7 +296,7 @@ class PokemonPokedexInfo_Scene # defined point in town_map.txt, and which either have no Self Switch # controlling their visibility or whose Self Switch is ON) visible_points = [] - @mapdata[@region][2].each do |loc| + @mapdata.point.each do |loc| next if loc[7] && !$game_switches[loc[7]] # Point is not visible visible_points.push([loc[0], loc[1]]) end @@ -375,7 +375,7 @@ class PokemonPokedexInfo_Scene ) textpos.push([_INTL("Area unknown"), Graphics.width / 2, (Graphics.height / 2) + 6, 2, base, shadow]) end - textpos.push([pbGetMessage(MessageTypes::RegionNames, @region), 414, 50, 2, base, shadow]) + textpos.push([@mapdata.name, 414, 50, 2, base, shadow]) textpos.push([_INTL("{1}'s area", GameData::Species.get(@species).name), Graphics.width / 2, 358, 2, base, shadow]) pbDrawTextPositions(overlay, textpos) diff --git a/Data/Scripts/016_UI/009_UI_RegionMap.rb b/Data/Scripts/016_UI/009_UI_RegionMap.rb index 5c5b4264b..bd902a26e 100644 --- a/Data/Scripts/016_UI/009_UI_RegionMap.rb +++ b/Data/Scripts/016_UI/009_UI_RegionMap.rb @@ -72,27 +72,26 @@ class PokemonRegionMap_Scene @viewport = Viewport.new(0, 0, Graphics.width, Graphics.height) @viewport.z = 99999 @sprites = {} - @map_data = pbLoadTownMapData @fly_map = fly_map @mode = fly_map ? 1 : 0 map_metadata = $game_map.metadata playerpos = (map_metadata) ? map_metadata.town_map_position : nil if !playerpos mapindex = 0 - @map = @map_data[0] + @map = GameData::TownMap.get(0) @map_x = LEFT @map_y = TOP - elsif @region >= 0 && @region != playerpos[0] && @map_data[@region] + elsif @region >= 0 && @region != playerpos[0] && GameData::TownMap.exists?(@region) mapindex = @region - @map = @map_data[@region] + @map = GameData::TownMap.get(@region) @map_x = LEFT @map_y = TOP else mapindex = playerpos[0] - @map = @map_data[playerpos[0]] - @map_x = playerpos[1] - @map_y = playerpos[2] - mapsize = map_metadata.town_map_size + @map = GameData::TownMap.get(playerpos[0]) + @map_x = playerpos[1] + @map_y = playerpos[2] + mapsize = map_metadata.town_map_size if mapsize && mapsize[0] && mapsize[0] > 0 sqwidth = mapsize[0] sqheight = (mapsize[1].length.to_f / mapsize[0]).ceil @@ -106,7 +105,7 @@ class PokemonRegionMap_Scene end addBackgroundOrColoredPlane(@sprites, "background", "Town Map/bg", Color.black, @viewport) @sprites["map"] = IconSprite.new(0, 0, @viewport) - @sprites["map"].setBitmap("Graphics/UI/Town Map/#{@map[1]}") + @sprites["map"].setBitmap("Graphics/UI/Town Map/#{@map.filename}") @sprites["map"].x += (Graphics.width - @sprites["map"].bitmap.width) / 2 @sprites["map"].y += (Graphics.height - @sprites["map"].bitmap.height) / 2 Settings::REGION_MAP_EXTRAS.each do |graphic| @@ -122,7 +121,7 @@ class PokemonRegionMap_Scene ) end @sprites["mapbottom"] = MapBottomSprite.new(@viewport) - @sprites["mapbottom"].mapname = pbGetMessage(MessageTypes::RegionNames, mapindex) + @sprites["mapbottom"].mapname = @map.name @sprites["mapbottom"].maplocation = pbGetMapLocation(@map_x, @map_y) @sprites["mapbottom"].mapdetails = pbGetMapDetails(@map_x, @map_y) if playerpos && mapindex == playerpos[0] @@ -177,27 +176,13 @@ class PokemonRegionMap_Scene end def pbSaveMapData - File.open("PBS/town_map.txt", "wb") { |f| - Compiler.add_PBS_header_to_file(f) - @map_data.length.times do |i| - map = @map_data[i] - next if !map - f.write("\#-------------------------------\r\n") - f.write(sprintf("[%d]\r\n", i)) - f.write(sprintf("Name = %s\r\n", Compiler.csvQuote(map[0]))) - f.write(sprintf("Filename = %s\r\n", Compiler.csvQuote(map[1]))) - map[2].each do |loc| - f.write("Point = ") - Compiler.pbWriteCsvRecord(loc, f, [nil, "uussUUUU"]) - f.write("\r\n") - end - end - } + GameData::TownMap.save + Compiler.write_town_map end def pbGetMapLocation(x, y) - return "" if !@map[2] - @map[2].each do |point| + return "" if !@map.point + @map.point.each do |point| next if point[0] != x || point[1] != y return "" if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) name = pbGetMessageFromHash(MessageTypes::PlaceNames, point[2]) @@ -207,25 +192,25 @@ class PokemonRegionMap_Scene end def pbChangeMapLocation(x, y) - return "" if !@editor || !@map[2] - map = @map[2].select { |loc| loc[0] == x && loc[1] == y }[0] - currentobj = map - currentname = (map) ? map[2] || "" : "" + return "" if !@editor || !@map.point + point = @map.point.select { |loc| loc[0] == x && loc[1] == y }[0] + currentobj = point + currentname = (point) ? point[2] : "" currentname = pbMessageFreeText(_INTL("Set the name for this point."), currentname, false, 250) { pbUpdate } if currentname if currentobj currentobj[2] = currentname else newobj = [x, y, currentname, ""] - @map[2].push(newobj) + @map.point.push(newobj) end @changed = true end end def pbGetMapDetails(x, y) # From Wichu, with my help - return "" if !@map[2] - @map[2].each do |point| + return "" if !@map.point + @map.point.each do |point| next if point[0] != x || point[1] != y return "" if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) mapdesc = pbGetMessageFromHash(MessageTypes::PlaceDescriptions, point[3]) @@ -235,8 +220,8 @@ class PokemonRegionMap_Scene end def pbGetHealingSpot(x, y) - return nil if !@map[2] - @map[2].each do |point| + return nil if !@map.point + @map.point.each do |point| next if point[0] != x || point[1] != y return nil if point[7] && (@wallmap || point[7] <= 0 || !$game_switches[point[7]]) return (point[4] && point[5] && point[6]) ? [point[4], point[5], point[6]] : nil diff --git a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb index 8b970efd2..ae47d55bd 100644 --- a/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb +++ b/Data/Scripts/020_Debug/001_Editor screens/003_EditorScreens_MapConnections.rb @@ -105,9 +105,8 @@ class RegionMapSprite end def createRegionMap(map) - @mapdata = pbLoadTownMapData - @map = @mapdata[map] - bitmap = AnimatedBitmap.new("Graphics/UI/Town Map/#{@map[1]}").deanimate + town_map = GameData::TownMap.get(map) + bitmap = AnimatedBitmap.new("Graphics/UI/Town Map/#{town_map.filename}").deanimate retbitmap = BitmapWrapper.new(bitmap.width / 2, bitmap.height / 2) retbitmap.stretch_blt( Rect.new(0, 0, bitmap.width / 2, bitmap.height / 2), diff --git a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb index de0beff16..8a5b6d45d 100644 --- a/Data/Scripts/020_Debug/002_Editor_DataTypes.rb +++ b/Data/Scripts/020_Debug/002_Editor_DataTypes.rb @@ -769,15 +769,10 @@ module RegionMapCoordsProperty selregion = regions[0][0] else cmds = [] - regions.each do |region| - cmds.push(region[1]) - end + regions.each { |region| cmds.push(region[1]) } selcmd = pbMessage(_INTL("Choose a region map."), cmds, -1) - if selcmd >= 0 - selregion = regions[selcmd][0] - else - return oldsetting - end + return oldsetting if selcmd < 0 + selregion = regions[selcmd][0] end mappoint = chooseMapPoint(selregion, true) return (mappoint) ? [selregion, mappoint[0], mappoint[1]] : oldsetting @@ -788,12 +783,8 @@ module RegionMapCoordsProperty end def self.getMapNameList - mapdata = pbLoadTownMapData ret = [] - mapdata.length.times do |i| - next if !mapdata[i] - ret.push([i, pbGetMessage(MessageTypes::RegionNames, i)]) - end + GameData::TownMap.each { |town_map| ret.push([town_map.id, town_map.name]) } return ret end end diff --git a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb index 00fa43090..9dd7d2da1 100644 --- a/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb +++ b/Data/Scripts/021_Compiler/002_Compiler_CompilePBS.rb @@ -60,80 +60,28 @@ module Compiler # Compile Town Map data #============================================================================= def compile_town_map(path = "PBS/town_map.txt") - compile_pbs_file_message_start(path) - sections = [] - # Read from PBS file - File.open(path, "rb") { |f| - FileLineData.file = path # For error reporting - # Read a whole section's lines at once, then run through this code. - # contents is a hash containing all the XXX=YYY lines in that section, where - # the keys are the XXX and the values are the YYY (as unprocessed strings). - schema = { - "SectionName" => [:id, "u"], - "Name" => [:real_name, "s"], - "Filename" => [:filename, "s"], - "Point" => [:point, "^uussUUUU"] - } - idx = 0 - pbEachFileSection(f, schema) { |contents, section_name| - echo "." if idx % 50 == 0 - Graphics.update if idx % 250 == 0 - idx += 1 - data_hash = {:id => section_name.to_sym} - # Go through schema hash of compilable data and compile this section - schema.each_key do |key| - FileLineData.setSection(section_name, key, contents[key]) # For error reporting - if key == "SectionName" - data_hash[schema[key][0]] = pbGetCsvRecord(section_name, key, schema[key]) - next - end - # Skip empty properties - next if contents[key].nil? - # Compile value for key - if schema[key][1][0] == "^" - contents[key].each do |val| - value = pbGetCsvRecord(val, key, schema[key]) - value = nil if value.is_a?(Array) && value.empty? - data_hash[schema[key][0]] ||= [] - data_hash[schema[key][0]].push(value) - end - data_hash[schema[key][0]].compact! - else - value = pbGetCsvRecord(contents[key], key, schema[key]) - value = nil if value.is_a?(Array) && value.empty? - data_hash[schema[key][0]] = value - end - end - # Validate and modify the compiled data - validate_compiled_town_map(data_hash) - if sections[data_hash[:id]] - raise _INTL("Region ID '{1}' is used twice.\r\n{2}", data_hash[:id], FileLineData.linereport) - end - # Add town map messages to records - sections[data_hash[:id]] = [data_hash[:real_name], data_hash[:filename], data_hash[:point]] - } - } - validate_all_compiled_town_maps(sections) - # Save all data - save_data(sections, "Data/town_map.dat") - process_pbs_file_message_end + compile_PBS_file_generic(GameData::TownMap, path) do |final_validate, hash| + (final_validate) ? validate_all_compiled_town_maps : validate_compiled_town_map(hash) + end end def validate_compiled_town_map(hash) end - def validate_all_compiled_town_maps(sections) + def validate_all_compiled_town_maps # Get town map names and descriptions for translating region_names = [] point_names = [] interest_names = [] - sections.each_with_index do |region, i| - region_names[i] = region[0] - region[2].each do |point| + GameData::TownMap.each do |town_map| + region_names[town_map.id] = town_map.real_name + town_map.point.each do |point| point_names.push(point[2]) interest_names.push(point[3]) end end + point_names.uniq! + interest_names.uniq! MessageTypes.setMessages(MessageTypes::RegionNames, region_names) MessageTypes.setMessagesAsHash(MessageTypes::PlaceNames, point_names) MessageTypes.setMessagesAsHash(MessageTypes::PlaceDescriptions, interest_names) @@ -182,43 +130,6 @@ module Compiler process_pbs_file_message_end end - #============================================================================= - # Compile phone messages - #============================================================================= - def compile_phone(path = "PBS/phone.txt") - compile_PBS_file_generic(GameData::PhoneMessage, path) do |final_validate, hash| - (final_validate) ? validate_all_compiled_phone_contacts : validate_compiled_phone_contact(hash) - end - end - - def validate_compiled_phone_contact(hash) - # Split trainer type/name/version into their own values, generate compound ID from them - if hash[:id].strip.downcase == "default" - hash[:id] = "default" - hash[:trainer_type] = hash[:id] - else - line_data = pbGetCsvRecord(hash[:id], -1, [0, "esU", :TrainerType]) - hash[:trainer_type] = line_data[0] - hash[:real_name] = line_data[1] - hash[:version] = line_data[2] || 0 - hash[:id] = [hash[:trainer_type], hash[:real_name], hash[:version]] - end - end - - def validate_all_compiled_phone_contacts - # Get all phone messages for translating - messages = [] - GameData::PhoneMessage.each do |contact| - [:intro, :intro_morning, :intro_afternoon, :intro_evening, :body, :body1, - :body2, :battle_request, :battle_remind, :end].each do |msg_type| - msgs = contact.send(msg_type) - next if !msgs || msgs.length == 0 - msgs.each { |msg| messages.push(msg) } - end - end - MessageTypes.setMessagesAsHash(MessageTypes::PhoneMessages, messages) - end - #============================================================================= # Compile type data #============================================================================= @@ -1220,6 +1131,43 @@ module Compiler def validate_all_compiled_dungeon_parameters end + #============================================================================= + # Compile phone messages + #============================================================================= + def compile_phone(path = "PBS/phone.txt") + compile_PBS_file_generic(GameData::PhoneMessage, path) do |final_validate, hash| + (final_validate) ? validate_all_compiled_phone_contacts : validate_compiled_phone_contact(hash) + end + end + + def validate_compiled_phone_contact(hash) + # Split trainer type/name/version into their own values, generate compound ID from them + if hash[:id].strip.downcase == "default" + hash[:id] = "default" + hash[:trainer_type] = hash[:id] + else + line_data = pbGetCsvRecord(hash[:id], -1, [0, "esU", :TrainerType]) + hash[:trainer_type] = line_data[0] + hash[:real_name] = line_data[1] + hash[:version] = line_data[2] || 0 + hash[:id] = [hash[:trainer_type], hash[:real_name], hash[:version]] + end + end + + def validate_all_compiled_phone_contacts + # Get all phone messages for translating + messages = [] + GameData::PhoneMessage.each do |contact| + [:intro, :intro_morning, :intro_afternoon, :intro_evening, :body, :body1, + :body2, :battle_request, :battle_remind, :end].each do |msg_type| + msgs = contact.send(msg_type) + next if !msgs || msgs.length == 0 + msgs.each { |msg| messages.push(msg) } + end + end + MessageTypes.setMessagesAsHash(MessageTypes::PhoneMessages, messages) + end + #============================================================================= # Compile battle animations #============================================================================= diff --git a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb index c93410f9b..0a85c3e1a 100644 --- a/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb +++ b/Data/Scripts/021_Compiler/003_Compiler_WritePBS.rb @@ -48,36 +48,7 @@ module Compiler # Save Town Map data to PBS file #============================================================================= def write_town_map(path = "PBS/town_map.txt") - write_pbs_file_message_start(path) - schema = { - "Name" => [0, "s"], - "Filename" => [1, "s"], - "Point" => [2, "^uussUUUU"] - } - File.open(path, "wb") { |f| - add_PBS_header_to_file(f) - # Write each element in turn - pbLoadTownMapData.each_with_index do |element, i| - f.write("\#-------------------------------\r\n") - f.write(sprintf("[%d]\r\n", i)) - schema.each_key do |key| - val = element[schema[key][0]] - next if val.nil? - if schema[key][1][0] == "^" && val.is_a?(Array) - val.each do |sub_val| - f.write(sprintf("%s = ", key)) - pbWriteCsvRecord(sub_val, f, schema[key]) - f.write("\r\n") - end - else - f.write(sprintf("%s = ", key)) - pbWriteCsvRecord(val, f, schema[key]) - f.write("\r\n") - end - end - end - } - process_pbs_file_message_end + write_PBS_file_generic(GameData::TownMap, path) end #============================================================================= @@ -140,13 +111,6 @@ module Compiler process_pbs_file_message_end end - #============================================================================= - # Save phone messages to PBS file - #============================================================================= - def write_phone(path = "PBS/phone.txt") - write_PBS_file_generic(GameData::PhoneMessage, path) - end - #============================================================================= # Save type data to PBS file #============================================================================= @@ -712,6 +676,13 @@ module Compiler write_PBS_file_generic(GameData::DungeonParameters, path) end + #============================================================================= + # Save phone messages to PBS file + #============================================================================= + def write_phone(path = "PBS/phone.txt") + write_PBS_file_generic(GameData::PhoneMessage, path) + end + #============================================================================= # Save all data to PBS files #=============================================================================