Added new section-based format for items.txt

This commit is contained in:
Maruno17
2021-06-20 00:13:34 +01:00
parent 9b4bc66dc0
commit e4cdb95314
5 changed files with 5183 additions and 700 deletions

View File

@@ -14,6 +14,25 @@ module GameData
DATA = {}
DATA_FILENAME = "items.dat"
SCHEMA = {
"Name" => [:name, "s"],
"NamePlural" => [:name_plural, "s"],
"Pocket" => [:pocket, "v"],
"Price" => [:price, "u"],
"Description" => [:description, "q"],
"FieldUse" => [:field_use, "e", {"OnPokemon" => 1, "Direct" => 2, "TM" => 3,
"HM" => 4, "OnPokemonReusable" => 5, "TR" => 6}],
"BattleUse" => [:battle_use, "e", {"OnPokemon" => 1, "OnMove" => 2, "OnBattler" => 3,
"OnFoe" => 4, "Direct" => 5, "OnPokemonReusable" => 6,
"OnMoveReusable" => 7, "OnBattlerReusable" => 8,
"OnFoeReusable" => 9, "DirectReusable" => 10}],
"Type" => [:type, "e", {"Mail" => 1, "IconMail" => 2, "SnagBall" => 3,
"PokeBall" => 4, "Berry" => 5, "KeyItem" => 6,
"EvolutionStone" => 7, "Fossil" => 8, "Apricorn" => 9,
"TypeGem" => 10, "Mulch" => 11, "MegaStone" => 12}],
"Move" => [:move, "e", :Move]
}
extend ClassMethodsSymbols
include InstanceMethods

View File

@@ -796,30 +796,23 @@ end
# Item editor
#===============================================================================
def pbItemEditor
field_use_array = [_INTL("Can't use in field")]
GameData::Item::SCHEMA["FieldUse"][2].each { |key, value| field_use_array[value] = key }
battle_use_array = [_INTL("Can't use in battle")]
GameData::Item::SCHEMA["BattleUse"][2].each { |key, value| battle_use_array[value] = key }
type_array = [_INTL("No special type")]
GameData::Item::SCHEMA["Type"][2].each { |key, value| type_array[value] = key }
item_properties = [
[_INTL("Internal Name"), ReadOnlyProperty, _INTL("Internal name that is used as a symbol like :XXX.")],
[_INTL("Item Name"), ItemNameProperty, _INTL("Name of the item as displayed by the game.")],
[_INTL("Item Name Plural"), ItemNameProperty, _INTL("Plural name of the item as displayed by the game.")],
[_INTL("Pocket"), PocketProperty, _INTL("Pocket in the bag where the item is stored.")],
[_INTL("Purchase price"), LimitProperty.new(999999), _INTL("Purchase price of the item.")],
[_INTL("Description"), StringProperty, _INTL("Description of the item")],
[_INTL("Use Out of Battle"), EnumProperty.new([
_INTL("Can't Use"), _INTL("On a Pokémon"), _INTL("Use directly"),
_INTL("TM"), _INTL("HM"), _INTL("On a Pokémon reusable"),
_INTL("TR")]), _INTL("Specifies how this item can be used outside of battle.")],
[_INTL("Use In Battle"), EnumProperty.new([
_INTL("Can't Use"), _INTL("On a Pokémon"), _INTL("On Pokémon's move"),
_INTL("On battler"), _INTL("On foe battler"), _INTL("Use directly"),
_INTL("On a Pokémon reusable"), _INTL("On Pokémon's move reusable"),
_INTL("On battler reusable"), _INTL("On foe battler reusable"),
_INTL("Use directly reusable")]), _INTL("Specifies how this item can be used within a battle.")],
[_INTL("Special Items"), EnumProperty.new([
_INTL("None of below"), _INTL("Mail"), _INTL("Mail with Pictures"),
_INTL("Snag Ball"), _INTL("Poké Ball"), _INTL("Plantable Berry"),
_INTL("Key Item"), _INTL("Evolution Stone"), _INTL("Fossil"),
_INTL("Apricorn"), _INTL("Type-boosting Gem"), _INTL("Mulch"),
_INTL("Mega Stone")]), _INTL("For special kinds of items.")],
[_INTL("Machine"), MoveProperty, _INTL("Move taught by this TM or HM.")]
[_INTL("ID"), ReadOnlyProperty, _INTL("ID of this item (used as a symbol like :XXX).")],
[_INTL("Name"), ItemNameProperty, _INTL("Name of this item as displayed by the game.")],
[_INTL("NamePlural"), ItemNameProperty, _INTL("Plural name of this item as displayed by the game.")],
[_INTL("Pocket"), PocketProperty, _INTL("Pocket in the Bag where this item is stored.")],
[_INTL("Price"), LimitProperty.new(999999), _INTL("Purchase price of this item.")],
[_INTL("Description"), StringProperty, _INTL("Description of this item")],
[_INTL("FieldUse"), EnumProperty.new(field_use_array), _INTL("How this item can be used outside of battle.")],
[_INTL("BattleUse"), EnumProperty.new(battle_use_array), _INTL("How this item can be used within a battle.")],
[_INTL("Type"), EnumProperty.new(type_array), _INTL("For special kinds of items.")],
[_INTL("Move"), MoveProperty, _INTL("Move taught by this HM, TM or TR.")]
]
pbListScreenBlock(_INTL("Items"), ItemLister.new(0, true)) { |button, item|
if item

View File

@@ -292,19 +292,57 @@ module Compiler
#=============================================================================
def compile_items(path = "PBS/items.txt")
GameData::Item::DATA.clear
schema = GameData::Item::SCHEMA
item_names = []
item_names_plural = []
item_descriptions = []
item_hash = nil
# Read each line of items.txt at a time and compile it into an item
pbCompilerEachCommentedLine(path) { |line, line_no|
line = pbGetCsvRecord(line, line_no, [0, "snssuusuuUN"])
item_symbol = line[1].to_sym
if GameData::Item::DATA[item_symbol]
raise _INTL("Item ID '{1}' is used twice.\r\n{2}", item_symbol, FileLineData.linereport)
pbCompilerEachPreppedLine(path) { |line, line_no|
if line[/^\s*\[\s*(.+)\s*\]\s*$/] # New section [item_id]
# Add previous item's data to records
GameData::Item.register(item_hash) if item_hash
# Parse item ID
item_id = $~[1].to_sym
if GameData::Item.exists?(item_id)
raise _INTL("Item ID '{1}' is used twice.\r\n{2}", item_id, FileLineData.linereport)
end
# Construct item hash
item_hash = {
:id => item_symbol,
:id => item_id
}
elsif line[/^\s*(\w+)\s*=\s*(.*)\s*$/] # XXX=YYY lines
if !item_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
item_hash[line_schema[0]] = property_value
case property_name
when "Name"
item_names.push(item_hash[:name])
when "NamePlural"
item_names_plural.push(item_hash[:name_plural])
when "Description"
item_descriptions.push(item_hash[:description])
end
else # Old format
# Add previous item's data to records
GameData::Item.register(item_hash) if item_hash
# Parse item
line = pbGetCsvRecord(line, line_no, [0, "snssvusuuUE", nil, nil, nil,
nil, nil, nil, nil, nil, nil, nil, :Move])
item_id = line[1].to_sym
if GameData::Item.exists?(item_id)
raise _INTL("Item ID '{1}' is used twice.\r\n{2}", item_id, FileLineData.linereport)
end
# Construct item hash
item_hash = {
:id => item_id,
:name => line[2],
:name_plural => line[3],
:pocket => line[4],
@@ -312,15 +350,19 @@ module Compiler
:description => line[6],
:field_use => line[7],
:battle_use => line[8],
:type => line[9]
:type => line[9],
:move => line[10]
}
item_hash[:move] = parseMove(line[10]) if !nil_or_empty?(line[10])
# Add item's data to records
GameData::Item.register(item_hash)
item_names.push(item_hash[:name])
item_names_plural.push(item_hash[:name_plural])
item_descriptions.push(item_hash[:description])
item_hash = nil
end
}
# Add last item's data to records
GameData::Item.register(item_hash) if item_hash
# Save all data
GameData::Item.save
MessageTypes.setMessagesAsHash(MessageTypes::Items, item_names)

View File

@@ -207,27 +207,21 @@ module Compiler
def write_items
File.open("PBS/items.txt", "wb") { |f|
add_PBS_header_to_file(f)
current_pocket = 0
GameData::Item.each do |i|
if current_pocket != i.pocket
current_pocket = i.pocket
GameData::Item.each do |item|
f.write("\#-------------------------------\r\n")
end
move_name = (i.move) ? GameData::Move.get(i.move).id.to_s : ""
sprintf_text = "0,%s,%s,%s,%d,%d,%s,%d,%d,%d\r\n"
sprintf_text = "0,%s,%s,%s,%d,%d,%s,%d,%d,%d,%s\r\n" if move_name != ""
f.write(sprintf(sprintf_text,
csvQuote(i.id.to_s),
csvQuote(i.real_name),
csvQuote(i.real_name_plural),
i.pocket,
i.price,
csvQuoteAlways(i.real_description),
i.field_use,
i.battle_use,
i.type,
csvQuote(move_name)
))
f.write(sprintf("[%s]\r\n", item.id))
f.write(sprintf("Name = %s\r\n", item.real_name))
f.write(sprintf("NamePlural = %s\r\n", item.real_name_plural))
f.write(sprintf("Pocket = %d\r\n", item.pocket))
f.write(sprintf("Price = %d\r\n", item.price))
field_use = GameData::Item::SCHEMA["FieldUse"][2].key(item.field_use)
f.write(sprintf("FieldUse = %s\r\n", field_use)) if field_use
battle_use = GameData::Item::SCHEMA["BattleUse"][2].key(item.battle_use)
f.write(sprintf("BattleUse = %s\r\n", battle_use)) if battle_use
type = GameData::Item::SCHEMA["Type"][2].key(item.type)
f.write(sprintf("Type = %s\r\n", type)) if type
f.write(sprintf("Move = %s\r\n", item.move)) if item.move
f.write(sprintf("Description = %s\r\n", item.real_description))
end
}
Graphics.update

File diff suppressed because it is too large Load Diff