Added compiler schema letter "m" which makes the value a symbol, refactored many PBS file compilers, removed support for old PBS formats/properties

This commit is contained in:
Maruno17
2022-11-16 22:03:12 +00:00
parent bbe654028c
commit 5d439de87d
18 changed files with 887 additions and 1193 deletions

View File

@@ -129,7 +129,10 @@ module Compiler
yield lastsection, sectionname if havesection
end
# Used for types.txt, pokemon.txt, battle_facility_lists.txt and Battle Tower trainers PBS files
# Used for types.txt, abilities.txt, moves.txt, items.txt, berry_plants.txt,
# pokemon.txt, pokemon_forms.txt, pokemon_metrics.txt, shadow_pokemon.txt,
# ribbons.txt, trainer_types.txt, battle_facility_lists.txt, Battle Tower
# trainers PBS files and dungeon_parameters.txt
def pbEachFileSection(f)
pbEachFileSectionEx(f) { |section, name|
yield section, name if block_given? && name[/^.+$/]
@@ -143,14 +146,7 @@ module Compiler
}
end
# Used for pokemon_forms.txt
def pbEachFileSectionPokemonForms(f)
pbEachFileSectionEx(f) { |section, name|
yield section, name if block_given? && name[/^\w+[-,\s]{1}\d+$/]
}
end
# Used for phone.txt
# Unused
def pbEachSection(f)
lineno = 1
havesection = false
@@ -193,7 +189,7 @@ module Compiler
}
end
# Used for many PBS files
# Used for town_map.txt and Battle Tower Pokémon PBS files
def pbCompilerEachCommentedLine(filename)
File.open(filename, "rb") { |f|
FileLineData.file = filename
@@ -226,7 +222,8 @@ module Compiler
}
end
# Used for map_connections.txt, abilities.txt, moves.txt, regional_dexes.txt
# Used for map_connections.txt, phone.txt, regional_dexes.txt, encounters.txt,
# trainers.txt and dungeon_tilesets.txt
def pbCompilerEachPreppedLine(filename)
File.open(filename, "rb") { |f|
FileLineData.file = filename
@@ -519,6 +516,21 @@ module Compiler
subrecord.push(rec)
rec = ""
end
when "m" # Symbol
field = csvfield!(rec)
if !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\r\nunderscores and can't begin with a number.\r\n{2}", field, FileLineData.linereport)
end
subrecord.push(field.to_sym)
when "M" # Optional symbol
field = csvfield!(rec)
if nil_or_empty?(field)
subrecord.push(nil)
elsif !field[/^(?![0-9])\w+$/]
raise _INTL("Field '{1}' must contain only letters, digits, and\r\nunderscores and can't begin with a number.\r\n{2}", field, FileLineData.linereport)
else
subrecord.push(field.to_sym)
end
when "e" # Enumerable
subrecord.push(csvEnumField!(rec, schema[2 + i - start], "", FileLineData.linereport))
when "E" # Optional enumerable
@@ -548,7 +560,7 @@ module Compiler
break if repeat && nil_or_empty?(rec)
break unless repeat
end
return (schema[1].length == 1) ? record[0] : record
return (!repeat && schema[1].length == 1) ? record[0] : record
end
#=============================================================================

File diff suppressed because it is too large Load Diff

View File

@@ -812,8 +812,7 @@ module Compiler
f.write("[0]\r\n")
metadata = GameData::Metadata.get
schema = GameData::Metadata::SCHEMA
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
keys.each do |key|
schema.keys.each do |key|
record = metadata.property_from_string(key)
next if record.nil? || (record.is_a?(Array) && record.empty?)
f.write(sprintf("%s = ", key))
@@ -822,11 +821,10 @@ module Compiler
end
# Write player metadata
schema = GameData::PlayerMetadata::SCHEMA
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
GameData::PlayerMetadata.each do |player_data|
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%d]\r\n", player_data.id))
keys.each do |key|
schema.keys.each do |key|
record = player_data.property_from_string(key)
next if record.nil? || (record.is_a?(Array) && record.empty?)
f.write(sprintf("%s = ", key))
@@ -845,7 +843,6 @@ module Compiler
write_pbs_file_message_start(path)
map_infos = pbLoadMapInfos
schema = GameData::MapMetadata::SCHEMA
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
File.open(path, "wb") { |f|
idx = 0
add_PBS_header_to_file(f)
@@ -861,7 +858,7 @@ module Compiler
else
f.write(sprintf("[%03d]\r\n", map_data.id))
end
keys.each do |key|
schema.keys.each do |key|
record = map_data.property_from_string(key)
next if record.nil? || (record.is_a?(Array) && record.empty?)
f.write(sprintf("%s = ", key))