diff --git a/lib/ika3/weapons.rb b/lib/ika3/weapons.rb index 5959c0e..1d7830a 100644 --- a/lib/ika3/weapons.rb +++ b/lib/ika3/weapons.rb @@ -41,12 +41,20 @@ def filter_by_sub(sub_name) weapons.map { |weapon| W.new(weapon) } end + def filter_by_special(special_name) + raise "unknown special weapon: #{special_name}" unless special_weapons.values.include?(special_name) + + weapons = config.values.filter { |weapon| weapon[:special] == special_name } + weapons.map { |weapon| W.new(weapon) } + end + def reload_config! @cache = {} @config = nil @sub_weapons = nil config config_sub_weapons + config_special_weapons end private @@ -75,6 +83,16 @@ def sub_weapons @sub_weapon_hash end + def special_weapons + @special_weapon_hash ||= {} + if @special_weapon_hash.empty? + config_special_weapons.each do |key, value| + @special_weapon_hash[key] = value[:name] + end + end + @special_weapon_hash + end + def config @config ||= load_yaml_file("#{File.dirname(__FILE__)}/../../config/weapons.yml").deep_symbolize_keys @config @@ -85,6 +103,11 @@ def config_sub_weapons @sub_weapons end + def config_special_weapons + @special_weapons ||= load_yaml_file("#{File.dirname(__FILE__)}/../../config/special_weapons.yml").deep_symbolize_keys + @special_weapons + end + def valid?(weapon_key) names.include?(weapon_key) end diff --git a/sig/ika3/weapon.rbs b/sig/ika3/weapon.rbs index 5d7ac03..6936858 100644 --- a/sig/ika3/weapon.rbs +++ b/sig/ika3/weapon.rbs @@ -5,16 +5,21 @@ module Ika3 self.@weapon_hash: Hash[untyped, untyped] self.@sub_weapon_hash: Hash[untyped, untyped] self.@sub_weapons: untyped + self.@special_weapon_hash: Hash[untyped, untyped] + self.@special_weapons: untyped def self.find: (Symbol weapon_key) -> W def self.find_by_name: (String weapon_name) -> W def self.filter_by_sub: (String sub_name) -> Array[W] + def self.filter_by_special: (String special_name) -> Array[W] def self.reload_config!: -> nil def self.names: -> Array[Symbol] def self.weapons: -> Hash[untyped, untyped] def self.sub_weapons: -> Hash[untyped, untyped] + def self.special_weapons: -> Hash[untyped, untyped] def self.config: -> untyped def self.config_sub_weapons: -> untyped + def self.config_special_weapons: -> untyped def self.valid?: (Symbol weapon_key) -> bool def self.load_yaml_file: (String file) -> untyped diff --git a/spec/ika3/weapons_spec.rb b/spec/ika3/weapons_spec.rb index a1c6409..129f47d 100644 --- a/spec/ika3/weapons_spec.rb +++ b/spec/ika3/weapons_spec.rb @@ -19,6 +19,12 @@ end end + describe '#filter_by_special' do + it 'get weapon info list from special weapon' do + expect(described_class.filter_by_special(special_name).map(&:name)).to include weapon_name + end + end + describe '#name' do it 'get weapon name' do expect(described_class.find(key_name).name).to eq weapon_name