Module:Sandbox/Aurelain

From Heroes of Might and Magic: Olden Era Official Wiki
Revision as of 16:02, 13 May 2026 by Aurelain (talk | contribs)

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

local p = {}

-- Cache for data
local dataCache = nil
-- Cache for reverse lookup: id -> unitName
local idIndexCache = nil

local function loadUnits()
    if dataCache then return dataCache end
    dataCache = {}
    idIndexCache = {}

    local units = loadJson("Data:units.json")

    for name, unit in pairs(units) do
        dataCache[name] = unit
        -- Build reverse index: id -> display name (key in the JSON object)
        if unit.id and unit.id ~= "" then
            idIndexCache[unit.id] = name
        end
    end

    return dataCache
end

function p.hello(frame)
    return dataCache[frame.args[1]].name
end

return p