Module:ItemCategories
Jump to navigation
Jump to search
Documentation for this module may be created at Module:ItemCategories/doc
-- this will be mw.loadData later
local config = {
-- Direct mappings
direct = {
-- Loot
["LootTier.1"] = "LootTier 1",
["LootTier.2"] = "LootTier 2",
["LootTier.3"] = "LootTier 3",
["LootTier.4"] = "LootTier 4",
["LootTier.5"] = "LootTier 5",
["LootTier.6"] = "LootTier 6",
["Loot.GreatHouse"] = "Loot from Great Houses",
["Loot.Fremen"] = "Loot from Fremen",
["Loot.OldImperial"] = "Loot from Old Imperial",
["Loot.Component"] = "Component",
["Rarity.Rare"] = {category = "Rare", except = {"Items.Schematics"}},
-- Armor
["Items.Clothes.HeavyArmor.Head"] = "Head",
["Items.Clothes.ScoutArmor.Head"] = "Head",
["Items.Clothes.Stillsuit.Head"] = "Head",
["Items.Clothes.Social.Head"] = "Head",
["Items.Clothes.HeavyArmor.Torso"] = "Torso",
["Items.Clothes.ScoutArmor.Torso"] = "Torso",
["Items.Clothes.Stillsuit.Torso"] = "Torso",
["Items.Clothes.Social.Torso"] = "Torso",
-- This is technically Torso
["Items.Clothes.Utility"] = "Utility",
["Items.Clothes.HeavyArmor.Legs"] = "Legs",
["Items.Clothes.ScoutArmor.Legs"] = "Legs",
["Items.Clothes.Social.Legs"] = "Legs",
["Items.Clothes.HeavyArmor.Hands"] = "Hands",
["Items.Clothes.ScoutArmor.Hands"] = "Hands",
["Items.Clothes.Stillsuit.Hands"] = "Hands",
["Items.Clothes.Social.Hands"] = "Hands",
["Items.Clothes.HeavyArmor.Feet"] = "Feet",
["Items.Clothes.ScoutArmor.Feet"] = "Feet",
["Items.Clothes.Stillsuit.Feet"] = "Feet",
["Items.Clothes.Social.Feet"] = "Feet",
-- Tools
["Items.Holsters.HydrationTools"] = "Hydration Tools",
["Items.Holsters.CartographyTools"] = "Cartography Tools",
["Items.Holsters.GatheringTools.Cutteray"] = "Cutteray",
["Items.Holsters.GatheringTools.Compactor"] = "Compactor",
["Items.Holsters.UtilityTools.Repair"] = "Repair",
["Items.Holsters.UtilityTools.Respawn"] = "Respawn",
["Items.Holsters.UtilityTools.Thumper"] = "Thumper",
["Items.Holsters.UtilityTools.Suspensor"] = "Suspensor",
["Items.Holsters.UtilityTools.Light"] = "Light",
["Items.Holsters.UtilityTools.Shield"] = "Shield",
-- Items
["Items.Consumables"] = "Consumables",
["Items.Consumables.Spice"] = "Consumables",
["Items.Consumables.Health"] = "Consumables",
},
-- Partial mappings, matches the start only
partial = {
["Items"] = "Items",
["Items.Schematics"] = "Schematics",
["Items.Contract"] = "Contract Items",
-- Weapons
["Items.Holsters.RangedWeapons.Heavy"] = "Heavy Ranged Weapons",
["Items.Holsters.RangedWeapons.Light"] = "Light Ranged Weapons",
["Items.Holsters.MeleeWeapons"] = "Melee Weapons",
["Items.Ammo"] = "Ammo",
["Items.Holsters.MeleeWeapons.Sword"] = "Sword",
["Items.Holsters.MeleeWeapons.Knife"] = "Knife",
["Items.Holsters.RangedWeapons.Heavy.Flamethrower"] = "Flamethrower",
["Items.Holsters.RangedWeapons.Heavy.Lasgun"] = "Lasgun",
["Items.Holsters.RangedWeapons.Heavy.LMG"] = "LMG",
["Items.Holsters.RangedWeapons.Heavy.Pistol"] = "Pistol",
["Items.Holsters.RangedWeapons.Heavy.RocketLauncher"] = "RocketLauncher",
["Items.Holsters.RangedWeapons.Heavy.Shotgun"] = "Shotgun",
["Items.Holsters.RangedWeapons.Light.Pistol"] = "Pistol",
["Items.Holsters.RangedWeapons.Light.Rifle"] = "Rifle",
["Items.Holsters.RangedWeapons.Light.Shotgun"] = "Shotgun",
["Items.Holsters.RangedWeapons.Light.SMG"] = "SMG",
-- Clothes
["Items.Clothes.ScoutArmor"] = "Light Armor",
["Items.Clothes.HeavyArmor"] = "Heavy Armor",
["Items.Clothes.Stillsuit"] = "Stillsuit",
--["Items.Clothes"] = "Clothes",
-- Resources
["Items.RefinedResources"] = "Refined Resources",
["Items.RawResources"] = "Raw Resources",
["Items.CraftedResources"] = "Crafted Resources",
-- Tools
["Items.Holsters.BuildingTools"] = "Building Tools",
}
}
local function shouldSkip(entry, itemtags)
if type(entry) == "table" and entry.except then
for _, exclude in ipairs(entry.except) do
for _, tag in ipairs(itemtags) do
if tag == exclude or string.sub(tag, 1, #exclude) == exclude then
return true
end
end
end
end
return false
end
local p = {}
function p.fromItemTags(frame)
local itemtags = frame.args[1] or ""
local out = {}
local seen = {}
mw.log(itemtags)
local itemtags_str = frame.args[1] or ""
local itemtags = {}
for tag in string.gmatch(itemtags_str, '"(.-)"') do
table.insert(itemtags, tag)
end
for _, tag in ipairs(itemtags) do
tag = mw.text.trim(tag)
mw.log("checking tag: " .. tag)
-- direct tag match from config
local direct = config.direct[tag]
if direct then
local category = type(direct) == "table" and direct.category or direct
if not shouldSkip(direct, itemtags) then
seen[category] = true
mw.log("added " .. category .. " by direct mapping with " .. tag)
else
mw.log("skipped " .. category .. " due to exclude ")
end
end
-- partial match
for partial, category in pairs(config.partial) do
if string.sub(tag, 1, #partial) == partial then
seen[category] = true
mw.log("added " .. category .. " by partial match on " .. partial)
end
end
end
for cat in pairs(seen) do
table.insert(out, string.format("[[Category:%s]]", cat))
end
return table.concat(out, "\n")
end
return p