enUS Localization Update Announcement / localization-update-announcement (push) Canceled after 0s
127 lines
4.8 KiB
Lua
127 lines
4.8 KiB
Lua
-- Bagshui Rule Function Templates
|
|
-- Exposes: Bagshui.config.RuleFunctionTemplates
|
|
--
|
|
-- Templates for most rule functions that have dynamic lists of potential parameters
|
|
-- are generated here.
|
|
--
|
|
-- Anything that's just static should be defined in localization --
|
|
-- see `Rules:AddRuleExamplesFromLocalization() for details.
|
|
|
|
Bagshui:AddComponent(function()
|
|
-- Keys are rule function names, values are an array of templates that
|
|
-- will be consumed by `Rules:AddFunction()`'s `ruleTemplates` parameter.
|
|
---@type table<string, { code: string, description: string }[]>
|
|
local ruleFunctionTemplates = {}
|
|
Bagshui.config.RuleFunctionTemplates = ruleFunctionTemplates
|
|
|
|
-- Bag()
|
|
-- These are added in Components\Categories.Ui.lua because the containerIds array
|
|
-- for each inventory type isn't built until very late in the startup process.
|
|
|
|
-- Location()
|
|
-- List of available Bagshui inventory types.
|
|
ruleFunctionTemplates.Location = {}
|
|
for _, inventoryType in pairs(BS_INVENTORY_TYPE) do
|
|
table.insert(ruleFunctionTemplates.Location, {
|
|
code = string.format('Location("%s")', L[inventoryType]),
|
|
description = string.format(L.RuleFunction_Location_ExampleDescription, L[inventoryType]),
|
|
})
|
|
end
|
|
|
|
-- Type()
|
|
-- List of built-in item types.
|
|
ruleFunctionTemplates.Type = {}
|
|
for enUSItemClass, _ in pairs(BsGameInfo.itemClasses) do
|
|
table.insert(ruleFunctionTemplates.Type, {
|
|
code = string.format('Type("%s")', L[enUSItemClass]),
|
|
description = string.format(L.RuleFunction_Type_ExampleDescription, L[enUSItemClass]),
|
|
})
|
|
end
|
|
|
|
-- Subtype() / BagType()
|
|
-- List of built-in item subtypes. Since container types can be inferred
|
|
-- from subtypes, that gets built out here too.
|
|
ruleFunctionTemplates.Subtype = {}
|
|
ruleFunctionTemplates.BagType = {}
|
|
local seenSubtypes = {}
|
|
local duplicateSubtypes = {}
|
|
for enUSItemClass, subClassList in pairs(BsGameInfo.itemSubclasses) do
|
|
for enUSItemSubClass, _ in pairs(subClassList) do
|
|
if seenSubtypes[enUSItemSubClass] then
|
|
duplicateSubtypes[enUSItemSubClass] = true
|
|
end
|
|
seenSubtypes[enUSItemSubClass] = true
|
|
end
|
|
end
|
|
seenSubtypes = nil
|
|
for enUSItemClass, subClassList in pairs(BsGameInfo.itemSubclasses) do
|
|
for enUSItemSubClass, _ in pairs(subClassList) do
|
|
local code = string.format('Subtype("%s")', L[enUSItemSubClass])
|
|
if duplicateSubtypes[enUSItemSubClass] then
|
|
code = code .. string.format(' and Type("%s")', L[enUSItemClass])
|
|
end
|
|
table.insert(ruleFunctionTemplates.Subtype, {
|
|
code = code,
|
|
description = string.format(L.RuleFunction_Subtype_ExampleDescription, L[enUSItemSubClass]),
|
|
})
|
|
-- Container Types can be autogenerated from subtypes
|
|
if enUSItemClass == "Container" or enUSItemClass == "Quiver" then
|
|
table.insert(ruleFunctionTemplates.BagType, {
|
|
code = string.format('BagType("%s")', L[enUSItemSubClass]),
|
|
description = string.format(L.RuleFunction_BagType_ExampleDescription, L[enUSItemSubClass]),
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|
|
-- EquipLocation()
|
|
-- List of inventory slot locations.
|
|
ruleFunctionTemplates.EquipLocation = {}
|
|
for enUSInventorySlotName, localizedInvSlotName in pairs(BsGameInfo.inventorySlots) do
|
|
table.insert(ruleFunctionTemplates.EquipLocation, {
|
|
code = 'EquipLocation("' .. localizedInvSlotName .. '")',
|
|
description = string.format(L.RuleFunction_EquipLocation_ExampleDescription, L[enUSInventorySlotName]),
|
|
})
|
|
end
|
|
|
|
-- Quality()
|
|
-- List of item quality levels.
|
|
ruleFunctionTemplates.Quality = {}
|
|
for i = 1, 20 do
|
|
-- Once we find the first quality level that doesn't have a built-in localized
|
|
-- string, we know we've reached the end.
|
|
if not _G[string.format("ITEM_QUALITY%d_DESC", i)] then
|
|
break
|
|
end
|
|
table.insert(ruleFunctionTemplates.Quality, {
|
|
code = string.format("Quality(%d)", i),
|
|
description = string.format(
|
|
L.RuleFunction_Quality_ExampleDescription,
|
|
_G[string.format("ITEM_QUALITY%d_DESC", i)]
|
|
),
|
|
})
|
|
end
|
|
|
|
-- RequiresClass()
|
|
-- List of character classes.
|
|
ruleFunctionTemplates.RequiresClass = {}
|
|
for _, class in pairs(BsGameInfo.characterClasses) do
|
|
table.insert(ruleFunctionTemplates.RequiresClass, {
|
|
code = string.format('RequiresClass("%s")', L[class]),
|
|
description = string.format(L.RuleFunction_RequiresClass_ExampleDescription, L[class]),
|
|
})
|
|
end
|
|
|
|
-- PeriodicTable()
|
|
-- List of all PeriodicTable sets.
|
|
ruleFunctionTemplates.PeriodicTable = {}
|
|
for _, setName in pairs(BsItemInfo:GetPeriodicTableSets()) do
|
|
table.insert(ruleFunctionTemplates.PeriodicTable, {
|
|
code = string.format('PeriodicTable("%s")', setName),
|
|
text = setName,
|
|
tooltipTitle = string.format('PeriodicTable("%s")', setName),
|
|
description = string.format(L.RuleFunction_PeriodicTable_ExampleDescription, setName),
|
|
})
|
|
end
|
|
end)
|