Difference between revisions of "Module:Items"
From Nookipedia, the Animal Crossing wiki
SuperHamster (talk | contribs) (New split function, courtesy Cuyler) |
PanchamBro (talk | contribs) (adding SSBU spirit functions) |
||
Line 3: | Line 3: | ||
function insert(str1, str2, pos) | function insert(str1, str2, pos) | ||
return str1:sub(1,pos)..str2..str1:sub(pos+1) | return str1:sub(1,pos)..str2..str1:sub(pos+1) | ||
+ | end | ||
+ | |||
+ | |||
+ | function isEmpty(s) | ||
+ | return s == nil or s == '' | ||
end | end | ||
Line 102: | Line 107: | ||
return root | return root | ||
+ | end | ||
+ | |||
+ | function fighterFormat(fighter) | ||
+ | if fighter == 'Villager' then | ||
+ | return '[[Villager (Super Smash Bros. series)|Villager]]' | ||
+ | elseif fighter == 'Isabelle' then | ||
+ | return '[[Isabelle]]' | ||
+ | else | ||
+ | return '[[smashwiki:' .. fighter .. ' (SSBU)|' .. fighter .. ']]' | ||
+ | end | ||
+ | end | ||
+ | |||
+ | function p.outputEnemies(frame) | ||
+ | local data = mw.text.jsonDecode(mw.text.decode(frame.args['1'])) | ||
+ | local enemy = "" | ||
+ | for k, e in pairs(data) do | ||
+ | enemy = enemy .. "<li style=\"list-style-position: inside; padding-left: 5px\">" | ||
+ | if not isEmpty(e['fighter-condition']) then | ||
+ | enemy = enemy .. e['fighter-condition'] .. " " | ||
+ | end | ||
+ | if not isEmpty(e['fighter-variant']) then | ||
+ | enemy = enemy .. e['fighter-variant'] .. " " | ||
+ | end | ||
+ | enemy = enemy .. fighterFormat(e['fighter']) .. "</li>" | ||
+ | end | ||
+ | return enemy | ||
+ | end | ||
+ | |||
+ | function p.outputRules(frame) | ||
+ | local data = mw.text.jsonDecode(mw.text.decode(frame.args['1'])) | ||
+ | local rules = "" | ||
+ | for k, r in pairs(data) do | ||
+ | rules = rules .. "<li style=\"list-style-position: inside; padding-left: 5px\">" .. r['rule'] .. "</li>" | ||
+ | end | ||
+ | return rules | ||
+ | end | ||
+ | |||
+ | function p.outputConditions(frame) | ||
+ | local data = mw.text.jsonDecode(mw.text.decode(frame.args['1'])) | ||
+ | local conditions = "" | ||
+ | for k, r in pairs(data) do | ||
+ | conditions = conditions .. "<li style=\"list-style-position: inside; padding-left: 5px\">" .. r['condition'] .. "</li>" | ||
+ | end | ||
+ | return conditions | ||
end | end | ||
return p | return p |
Revision as of 16:44, May 4, 2022
Documentation for this module may be created at Module:Items/doc
local p = {}
function insert(str1, str2, pos)
return str1:sub(1,pos)..str2..str1:sub(pos+1)
end
function isEmpty(s)
return s == nil or s == ''
end
function split(str, pattern)
local out = {}
for m in string.gmatch(str, "[^" .. pattern .. "]+") do
table.insert(out, m)
end
return out
end
function p.italicizeGameInTitle(frame)
local title = frame.args[1]
local openParenthIndex = string.len(title) - (title:reverse()):find("%(")
local closeParenthIndex = string.len(title) - (title:reverse()):find("%)")
local newTitle = title
newTitle = insert(newTitle, "''", openParenthIndex + 1)
newTitle = insert(newTitle, "''", closeParenthIndex + 2)
local root = mw.html.create()
root:wikitext(newTitle)
return newTitle
end
function p.outputSortedFurniture (frame)
local game = frame.args[2]
local data = mw.text.jsonDecode(frame.args[1])
table.sort(data, function(k1, k2) return string.len(k1.name) < string.len(k2.name) end)
local furnitureOutput = ""
for k, v in ipairs(data) do
furnitureOutput = furnitureOutput .. frame:expandTemplate{ title = "HouseItem", args = { item = v['name'], count = v['count'], img = v['img'], note = v['note'], game = game } }
end
return furnitureOutput
end
function p.outputAvailabilitiesFromList (frame)
local data = frame.args[1]
local availabilityTable = split( data, "," )
local availability = ""
local availabilityList = ""
local mainAvailability = ""
local availabilityText = ""
local availabilityOutput = ""
for k, avail in ipairs(availabilityTable) do
if avail:match("%((.-)%)") then
availabilityText = avail:match("(.+)%(")
availability = frame:expandTemplate{ title = "Availability", args = { availabilityText, note = avail:match("%((.-)%)") } }
else
availabilityText = avail
availability = frame:expandTemplate{ title = "Availability", args = { availabilityText } }
end
availabilityList = availabilityList .. availability
end
local root = mw.html.create()
root:wikitext(availabilityList)
return root
end
function p.outputVillagerFromList (frame)
local data = frame.args[1]
local villagerTable = split( data, "," )
local villager = ""
local villagerList = ""
local mainVillager = ""
local villagerOutput = ""
local argument = "Villager"
for k, villa in ipairs(villagerTable) do
villager = frame:expandTemplate{ title = "Availability", args = { argument, villa } }
villagerList = villagerList .. villager
end
local root = mw.html.create()
root:wikitext(villagerList)
return root
end
function p.outputRVAvailabilitiesFromList (frame)
local data = frame.args[1]
local rvTable = split( data, "," )
local rv = ""
local rvList = ""
local mainRV = ""
local rvOutput = ""
local argument = "RV"
for k, villa in ipairs(rvTable) do
rv = frame:expandTemplate{ title = "Availability", args = { argument, villa } }
rvList = rvList .. string.gsub(rv, "\s+$", "");
end
local root = mw.html.create()
root:wikitext(rvList)
return root
end
function fighterFormat(fighter)
if fighter == 'Villager' then
return '[[Villager (Super Smash Bros. series)|Villager]]'
elseif fighter == 'Isabelle' then
return '[[Isabelle]]'
else
return '[[smashwiki:' .. fighter .. ' (SSBU)|' .. fighter .. ']]'
end
end
function p.outputEnemies(frame)
local data = mw.text.jsonDecode(mw.text.decode(frame.args['1']))
local enemy = ""
for k, e in pairs(data) do
enemy = enemy .. "<li style=\"list-style-position: inside; padding-left: 5px\">"
if not isEmpty(e['fighter-condition']) then
enemy = enemy .. e['fighter-condition'] .. " "
end
if not isEmpty(e['fighter-variant']) then
enemy = enemy .. e['fighter-variant'] .. " "
end
enemy = enemy .. fighterFormat(e['fighter']) .. "</li>"
end
return enemy
end
function p.outputRules(frame)
local data = mw.text.jsonDecode(mw.text.decode(frame.args['1']))
local rules = ""
for k, r in pairs(data) do
rules = rules .. "<li style=\"list-style-position: inside; padding-left: 5px\">" .. r['rule'] .. "</li>"
end
return rules
end
function p.outputConditions(frame)
local data = mw.text.jsonDecode(mw.text.decode(frame.args['1']))
local conditions = ""
for k, r in pairs(data) do
conditions = conditions .. "<li style=\"list-style-position: inside; padding-left: 5px\">" .. r['condition'] .. "</li>"
end
return conditions
end
return p