Battlers now make use of Ability objects to be consistent with Pokemon objects

This commit is contained in:
Maruno17
2020-11-04 21:27:56 +00:00
parent 9dc6da0742
commit ff70791104
26 changed files with 189 additions and 183 deletions

View File

@@ -1,8 +1,7 @@
class Data
module PokemonData
# A mixin module for data classes which provides common class methods (called
# by Data::Thing.method) that provide access to data held within. Assumes the
# data class's data is stored in a class constant hash called DATA.
# by PokemonData::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]
# @return [Boolean] whether the given other is defined as a self
@@ -37,7 +36,7 @@ class Data
def each
keys = self::DATA.keys
keys.sort! { |a, b| a.to_s <=> b.to_s }
keys.sort! { |a, b| a.id_number <=> b.id_number }
keys.each do |key|
yield self::DATA[key] if key.is_a?(Symbol)
end
@@ -71,5 +70,4 @@ class Data
return false
end
end
end

View File

@@ -1,5 +1,4 @@
class Data
module PokemonData
class Item
attr_reader :id
attr_reader :id_number
@@ -49,7 +48,6 @@ class Data
return pbGetMessage(MessageTypes::ItemDescriptions, @id_number)
end
end
end
@@ -66,9 +64,9 @@ module Compiler
line = pbGetCsvRecord(line, line_no, [0, "vnssuusuuUN"])
item_number = line[0]
item_symbol = line[1].to_sym
if Data::Item::DATA[item_number]
if PokemonData::Item::DATA[item_number]
raise _INTL("Item ID number '{1}' is used twice.\r\n{2}", item_number, FileLineData.linereport)
elsif Data::Item::DATA[item_symbol]
elsif PokemonData::Item::DATA[item_symbol]
raise _INTL("Item ID '{1}' is used twice.\r\n{2}", item_symbol, FileLineData.linereport)
end
# Construct item hash
@@ -86,13 +84,13 @@ module Compiler
}
item_hash[:move] = parseMove(line[10]) if !nil_or_empty?(line[10])
# Add item's data to records
Data::Item::DATA[item_number] = Data::Item::DATA[item_symbol] = Data::Item.new(item_hash)
PokemonData::Item::DATA[item_number] = PokemonData::Item::DATA[item_symbol] = PokemonData::Item.new(item_hash)
item_names[item_number] = item_hash[:name]
item_names_plural[item_number] = item_hash[:name_plural]
item_descriptions[item_number] = item_hash[:description]
}
# Save all data
Data::Item.save
PokemonData::Item.save
MessageTypes.setMessages(MessageTypes::Items, item_names)
MessageTypes.setMessages(MessageTypes::ItemPlurals, item_names_plural)
MessageTypes.setMessages(MessageTypes::ItemDescriptions, item_descriptions)

View File

@@ -1,30 +1,32 @@
class Ability
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :real_description
module PokemonData
class Ability
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :real_description
DATA = {}
DATA_FILENAME = "abilities.dat"
DATA = {}
DATA_FILENAME = "abilities.dat"
extend ClassMethods
include InstanceMethods
extend ClassMethods
include InstanceMethods
def initialize(hash)
validate hash => Hash, hash[:id] => Symbol
@id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed"
@real_description = hash[:description] || "???"
end
def initialize(hash)
validate hash => Hash, hash[:id] => Symbol
@id = hash[:id]
@id_number = hash[:id_number] || -1
@real_name = hash[:name] || "Unnamed"
@real_description = hash[:description] || "???"
end
# @return [String] the translated name of this ability
def name
return pbGetMessage(MessageTypes::Abilities, @id_number)
end
# @return [String] the translated name of this ability
def name
return pbGetMessage(MessageTypes::Abilities, @id_number)
end
# @return [String] the translated description of this ability
def description
return pbGetMessage(MessageTypes::AbilityDescs, @id_number)
# @return [String] the translated description of this ability
def description
return pbGetMessage(MessageTypes::AbilityDescs, @id_number)
end
end
end