Module:Item/Mod: Difference between revisions
From Growtopia
Jump to navigationJump to search
>HashJona m fix ItemModError condition |
>HashJona refactor, add table support |
||
| Line 38: | Line 38: | ||
local item = {} | local item = {} | ||
function | function joinWithAnd(list) | ||
local n = #list | |||
if n == 0 then | |||
return "" | |||
elseif n == 1 then | |||
return list[1] | |||
elseif n == 2 then | |||
return list[1] .. " and " .. list[2] | |||
elseif n >= 3 then | |||
local firstPart = table.concat(list, ", ", 1, n - 1) | |||
return firstPart .. ", and " .. list[n] | |||
end | |||
end | |||
function parseArgs(args) | |||
local keys = {} | local keys = {} | ||
for k, _ in pairs(args) do | for k, _ in pairs(args) do | ||
if type(k) == 'number' | if type(k) == 'number' then | ||
table.insert(keys, k) | table.insert(keys, k) | ||
end | end | ||
end | end | ||
return keys | |||
end | |||
function item.parseDescriptionEffects(args) | |||
local parsedEffects = {} | |||
local categories = {} | |||
local keys = parseArgs(args) | |||
for i = 2, #keys do | for i = 2, #keys do | ||
local argIndex = keys[i] | local argIndex = keys[i] | ||
local key = args[argIndex] | local key = args[argIndex] | ||
if type(effect[key]) == "function" | if effect[key] ~= nil then | ||
local text = effect[key] | |||
if type(effect[key]) == "function" then | |||
text = effect[key](args) | |||
end | |||
table.insert(categories, "[[Category:" .. key .. " Mod Items]]") | table.insert(categories, "[[Category:" .. key .. " Mod Items]]") | ||
table.insert(parsedEffects, text) | table.insert(parsedEffects, text) | ||
| Line 68: | Line 83: | ||
end | end | ||
if (#keys - #parsedEffects) ~= 1 then | |||
if (#keys - | |||
table.insert(categories, "[[Category:ItemModError]]") | table.insert(categories, "[[Category:ItemModError]]") | ||
end | end | ||
return { | return { | ||
description = | description = joinWithAnd(parsedEffects), | ||
categories = table.concat(categories) | categories = table.concat(categories) | ||
} | } | ||
end | |||
function item.parseTableCategories(args) | |||
local categories = {} | |||
local keys = parseArgs(args) | |||
for i = 2, #keys do | |||
local argIndex = keys[i] | |||
local key = args[argIndex] | |||
if effect[key] ~= nil then | |||
table.insert(categories, "[[Mods/" .. key .. "|".. key .."]]") | |||
end | |||
end | |||
return joinWithAnd(categories) | |||
end | end | ||
| Line 98: | Line 113: | ||
local title = mw.title.getCurrentTitle().text or 'unknown' | local title = mw.title.getCurrentTitle().text or 'unknown' | ||
local label = parent['label'] or parent[1] | local label = parent['label'] or parent[1] | ||
local parsedEffects = item. | local parsedEffects = item.parseDescriptionEffects(parent) | ||
local baseSentence = "When equipped, the '''" .. title .. "''' grants the ''" .. label .. "'' [[Mods|mod]]" | local baseSentence = "When equipped, the '''" .. title .. "''' grants the ''" .. label .. "'' [[Mods|mod]]" | ||
local fullSentence | local fullSentence | ||
if parsedEffects.description == "" | if parsedEffects.description == "" then | ||
fullSentence = baseSentence .. "." | fullSentence = baseSentence .. "." | ||
else | else | ||
fullSentence = baseSentence.. ", which allows the player to " .. parsedEffects.description .. "." | fullSentence = baseSentence .. ", which allows the player to " .. parsedEffects.description .. "." | ||
end | end | ||
return fullSentence .. parsedEffects.categories | return fullSentence .. parsedEffects.categories | ||
end | |||
function item.table(frame) | |||
local parent = farme:getParent().args | |||
local label = parent['label'] or parent[1] | |||
local notes = item.parseTableCategories(parent) or "" | |||
if notes ~= "" then | |||
notes = "Also grants " .. notes | |||
end | |||
return label .. " | " .. notes | |||
end | end | ||
return item | return item | ||
Revision as of 15:37, 4 March 2025
Documentation for this module may be created at Module:Item/Mod/doc
local effect = {
['Double Jump'] = 'jump a second time in mid-air',
['Speedy'] = 'move faster on land',
['Punch Damage'] = 'break blocks faster',
['Punch Range'] = 'punch one tile further',
['Punch Power'] = 'knock back other players further',
['Skin Color'] = function(args)
local skin = args['skin'] or 'a specific tone'
return 'change their skin color to ' .. skin
end,
['Miscellaneous'] = function(args)
return args['misc'] or ""
end,
['Light Source'] = 'emit light in [[Dark Background Block (block category)|dark areas]]',
['Build Range'] = 'build one tile further',
['Punch Pull'] = 'pull other players towards them upon punching them',
['High Jump'] = 'jump higher',
['Slow Fall'] = 'glide slowly to the ground when holding the jump button',
['Wall Climbing'] = 'cling onto [[Climbing Wall|Climbing Walls]] by pressing the jump button',
['Fire Hose'] = 'extinguish [[Fire|fires]]',
['Fireproof'] = 'take 50% less damage from [[Lava Pain Block (block category)|lava pain blocks]]',
['Ghost Immunity'] = 'immunity against certain types of ghosts',
['Healing'] = 'heal faster than usual after receiving damage from hitting a [[Pain Block (block category)|pain block]]',
['XP Buff'] = 'gain more [[Leveling|XP]]',
['Slippery'] = 'glide on any surface as if it is [[Slippery Block (block category)|slippery]]',
['Putt Putt Putt'] = 'move slower, but allows the player to harvest trees by walking through them',
['Damage Reduction'] = 'break blocks more slowly',
['Knock Back Reduction'] = 'resist a percentage of knockback when [[Punching|punched]] by other players',
['Speedy in Water'] = 'move faster in water',
['Float on Water'] = 'float on [[Water Bucket|water]]',
['Grow Effect'] = 'expand in size',
['Zombie Weapon'] = 'kill [[G-Virus|zombies]] during a Pandemic',
['Low Jump'] = 'decrease the player\'s jump height',
['Card Battle Health'] = 'adds 2 additional health to the player during card battles against a [[Villains|villain]] or another player',
['Night Vision'] = 'eliminate the darkness effect created by [[Dark Background Block (block category)|dark background blocks]]'
}
local item = {}
function joinWithAnd(list)
local n = #list
if n == 0 then
return ""
elseif n == 1 then
return list[1]
elseif n == 2 then
return list[1] .. " and " .. list[2]
elseif n >= 3 then
local firstPart = table.concat(list, ", ", 1, n - 1)
return firstPart .. ", and " .. list[n]
end
end
function parseArgs(args)
local keys = {}
for k, _ in pairs(args) do
if type(k) == 'number' then
table.insert(keys, k)
end
end
return keys
end
function item.parseDescriptionEffects(args)
local parsedEffects = {}
local categories = {}
local keys = parseArgs(args)
for i = 2, #keys do
local argIndex = keys[i]
local key = args[argIndex]
if effect[key] ~= nil then
local text = effect[key]
if type(effect[key]) == "function" then
text = effect[key](args)
end
table.insert(categories, "[[Category:" .. key .. " Mod Items]]")
table.insert(parsedEffects, text)
end
end
if (#keys - #parsedEffects) ~= 1 then
table.insert(categories, "[[Category:ItemModError]]")
end
return {
description = joinWithAnd(parsedEffects),
categories = table.concat(categories)
}
end
function item.parseTableCategories(args)
local categories = {}
local keys = parseArgs(args)
for i = 2, #keys do
local argIndex = keys[i]
local key = args[argIndex]
if effect[key] ~= nil then
table.insert(categories, "[[Mods/" .. key .. "|".. key .."]]")
end
end
return joinWithAnd(categories)
end
function item.description(frame)
local parent = frame:getParent().args
local title = mw.title.getCurrentTitle().text or 'unknown'
local label = parent['label'] or parent[1]
local parsedEffects = item.parseDescriptionEffects(parent)
local baseSentence = "When equipped, the '''" .. title .. "''' grants the ''" .. label .. "'' [[Mods|mod]]"
local fullSentence
if parsedEffects.description == "" then
fullSentence = baseSentence .. "."
else
fullSentence = baseSentence .. ", which allows the player to " .. parsedEffects.description .. "."
end
return fullSentence .. parsedEffects.categories
end
function item.table(frame)
local parent = farme:getParent().args
local label = parent['label'] or parent[1]
local notes = item.parseTableCategories(parent) or ""
if notes ~= "" then
notes = "Also grants " .. notes
end
return label .. " | " .. notes
end
return item