feat/redesign (#1)

Reviewed-on: #1
Co-authored-by: Gonçalo Correia <goncalojoaocorreia@gmail.com>
Co-committed-by: Gonçalo Correia <goncalojoaocorreia@gmail.com>
This commit is contained in:
Gonçalo Correia 2026-05-15 14:53:15 +01:00 committed by rukira
parent 6a44458443
commit 6ebb92c62b
21 changed files with 1395 additions and 273 deletions

125
Data.lua Normal file → Executable file
View file

@ -39,6 +39,27 @@ local SKILL_KEYWORD_RANGES = {
["Master"] = { min = 20, max = 20 },
}
-- Shared lookup tables for the Build Skills tab
AltSystem.Data.SkillValueRanges = {
["Inept"] = { min = 0, max = 0 },
["Novice"] = { min = 1, max = 5 },
["Adept"] = { min = 6, max = 10 },
["Expert"] = { min = 11, max = 19 },
["Master"] = { min = 20, max = 20 },
}
-- Ordered list of skill levels for dropdown display
AltSystem.Data.SkillLevelOrder = { "Inept", "Novice", "Adept", "Expert", "Master" }
-- Returns the minimum value for a given skill level
function AltSystem.Data:GetDefaultValueForLevel(level)
local range = AltSystem.Data.SkillValueRanges[level]
if range then
return range.min
end
return 1
end
-- Check if the trait's right text field contains a valid skill keyword.
-- Returns the matched keyword if found, nil otherwise.
local function FindSkillKeyword(rightText)
@ -134,24 +155,112 @@ function AltSystem.Data:RefreshSkills()
return skills
end
-- Returns an array of {name, level, value, icon} for each valid skill trait in the TRP3 profile.
-- Excludes Base Roll and Unskilled (system-generated). Sorted by level order (Inept first, Master last).
function AltSystem.Data:GetEditableSkills()
local skills = {}
if TRP3_API and TRP3_API.profile and TRP3_API.profile.getData then
local ok, characteristics = pcall(TRP3_API.profile.getData, "player/characteristics")
if ok and characteristics and characteristics.PS then
for _, trait in ipairs(characteristics.PS) do
local skillName = trait.LT
local numericValue = trait.V2 or 0
local keyword = FindSkillKeyword(trait.RT)
if skillName and skillName ~= "" and keyword then
table.insert(skills, {
name = skillName,
level = keyword,
value = numericValue,
icon = trait.IC or "inv_misc_questionmark",
})
end
end
end
end
-- Sort by level order descending (Master first, Inept last)
local levelOrderMap = {}
for i, lvl in ipairs(AltSystem.Data.SkillLevelOrder) do
levelOrderMap[lvl] = i
end
table.sort(skills, function(a, b)
return (levelOrderMap[a.level] or 99) > (levelOrderMap[b.level] or 99)
end)
return skills
end
-- Saves the edited skills back to the TRP3 profile.
-- editedSkills is an array of {name, level, value, icon}.
function AltSystem.Data:SaveSkills(editedSkills)
if not TRP3_API or not TRP3_API.profile or not TRP3_API.profile.getData then
print("|cFFFF0000AltSystem:|r TRP3 API is unavailable. Cannot save skills.")
return false
end
local ok, characteristics = pcall(TRP3_API.profile.getData, "player/characteristics")
if not ok or not characteristics then
print("|cFFFF0000AltSystem:|r Could not access TRP3 profile characteristics. Cannot save skills.")
return false
end
-- Ensure PS array exists
if not characteristics.PS then
characteristics.PS = {}
end
-- Separate non-skill traits from skill traits in the existing PS
local nonSkillTraits = {}
for _, trait in ipairs(characteristics.PS) do
local keyword = FindSkillKeyword(trait.RT)
if not keyword then
-- This is not a skill trait, preserve it
table.insert(nonSkillTraits, trait)
end
end
-- Rebuild PS: non-skill traits first, then edited skills
local newPS = {}
for _, trait in ipairs(nonSkillTraits) do
table.insert(newPS, trait)
end
for _, skill in ipairs(editedSkills) do
table.insert(newPS, {
LT = skill.name,
RT = skill.level,
V2 = skill.value,
IC = skill.icon or "inv_misc_questionmark",
})
end
characteristics.PS = newPS
-- Refresh the Use Skills tab data
AltSystem.Data:RefreshSkills()
print("|cFF00FF00AltSystem:|r Skills saved to TRP profile successfully.")
return true
end
-- Initialize with the default skill list
AltSystem.Data.Skills = {}
for _, skill in ipairs(DEFAULT_SKILLS) do
table.insert(AltSystem.Data.Skills, { name = skill.name, level = skill.level, modifier = skill.modifier })
end
-- Item options: name and modifier (first entry = no item)
-- Item options: name, label (used in roll messages), and modifier (first entry = no item)
AltSystem.Data.Items = {
{ name = "No item", modifier = 0 },
{ name = "Rare item", modifier = 3 },
{ name = "Epic item", modifier = 5 },
{ name = "No item", label = "No item", modifier = 0 },
{ name = "Rare", label = "Rare item", modifier = 3 },
{ name = "Epic", label = "Epic item", modifier = 5 },
}
-- Defense options: name and modifier
-- Defense / Armor options: name, label (used in roll messages), and modifier
AltSystem.Data.Defenses = {
{ name = "Base armor", modifier = 0 },
{ name = "Extra small armor", modifier = 1 },
{ name = "Extra large armor", modifier = 2 },
{ name = "None", label = "No armor", modifier = 0 },
{ name = "Partial", label = "Extra armor", modifier = 1 },
{ name = "Full", label = "Extra armor", modifier = 2 },
}
-- Shield modifier