Added new section-based format for trainertypes.txt

This commit is contained in:
Maruno17
2021-06-20 01:00:21 +01:00
parent e4cdb95314
commit 1cec4fc90d
5 changed files with 520 additions and 147 deletions

View File

@@ -2,17 +2,31 @@ module GameData
class TrainerType
attr_reader :id
attr_reader :real_name
attr_reader :base_money
attr_reader :battle_BGM
attr_reader :victory_ME
attr_reader :intro_ME
attr_reader :gender
attr_reader :base_money
attr_reader :skill_level
attr_reader :skill_code
attr_reader :intro_ME
attr_reader :battle_BGM
attr_reader :victory_ME
DATA = {}
DATA_FILENAME = "trainer_types.dat"
SCHEMA = {
"Name" => [:name, "s"],
"Gender" => [:gender, "e", {"Male" => 0, "male" => 0, "M" => 0, "m" => 0, "0" => 0,
"Female" => 1, "female" => 1, "F" => 1, "f" => 1, "1" => 1,
"Unknown" => 2, "unknown" => 2, "Other" => 2, "other" => 2,
"Mixed" => 2, "mixed" => 2, "X" => 2, "x" => 2, "2" => 2}],
"BaseMoney" => [:base_money, "u"],
"SkillLevel" => [:skill_level, "u"],
"SkillCode" => [:skill_code, "s"],
"IntroME" => [:intro_ME, "s"],
"BattleBGM" => [:battle_BGM, "s"],
"VictoryME" => [:victory_ME, "s"]
}
extend ClassMethodsSymbols
include InstanceMethods
@@ -68,13 +82,13 @@ module GameData
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@base_money = hash[:base_money] || 30
@battle_BGM = hash[:battle_BGM]
@victory_ME = hash[:victory_ME]
@intro_ME = hash[:intro_ME]
@gender = hash[:gender] || 2
@base_money = hash[:base_money] || 30
@skill_level = hash[:skill_level] || @base_money
@skill_code = hash[:skill_code]
@intro_ME = hash[:intro_ME]
@battle_BGM = hash[:battle_BGM]
@victory_ME = hash[:victory_ME]
end
# @return [String] the translated name of this trainer type

View File

@@ -342,18 +342,18 @@ end
# Trainer type editor
#===============================================================================
def pbTrainerTypeEditor
gender_array = []
GameData::TrainerType::SCHEMA["Gender"][2].each { |key, value| gender_array[value] = key if !gender_array[value] }
trainer_type_properties = [
[_INTL("Internal Name"), ReadOnlyProperty, _INTL("Internal name that is used as a symbol like :XXX.")],
[_INTL("Trainer Name"), StringProperty, _INTL("Name of the trainer type as displayed by the game.")],
[_INTL("Base Money"), LimitProperty.new(9999), _INTL("Player earns this much money times the highest level among the trainer's Pokémon.")],
[_INTL("Battle BGM"), BGMProperty, _INTL("BGM played in battles against trainers of this type.")],
[_INTL("Battle End ME"), MEProperty, _INTL("ME played when player wins battles against trainers of this type.")],
[_INTL("Battle Intro ME"), MEProperty, _INTL("ME played before battles against trainers of this type.")],
[_INTL("Gender"), EnumProperty.new([
_INTL("Male"), _INTL("Female"), _INTL("Undefined")]),
_INTL("Gender of this Trainer type.")],
[_INTL("Skill Level"), LimitProperty.new(9999), _INTL("Skill level of this Trainer type.")],
[_INTL("Skill Code"), StringProperty, _INTL("Letters/phrases representing AI modifications of trainers of this type.")],
[_INTL("ID"), ReadOnlyProperty, _INTL("ID of this Trainer Type (used as a symbol like :XXX).")],
[_INTL("Name"), StringProperty, _INTL("Name of this Trainer Type as displayed by the game.")],
[_INTL("Gender"), EnumProperty.new(gender_array), _INTL("Gender of this Trainer Type.")],
[_INTL("BaseMoney"), LimitProperty.new(9999), _INTL("Player earns this much money times the highest level among the trainer's Pokémon.")],
[_INTL("SkillLevel"), LimitProperty.new(9999), _INTL("Skill level of this Trainer Type.")],
[_INTL("SkillCode"), StringProperty, _INTL("Letters/phrases representing AI modifications of trainers of this type.")],
[_INTL("IntroME"), MEProperty, _INTL("ME played before battles against trainers of this type.")],
[_INTL("BattleBGM"), BGMProperty, _INTL("BGM played in battles against trainers of this type.")],
[_INTL("VictoryME"), MEProperty, _INTL("ME played when player wins battles against trainers of this type.")]
]
pbListScreenBlock(_INTL("Trainer Types"), TrainerTypeLister.new(0, true)) { |button, tr_type|
if tr_type
@@ -372,26 +372,26 @@ def pbTrainerTypeEditor
data = [
t_data.id.to_s,
t_data.real_name,
t_data.base_money,
t_data.battle_BGM,
t_data.victory_ME,
t_data.intro_ME,
t_data.gender,
t_data.base_money,
t_data.skill_level,
t_data.skill_code
t_data.skill_code,
t_data.intro_ME,
t_data.battle_BGM,
t_data.victory_ME
]
if pbPropertyList(t_data.id.to_s, data, trainer_type_properties, true)
# Construct trainer type hash
type_hash = {
:id => t_data.id,
:name => data[1],
:base_money => data[2],
:battle_BGM => data[3],
:victory_ME => data[4],
:intro_ME => data[5],
:gender => data[6],
:skill_level => data[7],
:skill_code => data[8]
:gender => data[2],
:base_money => data[3],
:skill_level => data[4],
:skill_code => data[5],
:intro_ME => data[6],
:battle_BGM => data[7],
:victory_ME => data[8]
}
# Add trainer type's data to records
GameData::TrainerType.register(type_hash)
@@ -436,8 +436,8 @@ def pbTrainerTypeEditorNew(default_name)
return nil
end
# Choose a gender
gender = pbMessage(_INTL("Is the Trainer male, female or undefined?"), [
_INTL("Male"), _INTL("Female"), _INTL("Undefined")], 0)
gender = pbMessage(_INTL("Is the Trainer male, female or unknown?"), [
_INTL("Male"), _INTL("Female"), _INTL("Unknown")], 0)
# Choose a base money value
params = ChooseNumberParams.new
params.setRange(0, 255)
@@ -445,10 +445,10 @@ def pbTrainerTypeEditorNew(default_name)
base_money = pbMessageChooseNumber(_INTL("Set the money per level won for defeating the Trainer."), params)
# Construct trainer type hash
tr_type_hash = {
:id => id.to_sym,
:name => name,
:base_money => base_money,
:gender => gender
:id => id.to_sym,
:name => name,
:gender => gender,
:base_money => base_money
}
# Add trainer type's data to records
GameData::TrainerType.register(tr_type_hash)

View File

@@ -952,36 +952,69 @@ module Compiler
#=============================================================================
def compile_trainer_types(path = "PBS/trainertypes.txt")
GameData::TrainerType::DATA.clear
schema = GameData::TrainerType::SCHEMA
tr_type_names = []
tr_type_hash = nil
# Read each line of trainertypes.txt at a time and compile it into a trainer type
pbCompilerEachCommentedLine(path) { |line, line_no|
line = pbGetCsvRecord(line, line_no, [0, "snsUSSSeUS",
nil, nil, nil, nil, nil, nil, nil, {
"Male" => 0, "M" => 0, "0" => 0,
"Female" => 1, "F" => 1, "1" => 1,
"Mixed" => 2, "X" => 2, "2" => 2, "" => 2
}, nil, nil]
)
type_symbol = line[1].to_sym
if GameData::TrainerType::DATA[type_symbol]
raise _INTL("Trainer type ID '{1}' is used twice.\r\n{2}", type_symbol, FileLineData.linereport)
pbCompilerEachPreppedLine(path) { |line, line_no|
if line[/^\s*\[\s*(.+)\s*\]\s*$/] # New section [tr_type_id]
# Add previous trainer type's data to records
GameData::TrainerType.register(tr_type_hash) if tr_type_hash
# Parse trainer type ID
tr_type_id = $~[1].to_sym
if GameData::TrainerType.exists?(tr_type_id)
raise _INTL("Trainer Type ID '{1}' is used twice.\r\n{2}", tr_type_id, FileLineData.linereport)
end
# Construct trainer type hash
tr_type_hash = {
:id => tr_type_id
}
elsif line[/^\s*(\w+)\s*=\s*(.*)\s*$/] # XXX=YYY lines
if !tr_type_hash
raise _INTL("Expected a section at the beginning of the file.\r\n{1}", FileLineData.linereport)
end
# Parse property and value
property_name = $~[1]
line_schema = schema[property_name]
next if !line_schema
property_value = pbGetCsvRecord($~[2], line_no, line_schema)
# Record XXX=YYY setting
tr_type_hash[line_schema[0]] = property_value
tr_type_names.push(tr_type_hash[:name]) if property_name == "Name"
else # Old format
# Add previous trainer type's data to records
GameData::TrainerType.register(tr_type_hash) if tr_type_hash
# Parse trainer type
line = pbGetCsvRecord(line, line_no, [0, "snsUSSSeUS",
nil, nil, nil, nil, nil, nil, nil, {
"Male" => 0, "M" => 0, "0" => 0,
"Female" => 1, "F" => 1, "1" => 1,
"Mixed" => 2, "X" => 2, "2" => 2, "" => 2
}, nil, nil])
tr_type_id = line[1].to_sym
if GameData::TrainerType.exists?(tr_type_id)
raise _INTL("Trainer Type ID '{1}' is used twice.\r\n{2}", tr_type_id, FileLineData.linereport)
end
# Construct trainer type hash
tr_type_hash = {
:id => tr_type_id,
:name => line[2],
:base_money => line[3],
:battle_BGM => line[4],
:victory_ME => line[5],
:intro_ME => line[6],
:gender => line[7],
:skill_level => line[8],
:skill_code => line[9]
}
# Add trainer type's data to records
GameData::TrainerType.register(tr_type_hash)
tr_type_names.push(tr_type_hash[:name])
tr_type_hash = nil
end
# Construct trainer type hash
type_hash = {
:id => type_symbol,
:name => line[2],
:base_money => line[3],
:battle_BGM => line[4],
:victory_ME => line[5],
:intro_ME => line[6],
:gender => line[7],
:skill_level => line[8],
:skill_code => line[9]
}
# Add trainer type's data to records
GameData::TrainerType.register(type_hash)
tr_type_names.push(type_hash[:name])
}
# Add last trainer type's data to records
GameData::TrainerType.register(tr_type_hash) if tr_type_hash
# Save all data
GameData::TrainerType.save
MessageTypes.setMessagesAsHash(MessageTypes::TrainerTypes, tr_type_names)

View File

@@ -556,19 +556,18 @@ module Compiler
def write_trainer_types
File.open("PBS/trainertypes.txt", "wb") { |f|
add_PBS_header_to_file(f)
f.write("\#-------------------------------\r\n")
GameData::TrainerType.each do |t|
f.write(sprintf("0,%s,%s,%d,%s,%s,%s,%s,%s,%s\r\n",
csvQuote(t.id.to_s),
csvQuote(t.real_name),
t.base_money,
csvQuote(t.battle_BGM),
csvQuote(t.victory_ME),
csvQuote(t.intro_ME),
["Male", "Female", "Mixed"][t.gender],
(t.skill_level == t.base_money) ? "" : t.skill_level.to_s,
csvQuote(t.skill_code)
))
f.write("\#-------------------------------\r\n")
f.write(sprintf("[%s]\r\n", t.id))
f.write(sprintf("Name = %s\r\n", t.real_name))
gender = GameData::TrainerType::SCHEMA["Gender"][2].key(t.gender)
f.write(sprintf("Gender = %s\r\n", gender))
f.write(sprintf("BaseMoney = %d\r\n", t.base_money))
f.write(sprintf("SkillLevel = %d\r\n", t.skill_level)) if t.skill_level != t.base_money
f.write(sprintf("SkillCode = %s\r\n", t.skill_code)) if !nil_or_empty?(t.skill_code)
f.write(sprintf("IntroME = %s\r\n", t.intro_ME)) if !nil_or_empty?(t.intro_ME)
f.write(sprintf("BattleBGM = %s\r\n", t.battle_BGM)) if !nil_or_empty?(t.battle_BGM)
f.write(sprintf("VictoryME = %s\r\n", t.victory_ME)) if !nil_or_empty?(t.victory_ME)
end
}
Graphics.update