Better skill detection
This commit is contained in:
parent
9e629aec31
commit
3e4ac9888a
2 changed files with 35 additions and 20 deletions
45
Data.lua
45
Data.lua
|
|
@ -24,24 +24,35 @@ local DEFAULT_SKILLS = {
|
||||||
{ name = "Master Skill", level = "Master", modifier = 4 },
|
{ name = "Master Skill", level = "Master", modifier = 4 },
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Parse the skill level from the right-side text of a TRP3 personality trait.
|
-- Valid skill level keywords that must appear in the trait's right field (RT)
|
||||||
-- The level keyword must appear at the start of the string; anything after it is ignored.
|
local VALID_SKILL_KEYWORDS = { "Novice", "Adept", "Expert", "Master" }
|
||||||
-- 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
|
|
||||||
|
|
||||||
-- Trim leading/trailing whitespace
|
-- Check if the trait's right text field contains a valid skill keyword.
|
||||||
local trimmed = rightText:match("^%s*(.-)%s*$")
|
-- Returns true if any keyword is found, false otherwise.
|
||||||
if not trimmed or trimmed == "" then return nil, nil end
|
local function HasSkillKeyword(rightText)
|
||||||
|
if not rightText or rightText == "" then return false end
|
||||||
-- Check if the text starts with a recognized level keyword
|
for _, keyword in ipairs(VALID_SKILL_KEYWORDS) do
|
||||||
for _, levelName in ipairs({"Master", "Expert", "Adept", "Novice"}) do
|
if rightText:find(keyword) then
|
||||||
if trimmed == levelName or trimmed:match("^" .. levelName .. "[%s%p]") then
|
return true
|
||||||
return levelName, AltSystem.Data.SkillLevels[levelName]
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
-- Fetch skills from the current TRP3 profile's personality traits.
|
-- 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
|
if ok and characteristics and characteristics.PS then
|
||||||
for _, trait in ipairs(characteristics.PS) do
|
for _, trait in ipairs(characteristics.PS) do
|
||||||
local skillName = trait.LT
|
local skillName = trait.LT
|
||||||
local rightText = trait.RT
|
local numericValue = trait.V2
|
||||||
|
|
||||||
if skillName and skillName ~= "" then
|
if skillName and skillName ~= "" and HasSkillKeyword(trait.RT) then
|
||||||
local level, modifier = ParseSkillLevel(rightText)
|
local level, modifier = ParseSkillLevel(numericValue)
|
||||||
if level and modifier then
|
if level and modifier then
|
||||||
foundAny = true
|
foundAny = true
|
||||||
table.insert(skills, {
|
table.insert(skills, {
|
||||||
|
|
|
||||||
|
|
@ -3,9 +3,13 @@
|
||||||
- The skills are defined in the TRP profile as 'Personality traits'
|
- The skills are defined in the TRP profile as 'Personality traits'
|
||||||
- For each trait:
|
- For each trait:
|
||||||
- the left field represents the skill name
|
- the left field represents the skill name
|
||||||
- the right field represents the skill level as a string (Novice, Adept, Expert, Master)
|
- the right field must contain a valid skill keyword (Novice, Adept, Expert, Master) — traits without one of these keywords are omitted
|
||||||
- should the right field have anything after the level, it is to be ignored
|
- the first numeric value (V2) determines the skill level based on these ranges:
|
||||||
- should a skill have no recognizable level, it should be omitted from the list
|
- 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
|
- 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
|
- 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
|
- Unskilled, Novice Skill, Adept Skill, Expert Skill, Master Skill
|
||||||
Loading…
Add table
Add a link
Reference in a new issue