Module:OrdersData: Difference between revisions
From Against the Storm Official Wiki
Anteprefix (talk | contribs) Basic Orders Data schema, no functionality yet |
Anteprefix (talk | contribs) No edit summary |
||
| Line 20: | Line 20: | ||
NAME = "displayName", | NAME = "displayName", | ||
TIERS = "tiers", | TIERS = "tiers", | ||
TIMED_ORDER = "isTimed", | |||
TIME_LIMIT = "timeToFail", | TIME_LIMIT = "timeToFail", | ||
OBJECTIVES = "objectivesSets", | OBJECTIVES = "objectivesSets", | ||
REWARD_1 = "rewards1", | REWARD_1 = "rewards1", | ||
Revision as of 04:33, 30 July 2025
Documentation for this module may be created at Module:OrdersData/doc
---@class OrdersData
local OrdersData = {}
--region Dependencies
local JsonUtils = require("Module:JsonUtils")
--endregion
--region Private constants
local DATA_FILE = "Module:OrdersData/Biomes.json"
local SCHEMA = {
ID = "id",
NAME = "displayName",
TIERS = "tiers",
TIMED_ORDER = "isTimed",
TIME_LIMIT = "timeToFail",
OBJECTIVES = "objectivesSets",
REWARD_1 = "rewards1",
REWARD_2 = "rewards2",
REWARD_3 = "rewards3",
}
--endregion
--region Localization string constants
--endregion
--region Private member variables
local OrdersData
--endregion
--region Private methods
local function loadData()
if not OrdersData then
local newData = JsonUtils.convertJSONToLuaTable(DATA_FILE)
--Promote the ID to be the key of the main data table.
OrdersData = {}
for _, order in ipairs(newData) do
OrdersData[order[SCHEMA.ID]] = order
end
end
end
local function getOrderFieldByID(orderID, fieldName)
loadData()
local order = OrdersData[orderID]
if not order then
return nil
else
return order[fieldName]
end
end
--endregion
--region Public methods
---@public
---Gets an array of all IDs of orders in the data.
---
---@return table an array of IDs
function OrdersData.getAllOrderIDs()
loadData()
local orderIDs = {}
for id, _ in pairs(OrdersData) do
table.insert(orderIDs, id)
end
return orderIDs
end
---@public
-----Gets the name of the specified order.
-----
-----@param orderID string
-----@return string the display name
function OrdersData.getName(orderID)
return getOrderFieldByID(orderID, SCHEMA.NAME)
end
--endregion
return OrdersData


