Module:Recipes: Difference between revisions
From Guinea Isles Wiki
No edit summary |
No edit summary |
||
| (28 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
-------------------------- | -------------------------- | ||
-- Module for crafting | -- Module for crafting recipe data | ||
------------------------ | ------------------------ | ||
local data = mw.loadJsonData('Module:Recipes/data.json') | |||
local p = {} | local p = {} | ||
function p. | -- Returns the entry in data.json with the corresponding id as a key. Args: | ||
local | -- id is they key in data.json to lookup. This is generally an item name as a page title | ||
-- eg. "Plainwood Log" will return all recipes involving a plainwood log | |||
function p.get_entry(id) | |||
if data[id] ~= nil then | |||
return data[id] | |||
end | |||
return nil | |||
end | |||
-- Similar to get_entry, but only returns a list of recipes where id is | |||
-- in the input/materials, not the output. i.e. returns a table of every | |||
-- "product" this item makes. | |||
function p.get_item_products(id) | |||
local entry_data = p.get_entry(id) | |||
if entry_data ~= nil then | |||
local ret = {} | |||
-- Iterate over each recipe and then each output | |||
for recipe_id, recipe in pairs(entry_data) do | |||
if recipe["mats"] ~= nil then | |||
for _, mat in pairs(recipe["mats"]) do | |||
if mat["name"] == id then | |||
ret[recipe_id] = entry_data[recipe_id] | |||
break | |||
end | |||
end | |||
end | |||
end | |||
return ret | |||
end | |||
return {} | |||
end | |||
-- Similar to get_entry, but only returns a list of recipes where id is | |||
-- in the output, not the input/mateirals. i.e. returns a table of every | |||
-- way to make this item. | |||
function p.get_item_creation(id) | |||
local entry_data = p.get_entry(id) | |||
if entry_data ~= nil then | |||
local ret = {} | |||
-- Iterate over each recipe and then each output | |||
for recipe_id, recipe in pairs(entry_data) do | |||
if recipe["output"] ~= nil then | |||
for _, output in pairs(recipe["output"]) do | |||
if output["name"] == id then | |||
ret[recipe_id] = entry_data[recipe_id] | |||
break | |||
end | |||
end | |||
end | |||
end | |||
for key, _ in pairs(ret) do | |||
mw.log(key) | |||
end | |||
return ret | |||
end | |||
return | return {} | ||
end | end | ||
return p | return p | ||
Latest revision as of 18:43, 20 September 2025
Module:Recipes is a module designed around managing the data of in-game recipes of all kinds. It allows users to query Module:Recipes/data.json, which contains this information in JSON format.
Functions
--------------------------
-- Module for crafting recipe data
------------------------
local data = mw.loadJsonData('Module:Recipes/data.json')
local p = {}
-- Returns the entry in data.json with the corresponding id as a key. Args:
-- id is they key in data.json to lookup. This is generally an item name as a page title
-- eg. "Plainwood Log" will return all recipes involving a plainwood log
function p.get_entry(id)
if data[id] ~= nil then
return data[id]
end
return nil
end
-- Similar to get_entry, but only returns a list of recipes where id is
-- in the input/materials, not the output. i.e. returns a table of every
-- "product" this item makes.
function p.get_item_products(id)
local entry_data = p.get_entry(id)
if entry_data ~= nil then
local ret = {}
-- Iterate over each recipe and then each output
for recipe_id, recipe in pairs(entry_data) do
if recipe["mats"] ~= nil then
for _, mat in pairs(recipe["mats"]) do
if mat["name"] == id then
ret[recipe_id] = entry_data[recipe_id]
break
end
end
end
end
return ret
end
return {}
end
-- Similar to get_entry, but only returns a list of recipes where id is
-- in the output, not the input/mateirals. i.e. returns a table of every
-- way to make this item.
function p.get_item_creation(id)
local entry_data = p.get_entry(id)
if entry_data ~= nil then
local ret = {}
-- Iterate over each recipe and then each output
for recipe_id, recipe in pairs(entry_data) do
if recipe["output"] ~= nil then
for _, output in pairs(recipe["output"]) do
if output["name"] == id then
ret[recipe_id] = entry_data[recipe_id]
break
end
end
end
end
for key, _ in pairs(ret) do
mw.log(key)
end
return ret
end
return {}
end
return p