Documentation for this module may be created at Module:Infobox spawn command section/doc
local p = {}
function copyClipboard( contents )
return '<span class="copy-clipboard"><span class="copy-content" style="font-family:Courier,monospace;">' .. contents .. '</span></span>'
end
function getExampleCommand( isEntity, identifier, short )
if isEntity then
if short then
return 'admincheat summon ' .. identifier
end
return 'admincheat SpawnDino {{BlueprintPath|' .. identifier .. '}} 500 0 0 35'
else
if short then
return 'admincheat gfi ' .. identifier .. ' 1 0 0'
end
return 'admincheat giveitem {{BlueprintPath|' .. identifier .. '}} 1 0 0'
end
end
function makeCommandSet (isEntity, blueprintPath, entityClassName, shortItemName)
local commands = ''
local canShowSummon = isEntity and entityClassName ~= nil
local canShowGFI = not isEntity and shortItemName ~= nil
-- Loose, short commands
if canShowSummon then
commands = copyClipboard(getExampleCommand(true, entityClassName, true))
elseif canShowGFI then
commands = copyClipboard(getExampleCommand(false, shortItemName, true))
end
-- "or" between the two forms
if blueprintPath and (canShowSummon or canShowGFI) then
commands = commands .. '<br/><b>or</b><br/>'
end
-- Strict, BP-reliant command
if blueprintPath then
if isEntity then
commands = commands .. copyClipboard(getExampleCommand(true, blueprintPath, false))
else
commands = commands .. copyClipboard(getExampleCommand(true, blueprintPath, false))
end
end
return commands
end
function p.spawnCommand( f )
local args = f.args
local parentArgs = f:getParent().args
-- Infobox arguments
local blueprintPath = parentArgs.blueprintpath or nil
local entityClassName = parentArgs.entityId or nil
local shortItemName = parentArgs.gfi or nil
local isBaseClassIncomplete = parentArgs.incompleteBaseClass == 'yes' or false
-- Check if type is specified
if args.type == nil then
return 'error: "type" has to be specified (creature or item) for spawn command section to be generated'
end
-- Own hardcoded arguments
local isEntity = args.type == 'creature'
local captionLinkTarget = args.linkTarget or ''
-- Display flags
local canShowSummon = isEntity and entityClassName ~= nil
local canShowGFI = not isEntity and shortItemName ~= nil
-- Variable for generated commands text
local commands = ''
-- Main class
if (not isBaseClassIncomplete) and (blueprintPath or entityId or shortItemName) then
commands = makeCommandSet(isEntity, blueprintPath, entityClassName, shortItemName)
end
-- Collect variants
local variants = {}
for argName, argValue in pairs(parentArgs) do
argName = mw.text.trim(argName)
local variantName = nil
local isBP = false
-- Detect if this parameter is a BP/short ID
if mw.ustring.find(argName, 'blueprintpath ', 0, true) == 1 then
variantName = mw.ustring.sub(argName, 14)
isBP = true
elseif isEntity and mw.ustring.find(argName, 'entityId ', 0, true) == 1 then
variantName = mw.ustring.sub(argName, 9)
elseif (not isEntity) and mw.ustring.find(argName, 'gfi ', 0, true) == 1 then
variantName = mw.ustring.sub(argName, 4)
end
-- Save the value.
if variantName ~= nil and #variantName > 0 then
if variants[variantName] == nil then
variants[variantName] = {}
end
if isBP then
variants[variantName]['bp'] = mw.text.trim(argValue)
else
variants[variantName]['short'] = mw.text.trim(argValue)
end
end
end
-- Generate commands for variants
for variantName, spawnInfo in pairs(variants) do
commands = commands .. '<br/><span style="font-size:1.1em;font-weight:bold;">Variant ' .. variantName .. '</span><br/>'
commands = commands .. makeCommandSet(isEntity, spawnInfo['bp'], spawnInfo['short'], spawnInfo['short'])
end
-- Return nothing if no command was generated
if not commands then
return ''
end
local out = '<div class="info-arkitex info-module">'
.. '<div class="info-arkitex info-unit">'
.. '<div class="info-arkitex info-X1-100">'
.. '<div style="text-align:left; padding:0 8px 0 8px;" class="mw-collapsible mw-collapsed">' .. "'''[[" .. captionLinkTarget .. "|Spawn Command]]'''"
.. '<div class="mw-collapsible-content" style="text-align:left;font-size:0.8em;word-wrap:break-word;width:310px">'
.. commands
.. '</div>'
.. '</div>'
.. '</div>'
.. '</div>'
.. '</div>'
return f:preprocess(out)
end
return p