Модуль:DissectDlcItemName

Материал из ARK Wiki
Перейти к навигации Перейти к поиску

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'},
	{' %(Genesis: Часть 1%)', 'Genesis Part 1 Icon.png', 'Genesis: Часть 1'},
	{' %(Genesis: Часть 2%)', 'Genesis Part 2 Icon.png', 'Genesis: Часть 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'},
	{' %(Fjordur%)', 'Fjordur Icon.png', 'Fjordur'},
	{' %(The Survival of the Fittest%)', 'Tsotf icon.png', 'The Survival of the Fittest'},
	{' %(Survival Ascended%)', 'ARK Survival Ascended.png', 'ARK: Survival Ascended'},
	{' %(Survival Evolved%)', 'ARK Survival Evolved.png', 'ARK: Survival Evolved'},
	-- MOBILE
	{' %(Mobile%)', 'Logo Mobile.svg', 'ARK: Survival Evolved Mobile'},
	-- MODS
	{'Мод:Ebenus Astrum/', 'Ebenus Astrum Icon.png', 'Мод:Ebenus Astrum'},
	{'Мод:Primal Fear/', 'PrimalFearIcon.png', 'Мод:Primal Fear'},
	{'Мод:Ebenus Astrum/', 'Ebenus Astrum Icon.png', 'Мод:Ebenus Astrum'},
	{'Мод:ARK Additions/', 'ARK Additions Icon.png', 'Мод:ARK Additions'},
	{'Мод:Better MEKs!/', 'Mod Better MEKs! Icon.png', 'Мод:Better MEKs!'},
	{'Мод:Steampunk/', 'Mod Steampunk Icon.png', 'Мод:Steampunk'},
	{'Мод:Structures Plus/', 'Structures Plus Icon.png', 'Мод:Structures Plus'},
	{'Мод:Ark Eternal/', 'Mod Ark Eternal Icon.png', 'Мод:Ark Eternal'},
	{'Мод:Archaic Ascension/', 'Mod Archaic Ascension Icon.png', 'Мод:Archaic Ascension'},
	{'Мод:The Chasm/', 'ChasmLogoSmall.jpg', 'Мод:The Chasm'},
	{'Мод:Primal NPCs/', 'Mod Primal NPCs Icon.png', 'Мод:Primal NPCs'},
	{'Мод:Caballus/', 'Mod Caballus Icon.png', 'Мод:Caballus'},
	{'Мод:Prehistoric Beasts/', 'Mod Prehistoric Beasts Icon.png', 'Мод:Prehistoric Beasts'},
	{'Мод:Castles, Keeps, and Forts Remastered/', 'Mod Castles Keeps Forts Architecture Remastered Icon.png', 'Мод:Castles, Keeps, and Forts Remastered'},
	{'Мод:Crystal Isles Dino Collection/', 'Crystal Isles Dino Collection Icon.png', 'Мод:Crystal Isles Dino Collection'},
	{'Мод:Additional Creatures: Grand Hunt/', 'Additional Creatures Grand Hunt Icon.png', 'Мод:Additional Creatures: Grand Hunt'},
	{'Мод:Super Structures/', 'Mod Super Structures icon.png', 'Мод:Super Structures'},
	{'Мод:ARK: The Sunken World/', 'Mod ARK The Sunken World icon.png', 'Мод:ARK: The Sunken World'},
	{'Мод:Fjell/', 'Mod Fjell Icon.png', 'Мод:Fjell'},
	{'Мод:Glacius/', 'Mod Glacius Icon.png', 'Мод:Glacius'},
	{'Мод:Dino Storage/', 'Blank.png', 'Мод:Dino Storage'},
	{'Мод:The Eärrion/', 'Mod The Eärrion Icon.png', 'Мод:The Eärrion'},
	{'Мод:Alemia/', 'Mod Alemia Icon.png', 'Мод:Alemia'},
	{'Мод:Fixed Extinction/', 'Mod Fixed Extinction logo.jpg', 'Мод:Fixed Extinction'},
	{'Мод:Oceania/', 'Mod Oceania Icon.png', 'Мод:Oceania'},
	{'Мод:ARK: Project Anomaly/', 'Mod Project Anomaly.png', 'Мод:ARK: Project Anomaly'},
	{'Мод:Giga\'s Fancy Variants/', 'Mod Gigas Fancy Variants Icon.png', 'Мод:Giga\'s Fancy Variants'},
	{'Мод:Pentagon/', 'Mod Pentagon DLC Icon.png', 'Мод:Pentagon'},
	{'Мод:Godzillark/', 'Mod Godzillark logo.png', 'Мод:Godzillark'},
	{'Мод:ARK: Horizons/', 'Mod ARK Horizons Icon.png', 'Мод:ARK: Horizons'},
	{'Мод:Primeval Creatures/', 'Mod Primeval Creatures Icon.png', 'Мод:Primeval Creatures'},
	{'Мод:Mystic Menagerie/', 'Mod Mystic Menagerie Icon.png', 'Мод:Mystic Menagerie'},
	{'Мод:Oceania/', 'Mod Oceania logo.png', 'Мод:Oceania'},
	{'Мод:AlpsMap/', 'Mod Alps Logo.png', 'Мод:AlpsMap'},
	{'Мод:No Untameables/', 'Mod No Untameables icon.png', 'Мод:No Untameables'},
	{'Мод:Additions Ascended/', 'Mod Additions Ascended icon.png', 'Мод:Additions Ascended'},
	{'Мод:Random Configs/', 'Mod Random Configs icon.png', 'Мод:Random Configs'},
	{'Мод:Kraken\'s Better Dinos/', 'Mod Kraken\'s Better Dinos icon.png', 'Мод:Kraken\'s Better Dinos'},
	{'Мод:Any Colour Sets/', 'Mod Any Colour Sets icon.png', 'Мод:Any Colour Sets'},
	{'Мод:East Vinindia Ascended Tweaks/', 'Mod East Vinindia Ascended Tweaks icon.png', 'Мод:East Vinindia Ascended Tweaks'},
	{'Мод:Crafting Skill Potion/', 'Mod Crafting Skill Potion icon.png', 'Мод:Crafting Skill Potion'},
	{'Мод:DinoCloud/', 'Mod DinoCloud icon.png', 'Мод:DinoCloud'},
	{'Мод:BetterChat/', 'Mod BetterChat icon.png', 'Мод:BetterChat'}
}
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",
	["survival ascended"] = "ARK: Survival Ascended",
	["sa"] = "ARK: Survival Ascended",
	["survival evolved"] = "ARK: Survival Evolved",
	["se"] = "ARK: Survival Evolved",
	["mobile"] = "ARK: Survival Evolved Mobile",
	["s+"] = "Мод:Structures Plus",
	["better meks"] = "Мод: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