Made Compiler more modular

This commit is contained in:
Maruno17
2024-05-14 22:11:12 +01:00
parent 5bef70fb3a
commit 01c13ada76
6 changed files with 387 additions and 335 deletions

View File

@@ -1378,7 +1378,7 @@ MenuHandlers.add(:debug_menu, :create_pbs_files, {
loop do
cmd = pbShowCommands(nil, cmds, -1, cmd)
case cmd
when 0 then Compiler.write_all
when 0 then Compiler.write_all_pbs_files
when 1 then Compiler.write_abilities
when 2 then Compiler.write_trainer_lists
when 3 then Compiler.write_berry_plants

View File

@@ -54,6 +54,8 @@ end
# Compiler
#===============================================================================
module Compiler
@@categories = {}
module_function
def findIndex(a)
@@ -89,9 +91,9 @@ module Compiler
return csvQuote(str, true)
end
#=============================================================================
#-----------------------------------------------------------------------------
# PBS file readers
#=============================================================================
#-----------------------------------------------------------------------------
def pbEachFileSectionEx(f, schema = nil)
lineno = 1
havesection = false
@@ -248,10 +250,10 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Splits a string containing comma-separated values into an array of those
# values.
#=============================================================================
#-----------------------------------------------------------------------------
def split_csv_line(string)
# Split the string into an array of values, using a comma as the separator
values = string.split(",")
@@ -292,9 +294,9 @@ module Compiler
return values
end
#=============================================================================
#-----------------------------------------------------------------------------
# Convert a string to certain kinds of values
#=============================================================================
#-----------------------------------------------------------------------------
# Unused
# NOTE: This method is about 10 times slower than split_csv_line.
def csvfield!(str)
@@ -508,9 +510,9 @@ module Compiler
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)
@@ -684,9 +686,9 @@ module Compiler
return (!repeat && schema_length == 1) ? record[0] : record
end
#=============================================================================
#-----------------------------------------------------------------------------
# Convert a string to values using a schema
#=============================================================================
#-----------------------------------------------------------------------------
def get_csv_record(rec, schema)
ret = []
repeat = false
@@ -736,9 +738,9 @@ module Compiler
return (!repeat && schema_length == 1) ? ret[0] : ret
end
#=============================================================================
#-----------------------------------------------------------------------------
# Write values to a file using a schema
#=============================================================================
#-----------------------------------------------------------------------------
def pbWriteCsvRecord(record, file, schema)
rec = (record.is_a?(Array)) ? record.flatten : [record]
start = (["*", "^"].include?(schema[1][0, 1])) ? 1 : 0
@@ -841,10 +843,10 @@ module Compiler
return record
end
#=============================================================================
#-----------------------------------------------------------------------------
# Parse string into a likely constant name and return its ID number (if any).
# Last ditch attempt to figure out whether a constant is defined.
#=============================================================================
#-----------------------------------------------------------------------------
# Unused
def pbGetConst(mod, item, err)
isDef = false
@@ -918,9 +920,9 @@ module Compiler
return typ.id
end
#=============================================================================
#-----------------------------------------------------------------------------
# Replace text in PBS files before compiling them
#=============================================================================
#-----------------------------------------------------------------------------
def edit_and_rewrite_pbs_file_text(filename)
return if !block_given?
lines = []
@@ -946,160 +948,40 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile all data
#=============================================================================
def compile_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
Console.echo_li(_INTL("Compiling PBS file `{1}`...", filename.split("/").last))
end
def write_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
Console.echo_li(_INTL("Writing PBS file `{1}`...", filename.split("/").last))
end
def process_pbs_file_message_end
Console.echo_done(true)
Graphics.update
end
def get_all_pbs_files_to_compile
# Get the GameData classes and their respective base PBS filenames
ret = GameData.get_all_pbs_base_filenames
ret.merge!({
:BattleFacility => "battle_facility_lists",
:Connection => "map_connections",
:RegionalDex => "regional_dexes"
})
ret.each { |key, val| ret[key] = [val] } # [base_filename, ["PBS/file.txt", etc.]]
# Look through all PBS files and match them to a GameData class based on
# their base filenames
text_files_keys = ret.keys.sort! { |a, b| ret[b][0].length <=> ret[a][0].length }
Dir.chdir("PBS/") do
Dir.glob("*.txt") do |f|
base_name = File.basename(f, ".txt")
text_files_keys.each do |key|
next if base_name != ret[key][0] && !f.start_with?(ret[key][0] + "_")
ret[key][1] ||= []
ret[key][1].push("PBS/" + f)
break
end
end
#-----------------------------------------------------------------------------
def categories_to_compile(all_categories = false)
ret = []
Input.update
if all_categories || $full_compile || Input.press?(Input::CTRL)
ret = @@categories.keys.clone
return ret
end
@@categories.each_pair do |category, procs|
ret.push(category) if procs[:should_compile]&.call
end
return ret
end
def compile_pbs_files
text_files = get_all_pbs_files_to_compile
modify_pbs_file_contents_before_compiling
compile_town_map(*text_files[:TownMap][1])
compile_connections(*text_files[:Connection][1])
compile_types(*text_files[:Type][1])
compile_abilities(*text_files[:Ability][1])
compile_moves(*text_files[:Move][1]) # Depends on Type
compile_items(*text_files[:Item][1]) # Depends on Move
compile_berry_plants(*text_files[:BerryPlant][1]) # Depends on Item
compile_pokemon(*text_files[:Species][1]) # Depends on Move, Item, Type, Ability
compile_pokemon_forms(*text_files[:Species1][1]) # Depends on Species, Move, Item, Type, Ability
compile_pokemon_metrics(*text_files[:SpeciesMetrics][1]) # Depends on Species
compile_shadow_pokemon(*text_files[:ShadowPokemon][1]) # Depends on Species
compile_regional_dexes(*text_files[:RegionalDex][1]) # Depends on Species
compile_ribbons(*text_files[:Ribbon][1])
compile_encounters(*text_files[:Encounter][1]) # Depends on Species
compile_trainer_types(*text_files[:TrainerType][1])
compile_trainers(*text_files[:Trainer][1]) # Depends on Species, Item, Move
compile_trainer_lists # Depends on TrainerType
compile_metadata(*text_files[:Metadata][1]) # Depends on TrainerType
compile_map_metadata(*text_files[:MapMetadata][1])
compile_dungeon_tilesets(*text_files[:DungeonTileset][1])
compile_dungeon_parameters(*text_files[:DungeonParameters][1])
compile_phone(*text_files[:PhoneMessage][1]) # Depends on TrainerType
end
def compile_all(mustCompile)
Console.echo_h1(_INTL("Checking game data"))
if !mustCompile
Console.echoln_li(_INTL("Game data was not compiled"))
echoln ""
return
end
def compile_all(all_categories = false)
FileLineData.clear
compile_pbs_files
compile_animations
compile_trainer_events(mustCompile)
Console.echo_li(_INTL("Saving messages..."))
Translator.gather_script_and_event_texts
MessageTypes.save_default_messages
MessageTypes.load_default_messages if FileTest.exist?("Data/messages_core.dat")
Console.echo_done(true)
Console.echoln_li_done(_INTL("Successfully compiled all game data"))
to_compile = categories_to_compile(all_categories)
@@categories.each_pair do |category, procs|
Console.echo_h1(procs[:header_text]&.call || _INTL("Compiling {1}", category))
if to_compile.include?(category)
@@categories[category][:compile].call
else
Console.echoln_li(procs[:skipped_text]&.call || _INTL("Not compiled"))
end
echoln ""
end
end
def main
return if !$DEBUG
begin
mustCompile = false
# If no PBS file, create one and fill it, then recompile
if !FileTest.directory?("PBS")
Dir.mkdir("PBS") rescue nil
GameData.load_all
write_all
mustCompile = true
end
# Get all data files and PBS files to be checked for their last modified times
data_files = GameData.get_all_data_filenames
data_files += [ # Extra .dat files for data that isn't a GameData class
["map_connections.dat", true],
["regional_dexes.dat", true],
["trainer_lists.dat", true]
]
text_files = get_all_pbs_files_to_compile
latestDataTime = 0
latestTextTime = 0
# Should recompile if new maps were imported
mustCompile |= import_new_maps
# Check data files for their latest modify time
data_files.each do |filename| # filename = [string, boolean (whether mandatory)]
if FileTest.exist?("Data/" + filename[0])
begin
File.open("Data/#{filename[0]}") do |file|
latestDataTime = [latestDataTime, file.mtime.to_i].max
end
rescue SystemCallError
mustCompile = true
end
elsif filename[1]
mustCompile = true
break
end
end
# Check PBS files for their latest modify time
text_files.each do |key, value|
next if !value || !value[1].is_a?(Array)
value[1].each do |filepath|
begin
File.open(filepath) { |file| latestTextTime = [latestTextTime, file.mtime.to_i].max }
rescue SystemCallError
end
end
end
# Decide to compile if a PBS file was edited more recently than any .dat files
mustCompile |= (latestTextTime >= latestDataTime)
# Should recompile if holding Ctrl
Input.update
mustCompile = true if $full_compile || Input.press?(Input::CTRL)
# Delete old data files in preparation for recompiling
if mustCompile
data_files.each do |filename|
begin
File.delete("Data/#{filename[0]}") if FileTest.exist?("Data/#{filename[0]}")
rescue SystemCallError
end
end
end
# Recompile all data
compile_all(mustCompile)
compile_all
rescue Exception
e = $!
raise e if e.class.to_s == "Reset" || e.is_a?(Reset) || e.is_a?(SystemExit)

View File

@@ -1,6 +1,139 @@
module Compiler
@@categories[:pbs_files] = {
:should_compile => proc { next should_compile_pbs_files? },
:header_text => proc { next _INTL("Compiling PBS files") },
:skipped_text => proc { next _INTL("Not compiled") },
:compile => proc {
# Delete old data files in preparation for recompiling
get_all_pbs_data_filenames_to_compile.each do |filename|
begin
File.delete("Data/#{filename[0]}") if FileTest.exist?("Data/#{filename[0]}")
rescue SystemCallError
end
end
compile_pbs_files
}
}
module_function
def get_all_pbs_data_filenames_to_compile
ret = GameData.get_all_data_filenames
ret += [ # Extra .dat files for data that isn't a GameData class
["map_connections.dat", true],
["regional_dexes.dat", true],
["trainer_lists.dat", true]
]
return ret
end
def get_all_pbs_files_to_compile
# Get the GameData classes and their respective base PBS filenames
ret = GameData.get_all_pbs_base_filenames
ret.merge!({
:BattleFacility => "battle_facility_lists",
:Connection => "map_connections",
:RegionalDex => "regional_dexes"
})
ret.each { |key, val| ret[key] = [val] } # [base_filename, ["PBS/file.txt", etc.]]
# Look through all PBS files and match them to a GameData class based on
# their base filenames
text_files_keys = ret.keys.sort! { |a, b| ret[b][0].length <=> ret[a][0].length }
Dir.chdir("PBS/") do
Dir.glob("*.txt") do |f|
base_name = File.basename(f, ".txt")
text_files_keys.each do |key|
next if base_name != ret[key][0] && !f.start_with?(ret[key][0] + "_")
ret[key][1] ||= []
ret[key][1].push("PBS/" + f)
break
end
end
end
return ret
end
def should_compile_pbs_files?
# If no PBS folder exists, create one and fill it, then recompile
if !FileTest.directory?("PBS")
Dir.mkdir("PBS") rescue nil
GameData.load_all
write_all_pbs_files
return true
end
# Get all data files and PBS files to be checked for their last modified times
data_files = get_all_pbs_data_filenames_to_compile
text_files = get_all_pbs_files_to_compile
# Check data files for their latest modify time
latest_data_write_time = 0
data_files.each do |filename| # filename = [string, boolean (whether mandatory)]
if FileTest.exist?("Data/" + filename[0])
begin
File.open("Data/#{filename[0]}") do |file|
latest_data_write_time = [latest_data_write_time, file.mtime.to_i].max
end
rescue SystemCallError
return true
end
elsif filename[1]
return true
end
end
# Check PBS files for their latest modify time
latest_text_edit_time = 0
text_files.each_value do |value|
next if !value || !value[1].is_a?(Array)
value[1].each do |filepath|
begin
File.open(filepath) { |file| latest_text_edit_time = [latest_text_edit_time, file.mtime.to_i].max }
rescue SystemCallError
end
end
end
# Decide to compile if a PBS file was edited more recently than any .dat files
return (latest_text_edit_time >= latest_data_write_time)
end
def compile_pbs_files
text_files = get_all_pbs_files_to_compile
modify_pbs_file_contents_before_compiling
compile_town_map(*text_files[:TownMap][1])
compile_connections(*text_files[:Connection][1])
compile_types(*text_files[:Type][1])
compile_abilities(*text_files[:Ability][1])
compile_moves(*text_files[:Move][1]) # Depends on Type
compile_items(*text_files[:Item][1]) # Depends on Move
compile_berry_plants(*text_files[:BerryPlant][1]) # Depends on Item
compile_pokemon(*text_files[:Species][1]) # Depends on Move, Item, Type, Ability
compile_pokemon_forms(*text_files[:Species1][1]) # Depends on Species, Move, Item, Type, Ability
compile_pokemon_metrics(*text_files[:SpeciesMetrics][1]) # Depends on Species
compile_shadow_pokemon(*text_files[:ShadowPokemon][1]) # Depends on Species
compile_regional_dexes(*text_files[:RegionalDex][1]) # Depends on Species
compile_ribbons(*text_files[:Ribbon][1])
compile_encounters(*text_files[:Encounter][1]) # Depends on Species
compile_trainer_types(*text_files[:TrainerType][1])
compile_trainers(*text_files[:Trainer][1]) # Depends on Species, Item, Move
compile_trainer_lists # Depends on TrainerType
compile_metadata(*text_files[:Metadata][1]) # Depends on TrainerType
compile_map_metadata(*text_files[:MapMetadata][1])
compile_dungeon_tilesets(*text_files[:DungeonTileset][1])
compile_dungeon_parameters(*text_files[:DungeonParameters][1])
compile_phone(*text_files[:PhoneMessage][1]) # Depends on TrainerType
end
#-----------------------------------------------------------------------------
# Generic methods used when compiling PBS files
#-----------------------------------------------------------------------------
def compile_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
Console.echo_li(_INTL("Compiling PBS file `{1}`...", filename.split("/").last))
end
def process_pbs_file_message_end
Console.echo_done(true)
Graphics.update
end
def compile_PBS_file_generic(game_data, *paths)
if game_data.const_defined?(:OPTIONAL) && game_data::OPTIONAL
return if paths.none? { |p| FileTest.exist?(p) }
@@ -67,9 +200,9 @@ module Compiler
game_data.save
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Town Map data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_town_map(*paths)
compile_PBS_file_generic(GameData::TownMap, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_town_maps : validate_compiled_town_map(hash)
@@ -98,9 +231,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::REGION_LOCATION_DESCRIPTIONS, interest_names)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile map connections
#=============================================================================
#-----------------------------------------------------------------------------
def compile_connections(*paths)
hashenum = {
"N" => "N", "North" => "N",
@@ -137,9 +270,9 @@ module Compiler
save_data(records, "Data/map_connections.dat")
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile type data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_types(*paths)
compile_PBS_file_generic(GameData::Type, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_types : validate_compiled_type(hash)
@@ -175,9 +308,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::TYPE_NAMES, type_names)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile ability data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_abilities(*paths)
compile_PBS_file_generic(GameData::Ability, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_abilities : validate_compiled_ability(hash)
@@ -199,9 +332,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::ABILITY_DESCRIPTIONS, ability_descriptions)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile move data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_moves(*paths)
compile_PBS_file_generic(GameData::Move, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_moves : validate_compiled_move(hash)
@@ -229,9 +362,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::MOVE_DESCRIPTIONS, move_descriptions)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile item data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_items(*paths)
compile_PBS_file_generic(GameData::Item, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_items : validate_compiled_item(hash)
@@ -262,9 +395,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::ITEM_DESCRIPTIONS, item_descriptions)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile berry plant data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_berry_plants(*paths)
compile_PBS_file_generic(GameData::BerryPlant, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_berry_plants : validate_compiled_berry_plant(hash)
@@ -277,9 +410,9 @@ module Compiler
def validate_all_compiled_berry_plants
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Pokémon data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_pokemon(*paths)
compile_PBS_file_generic(GameData::Species, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_pokemon : validate_compiled_pokemon(hash)
@@ -380,11 +513,11 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::POKEDEX_ENTRIES, species_pokedex_entries)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Pokémon forms data
# NOTE: Doesn't use compile_PBS_file_generic because it needs its own schema
# and shouldn't clear GameData::Species at the start.
#=============================================================================
#-----------------------------------------------------------------------------
def compile_pokemon_forms(*paths)
schema = GameData::Species.schema(true)
# Read from PBS file(s)
@@ -537,9 +670,9 @@ module Compiler
MessageTypes.addMessagesAsHash(MessageTypes::POKEDEX_ENTRIES, species_pokedex_entries)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Pokémon metrics data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_pokemon_metrics(*paths)
compile_PBS_file_generic(GameData::SpeciesMetrics, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_pokemon_metrics : validate_compiled_pokemon_metrics(hash)
@@ -562,9 +695,9 @@ module Compiler
def validate_all_compiled_pokemon_metrics
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Shadow Pokémon data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_shadow_pokemon(*paths)
compile_PBS_file_generic(GameData::ShadowPokemon, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_shadow_pokemon : validate_compiled_shadow_pokemon(hash)
@@ -587,9 +720,9 @@ module Compiler
def validate_all_compiled_shadow_pokemon
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Regional Dexes
#=============================================================================
#-----------------------------------------------------------------------------
def compile_regional_dexes(*paths)
dex_lists = []
paths.each do |path|
@@ -628,9 +761,9 @@ module Compiler
save_data(dex_lists, "Data/regional_dexes.dat")
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile ribbon data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_ribbons(*paths)
compile_PBS_file_generic(GameData::Ribbon, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_ribbons : validate_compiled_ribbon(hash)
@@ -652,9 +785,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::RIBBON_DESCRIPTIONS, ribbon_descriptions)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile wild encounter data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_encounters(*paths)
GameData::Encounter::DATA.clear
max_level = GameData::GrowthRate.max_level
@@ -764,9 +897,9 @@ module Compiler
GameData::Encounter.save
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile trainer type data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_trainer_types(*paths)
compile_PBS_file_generic(GameData::TrainerType, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_trainer_types : validate_compiled_trainer_type(hash)
@@ -791,9 +924,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::TRAINER_TYPE_NAMES, trainer_type_names)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile individual trainer data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_trainers(*paths)
GameData::Trainer::DATA.clear
schema = GameData::Trainer.schema
@@ -951,9 +1084,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::POKEMON_NICKNAMES, pokemon_nicknames)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile Battle Tower and other Cups trainers/Pokémon
#=============================================================================
#-----------------------------------------------------------------------------
def compile_trainer_lists(path = "PBS/battle_facility_lists.txt")
compile_pbs_file_message_start(path)
btTrainersRequiredTypes = {
@@ -1068,11 +1201,11 @@ module Compiler
return sections
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile metadata
# NOTE: Doesn't use compile_PBS_file_generic because it contains data for two
# different GameData classes.
#=============================================================================
#-----------------------------------------------------------------------------
def compile_metadata(*paths)
GameData::Metadata::DATA.clear
GameData::PlayerMetadata::DATA.clear
@@ -1173,9 +1306,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::STORAGE_CREATOR_NAME, storage_creator)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile map metadata
#=============================================================================
#-----------------------------------------------------------------------------
def compile_map_metadata(*paths)
compile_PBS_file_generic(GameData::MapMetadata, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_map_metadata : validate_compiled_map_metadata(hash)
@@ -1196,9 +1329,9 @@ module Compiler
MessageTypes.setMessagesAsHash(MessageTypes::MAP_NAMES, map_names)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile dungeon tileset data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_dungeon_tilesets(*paths)
compile_PBS_file_generic(GameData::DungeonTileset, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_dungeon_tilesets : validate_compiled_dungeon_tileset(hash)
@@ -1211,9 +1344,9 @@ module Compiler
def validate_all_compiled_dungeon_tilesets
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile dungeon parameters data
#=============================================================================
#-----------------------------------------------------------------------------
def compile_dungeon_parameters(*paths)
compile_PBS_file_generic(GameData::DungeonParameters, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_dungeon_parameters : validate_compiled_dungeon_parameters(hash)
@@ -1237,9 +1370,9 @@ module Compiler
def validate_all_compiled_dungeon_parameters
end
#=============================================================================
#-----------------------------------------------------------------------------
# Compile phone messages
#=============================================================================
#-----------------------------------------------------------------------------
def compile_phone(*paths)
compile_PBS_file_generic(GameData::PhoneMessage, *paths) do |final_validate, hash|
(final_validate) ? validate_all_compiled_phone_contacts : validate_compiled_phone_contact(hash)
@@ -1273,55 +1406,4 @@ module Compiler
end
MessageTypes.setMessagesAsHash(MessageTypes::PHONE_MESSAGES, messages)
end
#=============================================================================
# Compile battle animations
#=============================================================================
def compile_animations
Console.echo_li(_INTL("Compiling animations..."))
begin
pbanims = load_data("Data/PkmnAnimations.rxdata")
rescue
pbanims = PBAnimations.new
end
changed = false
move2anim = [{}, {}]
# anims = load_data("Data/Animations.rxdata")
# for anim in anims
# next if !anim || anim.frames.length == 1
# found = false
# for i in 0...pbanims.length
# if pbanims[i] && pbanims[i].id == anim.id
# found = true if pbanims[i].array.length > 1
# break
# end
# end
# pbanims[anim.id] = pbConvertRPGAnimation(anim) if !found
# end
idx = 0
pbanims.length.times do |i|
echo "." if idx % 100 == 0
Graphics.update if idx % 500 == 0
idx += 1
next if !pbanims[i]
if pbanims[i].name[/^OppMove\:\s*(.*)$/]
if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i
move2anim[1][moveid] = i
end
elsif pbanims[i].name[/^Move\:\s*(.*)$/]
if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i
move2anim[0][moveid] = i
end
end
end
if changed
save_data(move2anim, "Data/move2anim.dat")
save_data(pbanims, "Data/PkmnAnimations.rxdata")
end
process_pbs_file_message_end
end
end

View File

@@ -1,6 +1,42 @@
module Compiler
module_function
def write_all_pbs_files
Console.echo_h1(_INTL("Writing all PBS files"))
write_town_map
write_connections
write_types
write_abilities
write_moves
write_items
write_berry_plants
write_pokemon
write_pokemon_forms
write_pokemon_metrics
write_shadow_pokemon
write_regional_dexes
write_ribbons
write_encounters
write_trainer_types
write_trainers
write_trainer_lists
write_metadata
write_map_metadata
write_dungeon_tilesets
write_dungeon_parameters
write_phone
echoln ""
Console.echo_h2(_INTL("Successfully rewrote all PBS files"), text: :green)
end
#-----------------------------------------------------------------------------
# Generic methods used when writing PBS files
#-----------------------------------------------------------------------------
def write_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
Console.echo_li(_INTL("Writing PBS file `{1}`...", filename.split("/").last))
end
def get_all_PBS_file_paths(game_data)
ret = []
game_data.each { |element| ret.push(element.pbs_file_suffix) if !ret.include?(element.pbs_file_suffix) }
@@ -64,16 +100,16 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Town Map data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_town_map
write_PBS_file_generic(GameData::TownMap)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save map connections to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def normalize_connection(conn)
ret = conn.clone
if conn[1].negative? != conn[4].negative? # Exactly one is negative
@@ -131,46 +167,46 @@ module Compiler
process_pbs_file_message_end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save type data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_types
write_PBS_file_generic(GameData::Type)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save ability data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_abilities
write_PBS_file_generic(GameData::Ability)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save move data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_moves
write_PBS_file_generic(GameData::Move)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save item data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_items
write_PBS_file_generic(GameData::Item)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save berry plant data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_berry_plants
write_PBS_file_generic(GameData::BerryPlant)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Pokémon data to PBS file
# NOTE: Doesn't use write_PBS_file_generic because it needs to ignore defined
# species with a form that isn't 0.
#=============================================================================
#-----------------------------------------------------------------------------
def write_pokemon
paths = []
GameData::Species.each_species { |element| paths.push(element.pbs_file_suffix) if !paths.include?(element.pbs_file_suffix) }
@@ -222,11 +258,11 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Pokémon forms data to PBS file
# NOTE: Doesn't use write_PBS_file_generic because it needs to ignore defined
# species with a form of 0, and needs its own schema.
#=============================================================================
#-----------------------------------------------------------------------------
def write_pokemon_forms
paths = []
GameData::Species.each do |element|
@@ -282,12 +318,12 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Write species metrics
# NOTE: Doesn't use write_PBS_file_generic because it needs to ignore defined
# metrics for forms of species where the metrics are the same as for the
# base species.
#=============================================================================
#-----------------------------------------------------------------------------
def write_pokemon_metrics
paths = []
GameData::SpeciesMetrics.each do |element|
@@ -350,17 +386,17 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Shadow Pokémon data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_shadow_pokemon
return if GameData::ShadowPokemon::DATA.empty?
write_PBS_file_generic(GameData::ShadowPokemon)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Regional Dexes to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_regional_dexes(path = "PBS/regional_dexes.txt")
write_pbs_file_message_start(path)
dex_lists = pbLoadRegionalDexes
@@ -390,16 +426,16 @@ module Compiler
process_pbs_file_message_end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save ability data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_ribbons
write_PBS_file_generic(GameData::Ribbon)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save wild encounter data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_encounters
paths = get_all_PBS_file_paths(GameData::Encounter)
map_infos = pbLoadMapInfos
@@ -441,16 +477,16 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save trainer type data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_trainer_types
write_PBS_file_generic(GameData::TrainerType)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save individual trainer data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_trainers
paths = get_all_PBS_file_paths(GameData::Trainer)
schema = GameData::Trainer.schema
@@ -505,9 +541,9 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save trainer list data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_trainer_lists(path = "PBS/battle_facility_lists.txt")
trainerlists = load_data("Data/trainer_lists.dat") rescue nil
return if !trainerlists
@@ -528,9 +564,9 @@ module Compiler
process_pbs_file_message_end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Battle Tower trainer data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_battle_tower_trainers(bttrainers, filename)
return if !bttrainers || !filename
btTrainersRequiredTypes = {
@@ -567,9 +603,9 @@ module Compiler
Graphics.update
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save Battle Tower Pokémon data to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_battle_tower_pokemon(btpokemon, filename)
return if !btpokemon || !filename
species = {}
@@ -618,11 +654,11 @@ module Compiler
Graphics.update
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save metadata data to PBS file
# NOTE: Doesn't use write_PBS_file_generic because it contains data for two
# different GameData classes.
#=============================================================================
#-----------------------------------------------------------------------------
def write_metadata
paths = []
GameData::Metadata.each do |element|
@@ -680,11 +716,11 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save map metadata data to PBS file
# NOTE: Doesn't use write_PBS_file_generic because it writes the RMXP map name
# next to the section header for each map.
#=============================================================================
#-----------------------------------------------------------------------------
def write_map_metadata
paths = get_all_PBS_file_paths(GameData::MapMetadata)
map_infos = pbLoadMapInfos
@@ -726,11 +762,11 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save dungeon tileset contents data to PBS file
# NOTE: Doesn't use write_PBS_file_generic because it writes the tileset name
# next to the section header for each tileset.
#=============================================================================
#-----------------------------------------------------------------------------
def write_dungeon_tilesets
paths = get_all_PBS_file_paths(GameData::DungeonTileset)
schema = GameData::DungeonTileset.schema
@@ -774,48 +810,17 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save dungeon parameters to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_dungeon_parameters
write_PBS_file_generic(GameData::DungeonParameters)
end
#=============================================================================
#-----------------------------------------------------------------------------
# Save phone messages to PBS file
#=============================================================================
#-----------------------------------------------------------------------------
def write_phone
write_PBS_file_generic(GameData::PhoneMessage)
end
#=============================================================================
# Save all data to PBS files
#=============================================================================
def write_all
Console.echo_h1(_INTL("Writing all PBS files"))
write_town_map
write_connections
write_types
write_abilities
write_moves
write_items
write_berry_plants
write_pokemon
write_pokemon_forms
write_pokemon_metrics
write_shadow_pokemon
write_regional_dexes
write_ribbons
write_encounters
write_trainer_types
write_trainers
write_trainer_lists
write_metadata
write_map_metadata
write_dungeon_tilesets
write_dungeon_parameters
write_phone
echoln ""
Console.echo_h2(_INTL("Successfully rewrote all PBS files"), text: :green)
end
end

View File

@@ -0,0 +1,61 @@
module Compiler
@@categories[:animations] = {
:should_compile => proc { next false },
:header_text => proc { next _INTL("Compiling animations") },
:skipped_text => proc { next _INTL("Not compiled") },
:compile => proc { compile_animations }
}
module_function
#-----------------------------------------------------------------------------
# Compile battle animations
#-----------------------------------------------------------------------------
def compile_animations
Console.echo_li(_INTL("Compiling animations..."))
begin
pbanims = load_data("Data/PkmnAnimations.rxdata")
rescue
pbanims = PBAnimations.new
end
changed = false
move2anim = [{}, {}]
# anims = load_data("Data/Animations.rxdata")
# for anim in anims
# next if !anim || anim.frames.length == 1
# found = false
# for i in 0...pbanims.length
# if pbanims[i] && pbanims[i].id == anim.id
# found = true if pbanims[i].array.length > 1
# break
# end
# end
# pbanims[anim.id] = pbConvertRPGAnimation(anim) if !found
# end
idx = 0
pbanims.length.times do |i|
echo "." if idx % 100 == 0
Graphics.update if idx % 500 == 0
idx += 1
next if !pbanims[i]
if pbanims[i].name[/^OppMove\:\s*(.*)$/]
if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[1][moveid] != i
move2anim[1][moveid] = i
end
elsif pbanims[i].name[/^Move\:\s*(.*)$/]
if GameData::Move.exists?($~[1])
moveid = GameData::Move.get($~[1]).id
changed = true if !move2anim[0][moveid] || move2anim[0][moveid] != i
move2anim[0][moveid] = i
end
end
end
if changed
save_data(move2anim, "Data/move2anim.dat")
save_data(pbanims, "Data/PkmnAnimations.rxdata")
end
process_pbs_file_message_end
end
end

View File

@@ -37,6 +37,28 @@ module Compiler
["calcStats", "calc_stats"]
]
@@categories[:map_data] = {
:should_compile => proc { next import_new_maps },
:header_text => proc { next _INTL("Modifying map data") },
:skipped_text => proc { next _INTL("Not modified") },
:compile => proc { compile_trainer_events }
}
@@categories[:messages] = {
:should_compile => proc { next false },
:header_text => proc { next _INTL("Gathering messages for translations") },
:skipped_text => proc { next _INTL("Not gathered") },
:compile => proc {
Console.echo_li(_INTL("Finding messages..."))
Translator.gather_script_and_event_texts
Console.echo_done(true)
Console.echo_li(_INTL("Saving messages..."))
MessageTypes.save_default_messages
MessageTypes.load_default_messages if FileTest.exist?("Data/messages_core.dat")
Console.echo_done(true)
}
}
module_function
#=============================================================================
@@ -1680,7 +1702,7 @@ module Compiler
#=============================================================================
# Main compiler method for events
#=============================================================================
def compile_trainer_events(_mustcompile)
def compile_trainer_events
mapData = MapData.new
t = System.uptime
Graphics.update