Module:OCIData: Difference between revisions

From MENACE Official Wiki
n tilted (talk | contribs)
No edit summary
n tilted (talk | contribs)
update to JSON 0.7.13
 
(One intermediate revision by the same user not shown)
Line 11: Line 11:


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


Line 47: Line 47:
end
end
--endregion
--endregion
function OCIData.getShortNameByTitle(frame)
    return getPropertyByTitle(frame, "ShortName")
end


function OCIData.getIconByTitle(frame)
function OCIData.getIconByTitle(frame)
Line 56: Line 52:
end
end


function OCIData.getCategoryByTitle(frame)
function OCIData.getShortNameByTitle(frame)
     return getPropertyByTitle(frame, "Category")
     return getPropertyByTitle(frame, "ShortName")
end
 
function OCIData.getFactionByTitle(frame)
    return getPropertyByTitle(frame, "Faction")
end
end


Line 80: Line 72:
end
end


function OCIData.getUpgradeToByTitle(frame)
function OCIData.getFactionByTitle(frame)
     return getPropertyByTitle(frame, "UpgradeTo")
     return getPropertyByTitle(frame, "Faction")
end
 
function OCIData.getCategoryByTitle(frame)
    return getPropertyByTitle(frame, "Category")
end
 
function OCIData.getParentOCIByTitle(frame)
    return getPropertyByTitle(frame, "ParentOCI")
end
 
function OCIData.getChildOCIByTitle(frame)
    return getPropertyByTitle(frame, "ChildOCI")
end
end


return OCIData
return OCIData

Latest revision as of 18:14, 14 August 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.13.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.getIconByTitle(frame)
    return getPropertyByTitle(frame, "Icon")
end

function OCIData.getShortNameByTitle(frame)
    return getPropertyByTitle(frame, "ShortName")
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.getFactionByTitle(frame)
    return getPropertyByTitle(frame, "Faction")
end

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

function OCIData.getParentOCIByTitle(frame)
    return getPropertyByTitle(frame, "ParentOCI")
end

function OCIData.getChildOCIByTitle(frame)
    return getPropertyByTitle(frame, "ChildOCI")
end

return OCIData