From 6c12a202ffed484c9a0515fade0f4f753c2667f6 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 18 Dec 2025 22:30:33 -0800 Subject: [PATCH] add name-based skill lookup for artifact import - cached_by_name indexes by both EN and JP names - find_by_name looks up skill by either language - strength_for_quality computes strength from quality tier --- app/models/artifact_skill.rb | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/models/artifact_skill.rb b/app/models/artifact_skill.rb index 8d6c6f8..9997690 100644 --- a/app/models/artifact_skill.rb +++ b/app/models/artifact_skill.rb @@ -28,6 +28,17 @@ class ArtifactSkill < ApplicationRecord @cached_skills ||= all.index_by { |s| [s.skill_group, s.modifier] } end + def cached_by_name + @name_cache ||= begin + cache = {} + all.each do |skill| + cache[skill.name_en] = skill + cache[skill.name_jp] = skill + end + cache + end + end + def find_skill(group, modifier) # Convert group number to enum key group_key = case group @@ -39,8 +50,13 @@ class ArtifactSkill < ApplicationRecord cached_skills[[group_key, modifier]] end + def find_by_name(name) + cached_by_name[name] + end + def clear_cache! @cached_skills = nil + @name_cache = nil end end @@ -71,4 +87,15 @@ class ArtifactSkill < ApplicationRecord base_values.include?(strength) end + + # Get the base strength value for a given quality tier + # @param quality [Integer] The quality tier (1-5) + # @return [Numeric, nil] The base strength value + def strength_for_quality(quality) + return nil if base_values.nil? || !base_values.is_a?(Array) || base_values.empty? + + # Quality 1-5 maps to index 0-4 + index = (quality - 1).clamp(0, base_values.size - 1) + base_values[index] + end end