Module:OCIData

From MENACE Official Wiki
Revision as of 13:47, 20 July 2026 by n tilted (talk | contribs)

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

---
--- Extracts attributes of oci from Module:Data/oci-vX.X.X.json
---

---@module ociData
local ociData = {}

--region Dependencies
local JsonUtils = require("Module:JsonUtils")
--endregion

--region Private constants
local DATA_FILE = "Module:Data/OCI-v0.7.9.json"
--endregion

--region Private member variables
local ociData
--endregion

--region Private methods
local function loadData()
    if not ociData then
        ociData = JsonUtils.convertJSONToLuaTable(DATA_FILE)
    end
end


local function getTitleFromArgs(frame)
    if frame.args then
        return frame.args[1] or frame.args.title
    else
        return frame
    end
end


local function getPropertyByTitle(frame, property)
    loadData()

    local ociTitle = getTitleFromArgs(frame)

    for _, oci in ipairs(ociData) do
        if string.lower(oci.Title) == string.lower(ociTitle) then
            return oci[property]
        end
    end
end
--endregion

function ociData.getShortNameByTitle(frame)
    return getPropertyByTitle(frame, "Title")
end

function ociData.getIconByTitle(frame)
    return getPropertyByTitle(frame, "Icon")
end

function ociData.getCategoryByTitle(frame)
    return getPropertyByTitle(frame, "Category")
end

function ociData.getFactionyByTitle(frame)
    return getPropertyByTitle(frame, "Faction")
end

function ociData.getDescriptionByTitle(frame)
    return getPropertyByTitle(frame, "Description")
end

function ociData.getShortDescriptionByTitle(frame)
    return getPropertyByTitle(frame, "ShortDescription")
end

function ociData.getPointCostByTitle(frame)
    return getPropertyByTitle(frame, "PointCost")
end

function ociData.getStackableByTitle(frame)
    return getPropertyByTitle(frame, "Stackable")
end

function ociData.getUpgradeToByTitle(frame)
    return getPropertyByTitle(frame, "UpgradeTo")
end

return ociData