Module:DissectDlcItemName

De ARK Wiki
Aller à la navigation Aller à la recherche
Template-info.png Documentation

local p = {}
local MAPPING_PATTERNS = {
	-- Ajouter la partie du nom qui doit être contrôlée pour trouver l'icône.
	-- Chaque entrée doit avoir les informations suivantes:
	-- 1: Forme à trouver de ce qui sera enlevé de l'affichage . Les parenthèses doivent être éludées avec %.
	-- 2: Nom de fichier de l'icône
	-- 3: Nom du lien pour l'icône
	{' %(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'},
	{' %(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
	{'Mod:Additional Creatures: Grand Hunt/', 'Additional Creatures Grand Hunt logo.png', 'Mod:Additional Creatures: Grand Hunt'},
	{'Mod:Additions Ascended/', 'Mod Additions Ascended logo.png', 'Mod:Additions Ascended'},
	{'Mod:Alemia/', 'Mod Alemia logo.png', 'Mod:Alemia'},
	{'Mod:Alps/', 'Mod Alps logo.png', 'Mod:Alps'},
	{'Mod:Amazing Potions/', 'Mod Amazing Potions logo.png', 'Mod:Amazing Potions'},
	{'Mod:Amazing Structures/', 'Mod Amazing Structures logo.png', 'Mod:Amazing Structures'},
	{'Mod:Arcadia Additional Dinos/', 'Mod Arcadia Additional Dinos logo.png', 'Mod:Arcadia Additional Dinos'},
	{'Mod:Archaic Ascension/', 'Mod Archaic Ascension logo.png', 'Mod:Archaic Ascension'},
	{'Mod:Archepelian/', 'Mod Archepelian logo.png', 'Mod:Archepelian'},
	{'Mod:ARK Additions/', 'Mod ARK Additions logo.png', 'Mod:ARK Additions'},
	{'Mod:Ark Eternal/', 'Mod Ark Eternal logo.png', 'Mod:Ark Eternal'},
	{'Mod:ARK: Horizons/', 'Mod ARK Horizons logo.png', 'Mod:ARK: Horizons'},
	{'Mod:ARK: Project Anomaly/', 'Mod ARK Project Anomaly logo.png', 'Mod:ARK: Project Anomaly'},
	{'Mod:ARK: The Sunken World/', 'Mod ARK The Sunken World logo.png', 'Mod:ARK: The Sunken World'},
	{'Mod:Better MEKs!/', 'Mod Better MEKs! logo.png', 'Mod:Better MEKs!'},	
	{'Mod:Caballus/', 'Mod Caballus logo.png', 'Mod:Caballus'},	
	{'Mod:Castles, Keeps, and Forts Remastered/', 'Mod Castles Keeps Forts Architecture Remastered logo.png', 'Mod:Castles, Keeps, and Forts Remastered'},
	{'Mod:Crafting Skill Potion/', 'Mod Crafting Skill Potion logo.png', 'Mod:Crafting Skill Potion'},
	{'Mod:Crystal Isles Dino Collection/', 'Crystal Isles Dino Collection logo.png', 'Mod:Crystal Isles Dino Collection'},
	{'Mod:DinoCloud/', 'Mod DinoCloud logo.png', 'Mod:DinoCloud'},
	{'Mod:Dino Storage/', 'Mod Dino Storage logo.png', 'Mod:Dino Storage'},
	{'Mod:East Vinindia Ascended Tweaks/', 'Mod East Vinindia Ascended Tweaks logo.png', 'Mod:East Vinindia Ascended Tweaks'},
	{'Mod:Ebenus Astrum/', 'Mod Ebenus Astrum logo.png', 'Mod:Ebenus Astrum'},
	{'Mod:Fixed Extinction/', 'Mod Fixed Extinction logo.jpg', 'Mod:Fixed Extinction'},
	{'Mod:Fjell/', 'Mod Fjell logo.png', 'Mod:Fjell'},
	{'Mod:Giga\'s Fancy Variants/', 'Mod Gigas Fancy Variants logo.png', 'Mod:Giga\'s Fancy Variants'},
	{'Mod:Glacius/', 'Mod Glacius logo.png', 'Mod:Glacius'},
	{'Mod:Godzillark/', 'Mod Godzillark logo.png', 'Mod:Godzillark'},
	{'Mod:Insaluna/', 'Mod Insaluna logo.png', 'Mod:Insaluna'},
	{'Mod:Kraken\'s Better Dinos/', 'Mod Krakens Better Dinos logo.jpg', 'Mod:Kraken\'s Better Dinos'},
	{'Mod:MuchStuffPack/', 'Mod MuchStuffPack logo.png', 'Mod:MuchStuffPack'},
	{'Mod:Mystic Menagerie/', 'Mod Mystic Menagerie logo.png', 'Mod:Mystic Menagerie'},
	{'Mod:No Untameables/', 'Mod No Untameables logo.png', 'Mod:No Untameables'},
	{'Mod:Oceania/', 'Mod Oceania logo.png', 'Mod:Oceania'},
	{'Mod:Pentagon/', 'Mod Pentagon logo.png', 'Mod:Pentagon'},
	{'Mod:Primal Fear/', 'Mod Primal Fear logo.png', 'Mod:Primal Fear'},
	{'Mod:Primeval Creatures/', 'Mod Primeval Creatures logo.png', 'Mod:Primeval Creatures'},
	{'Mod:Prehistoric Beasts/', 'Mod Prehistoric Beasts logo.png', 'Mod:Prehistoric Beasts'},
	{'Mod:Primal NPCs/', 'Mod Primal NPCs logo.png', 'Mod:Primal NPCs'},
	{'Mod:Random Configs/', 'Mod Random Configs logo.png', 'Mod:Random Configs'},	
	{'Mod:R.P. EDDitions/', 'Mod R P EDDitions logo.png', 'Mod:R.P. EDDitions'},
	{'Mod:Steampunk/', 'Mod Steampunk logo.png', 'Mod:Steampunk'},
	{'Mod:Structures Plus/', 'Mod Structures Plus logo.png', 'Mod:Structures Plus'},
	{'Mod:Super Structures/', 'Mod Super Structures logo.png', 'Mod:Super Structures'},
	{'Mod:Super Structures Ascended/', 'Mod Super Structures Ascended logo.png', 'Mod:Super Structures Ascended'},
	{'Mod:The Chasm/', 'Mod The Chasm logo.png', 'Mod:The Chasm'},
	{'Mod:The Eärrion/', 'Mod The Eärrion logo.png', 'Mod:The Eärrion'}
}
local EXTRA_DLC_NAMES = {
	-- Ajouter un nom alternatif aux DLC pour les recherches d'une icône de DLC lorsque
	-- il n'y a pas de nom d'objet.
	-- il y a une cartographie "de-vers". Le côté droit ne doit offrir qu'une seule
	-- entrée dans MAPPING_PATTERNS pour la troisième valeur. Le côté gauche doit être en minuscules.
	["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!",
}

-- La fonction Helper à utiliser avec les autres modules Lua pour disséquer un nom d'objet en
-- nom d'affichage, icône de DLC et article de DLC.
-- Retourne vide si le suffixe de DLC manque ou n'est pas reconnu.
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

-- La fonction Helper pour les modèles de Wiki afin de disséquer les noms d'objets en variables.
-- Règle chaque variable sur rien si le suffixe de DLC manque ou n'est pas reconnu.
-- Accepte cinq paramètres:
-- 1: Nom d'objet
-- 2: Nom variable pour le nom d'affichage
-- 3: Nom variable pour le nom d'icône du DLC
-- 4: Nom variable pour le nom d'article du DLC
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

-- Fonction Helper pour que les modèles du wiki trouvent un nom d'icône de DLC.
-- Règle chaque variable sur rien si le suffixe de DLC manque ou n'est pas reconnu.
-- Accepte trois paramètres:
-- 1: nom du DLC
-- 2: Nom variable pour le nom d'icône du DLC
-- 3: Nom variable pour le nom d'article du DLC
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