More actions
Content deleted Content added
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
Line 1: | Line 1: | ||
local p = {} |
local p = {} |
||
function p.c(frame) |
|||
local tags = { |
|||
local args = frame.args |
|||
traits = { |
|||
local rawAbilities = args['a'] or '' |
|||
undead = { |
|||
text = 'Undead', |
|||
link = 'Undead creatures', |
|||
symbol = '🪦', |
|||
}, |
|||
corporeal = { |
|||
text = 'Corporeal', |
|||
link = 'Corporeal undead creatures', |
|||
symbol = '🧟♀️', |
|||
}, |
|||
skeletal = { |
|||
text = 'Skeletal', |
|||
link = 'Skeletal undead creatures', |
|||
symbol = '🦴', |
|||
}, |
|||
spectral = { |
|||
text = 'Spectral', |
|||
link = 'Spectral undead creatures', |
|||
symbol = '👻', |
|||
}, |
|||
minor = { |
|||
text = 'Minor', |
|||
link = 'Minor undead creatures', |
|||
symbol = '🧟', |
|||
}, |
|||
full = { |
|||
text = 'Full', |
|||
link = 'Full undead creatures', |
|||
symbol = '💀', |
|||
}, |
|||
greater = { |
|||
text = 'Greater', |
|||
link = 'Greater undead creatures', |
|||
symbol = '🧛', |
|||
}, |
|||
outsider = { |
|||
text = 'Outsider', |
|||
link = 'Outsider creatures', |
|||
symbol = '👽️', |
|||
}, |
|||
angelic = { |
|||
text = 'Angelic', |
|||
link = 'Angelic creatures', |
|||
symbol = '😇', |
|||
}, |
|||
demonic = { |
|||
text = 'Demonic', |
|||
link = 'Demonic creatures', |
|||
symbol = '👿', |
|||
}, |
|||
elemental = { |
|||
text = 'Elemental', |
|||
link = 'Elemental creatures', |
|||
symbol = '🌞', |
|||
}, |
|||
plant = { |
|||
text = 'Plant', |
|||
link = 'Plant creatures', |
|||
symbol = '🌿' |
|||
}, |
|||
construct = { |
|||
text = 'Construct', |
|||
link = 'Construct creatures', |
|||
symbol = '🗿' |
|||
}, |
|||
draconic = { |
|||
text = 'Draconic', |
|||
link = 'Draconic creatures', |
|||
symbol = '🐲', |
|||
}, |
|||
fae = { |
|||
text = 'Fae', |
|||
link = 'Fae creatures', |
|||
symbol = '🧚', |
|||
}, |
|||
animal = { |
|||
text = 'Animal', |
|||
link = 'Animal creatures', |
|||
symbol = '🦀', |
|||
}, |
|||
common = { |
|||
text = 'Common', |
|||
link = 'Common animal creatures', |
|||
symbol = '🐾', |
|||
}, |
|||
ooze = { |
|||
text = 'Ooze', |
|||
link = 'Ooze creatures', |
|||
symbol = '💩', |
|||
}, |
|||
monstrous = { |
|||
text = 'Monstrous', |
|||
link = 'Monstrous creatures', |
|||
symbol = '🧌', |
|||
}, |
|||
humanoid = { |
|||
text = 'Humanoid', |
|||
link = 'Humanoid creatures', |
|||
symbol = '👤', |
|||
}, |
|||
partial = { |
|||
text = 'Partial', |
|||
link = 'Partial humanoid creatures', |
|||
symbol = '🐒', |
|||
}, |
|||
aquatic = { |
|||
text = 'Aquatic', |
|||
link = 'Aquatic creatures', |
|||
symbol = '🐟️', |
|||
}, |
|||
} |
|||
} |
|||
local |
local abilities = {} |
||
for ability in mw.text.gsplit(rawAbilities, ";;", true) do |
|||
local items = {} |
|||
ability = mw.text.trim(ability) |
|||
for item in string.gmatch(s, '([^,]+)') do |
|||
if ability ~= "" then |
|||
local trimmed_item = item:match("^%s*(.-)%s*$") |
|||
local name = ability |
|||
table.insert(items, trimmed_item) |
|||
local limited = "" |
|||
local improved = "" |
|||
local gifted = false |
|||
local adept = false |
|||
-- Look for gifted marker |
|||
if mw.ustring.find(ability, "%-g%-") then |
|||
gifted = true |
|||
end |
|||
-- Look for adept marker |
|||
if mw.ustring.find(ability, "%-a%-") then |
|||
adept = true |
|||
end |
|||
-- Limited (-l-) note |
|||
local limitedMatch = mw.ustring.match(ability, "%-l%-(.-)(%-[liag]%-|$)") |
|||
or mw.ustring.match(ability, "%-l%-(.+)$") |
|||
if limitedMatch then |
|||
limited = mw.text.trim(limitedMatch) |
|||
end |
|||
-- Improved (-i-) note |
|||
local improvedMatch = mw.ustring.match(ability, "%-i%-(.-)(%-[liag]%-|$)") |
|||
or mw.ustring.match(ability, "%-i%-(.+)$") |
|||
if improvedMatch then |
|||
improved = mw.text.trim(improvedMatch) |
|||
end |
|||
-- Remove all markers and their text for name cleanup |
|||
name = mw.ustring.gsub(name, "%-l%-.+", "") |
|||
name = mw.ustring.gsub(name, "%-i%-.+", "") |
|||
name = mw.ustring.gsub(name, "%-g%-", "") |
|||
name = mw.ustring.gsub(name, "%-a%-", "") |
|||
name = mw.text.trim(name) |
|||
table.insert(abilities, { |
|||
name = name, |
|||
limited = limited, |
|||
improved = improved, |
|||
gifted = gifted, |
|||
adept = adept |
|||
}) |
|||
end |
|||
end |
end |
||
table.sort(items) |
|||
return items |
|||
end |
|||
-- Sort alphabetically by name |
|||
local function makeTag(frame, key, value, makeCat, transparent) |
|||
table.sort(abilities, function(a, b) return a.name < b.name end) |
|||
if not tags[key] or not tags[key][value] then |
|||
if value then |
|||
local out = frame:preprocess("{{ucfirst:" .. tostring(value) .. "}}") |
|||
-- local out = 'pranked' |
|||
if not ('.' == out:sub(-1)) then |
|||
out = out .. '.' |
|||
end |
|||
return out |
|||
else |
|||
return '' |
|||
end |
|||
end |
|||
local tag = tags[key][value] |
|||
if tag.no then |
|||
local out = frame:preprocess("{{ucfirst:" .. tag.text .. "}}") |
|||
if not ('.' == out:sub(-1)) then |
|||
out = out .. '.' |
|||
end |
|||
return out |
|||
end |
|||
if tag.tags then |
|||
local out = '' |
|||
for _, t in ipairs(tag.tags) do |
|||
out = out .. makeTag(frame, key, t, makeCat, transparent) |
|||
end |
|||
return out |
|||
end |
|||
local tagText = "{{Tag|{{ucfirst:" .. tag.text .. "}}" |
|||
if tag.symbol then |
|||
tagText = tagText .. "|" .. tag.symbol |
|||
end |
|||
if tag.link then |
|||
tagText = tagText .. "|l=:Category:{{ucfirst:" .. tag.link .. "}}" |
|||
end |
|||
if tag.color then |
|||
tagText = tagText .. "|c=" .. tag.color |
|||
end |
|||
if transparent then |
|||
tagText = tagText .. "|o=1" |
|||
end |
|||
tagText = tagText .. "}}" |
|||
-- out = frame:preprocess(tagText) |
|||
out = tagText |
|||
return out |
|||
end |
|||
-- Intermediate table output |
|||
function p.c ( frame ) |
|||
return mw.dumpObject(abilities) |
|||
local args = frame.args |
|||
local tagIn = '' |
|||
local abilitiesIn = '' |
|||
local hp = '' |
|||
local mp = '' |
|||
local name = args['name'] |
|||
if not name then |
|||
return 'Must provide name.' |
|||
end |
|||
local catString = '[[Category:Creatures]]' |
|||
if args['t'] then |
|||
tagIn = args['t'] |
|||
end |
|||
if args['a'] then |
|||
abilitiesIn = args['a'] |
|||
end |
|||
if args['hp'] then |
|||
hp = args['hp'] |
|||
end |
|||
if args['mp'] then |
|||
mp = args['mp'] |
|||
end |
|||
local tagItems = sortString(tagIn) |
|||
tagOut = '' |
|||
for _, item in ipairs(tagItems) do |
|||
tag = makeTag(frame, 'traits', item, true) |
|||
tagOut = tagOut .. tag |
|||
catString = catString .. '[[Category:' .. tags['traits'][item]['link'] .. ']]' |
|||
end |
|||
local page = mw.title.getCurrentTitle().text |
|||
local namespace = frame:preprocess('{{NAMESPACE}}') |
|||
local addCats = ((namespace == 'Creature') and (page == name)) |
|||
local out = "'''CREATURE PAGES ARE A WORK IN PROGRESS'''\n\n" |
|||
out = out .. "'''Traits and Types:''' " .. tagOut .. '\n\n' |
|||
if hp ~= '' then |
|||
out = out .. "'''HP:''' " .. hp .. '\n\n' |
|||
end |
|||
if mp ~= '' then |
|||
out = out .. "'''MP:''' " .. mp .. '\n' |
|||
end |
|||
out = out .. "== Abilities ==\n" |
|||
out = out .. '{{AESort|' .. abilitiesIn .. '}}' |
|||
if addCats then |
|||
out = out .. catString |
|||
end |
|||
return frame:preprocess(out) |
|||
end |
end |
||
Revision as of 01:52, 12 August 2025
Documentation for this module may be created at Module:C/doc
local p = {}
function p.c(frame)
local args = frame.args
local rawAbilities = args['a'] or ''
local abilities = {}
for ability in mw.text.gsplit(rawAbilities, ";;", true) do
ability = mw.text.trim(ability)
if ability ~= "" then
local name = ability
local limited = ""
local improved = ""
local gifted = false
local adept = false
-- Look for gifted marker
if mw.ustring.find(ability, "%-g%-") then
gifted = true
end
-- Look for adept marker
if mw.ustring.find(ability, "%-a%-") then
adept = true
end
-- Limited (-l-) note
local limitedMatch = mw.ustring.match(ability, "%-l%-(.-)(%-[liag]%-|$)")
or mw.ustring.match(ability, "%-l%-(.+)$")
if limitedMatch then
limited = mw.text.trim(limitedMatch)
end
-- Improved (-i-) note
local improvedMatch = mw.ustring.match(ability, "%-i%-(.-)(%-[liag]%-|$)")
or mw.ustring.match(ability, "%-i%-(.+)$")
if improvedMatch then
improved = mw.text.trim(improvedMatch)
end
-- Remove all markers and their text for name cleanup
name = mw.ustring.gsub(name, "%-l%-.+", "")
name = mw.ustring.gsub(name, "%-i%-.+", "")
name = mw.ustring.gsub(name, "%-g%-", "")
name = mw.ustring.gsub(name, "%-a%-", "")
name = mw.text.trim(name)
table.insert(abilities, {
name = name,
limited = limited,
improved = improved,
gifted = gifted,
adept = adept
})
end
end
-- Sort alphabetically by name
table.sort(abilities, function(a, b) return a.name < b.name end)
-- Intermediate table output
return mw.dumpObject(abilities)
end
return p