Difference between revisions of "Module:Items"

From Nookipedia, the Animal Crossing wiki
m (Removed protection from "Module:Furniture": Namespace Protection)
(Code simplified (no more bad nested for loops), enabled by change in furniture JSON structure))
Line 3: Line 3:
 
     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])
    tbl = {}
+
     table.sort(data, function(k1, k2) return string.len(k1.name) < string.len(k2.name) end)
     table.foreach(data, function(k, v) table.insert(tbl, { [k] = v }) end )
 
    table.sort(tbl, function(k, v) return string.len(table.foreach(k, function(k2, v2) return k2 end)) < string.len(table.foreach(v, function(k2, v2) return k2 end)) end)
 
 
     local furnitureOutput = ""
 
     local furnitureOutput = ""
     table.foreach(tbl, function(k, v)
+
     for k, v in ipairs(data) do
         table.foreach(tbl[k], function(k2, v2) furnitureOutput = furnitureOutput .. frame:expandTemplate{ title = "HouseItem", args = { item = k2, count = v2['count'], img = v2['img'], note = v2['note'], game = game } } end ) end )
+
         furnitureOutput = furnitureOutput .. frame:expandTemplate{ title = "HouseItem", args = { item = v['name'], count = v['count'], img = v['img'], note = v['note'], game = game } }
 +
    end
 
     return furnitureOutput
 
     return furnitureOutput
 
end
 
end
 
return p
 
return p

Revision as of 02:45, 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 .. 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