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

-- <nowiki>
--------------------------------------------------------------------------------
-- Constructor for [[Module:MARDEK Items/data]], pulled into its own module for
-- legibility purposes.
--
-- @TODO:
--    * Check for missing fields?
--    * Check for extra fields?
--    * Check for proper types?
--    * Generalize this, so I don't need to write a separate constructor for
--      every data module.
--------------------------------------------------------------------------------
local data = {}

local function constructor(newFields)
    local fields = {
        element = "None",
        value = -1,
        hp = 0,
        mp = 0,
        str = 0,
        vit = 0,
        spr = 0,
        agl = 0,
        atk = 0,
        def = 0,
        mdef = 0,
        eva = 0,
        critical = 0,
        ["drains hp"] = false,
        ["drains mp"] = false,
        ["resist fire"] = 0,
        ["resist water"] = 0,
        ["resist air"] = 0,
        ["resist earth"] = 0,
        ["resist light"] = 0,
        ["resist dark"] = 0,
        ["resist aether"] = 0,
        ["resist fig"] = 0,
        ["resist physical"] = 0,
        ["resist thauma"] = 0,
        ["resist poison"] = 0,
        ["resist paralysis"] = 0,
        ["resist numbness"] = 0,
        ["resist silence"] = 0,
        ["resist curse"] = 0,
        ["resist confusion"] = 0,
        ["resist sleep"] = 0,
        ["resist blindness"] = 0,
        ["resist zombie"] = 0,
        ["resist bleed"] = 0,
        ["empower fire"] = 0,
        ["empower water"] = 0,
        ["empower air"] = 0,
        ["empower earth"] = 0,
        ["empower light"] = 0,
        ["empower dark"] = 0,
        ["empower aether"] = 0,
        ["empower fig"] = 0,
        ["empower physical"] = 0,
        ["empower thauma"] = 0,
        skills = {},
        canEquip = {},
    }

    -- merge newFields into fields, replacing where necessary
    for k, v in pairs(newFields) do
        fields[k] = v
    end

    -- compound fields
    fields.displayText = (fields.type == "PLOT" and "★ " or "") .. fields.name
    fields.link = fields.article == fields.displayText
        and ("[[" .. fields.article .. "]]")
        or ("[[" .. fields.article .. "|" .. fields.displayText .. "]]")
    fields.imageLink = "[[" .. fields.sprite .. "|" .. fields.displayText .. "|link=" .. fields.article .. "]]"
    fields.infoIcon = fields.imageLink .. "<br>" .. fields.link

    -- make the fields available
    table.insert(data, fields)
    data[fields.name] = fields
end

-- @see <https://stackoverflow.com/a/9470669>
return function ()
    return data, constructor
end

-- </nowiki>
-- [[Category:Lua Modules]]
Community content is available under CC-BY-SA unless otherwise noted.