Module:GameData/EvoCreo
Appearance
This documentation is transcluded from Module:GameData/EvoCreo/doc.
Contains raw game data for EvoCreo.
require( 'strict' )
local checkType = require( 'libraryUtil' ).checkType
local p = {}
--- Words that stay lowercase inside a page title unless they lead it,
--- e.g. TOME_OF_THE_VOID -> 'Tome of the Void'.
local smallWords = {
['a'] = true,
['an'] = true,
['and'] = true,
['at'] = true,
['by'] = true,
['for'] = true,
['in'] = true,
['of'] = true,
['on'] = true,
['the'] = true,
['to'] = true
}
--- Ids the display name does not spell out the same way.
---
--- getId() upper snake cases a name, which assumes the name splits into the
--- same words as the id. Breadcrumbs is one word as a name and two in the data,
--- so it derives BREADCRUMBS and never matches the stored BREAD_CRUMBS. That
--- mismatch is why Breadcrumbs was missing from Category:Items in EvoCreo:
--- getItem() found nothing, so nothing categorised it.
---
--- Keyed by what getId() derives, valued by what the data actually stores.
local idAliases = {
BREADCRUMBS = 'BREAD_CRUMBS'
}
--- Get the ID from a name
---
--- @param name string
--- @return string
local function getId( name )
local id = name:upper():gsub( ' ', '_' )
-- Special handling for Arcane V1, V2, V3
id = id:gsub( 'ARCANE_V(%d)', 'ARCANE_v%1' )
return idAliases[id] or id
end
--- Get the name from an ID
---
--- The inverse of getId(): the game data only stores upper snake case IDs, so
--- rendering a link to a Move or Item article means rebuilding its title.
--- Cross-checked against the English column of the EvoCreo 2 localization
--- workbook, whose keys are the lower case form of these IDs.
---
--- Words are split on underscores or whitespace, so this doubles as a
--- normaliser: passing an already spelled out name back through it repairs
--- casing (`Tome Of Electricity` -> `Tome of Electricity`) and returns
--- correctly cased names unchanged.
---
--- Note this is the subject's name, not necessarily its article title; where
--- another subject owns the plain title, Module:Move.getArticle disambiguates.
---
--- @param id string
--- @return string
function p.getName( id )
checkType( 'EvoCreo.getName', 1, id, 'string' )
local words = {}
for word in id:lower():gmatch( '[^_%s]+' ) do
if #words > 0 and smallWords[word] then
table.insert( words, word )
else
table.insert( words, word:sub( 1, 1 ):upper() .. word:sub( 2 ) )
end
end
return table.concat( words, ' ' )
end
--- Get a Creo by name
---
--- We split the CreoTable into individual files for each Creo
--- so we can load them individually.
---
--- @param name string
--- @return table
function p.getCreo( name )
checkType( 'EvoCreo.getCreo', 1, name, 'string' )
local creoData = mw.loadJsonData( 'Module:GameData/EvoCreo/CreoData.json' )
local id = getId( name )
for _, creo in ipairs( creoData ) do
if creo.id == id then
return creo
end
end
end
--- Get a Move by name
---
--- @param name string
--- @return table
function p.getMove( name )
checkType( 'EvoCreo.getMove', 1, name, 'string' )
local moves = mw.loadJsonData( 'Module:GameData/EvoCreo/MoveData.json' )
local id = getId( name )
for _, move in ipairs( moves ) do
if move.id == id then
return move
end
end
end
--- Get a Learnset by move name
---
--- @param name string
--- @return table
function p.getLearnset( name )
checkType( 'EvoCreo.getLearnset', 1, name, 'string' )
local learnsets = mw.loadJsonData( 'Module:GameData/EvoCreo/Learnsets.json' )
for _, learnset in ipairs( learnsets ) do
if learnset.name == name then
return learnset
end
end
end
--- Get an Item by name
---
--- @param name string
--- @return table
function p.getItem( name )
checkType( 'EvoCreo.getItem', 1, name, 'string' )
local items = mw.loadJsonData( 'Module:GameData/EvoCreo/ItemData.json' )
local id = getId( name )
for _, item in ipairs( items ) do
if item.id == id then
return item
end
end
end
--- Get an Ability by name
---
--- @param name string
--- @return table|nil
function p.getAbility( name )
checkType( 'EvoCreo.getAbility', 1, name, 'string' )
local abilities = mw.loadJsonData( 'Module:GameData/EvoCreo/AbilityData.json' )
local id = getId( name )
for _, ability in ipairs( abilities ) do
if ability.id == id then
return ability
end
end
end
--- Get a Trait by name
---
--- @param name string
--- @return table|nil
function p.getTrait( name )
checkType( 'EvoCreo.getTrait', 1, name, 'string' )
local traits = mw.loadJsonData( 'Module:GameData/EvoCreo/TraitData.json' )
local id = getId( name )
for _, trait in ipairs( traits ) do
if trait.id == id then
return trait
end
end
end
return p