More or less standardised separator comments in the code

This commit is contained in:
Maruno17
2024-06-27 21:21:26 +01:00
parent 225549bfce
commit 509a414f37
198 changed files with 1907 additions and 1263 deletions

View File

@@ -1,5 +1,5 @@
#===============================================================================
# Records which file, section and line are currently being read
# Records which file, section and line are currently being read.
#===============================================================================
module FileLineData
@file = ""
@@ -51,7 +51,7 @@ module FileLineData
end
#===============================================================================
# Compiler
# Compiler.
#===============================================================================
module Compiler
@@categories = {}
@@ -92,8 +92,9 @@ module Compiler
end
#-----------------------------------------------------------------------------
# PBS file readers
# PBS file readers.
#-----------------------------------------------------------------------------
def pbEachFileSectionEx(f, schema = nil)
lineno = 1
havesection = false
@@ -251,6 +252,7 @@ module Compiler
# 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,10 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Convert a string to certain kinds of values
# Convert a string to certain kinds of values.
#-----------------------------------------------------------------------------
# Unused
# Unused.
# NOTE: This method is about 10 times slower than split_csv_line.
def csvfield!(str)
ret = ""
@@ -331,7 +334,7 @@ module Compiler
return ret
end
# Unused
# Unused.
def csvBoolean!(str, _line = -1)
field = csvfield!(str)
return true if field[/^(?:1|TRUE|YES|Y)$/i]
@@ -339,7 +342,7 @@ module Compiler
raise _INTL("Field '{1}' is not a Boolean value (true, false, 1, 0).", field) + "\n" + FileLineData.linereport
end
# Unused
# Unused.
def csvInt!(str, _line = -1)
ret = csvfield!(str)
if !ret[/^\-?\d+$/]
@@ -348,7 +351,7 @@ module Compiler
return ret.to_i
end
# Unused
# Unused.
def csvPosInt!(str, _line = -1)
ret = csvfield!(str)
if !ret[/^\d+$/]
@@ -357,19 +360,19 @@ module Compiler
return ret.to_i
end
# Unused
# Unused.
def csvFloat!(str, _line = -1)
ret = csvfield!(str)
return Float(ret) rescue raise _INTL("Field '{1}' is not a number.", ret) + "\n" + FileLineData.linereport
end
# Unused
# Unused.
def csvEnumField!(value, enumer, _key, _section)
ret = csvfield!(value)
return checkEnumField(ret, enumer)
end
# Unused
# Unused.
def csvEnumFieldOrInt!(value, enumer, _key, _section)
ret = csvfield!(value)
return ret.to_i if ret[/\-?\d+/]
@@ -482,7 +485,7 @@ module Compiler
raise _INTL("Enumeration not defined.") + "\n" + FileLineData.linereport
end
# Unused
# Unused.
def checkEnumFieldOrNil(ret, enumer)
case enumer
when Module
@@ -508,9 +511,9 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Convert a string to values using a schema
#-----------------------------------------------------------------------------
# Unused
# Convert a string to values using a schema.
# Unused.
# @deprecated This method is slated to be removed in v22.
def pbGetCsvRecord(rec, lineno, schema)
Deprecation.warn_method("pbGetCsvRecord", "v22", "get_csv_record")
@@ -684,8 +687,8 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Convert a string to values using a schema
#-----------------------------------------------------------------------------
# Convert a string to values using a schema.
def get_csv_record(rec, schema)
ret = []
repeat = false
@@ -736,8 +739,8 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Write values to a file using a schema
#-----------------------------------------------------------------------------
# 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
@@ -844,6 +847,7 @@ module Compiler
# 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,8 +922,9 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Replace text in PBS files before compiling them
# Replace text in PBS files before compiling them.
#-----------------------------------------------------------------------------
def edit_and_rewrite_pbs_file_text(filename)
return if !block_given?
lines = []
@@ -946,8 +951,9 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile all data
# Compile all data.
#-----------------------------------------------------------------------------
def categories_to_compile(all_categories = false)
ret = []
Input.update

View File

@@ -1,3 +1,6 @@
#===============================================================================
#
#===============================================================================
module Compiler
@@categories[:pbs_files] = {
:should_compile => proc { |compiling| next should_compile_pbs_files? },
@@ -122,7 +125,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Generic methods used when compiling PBS files
# Generic methods used when compiling PBS files.
#-----------------------------------------------------------------------------
def compile_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
@@ -201,7 +204,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Town Map data
# Compile Town Map data.
#-----------------------------------------------------------------------------
def compile_town_map(*paths)
compile_PBS_file_generic(GameData::TownMap, *paths) do |final_validate, hash|
@@ -232,7 +235,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile map connections
# Compile map connections.
#-----------------------------------------------------------------------------
def compile_connections(*paths)
hashenum = {
@@ -271,7 +274,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile type data
# Compile type data.
#-----------------------------------------------------------------------------
def compile_types(*paths)
compile_PBS_file_generic(GameData::Type, *paths) do |final_validate, hash|
@@ -309,7 +312,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile ability data
# Compile ability data.
#-----------------------------------------------------------------------------
def compile_abilities(*paths)
compile_PBS_file_generic(GameData::Ability, *paths) do |final_validate, hash|
@@ -333,7 +336,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile move data
# Compile move data.
#-----------------------------------------------------------------------------
def compile_moves(*paths)
compile_PBS_file_generic(GameData::Move, *paths) do |final_validate, hash|
@@ -363,7 +366,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile item data
# Compile item data.
#-----------------------------------------------------------------------------
def compile_items(*paths)
compile_PBS_file_generic(GameData::Item, *paths) do |final_validate, hash|
@@ -396,7 +399,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile berry plant data
# Compile berry plant data.
#-----------------------------------------------------------------------------
def compile_berry_plants(*paths)
compile_PBS_file_generic(GameData::BerryPlant, *paths) do |final_validate, hash|
@@ -411,7 +414,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Pokémon data
# Compile Pokémon data.
#-----------------------------------------------------------------------------
def compile_pokemon(*paths)
compile_PBS_file_generic(GameData::Species, *paths) do |final_validate, hash|
@@ -514,7 +517,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Pokémon forms data
# 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.
#-----------------------------------------------------------------------------
@@ -671,7 +674,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Pokémon metrics data
# Compile Pokémon metrics data.
#-----------------------------------------------------------------------------
def compile_pokemon_metrics(*paths)
compile_PBS_file_generic(GameData::SpeciesMetrics, *paths) do |final_validate, hash|
@@ -696,7 +699,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Shadow Pokémon data
# Compile Shadow Pokémon data.
#-----------------------------------------------------------------------------
def compile_shadow_pokemon(*paths)
compile_PBS_file_generic(GameData::ShadowPokemon, *paths) do |final_validate, hash|
@@ -721,7 +724,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Regional Dexes
# Compile Regional Dexes.
#-----------------------------------------------------------------------------
def compile_regional_dexes(*paths)
dex_lists = []
@@ -762,7 +765,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile ribbon data
# Compile ribbon data.
#-----------------------------------------------------------------------------
def compile_ribbons(*paths)
compile_PBS_file_generic(GameData::Ribbon, *paths) do |final_validate, hash|
@@ -786,7 +789,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile wild encounter data
# Compile wild encounter data.
#-----------------------------------------------------------------------------
def compile_encounters(*paths)
GameData::Encounter::DATA.clear
@@ -898,7 +901,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile trainer type data
# Compile trainer type data.
#-----------------------------------------------------------------------------
def compile_trainer_types(*paths)
compile_PBS_file_generic(GameData::TrainerType, *paths) do |final_validate, hash|
@@ -925,7 +928,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile individual trainer data
# Compile individual trainer data.
#-----------------------------------------------------------------------------
def compile_trainers(*paths)
GameData::Trainer::DATA.clear
@@ -1085,7 +1088,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile Battle Tower and other Cups trainers/Pokémon
# 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)
@@ -1202,7 +1205,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile metadata
# Compile metadata.
# NOTE: Doesn't use compile_PBS_file_generic because it contains data for two
# different GameData classes.
#-----------------------------------------------------------------------------
@@ -1307,7 +1310,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile map metadata
# Compile map metadata.
#-----------------------------------------------------------------------------
def compile_map_metadata(*paths)
compile_PBS_file_generic(GameData::MapMetadata, *paths) do |final_validate, hash|
@@ -1330,7 +1333,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile dungeon tileset data
# Compile dungeon tileset data.
#-----------------------------------------------------------------------------
def compile_dungeon_tilesets(*paths)
compile_PBS_file_generic(GameData::DungeonTileset, *paths) do |final_validate, hash|
@@ -1345,7 +1348,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile dungeon parameters data
# Compile dungeon parameters data.
#-----------------------------------------------------------------------------
def compile_dungeon_parameters(*paths)
compile_PBS_file_generic(GameData::DungeonParameters, *paths) do |final_validate, hash|
@@ -1371,7 +1374,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Compile phone messages
# Compile phone messages.
#-----------------------------------------------------------------------------
def compile_phone(*paths)
compile_PBS_file_generic(GameData::PhoneMessage, *paths) do |final_validate, hash|

View File

@@ -1,3 +1,6 @@
#===============================================================================
#
#===============================================================================
module Compiler
module_function
@@ -30,7 +33,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Generic methods used when writing PBS files
# Generic methods used when writing PBS files.
#-----------------------------------------------------------------------------
def write_pbs_file_message_start(filename)
# The `` around the file's name turns it cyan
@@ -101,14 +104,14 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Town Map data to PBS file
# Save Town Map data to PBS file.
#-----------------------------------------------------------------------------
def write_town_map
write_PBS_file_generic(GameData::TownMap)
end
#-----------------------------------------------------------------------------
# Save map connections to PBS file
# Save map connections to PBS file.
#-----------------------------------------------------------------------------
def normalize_connection(conn)
ret = conn.clone
@@ -168,42 +171,42 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save type data to PBS file
# Save type data to PBS file.
#-----------------------------------------------------------------------------
def write_types
write_PBS_file_generic(GameData::Type)
end
#-----------------------------------------------------------------------------
# Save ability data to PBS file
# Save ability data to PBS file.
#-----------------------------------------------------------------------------
def write_abilities
write_PBS_file_generic(GameData::Ability)
end
#-----------------------------------------------------------------------------
# Save move data to PBS file
# Save move data to PBS file.
#-----------------------------------------------------------------------------
def write_moves
write_PBS_file_generic(GameData::Move)
end
#-----------------------------------------------------------------------------
# Save item data to PBS file
# Save item data to PBS file.
#-----------------------------------------------------------------------------
def write_items
write_PBS_file_generic(GameData::Item)
end
#-----------------------------------------------------------------------------
# Save berry plant data to PBS file
# 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
# 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.
#-----------------------------------------------------------------------------
@@ -259,7 +262,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Pokémon forms data to PBS file
# 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.
#-----------------------------------------------------------------------------
@@ -319,7 +322,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Write species metrics
# 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.
@@ -387,7 +390,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Shadow Pokémon data to PBS file
# Save Shadow Pokémon data to PBS file.
#-----------------------------------------------------------------------------
def write_shadow_pokemon
return if GameData::ShadowPokemon::DATA.empty?
@@ -395,7 +398,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Regional Dexes to PBS file
# Save Regional Dexes to PBS file.
#-----------------------------------------------------------------------------
def write_regional_dexes(path = "PBS/regional_dexes.txt")
write_pbs_file_message_start(path)
@@ -427,14 +430,14 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save ability data to PBS file
# Save ability data to PBS file.
#-----------------------------------------------------------------------------
def write_ribbons
write_PBS_file_generic(GameData::Ribbon)
end
#-----------------------------------------------------------------------------
# Save wild encounter data to PBS file
# Save wild encounter data to PBS file.
#-----------------------------------------------------------------------------
def write_encounters
paths = get_all_PBS_file_paths(GameData::Encounter)
@@ -478,14 +481,14 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save trainer type data to PBS file
# 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
# Save individual trainer data to PBS file.
#-----------------------------------------------------------------------------
def write_trainers
paths = get_all_PBS_file_paths(GameData::Trainer)
@@ -542,7 +545,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save trainer list data to PBS file
# 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
@@ -565,7 +568,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Battle Tower trainer data to PBS file
# Save Battle Tower trainer data to PBS file.
#-----------------------------------------------------------------------------
def write_battle_tower_trainers(bttrainers, filename)
return if !bttrainers || !filename
@@ -604,7 +607,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save Battle Tower Pokémon data to PBS file
# Save Battle Tower Pokémon data to PBS file.
#-----------------------------------------------------------------------------
def write_battle_tower_pokemon(btpokemon, filename)
return if !btpokemon || !filename
@@ -655,7 +658,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save metadata data to PBS file
# Save metadata data to PBS file.
# NOTE: Doesn't use write_PBS_file_generic because it contains data for two
# different GameData classes.
#-----------------------------------------------------------------------------
@@ -717,7 +720,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save map metadata data to PBS file
# 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.
#-----------------------------------------------------------------------------
@@ -763,7 +766,7 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save dungeon tileset contents data to PBS file
# 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.
#-----------------------------------------------------------------------------
@@ -811,14 +814,14 @@ module Compiler
end
#-----------------------------------------------------------------------------
# Save dungeon parameters to PBS file
# Save dungeon parameters to PBS file.
#-----------------------------------------------------------------------------
def write_dungeon_parameters
write_PBS_file_generic(GameData::DungeonParameters)
end
#-----------------------------------------------------------------------------
# Save phone messages to PBS file
# Save phone messages to PBS file.
#-----------------------------------------------------------------------------
def write_phone
write_PBS_file_generic(GameData::PhoneMessage)

View File

@@ -1,3 +1,6 @@
#===============================================================================
#
#===============================================================================
module Compiler
@@categories[:animations] = {
:should_compile => proc { |compiling| next false },
@@ -9,7 +12,7 @@ module Compiler
module_function
#-----------------------------------------------------------------------------
# Compile battle animations
# Compile battle animations.
#-----------------------------------------------------------------------------
def compile_animations
Console.echo_li(_INTL("Compiling animations..."))

View File

@@ -1,3 +1,6 @@
#===============================================================================
#
#===============================================================================
module Compiler
SCRIPT_REPLACEMENTS = [
["Kernel.", ""],
@@ -61,9 +64,9 @@ module Compiler
module_function
#=============================================================================
#-----------------------------------------------------------------------------
# Add new map files to the map tree.
#=============================================================================
#-----------------------------------------------------------------------------
def import_new_maps
return false if !$DEBUG
mapfiles = {}
@@ -104,9 +107,9 @@ module Compiler
return imported
end
#=============================================================================
#-----------------------------------------------------------------------------
# Generate and modify event commands.
#=============================================================================
#-----------------------------------------------------------------------------
def generate_move_route(commands)
route = RPG::MoveRoute.new
route.repeat = false
@@ -270,9 +273,8 @@ module Compiler
event.pages.push(page)
end
#=============================================================================
#
#=============================================================================
#-----------------------------------------------------------------------------
def safequote(x)
x = x.gsub(/\"\#\'\\/) { |a| "\\" + a }
x = x.gsub(/\t/, "\\t")
@@ -489,9 +491,9 @@ module Compiler
end
end
#=============================================================================
#-----------------------------------------------------------------------------
# Convert trainer comments to trainer event.
#=============================================================================
def convert_to_trainer_event(event, trainerChecker)
return nil if !event || event.pages.length == 0
list = event.pages[0].list
@@ -784,12 +786,12 @@ module Compiler
return ret
end
#=============================================================================
#-----------------------------------------------------------------------------
# Convert event name to item event.
# Checks if the event's name is "Item:POTION" or "HiddenItem:POTION". If so,
# rewrites the whole event into one now named "Item"/"HiddenItem" which gives
# that item when interacted with.
#=============================================================================
def convert_to_item_event(event)
return nil if !event || event.pages.length == 0
name = event.name
@@ -829,11 +831,11 @@ module Compiler
return ret
end
#=============================================================================
#-----------------------------------------------------------------------------
# Checks whether a given event is likely to be a door. If so, rewrite it to
# include animating the event as though it was a door opening and closing as the
# player passes through.
#=============================================================================
def update_door_event(event, mapData)
changed = false
return false if event.is_a?(RPG::CommonEvent)
@@ -924,9 +926,9 @@ module Compiler
return changed
end
#=============================================================================
# Fix up standard code snippets
#=============================================================================
#-----------------------------------------------------------------------------
# Fix up standard code snippets.
#-----------------------------------------------------------------------------
def event_is_empty?(e)
return true if !e
return false if e.is_a?(RPG::CommonEvent)
@@ -1597,9 +1599,9 @@ module Compiler
return (changed) ? event : nil
end
#=============================================================================
#-----------------------------------------------------------------------------
# Convert events used as counters into proper counters.
#=============================================================================
#-----------------------------------------------------------------------------
# Checks if the event has just 1 page, which has no conditions and no commands
# and whose movement type is "Fixed".
def plain_event?(event)
@@ -1699,9 +1701,9 @@ module Compiler
return changed
end
#=============================================================================
# Main compiler method for events
#=============================================================================
#-----------------------------------------------------------------------------
# Main compiler method for events.
#-----------------------------------------------------------------------------
def compile_trainer_events
mapData = MapData.new
t = System.uptime