Added new section-based format for moves.txt

This commit is contained in:
Maruno17
2021-06-20 17:29:16 +01:00
parent 1a55a391a3
commit 7c42e4ec20
7 changed files with 27831 additions and 2614 deletions

View File

@@ -2,38 +2,53 @@ module GameData
class Move
attr_reader :id
attr_reader :real_name
attr_reader :function_code
attr_reader :base_damage
attr_reader :type
attr_reader :category
attr_reader :base_damage
attr_reader :accuracy
attr_reader :total_pp
attr_reader :effect_chance
attr_reader :target
attr_reader :priority
attr_reader :function_code
attr_reader :flags
attr_reader :effect_chance
attr_reader :real_description
DATA = {}
DATA_FILENAME = "moves.dat"
SCHEMA = {
"Name" => [:name, "s"],
"Type" => [:type, "e", :Type],
"Category" => [:category, "e", ["Physical", "Special", "Status"]],
"BaseDamage" => [:base_damage, "u"],
"Accuracy" => [:accuracy, "u"],
"TotalPP" => [:total_pp, "u"],
"Target" => [:target, "e", :Target],
"Priority" => [:priority, "i"],
"FunctionCode" => [:function_code, "s"],
"Flags" => [:flags, "s"],
"EffectChance" => [:effect_chance, "u"],
"Description" => [:description, "q"]
}
extend ClassMethodsSymbols
include InstanceMethods
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@function_code = hash[:function_code]
@base_damage = hash[:base_damage]
@type = hash[:type]
@category = hash[:category]
@accuracy = hash[:accuracy]
@total_pp = hash[:total_pp]
@effect_chance = hash[:effect_chance]
@target = hash[:target]
@priority = hash[:priority]
@flags = hash[:flags]
@real_description = hash[:description] || "???"
@real_name = hash[:name] || "Unnamed"
@type = hash[:type] || :NONE
@category = hash[:category] || 2
@base_damage = hash[:base_damage] || 0
@accuracy = hash[:accuracy] || 100
@total_pp = hash[:total_pp] || 5
@target = hash[:target] || :None
@priority = hash[:priority] || 0
@function_code = hash[:function_code] || "000"
@flags = hash[:flags] || ""
@effect_chance = hash[:effect_chance] || 0
@real_description = hash[:description] || "???"
end
# @return [String] the translated name of this move

View File

@@ -240,46 +240,112 @@ module Compiler
#=============================================================================
def compile_moves(path = "PBS/moves.txt")
GameData::Move::DATA.clear
schema = GameData::Move::SCHEMA
move_names = []
move_descriptions = []
move_hash = nil
# Read each line of moves.txt at a time and compile it into an move
pbCompilerEachPreppedLine(path) { |line, line_no|
line = pbGetCsvRecord(line, line_no, [0, "snssueeuuueiss",
nil, nil, nil, nil, nil, :Type, ["Physical", "Special", "Status"],
nil, nil, nil, :Target, nil, nil, nil
])
move_symbol = line[1].to_sym
if GameData::Move::DATA[move_symbol]
raise _INTL("Move ID '{1}' is used twice.\r\n{2}", move_symbol, FileLineData.linereport)
if line[/^\s*\[\s*(.+)\s*\]\s*$/] # New section [move_id]
# Add previous move's data to records
if move_hash
# Sanitise data
if (move_hash[:category] || 2) == 2 && (move_hash[:base_damage] || 0) != 0
raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", line[2], FileLineData.linereport)
elsif (move_hash[:category] || 2) != 2 && (move_hash[:base_damage] || 0) == 0
print _INTL("Warning: Move {1} was defined as Physical or Special but had a base damage of 0. Changing it to a Status move.\r\n{2}", line[2], FileLineData.linereport)
move_hash[:category] = 2
end
GameData::Move.register(move_hash)
end
# Parse move ID
move_id = $~[1].to_sym
if GameData::Move.exists?(move_id)
raise _INTL("Move ID '{1}' is used twice.\r\n{2}", move_id, FileLineData.linereport)
end
# Construct move hash
move_hash = {
:id => move_id
}
elsif line[/^\s*(\w+)\s*=\s*(.*)\s*$/] # XXX=YYY lines
if !move_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
move_hash[line_schema[0]] = property_value
case property_name
when "Name"
move_names.push(move_hash[:name])
when "Description"
move_descriptions.push(move_hash[:description])
end
else # Old format
# Add previous move's data to records
if move_hash
# Sanitise data
if (move_hash[:category] || 2) == 2 && (move_hash[:base_damage] || 0) != 0
raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", line[2], FileLineData.linereport)
elsif (move_hash[:category] || 2) != 2 && (move_hash[:base_damage] || 0) == 0
print _INTL("Warning: Move {1} was defined as Physical or Special but had a base damage of 0. Changing it to a Status move.\r\n{2}", line[2], FileLineData.linereport)
move_hash[:category] = 2
end
GameData::Move.register(move_hash)
end
# Parse move
line = pbGetCsvRecord(line, line_no, [0, "snssueeuuueiss",
nil, nil, nil, nil, nil, :Type, ["Physical", "Special", "Status"],
nil, nil, nil, :Target, nil, nil, nil
])
move_id = line[1].to_sym
if GameData::Move::DATA[move_id]
raise _INTL("Move ID '{1}' is used twice.\r\n{2}", move_id, FileLineData.linereport)
end
# Sanitise data
if line[6] == 2 && line[4] != 0
raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", line[2], FileLineData.linereport)
elsif line[6] != 2 && line[4] == 0
print _INTL("Warning: Move {1} was defined as Physical or Special but had a base damage of 0. Changing it to a Status move.\r\n{2}", line[2], FileLineData.linereport)
line[6] = 2
end
# Construct move hash
move_hash = {
:id => move_id,
:name => line[2],
:function_code => line[3],
:base_damage => line[4],
:type => line[5],
:category => line[6],
:accuracy => line[7],
:total_pp => line[8],
:effect_chance => line[9],
:target => line[10],
:priority => line[11],
:flags => line[12],
:description => line[13]
}
# Add move's data to records
GameData::Move.register(move_hash)
move_names.push(move_hash[:name])
move_descriptions.push(move_hash[:description])
move_hash = nil
end
# Sanitise data
if line[6] == 2 && line[4] != 0
raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", line[2], FileLineData.linereport)
elsif line[6] != 2 && line[4] == 0
print _INTL("Warning: Move {1} was defined as Physical or Special but had a base damage of 0. Changing it to a Status move.\r\n{2}", line[2], FileLineData.linereport)
line[6] = 2
end
# Construct move hash
move_hash = {
:id => move_symbol,
:name => line[2],
:function_code => line[3],
:base_damage => line[4],
:type => line[5],
:category => line[6],
:accuracy => line[7],
:total_pp => line[8],
:effect_chance => line[9],
:target => line[10],
:priority => line[11],
:flags => line[12],
:description => line[13]
}
# Add move's data to records
GameData::Move.register(move_hash)
move_names.push(move_hash[:name])
move_descriptions.push(move_hash[:description])
}
# Add last move's data to records
if move_hash
# Sanitise data
if (move_hash[:category] || 2) == 2 && (move_hash[:base_damage] || 0) != 0
raise _INTL("Move {1} is defined as a Status move with a non-zero base damage.\r\n{2}", line[2], FileLineData.linereport)
elsif (move_hash[:category] || 2) != 2 && (move_hash[:base_damage] || 0) == 0
print _INTL("Warning: Move {1} was defined as Physical or Special but had a base damage of 0. Changing it to a Status move.\r\n{2}", line[2], FileLineData.linereport)
move_hash[:category] = 2
end
GameData::Move.register(move_hash)
end
# Save all data
GameData::Move.save
MessageTypes.setMessagesAsHash(MessageTypes::Moves, move_names)

View File

@@ -175,27 +175,23 @@ module Compiler
def write_moves
File.open("PBS/moves.txt", "wb") { |f|
add_PBS_header_to_file(f)
current_type = -1
GameData::Move.each do |m|
if current_type != m.type
current_type = m.type
f.write("\#-------------------------------\r\n")
end
f.write(sprintf("0,%s,%s,%s,%d,%s,%s,%d,%d,%d,%s,%d,%s,%s\r\n",
csvQuote(m.id.to_s),
csvQuote(m.real_name),
csvQuote(m.function_code),
m.base_damage,
m.type.to_s,
["Physical", "Special", "Status"][m.category],
m.accuracy,
m.total_pp,
m.effect_chance,
m.target,
m.priority,
csvQuote(m.flags),
csvQuoteAlways(m.real_description)
))
# Write each move in turn
GameData::Move.each do |move|
f.write("\#-------------------------------\r\n")
f.write("[#{move.id}]\r\n")
f.write("Name = #{move.real_name}\r\n")
f.write("Type = #{move.type}\r\n")
category = GameData::Move::SCHEMA["Category"][2][move.category]
f.write("Category = #{category}\r\n")
f.write("BaseDamage = #{move.base_damage}\r\n") if move.base_damage > 0
f.write("Accuracy = #{move.accuracy}\r\n")
f.write("TotalPP = #{move.total_pp}\r\n")
f.write("Target = #{move.target}\r\n")
f.write("Priority = #{move.priority}\r\n") if move.priority != 0
f.write("FunctionCode = #{move.function_code}\r\n")
f.write("Flags = #{move.flags}\r\n") if !nil_or_empty?(move.flags)
f.write("EffectChance = #{move.effect_chance}\r\n") if move.effect_chance > 0
f.write("Description = #{move.real_description}\r\n")
end
}
Graphics.update

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff