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,37 +2,52 @@ module GameData
class Move class Move
attr_reader :id attr_reader :id
attr_reader :real_name attr_reader :real_name
attr_reader :function_code
attr_reader :base_damage
attr_reader :type attr_reader :type
attr_reader :category attr_reader :category
attr_reader :base_damage
attr_reader :accuracy attr_reader :accuracy
attr_reader :total_pp attr_reader :total_pp
attr_reader :effect_chance
attr_reader :target attr_reader :target
attr_reader :priority attr_reader :priority
attr_reader :function_code
attr_reader :flags attr_reader :flags
attr_reader :effect_chance
attr_reader :real_description attr_reader :real_description
DATA = {} DATA = {}
DATA_FILENAME = "moves.dat" 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 extend ClassMethodsSymbols
include InstanceMethods include InstanceMethods
def initialize(hash) def initialize(hash)
@id = hash[:id] @id = hash[:id]
@real_name = hash[:name] || "Unnamed" @real_name = hash[:name] || "Unnamed"
@function_code = hash[:function_code] @type = hash[:type] || :NONE
@base_damage = hash[:base_damage] @category = hash[:category] || 2
@type = hash[:type] @base_damage = hash[:base_damage] || 0
@category = hash[:category] @accuracy = hash[:accuracy] || 100
@accuracy = hash[:accuracy] @total_pp = hash[:total_pp] || 5
@total_pp = hash[:total_pp] @target = hash[:target] || :None
@effect_chance = hash[:effect_chance] @priority = hash[:priority] || 0
@target = hash[:target] @function_code = hash[:function_code] || "000"
@priority = hash[:priority] @flags = hash[:flags] || ""
@flags = hash[:flags] @effect_chance = hash[:effect_chance] || 0
@real_description = hash[:description] || "???" @real_description = hash[:description] || "???"
end end

View File

@@ -240,17 +240,70 @@ module Compiler
#============================================================================= #=============================================================================
def compile_moves(path = "PBS/moves.txt") def compile_moves(path = "PBS/moves.txt")
GameData::Move::DATA.clear GameData::Move::DATA.clear
schema = GameData::Move::SCHEMA
move_names = [] move_names = []
move_descriptions = [] move_descriptions = []
move_hash = nil
# Read each line of moves.txt at a time and compile it into an move # Read each line of moves.txt at a time and compile it into an move
pbCompilerEachPreppedLine(path) { |line, line_no| pbCompilerEachPreppedLine(path) { |line, line_no|
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", line = pbGetCsvRecord(line, line_no, [0, "snssueeuuueiss",
nil, nil, nil, nil, nil, :Type, ["Physical", "Special", "Status"], nil, nil, nil, nil, nil, :Type, ["Physical", "Special", "Status"],
nil, nil, nil, :Target, nil, nil, nil nil, nil, nil, :Target, nil, nil, nil
]) ])
move_symbol = line[1].to_sym move_id = line[1].to_sym
if GameData::Move::DATA[move_symbol] if GameData::Move::DATA[move_id]
raise _INTL("Move ID '{1}' is used twice.\r\n{2}", move_symbol, FileLineData.linereport) raise _INTL("Move ID '{1}' is used twice.\r\n{2}", move_id, FileLineData.linereport)
end end
# Sanitise data # Sanitise data
if line[6] == 2 && line[4] != 0 if line[6] == 2 && line[4] != 0
@@ -261,7 +314,7 @@ module Compiler
end end
# Construct move hash # Construct move hash
move_hash = { move_hash = {
:id => move_symbol, :id => move_id,
:name => line[2], :name => line[2],
:function_code => line[3], :function_code => line[3],
:base_damage => line[4], :base_damage => line[4],
@@ -279,7 +332,20 @@ module Compiler
GameData::Move.register(move_hash) GameData::Move.register(move_hash)
move_names.push(move_hash[:name]) move_names.push(move_hash[:name])
move_descriptions.push(move_hash[:description]) move_descriptions.push(move_hash[:description])
move_hash = nil
end
} }
# 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 # Save all data
GameData::Move.save GameData::Move.save
MessageTypes.setMessagesAsHash(MessageTypes::Moves, move_names) MessageTypes.setMessagesAsHash(MessageTypes::Moves, move_names)

View File

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