Module:Sandbox/Aurelain: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
No edit summary |
No edit summary |
||
| Line 36: | Line 36: | ||
local Unit = require('Module:Unit') | local Unit = require('Module:Unit') | ||
-- A clean, private Lua function that wraps the target module's frame logic | |||
local function get(userName, baseLocation) | |||
-- 1. Construct the fake frame using the arguments passed to this function | |||
local fakeFrame = { | |||
args = { | |||
[1] = userName, | |||
["base"] = baseLocation | |||
} | |||
} | |||
-- 2. Call the target module and return its output directly | |||
return Unit.get(fakeFrame) | |||
end | |||
function p.hello(frame) | function p.hello(frame) | ||
Revision as of 16:24, 13 May 2026
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
-- Function to load JSON data from wiki page
local function loadJson(title)
local page = mw.title.new(title)
local content = page and page:getContent() or ""
if content == "" then return {} end
local ok, data = pcall(mw.text.jsonDecode, content)
if not ok then return {} end
return data
end
-- Load unit data from unitdata_work.json
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
local Unit = require('Module:Unit')
-- A clean, private Lua function that wraps the target module's frame logic
local function get(userName, baseLocation)
-- 1. Construct the fake frame using the arguments passed to this function
local fakeFrame = {
args = {
[1] = userName,
["base"] = baseLocation
}
}
-- 2. Call the target module and return its output directly
return Unit.get(fakeFrame)
end
function p.hello(frame)
return Unit.get(frame)
end
return p


