Skill level mismatch warning
This commit is contained in:
parent
961d642018
commit
0d9ec1913d
2 changed files with 70 additions and 6 deletions
35
Data.lua
35
Data.lua
|
|
@ -28,16 +28,37 @@ local DEFAULT_SKILLS = {
|
|||
-- Valid skill level keywords that must appear in the trait's right field (RT)
|
||||
local VALID_SKILL_KEYWORDS = { "Inept", "Novice", "Adept", "Expert", "Master" }
|
||||
|
||||
-- Expected numeric value ranges for each skill keyword
|
||||
local SKILL_KEYWORD_RANGES = {
|
||||
["Novice"] = { min = 1, max = 5 },
|
||||
["Adept"] = { min = 6, max = 10 },
|
||||
["Expert"] = { min = 11, max = 19 },
|
||||
["Master"] = { min = 20, max = 20 },
|
||||
}
|
||||
|
||||
-- Check if the trait's right text field contains a valid skill keyword.
|
||||
-- Returns true if any keyword is found, false otherwise.
|
||||
local function HasSkillKeyword(rightText)
|
||||
if not rightText or rightText == "" then return false end
|
||||
-- Returns the matched keyword if found, nil otherwise.
|
||||
local function FindSkillKeyword(rightText)
|
||||
if not rightText or rightText == "" then return nil end
|
||||
for _, keyword in ipairs(VALID_SKILL_KEYWORDS) do
|
||||
if rightText:find(keyword) then
|
||||
return true
|
||||
return keyword
|
||||
end
|
||||
end
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Check whether the numeric value matches the expected range for the given keyword.
|
||||
-- Returns a warning string if mismatched, or nil if everything is fine.
|
||||
local function CheckSkillMismatch(keyword, numericValue)
|
||||
if not keyword or keyword == "Inept" then return nil end
|
||||
local range = SKILL_KEYWORD_RANGES[keyword]
|
||||
if not range then return nil end
|
||||
if not numericValue or numericValue <= 0 then return nil end
|
||||
if numericValue < range.min or numericValue > range.max then
|
||||
return "Skill is marked as " .. keyword .. " (" .. range.min .. "-" .. range.max .. "), but the profile has a value of " .. numericValue .. "."
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Determine the skill level from the trait's right text and numeric value (V2 field, 0-20 range).
|
||||
|
|
@ -78,7 +99,8 @@ function AltSystem.Data:RefreshSkills()
|
|||
local skillName = trait.LT
|
||||
local numericValue = trait.V2
|
||||
|
||||
if skillName and skillName ~= "" and HasSkillKeyword(trait.RT) then
|
||||
local keyword = FindSkillKeyword(trait.RT)
|
||||
if skillName and skillName ~= "" and keyword then
|
||||
local level, modifier = ParseSkillLevel(trait.RT, numericValue)
|
||||
if level and modifier then
|
||||
foundAny = true
|
||||
|
|
@ -86,6 +108,7 @@ function AltSystem.Data:RefreshSkills()
|
|||
name = skillName,
|
||||
level = level,
|
||||
modifier = modifier,
|
||||
warning = CheckSkillMismatch(keyword, numericValue),
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
41
UI.lua
41
UI.lua
|
|
@ -83,18 +83,53 @@ function AltSystem:CreateMainFrame()
|
|||
-- Skill dropdown
|
||||
-------------------------
|
||||
local skillOptions = BuildSkillOptions()
|
||||
local UpdateSkillWarning -- forward declaration
|
||||
|
||||
local skillDropdown, getSkillIndex, setSkillIndex = CreateDropdown(
|
||||
f, "AltSystemSkillDropdown", yPos, "Skill:", skillOptions,
|
||||
AltSystem.State.selectedSkillIndex,
|
||||
function(index)
|
||||
AltSystem.State.selectedSkillIndex = index
|
||||
UpdateSkillWarning(index)
|
||||
end)
|
||||
|
||||
-- Warning icon for skill mismatch (shown next to dropdown when value doesn't match keyword)
|
||||
local skillWarning = CreateFrame("Frame", nil, f)
|
||||
skillWarning:SetSize(20, 20)
|
||||
skillWarning:SetPoint("LEFT", skillDropdown, "RIGHT", 4, 0)
|
||||
|
||||
local skillWarningIcon = skillWarning:CreateTexture(nil, "ARTWORK")
|
||||
skillWarningIcon:SetAllPoints()
|
||||
skillWarningIcon:SetAtlas("services-icon-warning")
|
||||
|
||||
skillWarning:SetScript("OnEnter", function(self)
|
||||
if self.tooltipText then
|
||||
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
|
||||
GameTooltip:SetText(self.tooltipText, 1, 0.82, 0)
|
||||
GameTooltip:Show()
|
||||
end
|
||||
end)
|
||||
skillWarning:SetScript("OnLeave", function()
|
||||
GameTooltip:Hide()
|
||||
end)
|
||||
skillWarning:Hide()
|
||||
|
||||
-- Update the warning icon visibility based on the currently selected skill
|
||||
UpdateSkillWarning = function(index)
|
||||
local skill = AltSystem.Data.Skills[index]
|
||||
if skill and skill.warning then
|
||||
skillWarning.tooltipText = skill.warning
|
||||
skillWarning:Show()
|
||||
else
|
||||
skillWarning:Hide()
|
||||
end
|
||||
end
|
||||
|
||||
-- Store references for refreshing
|
||||
AltSystem.SkillDropdown = skillDropdown
|
||||
AltSystem.GetSkillIndex = getSkillIndex
|
||||
AltSystem.SetSkillIndex = setSkillIndex
|
||||
AltSystem.UpdateSkillWarning = UpdateSkillWarning
|
||||
yPos = yPos - ROW_HEIGHT - 8
|
||||
|
||||
-------------------------
|
||||
|
|
@ -261,6 +296,9 @@ function AltSystem:RefreshSkillDropdown()
|
|||
if AltSystem.SetSkillIndex then
|
||||
AltSystem.SetSkillIndex(1)
|
||||
end
|
||||
if AltSystem.UpdateSkillWarning then
|
||||
AltSystem.UpdateSkillWarning(1)
|
||||
end
|
||||
|
||||
-- Rebuild the dropdown menu with the new skill list
|
||||
if AltSystem.SkillDropdown then
|
||||
|
|
@ -275,6 +313,9 @@ function AltSystem:RefreshSkillDropdown()
|
|||
if AltSystem.SetSkillIndex then
|
||||
AltSystem.SetSkillIndex(data)
|
||||
end
|
||||
if AltSystem.UpdateSkillWarning then
|
||||
AltSystem.UpdateSkillWarning(data)
|
||||
end
|
||||
end,
|
||||
i
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue