Removed all uses of ID numbers for species, some other code changes for abolishing ID numbers

This commit is contained in:
Maruno17
2021-06-16 22:42:20 +01:00
parent 8c67127f06
commit e9457a3ea8
22 changed files with 965 additions and 1750 deletions

View File

@@ -114,8 +114,13 @@ module GameData
return self::DATA.keys
end
# Yields all data in alphabetical order.
# Yields all data in the order they were defined.
def each
self::DATA.each_value { |value| yield value }
end
# Yields all data in alphabetical order.
def each_alphabetically
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

View File

@@ -1,7 +1,6 @@
module GameData
class Type
attr_reader :id
attr_reader :id_number
attr_reader :real_name
attr_reader :special_type
attr_reader :pseudo_type
@@ -27,10 +26,6 @@ module GameData
extend ClassMethodsSymbols
include InstanceMethods
def self.each
DATA.each_value { |type| yield type }
end
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"

View File

@@ -1,7 +1,6 @@
module GameData
class Species
attr_reader :id
attr_reader :id_number
attr_reader :species
attr_reader :form
attr_reader :real_name
@@ -51,9 +50,13 @@ module GameData
DATA = {}
DATA_FILENAME = "species.dat"
extend ClassMethods
extend ClassMethodsSymbols
include InstanceMethods
def self.each_species
DATA.each_value { |species| yield species if species.form == 0 }
end
# @param species [Symbol, self, String, Integer]
# @param form [Integer]
# @return [self, nil]
@@ -128,7 +131,6 @@ module GameData
def initialize(hash)
@id = hash[:id]
@id_number = hash[:id_number] || -1
@species = hash[:species] || @id
@form = hash[:form] || 0
@real_name = hash[:name] || "Unnamed"
@@ -182,22 +184,22 @@ module GameData
# @return [String] the translated name of this species
def name
return pbGetMessage(MessageTypes::Species, @id_number)
return pbGetMessageFromHash(MessageTypes::Species, @real_name)
end
# @return [String] the translated name of this form of this species
def form_name
return pbGetMessage(MessageTypes::FormNames, @id_number)
return pbGetMessageFromHash(MessageTypes::FormNames, @real_form_name)
end
# @return [String] the translated Pokédex category of this species
def category
return pbGetMessage(MessageTypes::Kinds, @id_number)
return pbGetMessageFromHash(MessageTypes::Kinds, @real_category)
end
# @return [String] the translated Pokédex entry of this species
def pokedex_entry
return pbGetMessage(MessageTypes::Entries, @id_number)
return pbGetMessageFromHash(MessageTypes::Entries, @real_pokedex_entry)
end
def apply_metrics_to_sprite(sprite, index, shadow = false)
@@ -234,7 +236,7 @@ module GameData
def get_family_evolutions(exclude_invalid = true)
evos = self.get_evolutions(exclude_invalid)
evos = evos.sort { |a, b| GameData::Species.get(a[0]).id_number <=> GameData::Species.get(b[0]).id_number }
evos = evos.sort { |a, b| GameData::Species.keys.index(a[0]) <=> GameData::Species.keys.index(b[0]) }
ret = []
evos.each do |evo|
ret.push([@species].concat(evo)) # [Prevo species, evo species, method, parameter]

View File

@@ -134,9 +134,10 @@ module GameData
pkmn.shiny = (pkmn_data[:shininess]) ? true : false
if pkmn_data[:nature]
pkmn.nature = pkmn_data[:nature]
else
nature = pkmn.species_data.id_number + GameData::TrainerType.get(trainer.trainer_type).id_number
pkmn.nature = nature % (GameData::Nature::DATA.length / 2)
else # Make the nature random but consistent for the same species used by the same trainer type
species_num = GameData::Species.keys.index(species) || 1
tr_type_num = GameData::TrainerType.keys.index(@trainer_type) || 1
pkmn.nature = (species_num + tr_type_num) % (GameData::Nature::DATA.length / 2)
end
GameData::Stat.each_main do |s|
if pkmn_data[:iv]