Difference between revisions of "Module:Items"

From Nookipedia, the Animal Crossing wiki
(Code simplified (no more bad nested for loops), enabled by change in furniture JSON structure))
(Trying preprocess instead of expandTemplate)
Line 6: Line 6:
 
     local furnitureOutput = ""
 
     local furnitureOutput = ""
 
     for k, v in ipairs(data) do
 
     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 } }
+
         furnitureOutput = furnitureOutput .. "{{HouseItem|item=" .. v['name'] .. "|count=" .. v['count'] .. "|img=" .. v['img'] .. "|note=" .. v['note'] .. "|game=" .. game .. "}}"
 
     end
 
     end
     return furnitureOutput
+
     return frame:preprocess( furnitureOutput )
 
end
 
end
 
return p
 
return p

Revision as of 04:25, July 6, 2020

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

local p = {}
function p.outputFurniture (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 .. "{{HouseItem|item=" .. v['name'] .. "|count=" .. v['count'] .. "|img=" .. v['img'] .. "|note=" .. v['note'] .. "|game=" .. game .. "}}"
    end
    return frame:preprocess( furnitureOutput )
end
return p