diff --git a/Data.lua b/Data.lua index 1291929..d95773d 100644 --- a/Data.lua +++ b/Data.lua @@ -24,24 +24,35 @@ local DEFAULT_SKILLS = { { name = "Master Skill", level = "Master", modifier = 4 }, } --- Parse the skill level from the right-side text of a TRP3 personality trait. --- The level keyword must appear at the start of the string; anything after it is ignored. --- Returns the level string and modifier, or nil if not recognized. -local function ParseSkillLevel(rightText) - if not rightText or rightText == "" then return nil, nil end +-- Valid skill level keywords that must appear in the trait's right field (RT) +local VALID_SKILL_KEYWORDS = { "Novice", "Adept", "Expert", "Master" } - -- Trim leading/trailing whitespace - local trimmed = rightText:match("^%s*(.-)%s*$") - if not trimmed or trimmed == "" then return nil, nil end - - -- Check if the text starts with a recognized level keyword - for _, levelName in ipairs({"Master", "Expert", "Adept", "Novice"}) do - if trimmed == levelName or trimmed:match("^" .. levelName .. "[%s%p]") then - return levelName, AltSystem.Data.SkillLevels[levelName] +-- 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 + for _, keyword in ipairs(VALID_SKILL_KEYWORDS) do + if rightText:find(keyword) then + return true end end + return false +end - return nil, nil +-- Determine the skill level from the trait's numeric value (V2 field, 0-20 range). +-- Returns the level string and modifier, or nil if the value is 0 or absent. +local function ParseSkillLevel(numericValue) + if not numericValue or numericValue <= 0 then return nil, nil end + + if numericValue >= 20 then + return "Master", AltSystem.Data.SkillLevels["Master"] + elseif numericValue >= 11 then + return "Expert", AltSystem.Data.SkillLevels["Expert"] + elseif numericValue >= 6 then + return "Adept", AltSystem.Data.SkillLevels["Adept"] + else + return "Novice", AltSystem.Data.SkillLevels["Novice"] + end end -- Fetch skills from the current TRP3 profile's personality traits. @@ -61,10 +72,10 @@ function AltSystem.Data:RefreshSkills() if ok and characteristics and characteristics.PS then for _, trait in ipairs(characteristics.PS) do local skillName = trait.LT - local rightText = trait.RT + local numericValue = trait.V2 - if skillName and skillName ~= "" then - local level, modifier = ParseSkillLevel(rightText) + if skillName and skillName ~= "" and HasSkillKeyword(trait.RT) then + local level, modifier = ParseSkillLevel(numericValue) if level and modifier then foundAny = true table.insert(skills, { diff --git a/docs/2-skills.md b/docs/2-skills.md index 1086cb5..c7ec7fb 100644 --- a/docs/2-skills.md +++ b/docs/2-skills.md @@ -3,9 +3,13 @@ - The skills are defined in the TRP profile as 'Personality traits' - For each trait: - the left field represents the skill name - - the right field represents the skill level as a string (Novice, Adept, Expert, Master) - - should the right field have anything after the level, it is to be ignored - - should a skill have no recognizable level, it should be omitted from the list + - the right field must contain a valid skill keyword (Novice, Adept, Expert, Master) — traits without one of these keywords are omitted + - the first numeric value (V2) determines the skill level based on these ranges: + - Novice: 1-5 + - Adept: 6-10 + - Expert: 11-19 + - Master: 20 + - should a skill have a value of 0 or no value, it should be omitted from the list - The list should have a default selected value of "Unskilled" which corresponds to a -4 modifier - In case no skills are found in the profile, or no profile is selected, a default list should be displayed - Unskilled, Novice Skill, Adept Skill, Expert Skill, Master Skill \ No newline at end of file