Jump to content

Module:GameData/EvoCreo2

From Creopedia

This documentation is transcluded from Module:GameData/EvoCreo2/doc.

Contains raw game data for EvoCreo2.

List of pages


require( 'strict' )

local checkType = require( 'libraryUtil' ).checkType

local p = {}

--- Decode an Apiunto response body into the EvoCreo 2 creoTable array.
--- Pure (no network) so it is unit-testable with fixtures. Returns the
--- creoTable array, or nil when the body is nil/empty, the Apiunto error
--- sentinel, not valid JSON, or missing a `creoTable` array.
---
--- @param body string|nil
--- @return table|nil
function p.decodeCreoTable( body )
	if type( body ) ~= 'string' or body == '' then
		return nil
	end

	local ok, data = pcall( mw.text.jsonDecode, body )
	if ok and type( data ) == 'table' and type( data.creoTable ) == 'table' then
		return data.creoTable
	end

	return nil
end

--- Find a Creo by name within a creoTable array. Pure.
---
--- @param list table|nil
--- @param name string
--- @return table|nil
function p.findCreo( list, name )
	if list == nil then
		return nil
	end

	for _, creo in ipairs( list ) do
		if creo.name == name then
			return creo
		end
	end

	return nil
end

--[==[ DISABLED: live API-backed creoTable fetch.
Decoding the full getGameData payload (~5.2 MB) per render (~29 MB Lua) exceeds
Scribunto's memory limit on full Creo article renders (the infobox renders, but
the per-section components error with "not enough memory"). Kept for future
reuse alongside the pure decodeCreoTable/findCreo above. To re-enable: uncomment
this block and change getCreo to `return p.findCreo( fetchCreoTable(), name )`.
See docs/superpowers/specs/2026-05-30-creo-api-data-design.md.

--- Cached creoTable array (nil until a successful fetch).
local creoTable
--- Whether a fetch has been attempted this render (success or failure).
local creoTableFetched = false

--- Fetch and decode the full creoTable from the ilmfinity API via Apiunto.
--- @return table|nil
local function fetchCreoTable()
	if creoTableFetched then
		return creoTable
	end
	creoTableFetched = true

	creoTable = p.decodeCreoTable( mw.ext.Apiunto.fetch( 'evocreo2', 'getGameData' ) )

	return creoTable
end
]==]

--- Get a Creo by name
---
--- Loads the per-Creo data from the static CreoTable JSON pages, regenerated
--- from the ilmfinity API (getGameData) by scripts/sync_creo_table.py.
---
--- @param name string
--- @return table|nil
function p.getCreo( name )
	checkType( 'EvoCreo2.getCreo', 1, name, 'string' )

	return mw.loadJsonData( 'Module:GameData/EvoCreo2/CreoTable/' .. name .. '.json' )
end

--- Get the Creo evolution index
---
--- Maps every Creo that evolves to its evolutions, each carrying the condition
--- that triggers it (`level`, or `element` for an affinity evolution). Only
--- that direction is stored, because the reverse is a single pass over the same
--- table and carrying a parent for all 339 Creo would be most of the page.
---
--- Regenerated from the export by .claude/tools/evolutions.py.
---
--- @return table
function p.getEvolutionIndex()
	return mw.loadJsonData( 'Module:GameData/EvoCreo2/EvolutionIndex.json' )
end


--- Get a Move by name
---
--- @param name string
--- @return table|nil
function p.getMove( name )
	checkType( 'EvoCreo2.getMove', 1, name, 'string' )

	local moves = mw.loadJsonData( 'Module:GameData/EvoCreo2/MoveTable.json' )

	for _, move in ipairs( moves ) do
		if move.name == name then
			return move
		end
	end
end

--- Get a Learnset by move name
---
--- @param name string
--- @return table|nil
function p.getLearnset( name )
	checkType( 'EvoCreo2.getLearnset', 1, name, 'string' )

	local learnsets = mw.loadJsonData( 'Module:GameData/EvoCreo2/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|nil
function p.getItem( name )
	checkType( 'EvoCreo2.getItem', 1, name, 'string' )

	local items = mw.loadJsonData( 'Module:GameData/EvoCreo2/ItemTable.json' )

	for _, item in ipairs( items ) do
		if item.name == name then
			return item
		end
	end
end

--- Get an Item by id
---
--- @param id number
--- @return table|nil
function p.getItemById( id )
	checkType( 'EvoCreo2.getItemById', 1, id, 'number' )

	local items = mw.loadJsonData( 'Module:GameData/EvoCreo2/ItemTable.json' )

	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( 'EvoCreo2.getAbility', 1, name, 'string' )

	local abilities = mw.loadJsonData( 'Module:GameData/EvoCreo2/AbilityTable.json' )

	for _, ability in ipairs( abilities ) do
		if ability.name == name then
			return ability
		end
	end
end

--- Get a Trait by name
---
--- @param name string
--- @return table|nil
function p.getTrait( name )
	checkType( 'EvoCreo2.getTrait', 1, name, 'string' )

	local traits = mw.loadJsonData( 'Module:GameData/EvoCreo2/TraitTable.json' )

	for _, trait in ipairs( traits ) do
		if trait.name == name then
			return trait
		end
	end
end

--- Get a Rarity by id
---
--- @param rarityId number
--- @return table|nil
function p.getRarityById( rarityId )
	checkType( 'EvoCreo2.getRarityById', 1, rarityId, 'number' )

	local rarities = mw.loadJsonData( 'Module:GameData/EvoCreo2/RarityTable.json' )

	for _, rarity in ipairs( rarities ) do
		if rarity.id == rarityId then
			return rarity
		end
	end
end

--- Get a Creo Type by name
---
--- @param name string
--- @return table|nil
function p.getCreoType( name )
	checkType( 'EvoCreo2.getCreoType', 1, name, 'string' )

	local creoTypes = mw.loadJsonData( 'Module:GameData/EvoCreo2/CreoTypeTable.json' )

	for _, creoType in ipairs( creoTypes ) do
		if creoType.name == name then
			return creoType
		end
	end
end

return p