Module:Bestiary
Module for handling bestiary related data.
Templates
- {{Bestiary}}
- {{Beastcrafting recipes}}
Subpages
- Module:Bestiary/components
- Module:Bestiary/components/doc
- Module:Bestiary/config
- Module:Bestiary/config/doc
- Module:Bestiary/config/sandbox
- Module:Bestiary/doc
- Module:Bestiary/recipe components
- Module:Bestiary/recipe components/doc
- Module:Bestiary/recipes
- Module:Bestiary/recipes/doc
- Module:Bestiary/sandbox
The above documentation is transcluded from Module:Bestiary/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
--
-- Module for bestiary templates
--
local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
local i18n = {
errors = {
invalid_table = 'Table supplied is invalid',
},
}
--mw.loadData('Module:QuestReward/vendor_reward_data')
-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Cargo
-- ----------------------------------------------------------------------------
local tables = {}
tables.recipes = {
table = 'bestiary_recipes',
fields = {
id = {
field = 'id',
type = 'String',
},
header = {
field = 'header',
type = 'Text',
},
subheader = {
field = 'subheader',
type = 'Text',
},
notes = {
field = 'notes',
type = 'Text',
},
},
}
tables.components = {
table = 'bestiary_components',
fields = {
id = {
field = 'id',
type = 'String',
},
min_level = {
field = 'min_level',
type = 'Intenger',
},
rarity = {
field = 'rarity',
type = 'String',
},
family = {
field = 'family',
type = 'String',
},
-- cargo is complaining. Rename to group when able
beast_group = {
field = 'beast_group',
type = 'String',
},
genus = {
field = 'genus',
type = 'String',
},
mod_id = {
field = 'mod_id',
type = 'String',
},
monster = {
field = 'monster',
type = 'String',
},
},
}
tables.recipe_components = {
table = 'bestiary_recipe_components',
fields = {
recipe_id = {
field = 'recipe_id',
type = 'String',
},
component_id = {
field = 'component_id',
type = 'String',
},
amount = {
field = 'amount',
type = 'Integer',
},
},
}
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------
local p = {}
p.table_bestiary_recipes = m_util.cargo.declare_factory{data=tables.recipes}
p.table_bestiary_components = m_util.cargo.declare_factory{data=tables.components}
p.table_bestiary_recipe_components = m_util.cargo.declare_factory{data=tables.recipe_components}
function p.store_data(frame)
-- Get args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
if tables[tpl_args.tbl] == nil then
error(i18n.errors.invalid_table)
end
-- mw.loadData has some problems...
local data = require(string.format('Module:Bestiary/%s', tpl_args.tbl))
for i=tpl_args.index_start or 1, tpl_args.index_end or #data do
local row = data[i]
if row == nil then
break
end
-- get full table name
row._table = tables[tpl_args.tbl].table
m_util.cargo.store(frame, row)
end
return string.format('Stored %s rows in "bestiary_%s" table', #data, tpl_args.tbl)
end
function p.recipe_table(frame)
-- Get args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
local results = m_util.cargo.query(
{'bestiary_recipes', 'bestiary_recipe_components', 'bestiary_components', 'mods'},
{
'bestiary_recipes.id',
'bestiary_recipes.header',
'bestiary_recipes.subheader',
'bestiary_recipes.notes',
'bestiary_recipe_components.amount',
'bestiary_components.min_level',
'bestiary_components.rarity',
'bestiary_components.family',
'bestiary_components.beast_group',
'bestiary_components.genus',
'bestiary_components.monster',
'mods.name',
},
{
join='bestiary_recipes.id=bestiary_recipe_components.recipe_id, bestiary_recipe_components.component_id=bestiary_components.id, bestiary_components.mod_id=mods.id',
limit=9999,
}
)
local order = m_util.cargo.query(
{'bestiary_recipes'},
{'bestiary_recipes.id'},
{
limit=9999,
orderBy='bestiary_recipes.header, bestiary_recipes.subheader',
}
)
results = m_util.cargo.map_results_to_id{results=results, field='bestiary_recipes.id'}
local tbl = mw.html.create('table')
tbl
:attr('class', 'wikitable sortable')
:tag('tr')
:tag('th')
:wikitext('Header')
:done()
:tag('th')
:wikitext('Subheader')
:done()
:tag('th')
:wikitext('Notes')
:done()
:tag('th')
:wikitext('Primary Component')
:done()
for _, order_row in ipairs(order) do
local row = results[order_row['bestiary_recipes.id']]
local components = {}
for _, component in ipairs(row) do
components[#components+1] = string.format('%sx ', component['bestiary_recipe_components.amount'])
if component['bestiary_components.min_level'] then
components[#components] = components[#components] .. string.format('level %s+ ', component['bestiary_components.min_level'])
end
for _, key in ipairs({'bestiary_components.rarity',
'bestiary_components.family',
'bestiary_components.beast_group',
'bestiary_components.genus',
'bestiary_components.monster'}) do
if component[key] then
components[#components] = components[#components] .. component[key] .. ' '
end
end
if component['mods.name'] then
components[#components] = components[#components] .. string.format('with modifier "%s"', component['mods.name'])
end
end
tbl
:tag('tr')
:tag('td')
:wikitext(row[1]['bestiary_recipes.header'] or '')
:done()
:tag('td')
:wikitext(row[1]['bestiary_recipes.subheader'] or '')
:done()
:tag('td')
:wikitext(row[1]['bestiary_recipes.notes'] or '')
:done()
:tag('td')
:wikitext(table.concat(components, '<br>'))
:done()
end
return tostring(tbl)
end
-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------
return p