Module:Creo/Components/LevelMoves
Appearance
This documentation is transcluded from Module:Creo/Components/LevelMoves/doc.
Output the level moves table for Module:Creo using Module:TableLua.
require( 'strict' )
local gameTabs = require( 'Module:GameTabs' )
local tableLua = require( 'Module:TableLua' )
local element = require( 'Module:Element' )._main
local level = require( 'Module:Level' )._main
local energy = require( 'Module:Energy' )._main
local nameCell = require( 'Module:Creo/NameCell' ).render
local getMoveArticle = require( 'Module:Move' ).getArticle
local getMoveThumbnail = require( 'Module:Move' ).getThumbnail
local ecGameData = require( 'Module:GameData/EvoCreo' )
local p = {}
--- @param levelNum number
--- @return string
local function getLevelWikitext( levelNum )
-- HACK: Create a hidden element so that Module:TableLua can sort by level
-- We need this because we are passing HTML in getRows()
local sort = mw.html.create( 'span' )
sort
:attr( 'hidden', 'true' )
:css( 'display', 'none' )
:wikitext( tostring( levelNum ) )
return tostring( sort ) .. ' ' .. level( levelNum )
end
--- Both games have their own move art, so the icon follows the tab it is shown
--- on rather than always using the EvoCreo 2 artwork.
---
--- @param name string
--- @param gameId string
--- @return string
local function getMoveWikitext( name, gameId )
return nameCell( getMoveThumbnail( name, gameId ), getMoveArticle( name ), name )
end
--- @param gameId string
--- @return TableColumn[]
local function getColumns( gameId )
if gameId == 'evocreo2' then
return {
{ id = 'level', label = 'Level' },
{ id = 'name', label = 'Name' },
{ id = 'element', label = 'Element' },
{ id = 'category', label = 'Category' },
{ id = 'type', label = 'Type' },
{ id = 'power', label = 'Power', textAlign = 'number' },
{ id = 'accuracy', label = 'Accuracy', textAlign = 'number' },
{ id = 'energy', label = 'Energy', textAlign = 'number' }
}
elseif gameId == 'evocreo' then
return {
{ id = 'level', label = 'Level' },
{ id = 'name', label = 'Name' },
{ id = 'element', label = 'Element' },
{ id = 'category', label = 'Category' },
{ id = 'type', label = 'Type' },
{ id = 'power', label = 'Power', textAlign = 'number' },
{ id = 'accuracy', label = 'Accuracy', textAlign = 'number' },
-- EvoCreo moves take a number of turns to recharge; they do not
-- consume energy the way EvoCreo 2 moves do.
{ id = 'recharge', label = 'Recharge', textAlign = 'number' }
}
end
return {}
end
--- @param data table
--- @param gameId string
--- @return TableRow[]
local function getRows( data, gameId )
local rows = {}
if gameId == 'evocreo2' then
for _, moveMap in ipairs( data ) do
if moveMap.level ~= nil then
local row = {
getLevelWikitext( moveMap.level ),
getMoveWikitext( moveMap.move.name, gameId ),
element( moveMap.move.element.name ),
moveMap.move.moveClass.name,
moveMap.move.moveType.name,
moveMap.move.damage,
string.format( '%d %%', moveMap.move.accuracy ),
energy( moveMap.move.recharge )
}
table.insert( rows, row )
end
end
elseif gameId == 'evocreo' then
for _, move in ipairs( data ) do
if move.level ~= nil then
local moveData = ecGameData.getMove( move.id )
if moveData ~= nil then
local row = {
getLevelWikitext( move.level ),
getMoveWikitext( ecGameData.getName( move.id ), gameId ),
element( moveData.element ),
moveData.type or '-',
moveData.skilltype or '-',
moveData.basedamage,
string.format( '%d %%', tonumber( moveData.accuracy or 1 ) * 100 ),
energy( moveData.recharge )
}
table.insert( rows, row )
end
end
end
end
return rows
end
--- @param data table
--- @param gameId string
--- @return TableProps
local function getTableProps( data, gameId )
return {
caption = 'Level moves',
hideCaption = true,
columns = getColumns( gameId ),
data = getRows( data, gameId ),
sort = {
level = 'asc',
},
class = table.concat( {
't-creo-level-moves-table',
'wikitable--fluid' -- Citizen built-in class for broad tables
}, ' ' )
}
end
--- @param gameData table
--- @param gameId string
--- @return string
local function getGameTabWikitext( gameData, gameId )
local html = mw.html.create( 'div' ):addClass( 't-tabbedCard-table-container' )
html:wikitext( tableLua.render( getTableProps( gameData, gameId ) ) )
return tostring( html )
end
--- @param data table
--- @return mw.html
local function getLevelMovesHtml( data )
local html = mw.html.create( 'div' ):addClass( 't-creo-level-moves' )
local gameTabsData = gameTabs.mapGameArgs( data, function ( gameData, game )
return getGameTabWikitext( gameData, game.id )
end )
gameTabsData.noPadding = true
html:wikitext( gameTabs._main( gameTabsData ) )
return html
end
--- @param context ComponentContext
--- @return string
function p.render( context )
return tostring( getLevelMovesHtml( context.data ) )
end
return p