ARK: Survival Evolved Wiki
Register
Advertisement

Documentation for this module may be created at Module:DissectDlcItemName/doc

local p = {}
local MAPPING_PATTERNS = {
	-- Add name parts that should be checked to retrieve an icon.
	-- Each entry must have following information:
	-- 1: Pattern to find that will be removed for display. Parenthesis need to be escaped with %.
	-- 2: Icon file name
	-- 3: Link name for the icon
	{' %(The Island%)', 'The Island Icon.png', 'The Island'},
	{' %(Scorched Earth%)', 'Scorched Earth Icon.png', 'Scorched Earth'},
	{' %(Aberration%)', 'Aberration Icon.png', 'Aberration'},
	{' %(Extinction%)', 'Extinction Icon.png', 'Extinction'},
	{' %(Genesis%)', 'Genesis Part 1 Icon.png', 'Genesis'},
	{' %(Genesis: Part 1%)', 'Genesis Part 1 Icon.png', 'Genesis: Part 1'},
	{' %(Genesis: Part 2%)', 'Genesis Part 2 Icon.png', 'Genesis: Part 2'},
	{' %(Primitive Plus%)', 'Primitive Plus Icon.png', 'Primitive Plus'},
	{' %(The Center%)', 'The Center Icon.png', 'The Center'},
	{' %(Ragnarok%)', 'Ragnarok Icon.png', 'Ragnarok'},
	{' %(Valguero%)', 'Valguero Icon.png', 'Valguero'},
	{' %(Crystal Isles%)', 'Crystal Isles Icon.png', 'Crystal Isles'},
	{' %(Lost Island%)', 'Lost Island Icon.png', 'Lost Island'},
	{' %(Mobile%)', 'Logo Mobile.svg', 'ARK: Survival Evolved Mobile'},
	{' %(Fjordur%)', 'Mod Fjordur Icon.png', 'Fjordur'},
	-- MODS
	{'Mod:Ebenus Astrum/', 'Ebenus Astrum Icon.png', 'Mod:Ebenus Astrum'},
	{'Mod:Primal Fear/', 'PrimalFearIcon.png', 'Mod:Primal Fear'},
	{'Mod:Ebenus Astrum/', 'Ebenus Astrum Icon.png', 'Mod:Ebenus Astrum'},
	{'Mod:ARK Additions/', 'ARK Additions Icon.png', 'Mod:ARK Additions'},
	{'Mod:Better MEKs!/', 'Mod Better MEKs! Icon.png', 'Mod:Better MEKs!'},
	{'Mod:Steampunk/', 'Mod Steampunk Icon.png', 'Mod:Steampunk'},
	{'Mod:Structures Plus/', 'Structures Plus Icon.png', 'Mod:Structures Plus'},
	{'Mod:Ark Eternal/', 'Mod Ark Eternal Icon.png', 'Mod:Ark Eternal'},
	{'Mod:Archaic Ascension/', 'Mod Archaic Ascension Icon.png', 'Mod:Archaic Ascension'},
	{'Mod:The Chasm/', 'ChasmLogoSmall.jpg', 'Mod:The Chasm'},
	{'Mod:Primal NPCs/', 'Mod Primal NPCs Icon.png', 'Mod:Primal NPCs'},
	{'Mod:Caballus/', 'Mod Caballus Icon.png', 'Mod:Caballus'},
	{'Mod:Prehistoric Beasts/', 'Mod Prehistoric Beasts Icon.png', 'Mod:Prehistoric Beasts'},
	{'Mod:Castles, Keeps, and Forts Remastered/', 'Mod Castles Keeps Forts Architecture Remastered Icon.png', 'Mod:Castles, Keeps, and Forts Remastered'},
	{'Mod:Crystal Isles Dino Collection/', 'Crystal Isles Dino Collection Icon.png', 'Mod:Crystal Isles Dino Collection'},
	{'Mod:Additional Creatures: Grand Hunt/', 'Additional Creatures Grand Hunt Icon.png', 'Mod:Additional Creatures: Grand Hunt'},
	{'Mod:Super Structures/', 'Mod Super Structures icon.png', 'Mod:Super Structures'},
	{'Mod:ARK: The Sunken World/', 'Mod ARK The Sunken World icon.png', 'Mod:ARK: The Sunken World'},
	{'Mod:Fjordur/', 'Mod Fjordur Icon.png', 'Mod:Fjordur'},
	{'Mod:Glacius/', 'Mod Glacius Icon.png', 'Mod:Glacius'},
	{'Mod:Dino Storage/', 'Blank.png', 'Mod:Dino Storage'},
	{'Mod:The Eärrion/', 'Mod The Eärrion Icon.png', 'Mod:The Eärrion'},
}
local EXTRA_DLC_NAMES = {
	-- Add alternative DLC names to look for when querying for a DLC icon with
	-- no item name.
	-- This is a "from-to" mapping. The right side should match a single
	-- entry in MAPPING_PATTERNS by their third value. Left side should be lower-case.
	["island"] = "The Island",
	["center"] = "The Center",
	["scorched"] = "Scorched Earth",
	["primitive"] = "Primitive Plus",
	["mobile"] = "ARK: Survival Evolved Mobile",
	["s+"] = "Mod:Structures Plus",
	["better meks"] = "Mod:Better MEKs!",
}

-- Helper function to use within other Lua modules to dissect an item name into
-- display name, DLC icon and DLC article.
-- Returns nil if DLC suffix is missing or unrecognized.
function p.tryMatch(name)
	for _, entry in ipairs(MAPPING_PATTERNS) do
		if string.find(name, entry[1]) ~= nil then
			return {
				["displayName"] = string.gsub(name, entry[1], ''),
				["dlcIcon"] = entry[2],
				["dlcArticle"] = entry[3]
			}
		end
	end
	return nil
end

-- Helper function for wiki templates to dissect item names into variables.
-- Sets every variable to nothing if DLC suffix is missing or unrecognized.
-- Accepts five parameters:
-- 1: Item name
-- 2: Variable name for the display name
-- 3: Variable name for the DLC icon file name
-- 4: Variable name for the DLC article name
function p.tryMatchW(frame)
	local args = frame.args
	local result = p.tryMatch(args[1])
	local varDisplayName = args[2]
	local varDlcIcon = args[3]
	local varDlcArticle = args[4]
	
	local displayName = result and result.displayName or ''
	local dlcIcon = result and result.dlcIcon or ''
	local dlcArticle = result and result.dlcArticle or ''

	frame:callParserFunction( '#vardefine', varDisplayName, displayName )
	frame:callParserFunction( '#vardefine', varDlcIcon, dlcIcon )
	frame:callParserFunction( '#vardefine', varDlcArticle, dlcArticle )

	return ''
end

-- Helper function for wiki templates to get an icon name for a DLC.
-- Sets every variable to nothing if DLC suffix is missing or unrecognized.
-- Accepts three parameters:
-- 1: DLC name
-- 2: Variable name for the DLC icon file name
-- 3: Variable name for the DLC article name
function p.getIcon(frame)
	local args = frame.args
	local dlc = mw.text.trim(mw.ustring.lower(args[1]))
	local varDlcIcon = args[2]
	local varDlcArticle = args[3]

	if EXTRA_DLC_NAMES[dlc] then
		dlc = mw.ustring.lower(EXTRA_DLC_NAMES[dlc])
	end

	local dlcIcon = ''
	local dlcArticle = ''

	for _, entry in ipairs(MAPPING_PATTERNS) do
		local third = mw.ustring.lower(entry[3])
		if dlc == third or (string.sub(third, 1, 4) == 'mod:' and 'mod:'..dlc == third) then
			dlcIcon = entry[2]
			dlcArticle = entry[3]
			break
		end
	end

	frame:callParserFunction( '#vardefine', varDlcIcon, dlcIcon )
	frame:callParserFunction( '#vardefine', varDlcArticle, dlcArticle )

	return ''
end

return p
Advertisement