mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-09 06:04:59 +00:00
Split metadata.txt into metadata.txt and map_metadata.txt, fixed bug when writing certain PBS files
This commit is contained in:
@@ -102,6 +102,7 @@ module Compiler
|
||||
line = line[3,line.length-3]
|
||||
end
|
||||
if !line[/^\#/] && !line[/^\s*$/]
|
||||
line = prepline(line)
|
||||
if line[/^\s*\[\s*(.*)\s*\]\s*$/] # Of the format: [something]
|
||||
yield lastsection,sectionname if havesection
|
||||
sectionname = $~[1]
|
||||
@@ -134,7 +135,7 @@ module Compiler
|
||||
}
|
||||
end
|
||||
|
||||
# Used for metadata.txt
|
||||
# Used for metadata.txt and map_metadata.txt
|
||||
def pbEachFileSectionNumbered(f)
|
||||
pbEachFileSectionEx(f) { |section,name|
|
||||
yield section,name.to_i if block_given? && name[/^\d+$/]
|
||||
@@ -547,11 +548,11 @@ module Compiler
|
||||
def pbWriteCsvRecord(record,file,schema)
|
||||
rec = (record.is_a?(Array)) ? record.flatten : [record]
|
||||
start = (schema[1][0, 1] == "*") ? 1 : 0
|
||||
index = 0
|
||||
index = -1
|
||||
begin
|
||||
for i in start...schema[1].length
|
||||
index += 1
|
||||
file.write(",") if index > 1
|
||||
file.write(",") if index > 0
|
||||
value = rec[index]
|
||||
if value.nil?
|
||||
# do nothing
|
||||
@@ -613,7 +614,7 @@ module Compiler
|
||||
file.write(value.inspect)
|
||||
end
|
||||
end
|
||||
break if start > 0 && index >= rec.length
|
||||
break if start > 0 && index >= rec.length - 1
|
||||
end while start > 0
|
||||
return record
|
||||
end
|
||||
@@ -739,6 +740,8 @@ module Compiler
|
||||
compile_trainer_lists # Depends on TrainerType
|
||||
yield(_INTL("Compiling metadata"))
|
||||
compile_metadata # Depends on TrainerType
|
||||
yield(_INTL("Compiling map metadata"))
|
||||
compile_map_metadata # No dependencies
|
||||
yield(_INTL("Compiling animations"))
|
||||
compile_animations
|
||||
yield("")
|
||||
@@ -766,6 +769,7 @@ module Compiler
|
||||
"metadata.dat",
|
||||
"moves.dat",
|
||||
"phone.dat",
|
||||
"player_metadata.dat",
|
||||
"regional_dexes.dat",
|
||||
"ribbons.dat",
|
||||
"shadow_movesets.dat",
|
||||
|
||||
@@ -1397,22 +1397,22 @@ module Compiler
|
||||
#=============================================================================
|
||||
def compile_metadata(path = "PBS/metadata.txt")
|
||||
GameData::Metadata::DATA.clear
|
||||
GameData::MapMetadata::DATA.clear
|
||||
GameData::PlayerMetadata::DATA.clear
|
||||
# Read from PBS file
|
||||
File.open(path, "rb") { |f|
|
||||
FileLineData.file = path # For error reporting
|
||||
# Read a whole section's lines at once, then run through this code.
|
||||
# contents is a hash containing all the XXX=YYY lines in that section, where
|
||||
# the keys are the XXX and the values are the YYY (as unprocessed strings).
|
||||
pbEachFileSectionNumbered(f) { |contents, map_id|
|
||||
schema = (map_id == 0) ? GameData::Metadata::SCHEMA : GameData::MapMetadata::SCHEMA
|
||||
pbEachFileSectionNumbered(f) { |contents, section_id|
|
||||
schema = (section_id == 0) ? GameData::Metadata::SCHEMA : GameData::PlayerMetadata::SCHEMA
|
||||
# Go through schema hash of compilable data and compile this section
|
||||
for key in schema.keys
|
||||
FileLineData.setSection(map_id, key, contents[key]) # For error reporting
|
||||
FileLineData.setSection(section_id, key, contents[key]) # For error reporting
|
||||
# Skip empty properties, or raise an error if a required property is
|
||||
# empty
|
||||
if contents[key].nil?
|
||||
if map_id == 0 && ["Home", "PlayerA"].include?(key)
|
||||
if section_id == 0 && ["Home"].include?(key)
|
||||
raise _INTL("The entry {1} is required in {2} section 0.", key, path)
|
||||
end
|
||||
next
|
||||
@@ -1422,10 +1422,10 @@ module Compiler
|
||||
value = nil if value.is_a?(Array) && value.length == 0
|
||||
contents[key] = value
|
||||
end
|
||||
if map_id == 0 # Global metadata
|
||||
if section_id == 0 # Metadata
|
||||
# Construct metadata hash
|
||||
metadata_hash = {
|
||||
:id => map_id,
|
||||
:id => section_id,
|
||||
:home => contents["Home"],
|
||||
:wild_battle_BGM => contents["WildBattleBGM"],
|
||||
:trainer_battle_BGM => contents["TrainerBattleBGM"],
|
||||
@@ -1433,51 +1433,90 @@ module Compiler
|
||||
:trainer_victory_ME => contents["TrainerVictoryME"],
|
||||
:wild_capture_ME => contents["WildCaptureME"],
|
||||
:surf_BGM => contents["SurfBGM"],
|
||||
:bicycle_BGM => contents["BicycleBGM"],
|
||||
:player_A => contents["PlayerA"],
|
||||
:player_B => contents["PlayerB"],
|
||||
:player_C => contents["PlayerC"],
|
||||
:player_D => contents["PlayerD"],
|
||||
:player_E => contents["PlayerE"],
|
||||
:player_F => contents["PlayerF"],
|
||||
:player_G => contents["PlayerG"],
|
||||
:player_H => contents["PlayerH"]
|
||||
:bicycle_BGM => contents["BicycleBGM"]
|
||||
}
|
||||
# Add metadata's data to records
|
||||
GameData::Metadata.register(metadata_hash)
|
||||
else # Map metadata
|
||||
else # Player metadata
|
||||
# Construct metadata hash
|
||||
metadata_hash = {
|
||||
:id => map_id,
|
||||
:outdoor_map => contents["Outdoor"],
|
||||
:announce_location => contents["ShowArea"],
|
||||
:can_bicycle => contents["Bicycle"],
|
||||
:always_bicycle => contents["BicycleAlways"],
|
||||
:teleport_destination => contents["HealingSpot"],
|
||||
:weather => contents["Weather"],
|
||||
:town_map_position => contents["MapPosition"],
|
||||
:dive_map_id => contents["DiveMap"],
|
||||
:dark_map => contents["DarkMap"],
|
||||
:safari_map => contents["SafariMap"],
|
||||
:snap_edges => contents["SnapEdges"],
|
||||
:random_dungeon => contents["Dungeon"],
|
||||
:battle_background => contents["BattleBack"],
|
||||
:wild_battle_BGM => contents["WildBattleBGM"],
|
||||
:trainer_battle_BGM => contents["TrainerBattleBGM"],
|
||||
:wild_victory_ME => contents["WildVictoryME"],
|
||||
:trainer_victory_ME => contents["TrainerVictoryME"],
|
||||
:wild_capture_ME => contents["WildCaptureME"],
|
||||
:town_map_size => contents["MapSize"],
|
||||
:battle_environment => contents["Environment"],
|
||||
:flags => contents["Flags"]
|
||||
:id => section_id,
|
||||
:trainer_type => contents["TrainerType"],
|
||||
:walk_charset => contents["WalkCharset"],
|
||||
:run_charset => contents["RunCharset"],
|
||||
:cycle_charset => contents["CycleCharset"],
|
||||
:surf_charset => contents["SurfCharset"],
|
||||
:dive_charset => contents["DiveCharset"],
|
||||
:fish_charset => contents["FishCharset"],
|
||||
:surf_fish_charset => contents["SurfFishCharset"]
|
||||
}
|
||||
# Add metadata's data to records
|
||||
GameData::MapMetadata.register(metadata_hash)
|
||||
GameData::PlayerMetadata.register(metadata_hash)
|
||||
end
|
||||
}
|
||||
}
|
||||
if !GameData::PlayerMetadata.exists?(1)
|
||||
raise _INTL("Metadata for player character 1 in {1} is not defined but should be.", path)
|
||||
end
|
||||
# Save all data
|
||||
GameData::Metadata.save
|
||||
GameData::PlayerMetadata.save
|
||||
Graphics.update
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Compile map metadata
|
||||
#=============================================================================
|
||||
def compile_map_metadata(path = "PBS/map_metadata.txt")
|
||||
GameData::MapMetadata::DATA.clear
|
||||
# Read from PBS file
|
||||
File.open(path, "rb") { |f|
|
||||
FileLineData.file = path # For error reporting
|
||||
# Read a whole section's lines at once, then run through this code.
|
||||
# contents is a hash containing all the XXX=YYY lines in that section, where
|
||||
# the keys are the XXX and the values are the YYY (as unprocessed strings).
|
||||
schema = GameData::MapMetadata::SCHEMA
|
||||
pbEachFileSectionNumbered(f) { |contents, map_id|
|
||||
# Go through schema hash of compilable data and compile this section
|
||||
for key in schema.keys
|
||||
FileLineData.setSection(map_id, key, contents[key]) # For error reporting
|
||||
# Skip empty properties
|
||||
next if contents[key].nil?
|
||||
# Compile value for key
|
||||
value = pbGetCsvRecord(contents[key], key, schema[key])
|
||||
value = nil if value.is_a?(Array) && value.length == 0
|
||||
contents[key] = value
|
||||
end
|
||||
# Construct map metadata hash
|
||||
metadata_hash = {
|
||||
:id => map_id,
|
||||
:outdoor_map => contents["Outdoor"],
|
||||
:announce_location => contents["ShowArea"],
|
||||
:can_bicycle => contents["Bicycle"],
|
||||
:always_bicycle => contents["BicycleAlways"],
|
||||
:teleport_destination => contents["HealingSpot"],
|
||||
:weather => contents["Weather"],
|
||||
:town_map_position => contents["MapPosition"],
|
||||
:dive_map_id => contents["DiveMap"],
|
||||
:dark_map => contents["DarkMap"],
|
||||
:safari_map => contents["SafariMap"],
|
||||
:snap_edges => contents["SnapEdges"],
|
||||
:random_dungeon => contents["Dungeon"],
|
||||
:battle_background => contents["BattleBack"],
|
||||
:wild_battle_BGM => contents["WildBattleBGM"],
|
||||
:trainer_battle_BGM => contents["TrainerBattleBGM"],
|
||||
:wild_victory_ME => contents["WildVictoryME"],
|
||||
:trainer_victory_ME => contents["TrainerVictoryME"],
|
||||
:wild_capture_ME => contents["WildCaptureME"],
|
||||
:town_map_size => contents["MapSize"],
|
||||
:battle_environment => contents["Environment"],
|
||||
:flags => contents["Flags"]
|
||||
}
|
||||
# Add map metadata's data to records
|
||||
GameData::MapMetadata.register(metadata_hash)
|
||||
}
|
||||
}
|
||||
# Save all data
|
||||
GameData::MapMetadata.save
|
||||
Graphics.update
|
||||
end
|
||||
|
||||
@@ -738,32 +738,57 @@ module Compiler
|
||||
def write_metadata
|
||||
File.open("PBS/metadata.txt", "wb") { |f|
|
||||
add_PBS_header_to_file(f)
|
||||
# Write global metadata
|
||||
# Write metadata
|
||||
f.write("\#-------------------------------\r\n")
|
||||
f.write("[000]\r\n")
|
||||
f.write("[0]\r\n")
|
||||
metadata = GameData::Metadata.get
|
||||
schema = GameData::Metadata::SCHEMA
|
||||
keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] }
|
||||
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
|
||||
for key in keys
|
||||
record = metadata.property_from_string(key)
|
||||
next if record.nil?
|
||||
next if record.nil? || (record.is_a?(Array) && record.empty?)
|
||||
f.write(sprintf("%s = ", key))
|
||||
pbWriteCsvRecord(record, f, schema[key])
|
||||
f.write("\r\n")
|
||||
end
|
||||
# Write map metadata
|
||||
map_infos = pbLoadMapInfos
|
||||
schema = GameData::MapMetadata::SCHEMA
|
||||
keys = schema.keys.sort {|a, b| schema[a][0] <=> schema[b][0] }
|
||||
# Write player metadata
|
||||
schema = GameData::PlayerMetadata::SCHEMA
|
||||
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
|
||||
GameData::PlayerMetadata.each do |player_data|
|
||||
f.write("\#-------------------------------\r\n")
|
||||
f.write(sprintf("[%d]\r\n", player_data.id))
|
||||
for key in keys
|
||||
record = player_data.property_from_string(key)
|
||||
next if record.nil? || (record.is_a?(Array) && record.empty?)
|
||||
f.write(sprintf("%s = ", key))
|
||||
pbWriteCsvRecord(record, f, schema[key])
|
||||
f.write("\r\n")
|
||||
end
|
||||
end
|
||||
}
|
||||
Graphics.update
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# Save map metadata data to PBS file
|
||||
#=============================================================================
|
||||
def write_map_metadata
|
||||
map_infos = pbLoadMapInfos
|
||||
schema = GameData::MapMetadata::SCHEMA
|
||||
keys = schema.keys.sort { |a, b| schema[a][0] <=> schema[b][0] }
|
||||
File.open("PBS/map_metadata.txt", "wb") { |f|
|
||||
add_PBS_header_to_file(f)
|
||||
GameData::MapMetadata.each do |map_data|
|
||||
f.write("\#-------------------------------\r\n")
|
||||
f.write(sprintf("[%03d]\r\n", map_data.id))
|
||||
if map_infos && map_infos[map_data.id]
|
||||
f.write(sprintf("# %s\r\n", map_infos[map_data.id].name))
|
||||
map_name = (map_infos && map_infos[map_data.id]) ? map_infos[map_data.id].name : nil
|
||||
if map_name
|
||||
f.write(sprintf("[%03d] # %s\r\n", map_data.id, map_name))
|
||||
else
|
||||
f.write(sprintf("[%03d]\r\n", map_data.id))
|
||||
end
|
||||
for key in keys
|
||||
record = map_data.property_from_string(key)
|
||||
next if record.nil?
|
||||
next if record.nil? || (record.is_a?(Array) && record.empty?)
|
||||
f.write(sprintf("%s = ", key))
|
||||
pbWriteCsvRecord(record, f, schema[key])
|
||||
f.write("\r\n")
|
||||
@@ -795,5 +820,6 @@ module Compiler
|
||||
write_trainers
|
||||
write_trainer_lists
|
||||
write_metadata
|
||||
write_map_metadata
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user