Module:Item/Mod: Difference between revisions

From Growtopia
Jump to navigationJump to search
>HashJona
No edit summary
>HashJona
mNo edit summary
Line 31: Line 31:
local item = {}
local item = {}


function item.parseEffects(args)  
function item.parseEffects(args)
local parsedEffects = {}
local parsedEffects = {}
mw.log("Debug - frame.args: " .. mw.dumpObject(args))
    for i = 2, #args do
local numericKeys = {}
        local key = args[i]
for k, _ in pairs(args) do
        if effect[key] then
if type(k) == 'number' then
            table.insert(parsedEffects, effect[key])
table.insert(numericKeys, k)
        end
end
    end
end
   
 
    local n = #parsedEffects
table.sort(numericKeys)
    if n == 0 then
 
        return ""
for i = 2, #numericKeys do
    elseif n == 1 then
local argIndex = numericKeys[i]
        return parsedEffects[1]
local key = args[argIndex]
    elseif n == 2 then
if effect[key] then
        return parsedEffects[1] .. " and " .. parsedEffects[2]
table.insert(parsedEffects, effect[key])
    else
end
        -- Join all elements except the last with ", " then append " and " with the last one
end
        local firstPart = table.concat(parsedEffects, ", ", 1, n - 1)
 
        return firstPart .. " and " .. parsedEffects[n]
local n = #parsedEffects
    end
if n == 0 then
return ""
elseif n == 1 then
return parsedEffects[1]
elseif n == 2 then
return parsedEffects[1] .. " and " .. parsedEffects[2]
else
local firstPart = table.concat(parsedEffects, ", ", 1, n - 1)
return firstPart .. " and " .. parsedEffects[n]
end
end
end
function item.description(frame)  
function item.description(frame)  
local parent = frame:getParent().args
local parent = frame:getParent().args
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 formattedEffects =  #frame.args
     local formattedEffects =  item.parseEffects(parent)
      
      
     return "When equipped, the "..title.." grants the player the ''"..label.."'' [[Mods|mod]], which allows the player to "..formattedEffects.."."
     return "When equipped, the "..title.." grants the player the ''"..label.."'' [[Mods|mod]], which allows the player to "..formattedEffects.."."
end
function item.debug(frame)
  local parsedEffects = {}
  local args =  frame:getParent().args
    -- 1. Gather numeric keys
    local numericKeys = {}
    for k, v in pairs(args) do
        if type(k) == 'number' then
            table.insert(numericKeys, k)
        end
    end
    -- 2. Sort them in ascending order
    table.sort(numericKeys)
    -- 3. Start iterating from the second numeric key
    for i = 2, #numericKeys do
        local actualKey = numericKeys[i]
        local key = args[actualKey]  -- this is the string that might appear in 'effect'
        if effect[key] then
            table.insert(parsedEffects, effect[key])
        end
    end
    -- Now do the same final formatting
    local n = #parsedEffects
    if n == 0 then
        return ""
    elseif n == 1 then
        return parsedEffects[1]
    elseif n == 2 then
        return parsedEffects[1] .. " and " .. parsedEffects[2]
    else
        local firstPart = table.concat(parsedEffects, ", ", 1, n - 1)
        return firstPart .. " and " .. parsedEffects[n]
    end
end
end


return item
return item

Revision as of 22:44, 2 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 1 tile further',
	['Punch Power'] = 'knock back other players further',
	['Changing Skin Colors'] = 'alter the color of the player\'s skin to a specific tone',
	['Miscellaneous'] = 'revist me',
	['Light Source'] = 'emit light in [[Dark Background Block (block category)|dark areas]]',
	['Build Range'] = 'build 1 tile further',
	['Punch Pull'] = 'pull other players towards them upon punching them',
	['High Jump'] = 'jump higher',
	['Slow Fall'] = 'glide slowly to the ground when pressing 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 Blocks]]',
	['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',
}

local item = {}

function item.parseEffects(args)
	local parsedEffects = {}
	
	local numericKeys = {}
	for k, _ in pairs(args) do
		if type(k) == 'number' then
			table.insert(numericKeys, k)
		end
	end

	table.sort(numericKeys)

	for i = 2, #numericKeys do
		local argIndex = numericKeys[i]
		local key = args[argIndex]
		if effect[key] then
			table.insert(parsedEffects, effect[key])
		end
	end

	local n = #parsedEffects
	if n == 0 then
		return ""
	elseif n == 1 then
		return parsedEffects[1]
	elseif n == 2 then
		return parsedEffects[1] .. " and " .. parsedEffects[2]
	else
		local firstPart = table.concat(parsedEffects, ", ", 1, n - 1)
		return firstPart .. " and " .. parsedEffects[n]
	end
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 formattedEffects =  item.parseEffects(parent)
    
    return "When equipped, the "..title.." grants the player the ''"..label.."'' [[Mods|mod]], which allows the player to "..formattedEffects.."."
end

return item