Module:OCIData: Difference between revisions

From MENACE Official Wiki
n tilted (talk | contribs)
No edit summary
n tilted (talk | contribs)
No edit summary
Line 1: Line 1:
---
---
--- Extracts attributes of oci from Module:Data/oci-vX.X.X.json
--- Extracts attributes of OCI from Module:Data/OCI-vX.X.X.json
---
---


---@module ociData
---@module OCIData
local ociData = {}
local OCIData = {}


--region Dependencies
--region Dependencies
Line 15: Line 15:


--region Private member variables
--region Private member variables
local ociData
local OCIData
--endregion
--endregion


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


     local ociTitle = getTitleFromArgs(frame)
     local OCITitle = getTitleFromArgs(frame)


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


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


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


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


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


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


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


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


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


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


return ociData
return OCIData

Revision as of 13:50, 20 July 2026

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