Actions

Module

Module:DataFetch

From Project Rebearth

Revision as of 22:20, 15 February 2026 by Sharkie (talk | contribs)

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

-- Written with ❤️ by fshark (initially, at least)

local p = {}

local cache

local function load()
    if not cache then
        local title = mw.title.new("Module:DataFetch/data.json")
        if title and title.exists then
            cache = mw.text.jsonDecode(title:getContent())
        else
            cache = {}
        end
    end
    return cache
end

local data = load()

function p.BuildingCost(f)
    local args = f.args
    local name = args.name
    local biome = args.biome
    local resource = args.resource
    if not name or not biome or not resource then
        error("Missing arguments")
    end
    local buildingData = data[name]
    return buildingData.cost.byBiome[biome][resource] or 0
end

return p