Module:Make EC link
Jump to navigation
Jump to search
This module takes an input armor set and armor name and returns a formatted string used for links to Eorzea Collection. Does not cover all possible use cases, so links must be manually checked to see if any are broken.
Usage: {{#invoke:Make EC link|ec_convert|<armor's set name>|<armor name>}}.
local p = {}
-- Convert a multi-word string to lowercase with dashes
function p.ec_convert(frame)
local input = frame.args[1] or frame.args.input or ""
local input2 = frame.args[2] or frame.args.input2 or ""
-- Remove apostrophes from input2 immediately (both types)
input = mw.ustring.gsub(input, "'", "")
input2 = mw.ustring.gsub(input2, "'", "")
local replacements = {
-- The search term (no apostrophes) - The replacement term (found in EC)
["Babyface Champions"] = "Cruiser",
["Dark Horse Champions"] = "Light-heavy",
["Ascension"] = "Anabaseios",
["Purgatory"] = "Abyssos",
["Limbo"] = "Asphodelos",
["Edenmorn"] = "edens promise",
["Edenmete"] = "edens promise",
["Edencall"] = "Edenchoir",
["Edengate"] = "Edengrace",
["Omicron"] = "Omega",
["Carborundum"] = "Diamond",
["Genta"] = "Genji",
["Yama"] = "Rakshasa",
["Yasha"] = "Asuran",
}
local patterns = {
"augmented",
"antiquated",
"+1",
"+2",
"ornate",
"of",
"prototype",
"replica",
"attire",
"set",
"armor",
"gear",
"glamour",
"crafting and gathering",
"weathered",
"uniform",
"replica",
}
local suffixes = {
"fending",
"maiming",
"striking",
"scouting",
"aiming",
"casting",
"healing",
"crafting",
"gathering"
}
-- Find and replace at the beginning of the string
local replacementMade = false
for find, replace in pairs(replacements) do
local pattern = "^" .. mw.ustring.gsub(find, "([%'%-%+])", "%%%1")
if mw.ustring.find(input, pattern) then
input = mw.ustring.gsub(input, pattern, replace, 1)
replacementMade = true
break
end
end
-- Convert to lowercase
local result = mw.ustring.lower(input)
-- Remove words matching the patterns
for _, pattern in ipairs(patterns) do
-- Escape special characters in the pattern
local escaped = mw.ustring.gsub(pattern, "([%+%-])", "%%%1")
-- Remove the word with word boundaries
result = mw.ustring.gsub(result, "%f[%w]" .. escaped .. "%f[%W]", "")
end
-- Clean up multiple spaces
result = mw.ustring.gsub(result, "%s+", " ")
-- Remove leading/trailing spaces
result = mw.ustring.gsub(result, "^%s+", "")
result = mw.ustring.gsub(result, "%s+$", "")
-- Check if processed input is present in input2 (only if no replacement was made)
local useInput2 = false
if not replacementMade and input2 ~= "" then
local input2_lower = mw.ustring.lower(input2)
-- Also create a version of input2 without "antiquated" or "weathered" at the start
local input2_stripped = input2_lower
input2_stripped = mw.ustring.gsub(input2_stripped, "^antiquated%s+", "")
input2_stripped = mw.ustring.gsub(input2_stripped, "^weathered%s+", "")
input2_stripped = mw.ustring.gsub(input2_stripped, "^augmented%s+", "")
input2_stripped = mw.ustring.gsub(input2_stripped, "^anemos%s+", "")
input2_stripped = mw.ustring.gsub(input2_stripped, "^idealized%s+", "")
input2_stripped = mw.ustring.gsub(input2_stripped, "^replica%s+", "")
-- Create a version of result that uses the original input terms for comparison
local result_for_comparison = mw.ustring.lower(input)
result_for_comparison = mw.ustring.gsub(result_for_comparison, "'", "")
-- Remove words matching the patterns
for _, pattern in ipairs(patterns) do
local escaped = mw.ustring.gsub(pattern, "([%+%-])", "%%%1")
result_for_comparison = mw.ustring.gsub(result_for_comparison, "%f[%w]" .. escaped .. "%f[%W]", "")
end
result_for_comparison = mw.ustring.gsub(result_for_comparison, "%s+", " ")
result_for_comparison = mw.ustring.gsub(result_for_comparison, "^%s+", "")
result_for_comparison = mw.ustring.gsub(result_for_comparison, "%s+$", "")
-- Check if result is NOT found in either version of input2
if result_for_comparison ~= "" and not mw.ustring.find(input2_lower, result_for_comparison, 1, true) and not mw.ustring.find(input2_stripped, result_for_comparison, 1, true) then
useInput2 = true
-- Extract first word from the stripped version of input2
local firstWord = mw.ustring.match(input2_stripped, "^([^%s]+)")
if firstWord then
result = firstWord
end
end
end
-- Now convert spaces to dashes
result = mw.ustring.gsub(result, "%s+", "-")
-- Remove leading/trailing dashes
result = mw.ustring.gsub(result, "^%-+", "")
result = mw.ustring.gsub(result, "%-+$", "")
-- Check for suffix phrases in the second input
if input2 ~= "" then
local input2_lower = mw.ustring.lower(input2)
for _, suffix in ipairs(suffixes) do
if mw.ustring.find(input2_lower, suffix) then
if result ~= "" then
result = result .. "-" .. suffix
else
result = suffix
end
break
end
end
end
return result
end
-- Simple function to convert string to lowercase, remove apostrophes, and replace spaces with dashes
function p.simple_ec_convert(frame)
local input = frame.args[1] or frame.args.input or ""
-- Convert to lowercase
local result = mw.ustring.lower(input)
-- Remove apostrophes
result = mw.ustring.gsub(result, "'", "")
-- Replace spaces with dashes
result = mw.ustring.gsub(result, "%s+", "-")
return result
end
return p