ARK: Survival Evolved Wiki
(Page créée avec « local p = {} function copyClipboard( contents ) return '<span class="copy-clipboard"><span class="copy-content" style="font-family:Courier,monospace;">' .. contents .. '... »)
 
(Màj)
 
(3 révisions intermédiaires par 2 utilisateurs non affichées)
Ligne 1 : Ligne 1 :
  +
local Utility = require('Module:Utility')
  +
 
local p = {}
 
local p = {}
  +
   
 
function copyClipboard( contents )
 
function copyClipboard( contents )
Ligne 5 : Ligne 8 :
 
end
 
end
   
  +
function getExampleCommand( isEntity, identifier, short )
 
  +
function getExampleShortCommand( isEntity, identifier )
 
if isEntity then
 
if isEntity then
 
return 'cheat summon ' .. identifier
if short then
 
return 'admincheat summon ' .. identifier
 
end
 
 
return 'admincheat SpawnDino {{BlueprintPath|' .. identifier .. '}} 500 0 0 35'
 
 
else
 
else
 
return 'cheat gfi ' .. identifier .. ' 1 0 0'
if short then
 
return 'admincheat gfi ' .. identifier .. ' 1 0 0'
 
end
 
 
return 'admincheat giveitem {{BlueprintPath|' .. identifier .. '}} 1 0 0'
 
 
end
 
end
 
end
 
end
   
  +
function makeCommandSet (isEntity, blueprintPath, entityClassName, shortItemName)
 
 
function getExampleBPCommand( isEntity, identifier, short )
 
if isEntity then
 
return 'cheat SpawnDino {{BlueprintPath|' .. identifier .. '}} 500 0 0 35'
  +
else
 
return 'cheat giveitem {{BlueprintPath|' .. identifier .. '}} 1 0 0'
 
end
 
end
  +
  +
  +
function getTekgramUnlockCommand( bp )
  +
return 'cheat unlockengram {{BlueprintPath|' .. bp .. '}}'
 
end
  +
  +
function getIdBasedItemCommand( identifier )
  +
return 'cheat giveitemnum ' .. identifier .. ' 1 0 0'
  +
end
  +
  +
 
function makeCommandSet (isEntity, blueprintPath, entityClassName, shortItemName, tekgramBP, itemId)
  +
local OR = '<br/><b>ou</b><br/>'
 
 
local commands = ''
 
local commands = ''
 
local canShowSummon = isEntity and entityClassName ~= nil
 
local canShowSummon = isEntity and entityClassName ~= nil
 
local canShowGFI = not isEntity and shortItemName ~= nil
 
local canShowGFI = not isEntity and shortItemName ~= nil
  +
  +
-- ID-based item command
  +
if not isEntity and itemId then
  +
commands = copyClipboard(getIdBasedItemCommand(itemId))
  +
if blueprintPath or shortItemName then
  +
commands = commands .. OR
 
end
  +
end
 
 
 
-- Loose, short commands
 
-- Loose, short commands
 
if canShowSummon then
 
if canShowSummon then
commands = copyClipboard(getExampleCommand(true, entityClassName, true))
+
commands = commands .. copyClipboard(getExampleShortCommand(true, entityClassName))
 
elseif canShowGFI then
 
elseif canShowGFI then
commands = copyClipboard(getExampleCommand(false, shortItemName, true))
+
commands = commands .. copyClipboard(getExampleShortCommand(false, shortItemName))
 
end
 
end
 
 
 
-- "or" between the two forms
 
-- "or" between the two forms
 
if blueprintPath and (canShowSummon or canShowGFI) then
 
if blueprintPath and (canShowSummon or canShowGFI) then
commands = commands .. '<br/><b>or</b><br/>'
+
commands = commands .. OR
 
end
 
end
 
 
 
-- Strict, BP-reliant command
 
-- Strict, BP-reliant command
 
if blueprintPath then
 
if blueprintPath then
commands = commands .. copyClipboard(getExampleCommand(isEntity, blueprintPath, false))
+
commands = commands .. copyClipboard(getExampleBPCommand(isEntity, blueprintPath))
  +
end
  +
  +
if tekgramBP then
  +
commands = commands .. '<br/><b>Déverrouille les [[Tekgramme]]s</b><br/>'
  +
.. copyClipboard(getTekgramUnlockCommand(tekgramBP))
 
end
 
end
 
 
 
return commands
 
return commands
 
end
 
end
  +
  +
  +
function guardStringArgument( args, name )
  +
local v = args[name] or nil
 
if v ~= nil then
 
v = mw.text.trim(v)
 
if #v == 0 then
  +
v = nil
 
end
  +
end
  +
return v
  +
end
  +
   
 
function p.spawnCommand( f )
 
function p.spawnCommand( f )
Ligne 50 : Ligne 93 :
 
local parentArgs = f:getParent().args
 
local parentArgs = f:getParent().args
   
-- Infobox arguments
+
-- Infobox arguments
local blueprintPath = parentArgs.blueprintpath or nil
+
local blueprintPath = guardStringArgument(parentArgs, 'blueprintpath')
local entityClassName = parentArgs.entityId or nil
+
local entityClassName = guardStringArgument(parentArgs, 'entityId')
local shortItemName = parentArgs.gfi or nil
+
local shortItemName = guardStringArgument(parentArgs, 'gfi')
  +
local tekgram = guardStringArgument(parentArgs, 'tekgram')
local isBaseClassIncomplete = parentArgs.incompleteBaseClass == 'yes' or parentArgs.incompleteData == 'yes' or false
 
  +
local itemId = guardStringArgument(parentArgs, 'itemid')
 
local incompleteBaseClassArg = parentArgs.incompleteBaseClass or parentArgs.incompleteData or args.baseClassIsTemplate
  +
local isBaseClassIncomplete = incompleteBaseClassArg ~= nil and incompleteBaseClassArg:lower() == 'yes' or false
  +
local baseNote = guardStringArgument(parentArgs, 'spawncommandnote')
 
 
 
-- Check if type is specified
 
-- Check if type is specified
 
if args.type == nil then
 
if args.type == nil then
return 'error: "type" has to be specified (creature or item) for spawn command section to be generated'
+
return 'error: "type" doit être spécifié (creature ou item) pour que la section de commande d\'invocation soit générée'
end
 
 
-- Trim blueprint path and short identifiers
 
if blueprintpath ~= nil then
 
blueprintpath = mw.text.trim(blueprintpath)
 
end
 
if entityClassName ~= nil then
 
entityClassName = mw.text.trim(entityClassName)
 
end
 
if shortItemName ~= nil then
 
shortItemName = mw.text.trim(shortItemName)
 
 
end
 
end
 
 
Ligne 79 : Ligne 115 :
 
-- Fill in info from variables set by Dv if creature
 
-- Fill in info from variables set by Dv if creature
 
if isEntity then
 
if isEntity then
if blueprintPath == nil or #blueprintPath == 0 then
+
if blueprintPath == nil then
 
blueprintPath = f:preprocess('{{#var:blueprintpath}}')
 
blueprintPath = f:preprocess('{{#var:blueprintpath}}')
 
end
 
end
if entityClassName == nil or #entityClassName == 0 then
+
if entityClassName == nil then
 
entityClassName = f:preprocess('{{#var:entityId}}')
 
entityClassName = f:preprocess('{{#var:entityId}}')
 
end
 
end
  +
-- Reduce to null if empty.
  +
if blueprintPath == '' then
  +
blueprintPath = nil
  +
end
 
if entityClassName == '' then
  +
entityClassName = nil
  +
end
  +
end
  +
  +
-- Remove object descriptor elements from the blueprint path if one is valid.
 
if blueprintPath ~= nil then
  +
blueprintPath = Utility.getUnqualifiedBlueprintPath(blueprintPath)
  +
end
  +
  +
-- Auto-generate class name for entities
  +
if isEntity and entityClassName == nil and blueprintPath ~= nil then
  +
entityClassName = Utility.getBlueprintClassName(blueprintPath, true)
 
end
 
end
 
 
Ligne 96 : Ligne 149 :
 
-- Main class
 
-- Main class
 
if (not isBaseClassIncomplete) and (blueprintPath or entityId or shortItemName) then
 
if (not isBaseClassIncomplete) and (blueprintPath or entityId or shortItemName) then
commands = makeCommandSet(isEntity, blueprintPath, entityClassName, shortItemName)
+
commands = makeCommandSet(isEntity, blueprintPath, entityClassName, shortItemName, tekgram, itemId)
  +
if baseNote ~= nil then
  +
commands = baseNote .. '\n' .. commands
  +
end
 
end
 
end
 
 
 
-- Initialize variants from variantOrderList
 
-- Initialize variants from variantOrderList
  +
-- We use an external list provided by the template to retain order of the variants.
 
local variants = {}
 
local variants = {}
 
local variantOrder = {}
 
local variantOrder = {}
Ligne 111 : Ligne 168 :
 
end
 
end
 
 
-- Collect variants
+
-- Collect variants (and their details) from arguments
 
for argName, argValue in pairs(parentArgs) do
 
for argName, argValue in pairs(parentArgs) do
 
argName = mw.text.trim(argName)
 
argName = mw.text.trim(argName)
Ligne 127 : Ligne 184 :
 
end
 
end
 
 
-- Save the value.
 
 
if variantName ~= nil then
 
if variantName ~= nil then
 
variantName = mw.text.trim(variantName)
 
variantName = mw.text.trim(variantName)
 
if #variantName > 0 then
 
if #variantName > 0 then
  +
-- Ensure the variant is initialized.
 
if variants[variantName] == nil then
 
if variants[variantName] == nil then
 
variants[variantName] = {}
 
variants[variantName] = {}
Ligne 136 : Ligne 193 :
 
end
 
end
 
 
 
-- Save the value.
 
if isBP then
 
if isBP then
variants[variantName]['bp'] = mw.text.trim(argValue)
+
local tempVariantBP = mw.text.trim(argValue)
  +
if tempVariantBP ~= nil then
  +
-- Remove object descriptor from the blueprint path.
  +
tempVariantBP = Utility.getUnqualifiedBlueprintPath(tempVariantBP)
  +
end
  +
variants[variantName]['bp'] = tempVariantBP
 
else
 
else
 
variants[variantName]['short'] = mw.text.trim(argValue)
 
variants[variantName]['short'] = mw.text.trim(argValue)
Ligne 146 : Ligne 209 :
 
 
 
-- Generate commands for variants
 
-- Generate commands for variants
  +
local firstRendered = isBaseClassIncomplete
for _, variantName in ipairs(variantOrder) do
+
for index, variantName in ipairs(variantOrder) do
 
local spawnInfo = variants[variantName]
 
local spawnInfo = variants[variantName]
  +
-- Auto-generate class name for entities
if spawnInfo['bp'] or spawnInfo['short'] then
 
  +
if isEntity and spawnInfo.bp and not spawnInfo.short then
commands = commands .. '<br/><span style="font-size:1.1em;font-weight:bold;">Variant ' .. variantName .. '</span><br/>'
 
  +
spawnInfo.short = Utility.getBlueprintClassName(spawnInfo.bp, true)
commands = commands .. makeCommandSet(isEntity, spawnInfo['bp'], spawnInfo['short'], spawnInfo['short'])
 
  +
end
 
 
if spawnInfo.bp or spawnInfo.short then
  +
if not firstRendered then
  +
commands = commands .. '<br/>'
  +
end
  +
firstRendered = false
 
commands = commands .. '<span style="font-size:1.1em;font-weight:bold;">Variante ' .. variantName .. '</span><br/>'
 
commands = commands .. makeCommandSet(isEntity, spawnInfo.bp, spawnInfo.short, spawnInfo.short)
 
end
 
end
 
end
 
end
   
 
-- Return nothing if no command was generated
 
-- Return nothing if no command was generated
if not commands then
+
if #commands == 0 then
 
return ''
 
return ''
 
end
 
end
Ligne 162 : Ligne 235 :
 
.. '<div class="info-arkitex info-unit">'
 
.. '<div class="info-arkitex info-unit">'
 
.. '<div class="info-arkitex info-X1-100">'
 
.. '<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 style="text-align:left; padding:0 8px 0 8px;" class="mw-collapsible mw-collapsed">' .. "'''[[" .. captionLinkTarget .. "|Commande]]'''"
 
.. '<div class="mw-collapsible-content" style="text-align:left;font-size:0.8em;word-wrap:break-word;width:310px">'
 
.. '<div class="mw-collapsible-content" style="text-align:left;font-size:0.8em;word-wrap:break-word;width:310px">'
 
.. commands
 
.. commands
Ligne 172 : Ligne 245 :
 
return f:preprocess(out)
 
return f:preprocess(out)
 
end
 
end
  +
   
 
return p
 
return p

Version actuelle datée du 29 décembre 2021 à 07:08


local Utility = require('Module:Utility')

local p = {}


function copyClipboard( contents )
	return '<span class="copy-clipboard"><span class="copy-content" style="font-family:Courier,monospace;">' .. contents .. '</span></span>'
end


function getExampleShortCommand( isEntity, identifier )
	if isEntity then
		return 'cheat summon ' .. identifier
	else
		return 'cheat gfi ' .. identifier .. ' 1 0 0'
	end
end


function getExampleBPCommand( isEntity, identifier, short )
	if isEntity then
		return 'cheat SpawnDino {{BlueprintPath|' .. identifier .. '}} 500 0 0 35'
	else
		return 'cheat giveitem {{BlueprintPath|' .. identifier .. '}} 1 0 0'
	end
end


function getTekgramUnlockCommand( bp )
	return 'cheat unlockengram {{BlueprintPath|' .. bp .. '}}'
end

function getIdBasedItemCommand( identifier )
	return 'cheat giveitemnum ' .. identifier .. ' 1 0 0'
end


function makeCommandSet (isEntity, blueprintPath, entityClassName, shortItemName, tekgramBP, itemId)
	local OR = '<br/><b>ou</b><br/>'
	
	local commands = ''
	local canShowSummon = isEntity and entityClassName ~= nil
	local canShowGFI = not isEntity and shortItemName ~= nil
	
	-- ID-based item command
	if not isEntity and itemId then
		commands = copyClipboard(getIdBasedItemCommand(itemId))
		if blueprintPath or shortItemName then
			commands = commands .. OR
		end
	end
	
	-- Loose, short commands
	if canShowSummon then
		commands = commands .. copyClipboard(getExampleShortCommand(true, entityClassName))
	elseif canShowGFI then
		commands = commands .. copyClipboard(getExampleShortCommand(false, shortItemName))
	end
		
	-- "or" between the two forms
	if blueprintPath and (canShowSummon or canShowGFI) then
		commands = commands .. OR
	end
		
	-- Strict, BP-reliant command
	if blueprintPath then
		commands = commands .. copyClipboard(getExampleBPCommand(isEntity, blueprintPath))
	end
	
	if tekgramBP then
		commands = commands .. '<br/><b>Déverrouille les [[Tekgramme]]s</b><br/>'
				   .. copyClipboard(getTekgramUnlockCommand(tekgramBP))
	end
	
	return commands
end


function guardStringArgument( args, name )
	local v = args[name] or nil
	if v ~= nil then
		v = mw.text.trim(v)
		if #v == 0 then
			v = nil
		end
	end
	return v
end


function p.spawnCommand( f )
	local args = f.args
	local parentArgs = f:getParent().args

-- Infobox arguments
	local blueprintPath = guardStringArgument(parentArgs, 'blueprintpath')
	local entityClassName = guardStringArgument(parentArgs, 'entityId')
	local shortItemName = guardStringArgument(parentArgs, 'gfi')
	local tekgram = guardStringArgument(parentArgs, 'tekgram')
	local itemId = guardStringArgument(parentArgs, 'itemid')
	local incompleteBaseClassArg = parentArgs.incompleteBaseClass or parentArgs.incompleteData or args.baseClassIsTemplate
	local isBaseClassIncomplete = incompleteBaseClassArg ~= nil and incompleteBaseClassArg:lower() == 'yes' or false
	local baseNote = guardStringArgument(parentArgs, 'spawncommandnote')
	
	-- Check if type is specified
	if args.type == nil then
		return 'error: "type" doit être spécifié (creature ou item) pour que la section de commande d\'invocation soit générée'
	end
	
	-- Own hardcoded arguments
	local isEntity = args.type == 'creature'
	local captionLinkTarget = args.linkTarget or ''
	local variantOrderList = args.variantOrder or ''
	
	-- Fill in info from variables set by Dv if creature
	if isEntity then
		if blueprintPath == nil then
			blueprintPath = f:preprocess('{{#var:blueprintpath}}')
		end
		if entityClassName == nil then
			entityClassName = f:preprocess('{{#var:entityId}}')
		end
		-- Reduce to null if empty.
		if blueprintPath == '' then
			blueprintPath = nil
		end
		if entityClassName == '' then
			entityClassName = nil
		end
	end
	
	-- Remove object descriptor elements from the blueprint path if one is valid.
	if blueprintPath ~= nil then
		blueprintPath = Utility.getUnqualifiedBlueprintPath(blueprintPath)
	end
	
	-- Auto-generate class name for entities
	if isEntity and entityClassName == nil and blueprintPath ~= nil then
		entityClassName = Utility.getBlueprintClassName(blueprintPath, true)
	end
	
	-- 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, tekgram, itemId)
	if baseNote ~= nil then
			commands = baseNote .. '\n' .. commands
		end
	end
	
	-- Initialize variants from variantOrderList
	-- We use an external list provided by the template to retain order of the variants.
	local variants = {}
	local variantOrder = {}
	if variantOrderList ~= '' then
		for _, variantName in ipairs(mw.text.split(variantOrderList, ';')) do
			if variants[variantName] == nil then
				variants[variantName] = {}
				table.insert(variantOrder, variantName)
			end
		end
	end
	
	-- Collect variants (and their details) from arguments
	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
		
		if variantName ~= nil then
			variantName = mw.text.trim(variantName)
			if #variantName > 0 then
				-- Ensure the variant is initialized.
				if variants[variantName] == nil then
					variants[variantName] = {}
					table.insert(variantOrder, variantName)
				end
			
				-- Save the value.
				if isBP then
					local tempVariantBP = mw.text.trim(argValue)
					if tempVariantBP ~= nil then
						-- Remove object descriptor from the blueprint path.
						tempVariantBP = Utility.getUnqualifiedBlueprintPath(tempVariantBP)
					end
					variants[variantName]['bp'] = tempVariantBP
				else
					variants[variantName]['short'] = mw.text.trim(argValue)
				end
			end
		end
	end
	
	-- Generate commands for variants
	local firstRendered = isBaseClassIncomplete
	for index, variantName in ipairs(variantOrder) do
		local spawnInfo = variants[variantName]
		-- Auto-generate class name for entities
		if isEntity and spawnInfo.bp and not spawnInfo.short then
			spawnInfo.short = Utility.getBlueprintClassName(spawnInfo.bp, true)
		end
		
		if spawnInfo.bp or spawnInfo.short then
			if not firstRendered then
				commands = commands .. '<br/>'
			end
			firstRendered = false
			commands = commands .. '<span style="font-size:1.1em;font-weight:bold;">Variante ' .. variantName .. '</span><br/>'
			commands = commands .. makeCommandSet(isEntity, spawnInfo.bp, spawnInfo.short, spawnInfo.short)
		end
	end

	-- Return nothing if no command was generated
	if #commands == 0 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 .. "|Commande]]'''"
				    	 .. '<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