Module:Crafting: Difference between revisions
From Space Station 14 Wiki
wip |
wawa |
||
Line 2: | Line 2: | ||
local crafting_stations_configs_json = mw.loadJsonData("Module:Crafting/data/auto/crafting_stations_configs.json") | local crafting_stations_configs_json = mw.loadJsonData("Module:Crafting/data/auto/crafting_stations_configs.json") | ||
-- an array of property names containing recipes in station configs. | |||
p.availability_prop_names = { | |||
"staticRecipes", | |||
"dynamicRecipes", | |||
"emagStaticRecipes", | |||
"emagDynamicRecipes", | |||
} | |||
-- maps availability property names to availability. | |||
p.map_of_availability_prop_name_to_availability = { | |||
["staticRecipes"] = "static", | |||
["dynamicRecipes"] = "dynamic", | |||
["emagStaticRecipes"] = "emag static", | |||
["emagDynamicRecipes"] = "emag dynamic", | |||
} | |||
-- Searches for a station config with given ID. | -- Searches for a station config with given ID. | ||
Line 19: | Line 35: | ||
function p.get_all_crafting_stations_configs() | function p.get_all_crafting_stations_configs() | ||
return crafting_stations_configs_json | return crafting_stations_configs_json | ||
end | |||
-- Searches for station configs that have given recipe ID in their recipes. | |||
-- availabilityStr | |||
-- Returns an array of results, each containing: | |||
-- * `station_type` - crafting station type. | |||
-- * `station_id` - crafting station ID. | |||
-- * `availability` - recipe availability, one of: `static`, `dynamic`, `emag static` or `emag dynamic`. | |||
-- * `recipe_id` - recipe ID. | |||
-- | |||
-- **Note: This is an expensive function.** | |||
function p.find_crafting_station_configs_by_recipe_id(recipe_id_query) | |||
local res = {} | |||
for _, cfg in ipairs(crafting_stations_configs_json) do | |||
for _, availabilityPropName in ipairs(p.availability_prop_names) do | |||
local availability = p.map_of_availability_prop_name_to_availability[availabilityPropName] | |||
local recipe_ids = cfg[availabilityPropName] | |||
if recipe_ids ~= nil then | |||
for _, recipe_id in ipairs(recipe_ids) do | |||
if recipe_id == recipe_id_query then | |||
table.insert(res, { | |||
station_type = cfg.stationType, | |||
station_id = cfg.id, | |||
availability = availability, | |||
recipe_id = recipe_id | |||
}) | |||
end | |||
end | |||
end | |||
end | |||
end | |||
return res | |||
end | end | ||
return p | return p |
Revision as of 06:02, 9 July 2025
Module documentation
|
---|
View or edit this documentation • (about module documentation) |
Uses JSON data
This module uses JSON data pages:
Contains various methods related to crafting. Currently, this only covers item recipes using lathes.
JSON files
JSON files that are updated automatically, syncing with the upstream:
- Module:Crafting/data/auto/crafting_stations_configs.json - contains configs for each crafting station - things like crafting time/resource modifiers, as well as producible IDs of recipes, grouped by availability.
local p = {}
local crafting_stations_configs_json = mw.loadJsonData("Module:Crafting/data/auto/crafting_stations_configs.json")
-- an array of property names containing recipes in station configs.
p.availability_prop_names = {
"staticRecipes",
"dynamicRecipes",
"emagStaticRecipes",
"emagDynamicRecipes",
}
-- maps availability property names to availability.
p.map_of_availability_prop_name_to_availability = {
["staticRecipes"] = "static",
["dynamicRecipes"] = "dynamic",
["emagStaticRecipes"] = "emag static",
["emagDynamicRecipes"] = "emag dynamic",
}
-- Searches for a station config with given ID.
-- Any casing is supported.
--
-- Returns found config or `nil`.
function p.find_crafting_station_config(id)
local id_lc = string.lower(id)
for _, config in ipairs(crafting_stations_configs_json) do
if string.lower(config.id) == id_lc then
return config
end
end
end
-- Returns all existing configs on crafting stations.
function p.get_all_crafting_stations_configs()
return crafting_stations_configs_json
end
-- Searches for station configs that have given recipe ID in their recipes.
-- availabilityStr
-- Returns an array of results, each containing:
-- * `station_type` - crafting station type.
-- * `station_id` - crafting station ID.
-- * `availability` - recipe availability, one of: `static`, `dynamic`, `emag static` or `emag dynamic`.
-- * `recipe_id` - recipe ID.
--
-- **Note: This is an expensive function.**
function p.find_crafting_station_configs_by_recipe_id(recipe_id_query)
local res = {}
for _, cfg in ipairs(crafting_stations_configs_json) do
for _, availabilityPropName in ipairs(p.availability_prop_names) do
local availability = p.map_of_availability_prop_name_to_availability[availabilityPropName]
local recipe_ids = cfg[availabilityPropName]
if recipe_ids ~= nil then
for _, recipe_id in ipairs(recipe_ids) do
if recipe_id == recipe_id_query then
table.insert(res, {
station_type = cfg.stationType,
station_id = cfg.id,
availability = availability,
recipe_id = recipe_id
})
end
end
end
end
end
return res
end
return p