Difference between revisions of "Module:Items"

From Nookipedia, the Animal Crossing wiki
(Self-undo)
m (Renaming (outputFurniture -> outputSortedFurniture))
Line 1: Line 1:
 
local p = {}
 
local p = {}
function p.outputFurniture (frame)
+
function p.outputSortedFurniture (frame)
 
     local game = frame.args[2]
 
     local game = frame.args[2]
 
     local data = mw.text.jsonDecode(frame.args[1])
 
     local data = mw.text.jsonDecode(frame.args[1])

Revision as of 21:33, December 22, 2020

Documentation for this module may be created at Module:Items/doc

local p = {}
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
return p