Added new section-based format for ribbons.txt

This commit is contained in:
Maruno17
2021-06-20 17:57:35 +01:00
parent e201821919
commit 53d27d3cf5
6 changed files with 470 additions and 107 deletions

View File

@@ -19,7 +19,7 @@ module GameData
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@icon_position = hash[:icon_position] || -1 # -1 means "no icon"
@icon_position = hash[:icon_position] || 0
end
# @return [String] the translated name of this body shape

View File

@@ -23,7 +23,7 @@ module GameData
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@animation = hash[:animation]
@icon_position = hash[:icon_position] || -1 # -1 means "no icon"
@icon_position = hash[:icon_position] || 0
end
# @return [String] the translated name of this status condition

View File

@@ -2,20 +2,26 @@ module GameData
class Ribbon
attr_reader :id
attr_reader :real_name
attr_reader :real_description
attr_reader :icon_position # Where this ribbon's graphic is within ribbons.png
attr_reader :real_description
DATA = {}
DATA_FILENAME = "ribbons.dat"
SCHEMA = {
"Name" => [:name, "s"],
"IconPosition" => [:icon_position, "u"],
"Description" => [:description, "q"]
}
extend ClassMethodsSymbols
include InstanceMethods
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@icon_position = hash[:icon_position] || 0
@real_description = hash[:description] || "???"
@icon_position = hash[:icon_position] || -1
end
# @return [String] the translated name of this ribbon

View File

@@ -921,26 +921,65 @@ module Compiler
#=============================================================================
def compile_ribbons(path = "PBS/ribbons.txt")
GameData::Ribbon::DATA.clear
schema = GameData::Ribbon::SCHEMA
ribbon_names = []
ribbon_descriptions = []
ribbon_hash = nil
pbCompilerEachPreppedLine(path) { |line, line_no|
line = pbGetCsvRecord(line, line_no, [0, "unss"])
ribbon_symbol = line[1].to_sym
if GameData::Ribbon::DATA[ribbon_symbol]
raise _INTL("Ribbon ID '{1}' is used twice.\r\n{2}", ribbon_symbol, FileLineData.linereport)
if line[/^\s*\[\s*(.+)\s*\]\s*$/] # New section [ribbon_id]
# Add previous ribbon's data to records
GameData::Ribbon.register(ribbon_hash) if ribbon_hash
# Parse ribbon ID
ribbon_id = $~[1].to_sym
if GameData::Ribbon.exists?(ribbon_id)
raise _INTL("Ribbon ID '{1}' is used twice.\r\n{2}", ribbon_id, FileLineData.linereport)
end
# Construct ribbon hash
ribbon_hash = {
:id => ribbon_id
}
elsif line[/^\s*(\w+)\s*=\s*(.*)\s*$/] # XXX=YYY lines
if !ribbon_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
ribbon_hash[line_schema[0]] = property_value
case property_name
when "Name"
ribbon_names.push(ribbon_hash[:name])
when "Description"
ribbon_descriptions.push(ribbon_hash[:description])
end
else # Old format
# Add previous ribbon's data to records
GameData::Ribbon.register(ribbon_hash) if ribbon_hash
# Parse ribbon
line = pbGetCsvRecord(line, line_no, [0, "unss"])
ribbon_id = line[1].to_sym
if GameData::Ribbon::DATA[ribbon_id]
raise _INTL("Ribbon ID '{1}' is used twice.\r\n{2}", ribbon_id, FileLineData.linereport)
end
# Construct ribbon hash
ribbon_hash = {
:id => ribbon_id,
:name => line[2],
:description => line[3],
:icon_position => line[0] - 1
}
# Add ribbon's data to records
GameData::Ribbon.register(ribbon_hash)
ribbon_names.push(ribbon_hash[:name])
ribbon_descriptions.push(ribbon_hash[:description])
ribbon_hash = nil
end
# Construct ribbon hash
ribbon_hash = {
:id => ribbon_symbol,
:name => line[2],
:description => line[3],
:icon_position => line[0] - 1
}
# Add ribbon's data to records
GameData::Ribbon.register(ribbon_hash)
ribbon_names.push(ribbon_hash[:name])
ribbon_descriptions.push(ribbon_hash[:description])
}
# Add last ribbon's data to records
GameData::Ribbon.register(ribbon_hash) if ribbon_hash
# Save all data
GameData::Ribbon.save
MessageTypes.setMessagesAsHash(MessageTypes::RibbonNames, ribbon_names)

View File

@@ -497,14 +497,13 @@ module Compiler
def write_ribbons
File.open("PBS/ribbons.txt", "wb") { |f|
add_PBS_header_to_file(f)
f.write("\#-------------------------------\r\n")
GameData::Ribbon.each do |r|
f.write(sprintf("%d,%s,%s,%s\r\n",
r.icon_position + 1,
csvQuote(r.id.to_s),
csvQuote(r.real_name),
csvQuoteAlways(r.real_description)
))
# Write each ability in turn
GameData::Ribbon.each do |ribbon|
f.write("\#-------------------------------\r\n")
f.write("[#{ribbon.id}]\r\n")
f.write("Name = #{ribbon.real_name}\r\n")
f.write("IconPosition = #{ribbon.icon_position}\r\n")
f.write("Description = #{ribbon.real_description}\r\n")
end
}
Graphics.update