Implemented GameData BagPocket

This commit is contained in:
Maruno17
2024-09-14 01:27:17 +01:00
parent d8263da05e
commit 801c2d35c6
15 changed files with 268 additions and 95 deletions

View File

@@ -0,0 +1,133 @@
#===============================================================================
#
#===============================================================================
module GameData
class BagPocket
attr_reader :id
attr_reader :real_name
attr_reader :icon_position # Where this pocket's icon is within icon_pocket.png
attr_reader :order
attr_reader :max_slots
attr_reader :auto_sort
DATA = {}
extend ClassMethodsSymbols
include InstanceMethods
def self.load; end
def self.save; end
def self.all_pockets
ret = []
DATA.each_value { |pocket| ret.push([pocket.id, pocket.order]) }
ret.sort_by! { |pckt| pckt[1] }
ret.map! { |pckt| pckt[0] }
return ret
end
def self.index(pocket)
return self.all_pockets.index(pocket)
end
# @param other [Symbol, self, String]
# @return [self]
def self.get(other)
validate other => [Symbol, self, String, Integer]
return other if other.is_a?(self)
other = self.all_pockets[other - 1] if other.is_a?(Integer)
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, Integer]
return other if other.is_a?(self)
other = self.all_pockets[other - 1] if other.is_a?(Integer)
other = other.to_sym if other.is_a?(String)
return (self::DATA.has_key?(other)) ? self::DATA[other] : nil
end
#---------------------------------------------------------------------------
def initialize(hash)
@id = hash[:id]
@real_name = hash[:name] || "Unnamed"
@icon_position = hash[:icon_position] || 0
@order = hash[:order] || 999
@max_slots = hash[:max_slots] || -1
@auto_sort = hash[:auto_sort] || false
end
# @return [String] the translated name of this nature
def name
return _INTL(@real_name)
end
end
end
#===============================================================================
#
#===============================================================================
GameData::BagPocket.register({
:id => :Items,
:name => _INTL("Items"),
:icon_position => 0,
:order => 10
})
GameData::BagPocket.register({
:id => :Medicine,
:name => _INTL("Medicine"),
:icon_position => 1,
:order => 20
})
GameData::BagPocket.register({
:id => :PokeBalls,
:name => _INTL("Poké Balls"),
:icon_position => 2,
:order => 30
})
GameData::BagPocket.register({
:id => :Machines,
:name => _INTL("TMs & HMs"),
:icon_position => 3,
:order => 40,
:auto_sort => true
})
GameData::BagPocket.register({
:id => :Berries,
:name => _INTL("Berries"),
:icon_position => 4,
:order => 50,
:auto_sort => true
})
GameData::BagPocket.register({
:id => :Mail,
:name => _INTL("Mail"),
:icon_position => 5,
:order => 60
})
GameData::BagPocket.register({
:id => :BattleItems,
:name => _INTL("Battle Items"),
:icon_position => 6,
:order => 70
})
GameData::BagPocket.register({
:id => :KeyItems,
:name => _INTL("Key Items"),
:icon_position => 7,
:order => 80
})

View File

@@ -30,7 +30,7 @@ module GameData
"NamePlural" => [:real_name_plural, "s"],
"PortionName" => [:real_portion_name, "s"],
"PortionNamePlural" => [:real_portion_name_plural, "s"],
"Pocket" => [:pocket, "v"],
"Pocket" => [:pocket, "y", :BagPocket],
"Price" => [:price, "u"],
"SellPrice" => [:sell_price, "u"],
"BPPrice" => [:bp_price, "u"],
@@ -126,7 +126,7 @@ module GameData
@real_name_plural = hash[:real_name_plural] || "Unnamed"
@real_portion_name = hash[:real_portion_name]
@real_portion_name_plural = hash[:real_portion_name_plural]
@pocket = hash[:pocket] || 1
@pocket = hash[:pocket] || :None
@price = hash[:price] || 0
@sell_price = hash[:sell_price] || (@price / Settings::ITEM_SELL_PRICE_DIVISOR)
@bp_price = hash[:bp_price] || 1