Implemented GameData::Metadata and GameData::MapMetadata

This commit is contained in:
Maruno17
2020-11-15 18:59:07 +00:00
parent d8476d1fa4
commit 52ffae9e8a
45 changed files with 803 additions and 540 deletions

View File

@@ -49,23 +49,6 @@ def pbClearData
end
end
#===============================================================================
# Methods to get metadata.
#===============================================================================
def pbLoadMetadata
$PokemonTemp = PokemonTemp.new if !$PokemonTemp
if !$PokemonTemp.metadata
$PokemonTemp.metadata = load_data("Data/metadata.dat") || []
end
return $PokemonTemp.metadata
end
def pbGetMetadata(map_id, metadata_type)
meta = pbLoadMetadata
return meta[map_id][metadata_type] if meta[map_id]
return nil
end
#===============================================================================
# Method to get Town Map data.
#===============================================================================

View File

@@ -2,6 +2,7 @@ module GameData
# A mixin module for data classes which provides common class methods (called
# by GameData::Thing.method) that provide access to data held within.
# Assumes the data class's data is stored in a class constant hash called DATA.
# For data that is known by a symbol or an ID number.
module ClassMethods
# @param other [Symbol, self, String, Integer]
# @return [Boolean] whether the given other is defined as a self
@@ -39,9 +40,51 @@ module GameData
def each
keys = self::DATA.keys.sort { |a, b| self::DATA[a].id_number <=> self::DATA[b].id_number }
keys.each do |key|
yield self::DATA[key] if key.is_a?(Symbol)
end
keys.each { |key| yield self::DATA[key] if key.is_a?(Symbol) }
end
def load
const_set(:DATA, load_data("Data/#{self::DATA_FILENAME}"))
end
def save
save_data(self::DATA, "Data/#{self::DATA_FILENAME}")
end
end
# A mixin module for data classes which provides common class methods (called
# by GameData::Thing.method) that provide access to data held within.
# Assumes the data class's data is stored in a class constant hash called DATA.
# For data that is only known by an ID number.
module ClassMethodsIDNumbers
# @param other [self, Integer]
# @return [Boolean] whether the given other is defined as a self
def exists?(other)
return false if other.nil?
validate other => [self, Integer]
other = other.id if other.is_a?(self)
return !self::DATA[other].nil?
end
# @param other [self, Integer]
# @return [self]
def get(other)
validate other => [self, Integer]
return other if other.is_a?(self)
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
return self::DATA[other]
end
def try_get(other)
return nil if other.nil?
validate other => [self, Integer]
return other if other.is_a?(self)
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
end
def each
keys = self::DATA.keys.sort
keys.each { |key| yield self::DATA[key] }
end
def load

View File

@@ -0,0 +1,229 @@
module GameData
class Metadata
attr_reader :id
attr_reader :home
attr_reader :wild_battle_BGM
attr_reader :trainer_battle_BGM
attr_reader :wild_victory_ME
attr_reader :trainer_victory_ME
attr_reader :wild_capture_ME
attr_reader :surf_BGM
attr_reader :bicycle_BGM
attr_reader :player_A
attr_reader :player_B
attr_reader :player_C
attr_reader :player_D
attr_reader :player_E
attr_reader :player_F
attr_reader :player_G
attr_reader :player_H
DATA = {}
DATA_FILENAME = "metadata.dat"
SCHEMA = {
"Home" => [1, "vuuu"],
"WildBattleBGM" => [2, "s"],
"TrainerBattleBGM" => [3, "s"],
"WildVictoryME" => [4, "s"],
"TrainerVictoryME" => [5, "s"],
"WildCaptureME" => [6, "s"],
"SurfBGM" => [7, "s"],
"BicycleBGM" => [8, "s"],
"PlayerA" => [9, "esssssss", :PBTrainers],
"PlayerB" => [10, "esssssss", :PBTrainers],
"PlayerC" => [11, "esssssss", :PBTrainers],
"PlayerD" => [12, "esssssss", :PBTrainers],
"PlayerE" => [13, "esssssss", :PBTrainers],
"PlayerF" => [14, "esssssss", :PBTrainers],
"PlayerG" => [15, "esssssss", :PBTrainers],
"PlayerH" => [16, "esssssss", :PBTrainers]
}
extend ClassMethodsIDNumbers
include InstanceMethods
def self.editor_properties
return [
["Home", MapCoordsFacingProperty, _INTL("Map ID and X and Y coordinates of where the player goes if no Pokémon Center was entered after a loss.")],
["WildBattleBGM", BGMProperty, _INTL("Default BGM for wild Pokémon battles.")],
["TrainerBattleBGM", BGMProperty, _INTL("Default BGM for Trainer battles.")],
["WildVictoryME", MEProperty, _INTL("Default ME played after winning a wild Pokémon battle.")],
["TrainerVictoryME", MEProperty, _INTL("Default ME played after winning a Trainer battle.")],
["WildCaptureME", MEProperty, _INTL("Default ME played after catching a Pokémon.")],
["SurfBGM", BGMProperty, _INTL("BGM played while surfing.")],
["BicycleBGM", BGMProperty, _INTL("BGM played while on a bicycle.")],
["PlayerA", PlayerProperty, _INTL("Specifies player A.")],
["PlayerB", PlayerProperty, _INTL("Specifies player B.")],
["PlayerC", PlayerProperty, _INTL("Specifies player C.")],
["PlayerD", PlayerProperty, _INTL("Specifies player D.")],
["PlayerE", PlayerProperty, _INTL("Specifies player E.")],
["PlayerF", PlayerProperty, _INTL("Specifies player F.")],
["PlayerG", PlayerProperty, _INTL("Specifies player G.")],
["PlayerH", PlayerProperty, _INTL("Specifies player H.")]
]
end
def self.get
return DATA[0]
end
def self.get_player(id)
case id
when 0 then return self.get.player_A
when 1 then return self.get.player_B
when 2 then return self.get.player_C
when 3 then return self.get.player_D
when 4 then return self.get.player_E
when 5 then return self.get.player_F
when 6 then return self.get.player_G
when 7 then return self.get.player_H
end
return nil
end
def initialize(hash)
validate hash => Hash, hash[:id] => Integer
@id = hash[:id]
@home = hash[:home]
@wild_battle_BGM = hash[:wild_battle_BGM]
@trainer_battle_BGM = hash[:trainer_battle_BGM]
@wild_victory_ME = hash[:wild_victory_ME]
@trainer_victory_ME = hash[:trainer_victory_ME]
@wild_capture_ME = hash[:wild_capture_ME]
@surf_BGM = hash[:surf_BGM]
@bicycle_BGM = hash[:bicycle_BGM]
@player_A = hash[:player_A]
@player_B = hash[:player_B]
@player_C = hash[:player_C]
@player_D = hash[:player_D]
@player_E = hash[:player_E]
@player_F = hash[:player_F]
@player_G = hash[:player_G]
@player_H = hash[:player_H]
end
def property_from_string(str)
case str
when "Home" then return @home
when "WildBattleBGM" then return @wild_battle_BGM
when "TrainerBattleBGM" then return @trainer_battle_BGM
when "WildVictoryME" then return @wild_victory_ME
when "TrainerVictoryME" then return @trainer_victory_ME
when "WildCaptureME" then return @wild_capture_ME
when "SurfBGM" then return @surf_BGM
when "BicycleBGM" then return @bicycle_BGM
when "PlayerA" then return @player_A
when "PlayerB" then return @player_B
when "PlayerC" then return @player_C
when "PlayerD" then return @player_D
when "PlayerE" then return @player_E
when "PlayerF" then return @player_F
when "PlayerG" then return @player_G
when "PlayerH" then return @player_H
end
return nil
end
end
end
#===============================================================================
# Deprecated methods
#===============================================================================
def pbLoadMetadata
Deprecation.warn_method('pbLoadMetadata', 'v20', 'GameData::Metadata.get or GameData::MapMetadata.get(map_id)')
return nil
end
def pbGetMetadata(map_id, metadata_type)
if map_id == 0 # Global metadata
Deprecation.warn_method('pbGetMetadata', 'v20', 'GameData::Metadata.get.something')
ret = GameData::Metadata.get
case metadata_type
when Metadata::HOME then return ret.home
when Metadata::WILD_BATTLE_BGM then return ret.wild_battle_BGM
when Metadata::TRAINER_BATTLE_BGM then return ret.trainer_battle_BGM
when Metadata::WILD_VICTORY_ME then return ret.wild_victory_ME
when Metadata::TRAINER_VICTORY_ME then return ret.trainer_victory_ME
when Metadata::WILD_CAPTURE_ME then return ret.wild_capture_ME
when Metadata::SURF_BGM then return ret.surf_BGM
when Metadata::BICYCLE_BGM then return ret.bicycle_BGM
when Metadata::PLAYER_A then return ret.player_A
when Metadata::PLAYER_B then return ret.player_B
when Metadata::PLAYER_C then return ret.player_C
when Metadata::PLAYER_D then return ret.player_D
when Metadata::PLAYER_E then return ret.player_E
when Metadata::PLAYER_F then return ret.player_F
when Metadata::PLAYER_G then return ret.player_G
when Metadata::PLAYER_H then return ret.player_H
end
else # Map metadata
Deprecation.warn_method('pbGetMetadata', 'v20', 'GameData::MapMetadata.get(map_id).something')
ret = GameData::MapMetadata.get(map_id)
case metadata_type
when MapMetadata::OUTDOOR then return ret.outdoor_map
when MapMetadata::SHOW_AREA then return ret.announce_location
when MapMetadata::BICYCLE then return ret.can_bicycle
when MapMetadata::BICYCLE_ALWAYS then return ret.always_bicycle
when MapMetadata::HEALING_SPOT then return ret.teleport_destination
when MapMetadata::WEATHER then return ret.weather
when MapMetadata::MAP_POSITION then return ret.town_map_position
when MapMetadata::DIVE_MAP then return ret.dive_map_id
when MapMetadata::DARK_MAP then return ret.dark_map
when MapMetadata::SAFARI_MAP then return ret.safari_map
when MapMetadata::SNAP_EDGES then return ret.snap_edges
when MapMetadata::DUNGEON then return ret.random_dungeon
when MapMetadata::BATTLE_BACK then return ret.battle_background
when MapMetadata::WILD_BATTLE_BGM then return ret.wild_battle_BGM
when MapMetadata::TRAINER_BATTLE_BGM then return ret.trainer_battle_BGM
when MapMetadata::WILD_VICTORY_ME then return ret.wild_victory_ME
when MapMetadata::TRAINER_VICTORY_ME then return ret.trainer_victory_ME
when MapMetadata::WILD_CAPTURE_ME then return ret.wild_capture_ME
when MapMetadata::MAP_SIZE then return ret.town_map_size
when MapMetadata::ENVIRONMENT then return ret.battle_environment
end
end
return nil
end
module Metadata
HOME = 1
WILD_BATTLE_BGM = 2
TRAINER_BATTLE_BGM = 3
WILD_VICTORY_ME = 4
TRAINER_VICTORY_ME = 5
WILD_CAPTURE_ME = 6
SURF_BGM = 7
BICYCLE_BGM = 8
PLAYER_A = 9
PLAYER_B = 10
PLAYER_C = 11
PLAYER_D = 12
PLAYER_E = 13
PLAYER_F = 14
PLAYER_G = 15
PLAYER_H = 16
end
module MapMetadata
OUTDOOR = 1
SHOW_AREA = 2
BICYCLE = 3
BICYCLE_ALWAYS = 4
HEALING_SPOT = 5
WEATHER = 6
MAP_POSITION = 7
DIVE_MAP = 8
DARK_MAP = 9
SAFARI_MAP = 10
SNAP_EDGES = 11
DUNGEON = 12
BATTLE_BACK = 13
WILD_BATTLE_BGM = 14
TRAINER_BATTLE_BGM = 15
WILD_VICTORY_ME = 16
TRAINER_VICTORY_ME = 17
WILD_CAPTURE_ME = 18
MAP_SIZE = 19
ENVIRONMENT = 20
end

View File

@@ -0,0 +1,130 @@
module GameData
class MapMetadata
attr_reader :id
attr_reader :outdoor_map
attr_reader :announce_location
attr_reader :can_bicycle
attr_reader :always_bicycle
attr_reader :teleport_destination
attr_reader :weather
attr_reader :town_map_position
attr_reader :dive_map_id
attr_reader :dark_map
attr_reader :safari_map
attr_reader :snap_edges
attr_reader :random_dungeon
attr_reader :battle_background
attr_reader :wild_battle_BGM
attr_reader :trainer_battle_BGM
attr_reader :wild_victory_ME
attr_reader :trainer_victory_ME
attr_reader :wild_capture_ME
attr_reader :town_map_size
attr_reader :battle_environment
DATA = {}
DATA_FILENAME = "map_metadata.dat"
SCHEMA = {
"Outdoor" => [1, "b"],
"ShowArea" => [2, "b"],
"Bicycle" => [3, "b"],
"BicycleAlways" => [4, "b"],
"HealingSpot" => [5, "vuu"],
"Weather" => [6, "eu", :PBFieldWeather],
"MapPosition" => [7, "uuu"],
"DiveMap" => [8, "v"],
"DarkMap" => [9, "b"],
"SafariMap" => [10, "b"],
"SnapEdges" => [11, "b"],
"Dungeon" => [12, "b"],
"BattleBack" => [13, "s"],
"WildBattleBGM" => [14, "s"],
"TrainerBattleBGM" => [15, "s"],
"WildVictoryME" => [16, "s"],
"TrainerVictoryME" => [17, "s"],
"WildCaptureME" => [18, "s"],
"MapSize" => [19, "us"],
"Environment" => [20, "e", :PBEnvironment]
}
extend ClassMethodsIDNumbers
include InstanceMethods
def self.editor_properties
return [
["Outdoor", BooleanProperty, _INTL("If true, this map is an outdoor map and will be tinted according to time of day.")],
["ShowArea", BooleanProperty, _INTL("If true, the game will display the map's name upon entry.")],
["Bicycle", BooleanProperty, _INTL("If true, the bicycle can be used on this map.")],
["BicycleAlways", BooleanProperty, _INTL("If true, the bicycle will be mounted automatically on this map and cannot be dismounted.")],
["HealingSpot", MapCoordsProperty, _INTL("Map ID of this Pokémon Center's town, and X and Y coordinates of its entrance within that town.")],
["Weather", WeatherEffectProperty, _INTL("Weather conditions in effect for this map.")],
["MapPosition", RegionMapCoordsProperty, _INTL("Identifies the point on the regional map for this map.")],
["DiveMap", MapProperty, _INTL("Specifies the underwater layer of this map. Use only if this map has deep water.")],
["DarkMap", BooleanProperty, _INTL("If true, this map is dark and a circle of light appears around the player. Flash can be used to expand the circle.")],
["SafariMap", BooleanProperty, _INTL("If true, this map is part of the Safari Zone (both indoor and outdoor). Not to be used in the reception desk.")],
["SnapEdges", BooleanProperty, _INTL("If true, when the player goes near this map's edge, the game doesn't center the player as usual.")],
["Dungeon", BooleanProperty, _INTL("If true, this map has a randomly generated layout. See the wiki for more information.")],
["BattleBack", StringProperty, _INTL("PNG files named 'XXX_bg', 'XXX_base0', 'XXX_base1', 'XXX_message' in Battlebacks folder, where XXX is this property's value.")],
["WildBattleBGM", BGMProperty, _INTL("Default BGM for wild Pokémon battles on this map.")],
["TrainerBattleBGM", BGMProperty, _INTL("Default BGM for trainer battles on this map.")],
["WildVictoryME", MEProperty, _INTL("Default ME played after winning a wild Pokémon battle on this map.")],
["TrainerVictoryME", MEProperty, _INTL("Default ME played after winning a Trainer battle on this map.")],
["WildCaptureME", MEProperty, _INTL("Default ME played after catching a wild Pokémon on this map.")],
["MapSize", MapSizeProperty, _INTL("The width of the map in Town Map squares, and a string indicating which squares are part of this map.")],
["Environment", EnvironmentProperty, _INTL("The default battle environment for battles on this map.")]
]
end
def initialize(hash)
validate hash => Hash, hash[:id] => Integer
@id = hash[:id]
@outdoor_map = hash[:outdoor_map]
@announce_location = hash[:announce_location]
@can_bicycle = hash[:can_bicycle]
@always_bicycle = hash[:always_bicycle]
@teleport_destination = hash[:teleport_destination]
@weather = hash[:weather]
@town_map_position = hash[:town_map_position]
@dive_map_id = hash[:dive_map_id]
@dark_map = hash[:dark_map]
@safari_map = hash[:safari_map]
@snap_edges = hash[:snap_edges]
@random_dungeon = hash[:random_dungeon]
@battle_background = hash[:battle_background]
@wild_battle_BGM = hash[:wild_battle_BGM]
@trainer_battle_BGM = hash[:trainer_battle_BGM]
@wild_victory_ME = hash[:wild_victory_ME]
@trainer_victory_ME = hash[:trainer_victory_ME]
@wild_capture_ME = hash[:wild_capture_ME]
@town_map_size = hash[:town_map_size]
@battle_environment = hash[:battle_environment]
end
def property_from_string(str)
case str
when "Outdoor" then return @outdoor_map
when "ShowArea" then return @announce_location
when "Bicycle" then return @can_bicycle
when "BicycleAlways" then return @always_bicycle
when "HealingSpot" then return @teleport_destination
when "Weather" then return @weather
when "MapPosition" then return @town_map_position
when "DiveMap" then return @dive_map_id
when "DarkMap" then return @dark_map
when "SafariMap" then return @safari_map
when "SnapEdges" then return @snap_edges
when "Dungeon" then return @random_dungeon
when "BattleBack" then return @battle_background
when "WildBattleBGM" then return @wild_battle_BGM
when "TrainerBattleBGM" then return @trainer_battle_BGM
when "WildVictoryME" then return @wild_victory_ME
when "TrainerVictoryME" then return @trainer_victory_ME
when "WildCaptureME" then return @wild_capture_ME
when "MapSize" then return @town_map_size
when "Environment" then return @battle_environment
end
return nil
end
end
end

View File

@@ -30,96 +30,6 @@ module PhoneMsgType
BattleRequest = 3
end
#===============================================================================
# Global metadata
#===============================================================================
module Metadata
HOME = 1
WILD_BATTLE_BGM = 2
TRAINER_BATTLE_BGM = 3
WILD_VICTORY_ME = 4
TRAINER_VICTORY_ME = 5
WILD_CAPTURE_ME = 6
SURF_BGM = 7
BICYCLE_BGM = 8
PLAYER_A = 9
PLAYER_B = 10
PLAYER_C = 11
PLAYER_D = 12
PLAYER_E = 13
PLAYER_F = 14
PLAYER_G = 15
PLAYER_H = 16
SCHEMA = {
"Home" => [HOME, "uuuu"],
"WildBattleBGM" => [WILD_BATTLE_BGM, "s"],
"TrainerBattleBGM" => [TRAINER_BATTLE_BGM, "s"],
"WildVictoryME" => [WILD_VICTORY_ME, "s"],
"TrainerVictoryME" => [TRAINER_VICTORY_ME, "s"],
"WildCaptureME" => [WILD_CAPTURE_ME, "s"],
"SurfBGM" => [SURF_BGM, "s"],
"BicycleBGM" => [BICYCLE_BGM, "s"],
"PlayerA" => [PLAYER_A, "esssssss", :PBTrainers],
"PlayerB" => [PLAYER_B, "esssssss", :PBTrainers],
"PlayerC" => [PLAYER_C, "esssssss", :PBTrainers],
"PlayerD" => [PLAYER_D, "esssssss", :PBTrainers],
"PlayerE" => [PLAYER_E, "esssssss", :PBTrainers],
"PlayerF" => [PLAYER_F, "esssssss", :PBTrainers],
"PlayerG" => [PLAYER_G, "esssssss", :PBTrainers],
"PlayerH" => [PLAYER_H, "esssssss", :PBTrainers]
}
end
#===============================================================================
# Map-specific metadata
#===============================================================================
module MapMetadata
OUTDOOR = 1
SHOW_AREA = 2
BICYCLE = 3
BICYCLE_ALWAYS = 4
HEALING_SPOT = 5
WEATHER = 6
MAP_POSITION = 7
DIVE_MAP = 8
DARK_MAP = 9
SAFARI_MAP = 10
SNAP_EDGES = 11
DUNGEON = 12
BATTLE_BACK = 13
WILD_BATTLE_BGM = 14
TRAINER_BATTLE_BGM = 15
WILD_VICTORY_ME = 16
TRAINER_VICTORY_ME = 17
WILD_CAPTURE_ME = 18
MAP_SIZE = 19
ENVIRONMENT = 20
SCHEMA = {
"Outdoor" => [OUTDOOR, "b"],
"ShowArea" => [SHOW_AREA, "b"],
"Bicycle" => [BICYCLE, "b"],
"BicycleAlways" => [BICYCLE_ALWAYS, "b"],
"HealingSpot" => [HEALING_SPOT, "uuu"],
"Weather" => [WEATHER, "eu", :PBFieldWeather],
"MapPosition" => [MAP_POSITION, "uuu"],
"DiveMap" => [DIVE_MAP, "u"],
"DarkMap" => [DARK_MAP, "b"],
"SafariMap" => [SAFARI_MAP, "b"],
"SnapEdges" => [SNAP_EDGES, "b"],
"Dungeon" => [DUNGEON, "b"],
"BattleBack" => [BATTLE_BACK, "s"],
"WildBattleBGM" => [WILD_BATTLE_BGM, "s"],
"TrainerBattleBGM" => [TRAINER_BATTLE_BGM, "s"],
"WildVictoryME" => [WILD_VICTORY_ME, "s"],
"TrainerVictoryME" => [TRAINER_VICTORY_ME, "s"],
"WildCaptureME" => [WILD_CAPTURE_ME, "s"],
"MapSize" => [MAP_SIZE, "us"],
"Environment" => [ENVIRONMENT, "e", :PBEnvironment]
}
end
#===============================================================================
# Pokémon data
#===============================================================================