Implemented usage of GameData::Item

This commit is contained in:
Maruno17
2020-11-08 22:45:59 +00:00
parent ff70791104
commit 1955d3698e
82 changed files with 1986 additions and 2195 deletions

View File

@@ -1,22 +1,24 @@
module PokemonData
module GameData
# A mixin module for data classes which provides common class methods (called
# by PokemonData::Thing.method) that provide access to data held within.
# 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.
module ClassMethods
# @param other [Symbol, self, Integer]
# @param other [Symbol, self, String, Integer]
# @return [Boolean] whether the given other is defined as a self
def exists?(other)
return false if other.nil?
validate other => [Symbol, self.class, Integer]
other = other.id if other.is_a?(self.class)
validate other => [Symbol, self, String, Integer]
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, Integer]
# @param other [Symbol, self, String, Integer]
# @return [self]
def get(other)
validate other => [Symbol, self.class, Integer]
return other if other.is_a?(self.class)
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = other.to_sym if other.is_a?(String)
# if other.is_a?(Integer)
# p "Please switch to symbols, thanks."
# end
@@ -26,8 +28,9 @@ module PokemonData
def try_get(other)
return nil if other.nil?
validate other => [Symbol, self.class, Integer]
return other if other.is_a?(self.class)
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = other.to_sym if other.is_a?(String)
# if other.is_a?(Integer)
# p "Please switch to symbols, thanks."
# end
@@ -35,8 +38,7 @@ module PokemonData
end
def each
keys = self::DATA.keys
keys.sort! { |a, b| a.id_number <=> b.id_number }
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
@@ -55,15 +57,17 @@ module PokemonData
# (called by thing.method) that analyse the data of a particular thing which
# the instance represents.
module InstanceMethods
# @param other [Symbol, self.class, Integer]
# @param other [Symbol, self.class, String, Integer]
# @return [Boolean] whether other represents the same thing as this thing
def ==(other)
return false if other.nil?
validate other => [Symbol, self.class, Integer]
validate other => [Symbol, self.class, String, Integer]
if other.is_a?(Symbol)
return @id == other
elsif other.is_a?(self.class)
return @id == other.id
elsif other.is_a?(String)
return @id_number == other.to_sym
elsif other.is_a?(Integer)
return @id_number == other
end