mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2026-01-22 06:06:01 +00:00
Added class GameData::Habitat
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
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
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self::DATA[hash[:id_number]] = self.new(hash)
|
||||
@@ -59,10 +61,68 @@ module GameData
|
||||
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 a symbol.
|
||||
#=============================================================================
|
||||
module ClassMethodsSymbols
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self.new(hash)
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [Boolean] whether the given other is defined as a self
|
||||
def exists?(other)
|
||||
return false if other.nil?
|
||||
validate other => [Symbol, self, String]
|
||||
other = other.id if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return !self::DATA[other].nil?
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [self]
|
||||
def get(other)
|
||||
validate other => [Symbol, self, String]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
raise "Unknown ID #{other}." unless self::DATA.has_key?(other)
|
||||
return self::DATA[other]
|
||||
end
|
||||
|
||||
# @param other [Symbol, self, String]
|
||||
# @return [self, nil]
|
||||
def try_get(other)
|
||||
return nil if other.nil?
|
||||
validate other => [Symbol, self, String]
|
||||
return other if other.is_a?(self)
|
||||
other = other.to_sym if other.is_a?(String)
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
|
||||
end
|
||||
|
||||
# Yields all data in alphabetical order.
|
||||
def each
|
||||
keys = self::DATA.keys.sort { |a, b| self::DATA[a].real_name <=> self::DATA[b].real_name }
|
||||
keys.each { |key| yield self::DATA[key] }
|
||||
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
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self.new(hash)
|
||||
@@ -93,6 +153,7 @@ module GameData
|
||||
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
|
||||
end
|
||||
|
||||
# Yields all data in numberical order.
|
||||
def each
|
||||
keys = self::DATA.keys.sort
|
||||
keys.each { |key| yield self::DATA[key] }
|
||||
@@ -107,9 +168,11 @@ module GameData
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A mixin module for data classes which provides common instance methods
|
||||
# (called by thing.method) that analyse the data of a particular thing which
|
||||
# the instance represents.
|
||||
#=============================================================================
|
||||
module InstanceMethods
|
||||
# @param other [Symbol, self.class, String, Integer]
|
||||
# @return [Boolean] whether other represents the same thing as this thing
|
||||
@@ -128,6 +191,9 @@ module GameData
|
||||
end
|
||||
end
|
||||
|
||||
#=============================================================================
|
||||
# A bulk loader method for all data stored in .dat files in the Data folder.
|
||||
#=============================================================================
|
||||
def self.load_all
|
||||
Ability.load
|
||||
Item.load
|
||||
|
||||
@@ -98,7 +98,7 @@ module GameData
|
||||
"Weight" => [0, "f"],
|
||||
"Color" => [0, "e", :PBColors],
|
||||
"Shape" => [0, "u"],
|
||||
"Habitat" => [0, "e", :PBHabitats],
|
||||
"Habitat" => [0, "e", :Habitat],
|
||||
"Generation" => [0, "i"],
|
||||
"BattlerPlayerX" => [0, "i"],
|
||||
"BattlerPlayerY" => [0, "i"],
|
||||
@@ -161,7 +161,7 @@ module GameData
|
||||
@weight = hash[:weight] || 1
|
||||
@color = hash[:color] || PBColors::Red
|
||||
@shape = hash[:shape] || 1
|
||||
@habitat = hash[:habitat] || PBHabitats::None
|
||||
@habitat = hash[:habitat] || :None
|
||||
@generation = hash[:generation] || 0
|
||||
@mega_stone = hash[:mega_stone]
|
||||
@mega_move = hash[:mega_move]
|
||||
|
||||
@@ -5,19 +5,9 @@ module GameData
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethods
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def register(hash)
|
||||
self::DATA[hash[:id]] = self.new(hash)
|
||||
end
|
||||
|
||||
# Yields all data in alphabetical order.
|
||||
def each
|
||||
keys = self::DATA.keys.sort { |a, b| self::DATA[a].real_name <=> self::DATA[b].real_name }
|
||||
keys.each { |key| yield self::DATA[key] }
|
||||
end
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
|
||||
74
Data/Scripts/011_Data/002_Hardcoded data/007_Habitat.rb
Normal file
74
Data/Scripts/011_Data/002_Hardcoded data/007_Habitat.rb
Normal file
@@ -0,0 +1,74 @@
|
||||
module GameData
|
||||
class Habitat
|
||||
attr_reader :id
|
||||
attr_reader :real_name
|
||||
|
||||
DATA = {}
|
||||
|
||||
extend ClassMethodsSymbols
|
||||
include InstanceMethods
|
||||
|
||||
def self.load; end
|
||||
def self.save; end
|
||||
|
||||
def initialize(hash)
|
||||
@id = hash[:id]
|
||||
@real_name = hash[:name] || "Unnamed"
|
||||
end
|
||||
|
||||
# @return [String] the translated name of this egg group
|
||||
def name
|
||||
return _INTL(@real_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :None,
|
||||
:name => _INTL("None")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Grassland,
|
||||
:name => _INTL("Grassland")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Forest,
|
||||
:name => _INTL("Forest")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :WatersEdge,
|
||||
:name => _INTL("Water's Edge")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Sea,
|
||||
:name => _INTL("Sea")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Cave,
|
||||
:name => _INTL("Cave")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Mountain,
|
||||
:name => _INTL("Mountain")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :RoughTerrain,
|
||||
:name => _INTL("Rough Terrain")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Urban,
|
||||
:name => _INTL("Urban")
|
||||
})
|
||||
|
||||
GameData::Habitat.register({
|
||||
:id => :Rare,
|
||||
:name => _INTL("Rare")
|
||||
})
|
||||
@@ -1,31 +0,0 @@
|
||||
module PBHabitats
|
||||
None = 0
|
||||
Grassland = 1
|
||||
Forest = 2
|
||||
WatersEdge = 3
|
||||
Sea = 4
|
||||
Cave = 5
|
||||
Mountain = 6
|
||||
RoughTerrain = 7
|
||||
Urban = 8
|
||||
Rare = 9
|
||||
|
||||
def self.maxValue; 9; end
|
||||
|
||||
def self.getName(id)
|
||||
id = getID(PBHabitats,id)
|
||||
names = [
|
||||
_INTL("None"),
|
||||
_INTL("Grassland"),
|
||||
_INTL("Forest"),
|
||||
_INTL("Water's Edge"),
|
||||
_INTL("Sea"),
|
||||
_INTL("Cave"),
|
||||
_INTL("Mountain"),
|
||||
_INTL("Rough Terrain"),
|
||||
_INTL("Urban"),
|
||||
_INTL("Rare")
|
||||
]
|
||||
return names[id]
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user