Module:SpellTableUtil/fr: Difference between revisions
From Heroes of Might and Magic: Olden Era Official Wiki
Created page with "local p = {} local moduleMap = { Arcane = "Module:ArcaneSpells/fr", Daylight = "Module:DaylightSpells/fr", Nightshade = "Module:NightshadeSpells/fr", Primal = "Module:PrimalSpells/fr", Neutral = "Module:NeutralSpells/fr" } -- Helper to find spell and its school local function findSpellByName(name) for school, moduleName in pairs(moduleMap) do local spellsModule = require(moduleName) local spells = spellsModule.spells or spellsMod..." |
mNo edit summary |
||
| (6 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
local moduleMap = { | local moduleMap = { | ||
Arcane = "Module:ArcaneSpells", | |||
Daylight = "Module:DaylightSpells", | |||
Nightshade = "Module:NightshadeSpells", | |||
Primal = "Module:PrimalSpells", | |||
Neutral = "Module:NeutralSpells" | |||
} | |||
local locModuleMap = { | |||
Arcane = "Module:ArcaneSpells/fr", | Arcane = "Module:ArcaneSpells/fr", | ||
Daylight = "Module:DaylightSpells/fr", | Daylight = "Module:DaylightSpells/fr", | ||
| Line 7: | Line 15: | ||
Primal = "Module:PrimalSpells/fr", | Primal = "Module:PrimalSpells/fr", | ||
Neutral = "Module:NeutralSpells/fr" | Neutral = "Module:NeutralSpells/fr" | ||
} | |||
local magicTypesfr = { | |||
["Arcane"] = "Arcanes", | |||
["Daylight"] = "Lumière", | |||
["Nightshade"] = "Belladone", | |||
["Primal"] = "Primordiaux", | |||
["Neutral"] = "Neutres", | |||
["Tier 1"] = "Rang 1", | |||
["Tier 2"] = "Rang 2", | |||
["Tier 3"] = "Rang 3", | |||
["Tier 4"] = "Rang 4", | |||
["Tier 5"] = "Rang 5" | |||
} | } | ||
| Line 12: | Line 33: | ||
local function findSpellByName(name) | local function findSpellByName(name) | ||
for school, moduleName in pairs(moduleMap) do | for school, moduleName in pairs(moduleMap) do | ||
local | local baseSpellsModule = require(moduleName) | ||
local locSpellsModule = require(locModuleMap[school]) | |||
local spellsModule = p.mergeSpellTables(baseSpellsModule, locSpellsModule) | |||
local spells = spellsModule.spells or spellsModule | local spells = spellsModule.spells or spellsModule | ||
local spell = spells[name] | local spell = spells[name] | ||
| Line 25: | Line 48: | ||
local school = frame.args["school"] or frame:getParent().args["school"] | local school = frame.args["school"] or frame:getParent().args["school"] | ||
local tier = frame.args["tier"] or frame:getParent().args["tier"] | local tier = frame.args["tier"] or frame:getParent().args["tier"] | ||
local school_fr = magicTypesfr[school] | |||
local tier_fr = magicTypesfr[tier] | |||
local moduleName = moduleMap[school] | local moduleName = moduleMap[school] | ||
local locModuleName = locModuleMap[school] | |||
if not moduleName then | if not moduleName then | ||
return "Unknown school: " .. tostring(school) | return "Unknown school: " .. tostring(school) | ||
end | end | ||
local | local baseSpellsModule = require(moduleName) | ||
local locSpellsModule = require(locModuleName) | |||
spellsModule = p.mergeSpellTables(baseSpellsModule, locSpellsModule) | |||
local spells = spellsModule.spells or spellsModule | local spells = spellsModule.spells or spellsModule | ||
local html = '{| class="wikitable"\n' .. | local html = '{| class="wikitable"\n' .. | ||
'|+ ' .. | '|+ style="margin-bottom:6px;" | ' .. school_fr .. ' — ' .. tier_fr .. '\n' .. | ||
'|-\n' .. | '|-\n' .. | ||
'! | '! style="width:10%;" | Sorts\n' .. | ||
'! style="width:6%;" align="center" | Mana\n' .. | |||
'! style="width:30%;" | Niveau 1\n' .. | |||
'! style="width:18%;" | Niveau 2\n' .. | |||
'! style="width:18%;" | Niveau 3\n' .. | |||
'! style="width:18%;" | Niveau 4\n' | |||
for _, spell in pairs(spells) do | for _, spell in pairs(spells) do | ||
if spell.tier == tier then | if spell.tier == tier then | ||
local name_safe = spell.name:match("^[^|]+"):gsub("^%s+", ""):gsub("%s+$", "") | |||
html = html .. | html = html .. | ||
'|-\n| [[' .. spell. | '|-\n| [[' .. name_safe..'/fr|'..spell.name_fr .. ']]\n' .. | ||
'| align="center" | [[File:Mana icon.png|32px]] ' .. (spell.mana or '–') .. '\n' .. | '| align="center" | [[File:Mana icon.png|32px]] ' .. (spell.mana or '–') .. '\n' .. | ||
'| ' .. (spell. | '| ' .. (spell.l1_fr or '') .. '\n' .. | ||
'| ' .. (spell. | '| ' .. (spell.l2_fr or '') .. '\n' .. | ||
'| ' .. (spell. | '| ' .. (spell.l3_fr or '') .. '\n' .. | ||
'| ' .. (spell. | '| ' .. (spell.l4_fr or '') .. '\n' | ||
end | end | ||
end | end | ||
| Line 66: | Line 104: | ||
local spellIcon = name .. ".png" | local spellIcon = name .. ".png" | ||
local manaIcon = "Mana icon.png" | local manaIcon = "Mana icon.png" | ||
local schoolName = spell. | local schoolName = spell.school_fr or school or "Unknown" | ||
local tier = spell. | local tier = spell.tier_fr or "–" | ||
local mana = spell.mana or "–" | local mana = spell.mana or "–" | ||
local html = '{| class="wikitable spellboxv" style="margin:1em auto; max-width: | local html = '{| class="wikitable spellboxv" style="margin:1em auto; max-width:600px; background:#1a1a1a; color:#eee; border:2px solid #444; border-radius:8px; box-shadow:0 0 6px rgba(0,0,0,0.4); overflow-x:hidden;"\n' | ||
html = html .. '|-\n| colspan=2 style="background:#304060; color:white; font-weight:bold; font-size:110%; text-align:center; padding:6px;" | ' .. spell. | html = html .. '|-\n| colspan=2 style="background:#304060; color:white; font-weight:bold; font-size:110%; text-align:center; padding:6px;" | ' .. spell.name_fr .. '\n' | ||
html = html .. '|-\n| colspan=2 align="center" style="padding:8px;" | [[File:' .. spellIcon .. '|64px]]\n' | html = html .. '|-\n| colspan=2 align="center" style="padding:8px;" | [[File:' .. spellIcon .. '|64px]]\n' | ||
html = html .. '|-\n| style="width:20%; font-weight:bold; text-align:left; background:#222;" | | html = html .. '|-\n| style="width:20%; font-weight:bold; text-align:left; background:#222;" | Ecole de magie || style="text-align:center;" | ' .. schoolName .. '\n' | ||
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | | html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Rang || style="text-align:center;" | ' .. tier .. '\n' | ||
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Mana || style="text-align:center;" | [[File:' .. manaIcon .. '|24px]] ' .. mana .. '\n' | html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Mana || style="text-align:center;" | [[File:' .. manaIcon .. '|24px]] ' .. mana .. '\n' | ||
-- Levels 1–4 | -- Levels 1–4 | ||
for i = 1, 4 do | for i = 1, 4 do | ||
local key = "l" .. i | local key = "l" .. i .. "_fr" | ||
if spell[key] then | if spell[key] then | ||
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | | html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Niveau ' .. i .. | ||
' || style="text-align:center;" | ' .. spell[key] .. '\n' | ' || style="text-align:center;" | ' .. spell[key] .. '\n' | ||
end | end | ||
| Line 88: | Line 126: | ||
-- Masterful | -- Masterful | ||
if spell. | if spell.masterful_fr then | ||
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | | html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Maîtrise || style="text-align:center;" | ' .. spell.masterful_fr .. '\n' | ||
end | end | ||
| Line 96: | Line 134: | ||
end | end | ||
-- Cette fonction fusionne les tables 'base' et 'translate' (pour la localisation) | |||
function p.mergeSpellTables(base, translate) | |||
local merged = {} | |||
for key, spell in pairs(base) do | |||
local s = {} | |||
-- On copie toutes les données depuis base[key] | |||
for k, v in pairs(spell) do | |||
s[k] = v | |||
end | |||
-- On ajoute ou remplace par les données de translate[key], si elles existent | |||
if translate[key] then | |||
for k, v in pairs(translate[key]) do | |||
s[k] = v | |||
end | |||
end | |||
merged[key] = s | |||
end | |||
return merged | |||
end | |||
return p | return p | ||
Latest revision as of 19:46, 10 May 2026
Documentation for this module may be created at Module:SpellTableUtil/fr/doc
local p = {}
local moduleMap = {
Arcane = "Module:ArcaneSpells",
Daylight = "Module:DaylightSpells",
Nightshade = "Module:NightshadeSpells",
Primal = "Module:PrimalSpells",
Neutral = "Module:NeutralSpells"
}
local locModuleMap = {
Arcane = "Module:ArcaneSpells/fr",
Daylight = "Module:DaylightSpells/fr",
Nightshade = "Module:NightshadeSpells/fr",
Primal = "Module:PrimalSpells/fr",
Neutral = "Module:NeutralSpells/fr"
}
local magicTypesfr = {
["Arcane"] = "Arcanes",
["Daylight"] = "Lumière",
["Nightshade"] = "Belladone",
["Primal"] = "Primordiaux",
["Neutral"] = "Neutres",
["Tier 1"] = "Rang 1",
["Tier 2"] = "Rang 2",
["Tier 3"] = "Rang 3",
["Tier 4"] = "Rang 4",
["Tier 5"] = "Rang 5"
}
-- Helper to find spell and its school
local function findSpellByName(name)
for school, moduleName in pairs(moduleMap) do
local baseSpellsModule = require(moduleName)
local locSpellsModule = require(locModuleMap[school])
local spellsModule = p.mergeSpellTables(baseSpellsModule, locSpellsModule)
local spells = spellsModule.spells or spellsModule
local spell = spells[name]
if spell then
return spell, school
end
end
return nil, nil
end
function p.spellTable(frame)
local school = frame.args["school"] or frame:getParent().args["school"]
local tier = frame.args["tier"] or frame:getParent().args["tier"]
local school_fr = magicTypesfr[school]
local tier_fr = magicTypesfr[tier]
local moduleName = moduleMap[school]
local locModuleName = locModuleMap[school]
if not moduleName then
return "Unknown school: " .. tostring(school)
end
local baseSpellsModule = require(moduleName)
local locSpellsModule = require(locModuleName)
spellsModule = p.mergeSpellTables(baseSpellsModule, locSpellsModule)
local spells = spellsModule.spells or spellsModule
local html = '{| class="wikitable"\n' ..
'|+ style="margin-bottom:6px;" | ' .. school_fr .. ' — ' .. tier_fr .. '\n' ..
'|-\n' ..
'! style="width:10%;" | Sorts\n' ..
'! style="width:6%;" align="center" | Mana\n' ..
'! style="width:30%;" | Niveau 1\n' ..
'! style="width:18%;" | Niveau 2\n' ..
'! style="width:18%;" | Niveau 3\n' ..
'! style="width:18%;" | Niveau 4\n'
for _, spell in pairs(spells) do
if spell.tier == tier then
local name_safe = spell.name:match("^[^|]+"):gsub("^%s+", ""):gsub("%s+$", "")
html = html ..
'|-\n| [[' .. name_safe..'/fr|'..spell.name_fr .. ']]\n' ..
'| align="center" | [[File:Mana icon.png|32px]] ' .. (spell.mana or '–') .. '\n' ..
'| ' .. (spell.l1_fr or '') .. '\n' ..
'| ' .. (spell.l2_fr or '') .. '\n' ..
'| ' .. (spell.l3_fr or '') .. '\n' ..
'| ' .. (spell.l4_fr or '') .. '\n'
end
end
html = html .. '|}'
return html
end
function p.spellBoxV(frame)
local args = frame.args
local name = args.name or frame:getParent().args.name
local spell, school = findSpellByName(name)
if not spell then
return "Unknown spell: " .. tostring(name)
end
local spellIcon = name .. ".png"
local manaIcon = "Mana icon.png"
local schoolName = spell.school_fr or school or "Unknown"
local tier = spell.tier_fr or "–"
local mana = spell.mana or "–"
local html = '{| class="wikitable spellboxv" style="margin:1em auto; max-width:600px; background:#1a1a1a; color:#eee; border:2px solid #444; border-radius:8px; box-shadow:0 0 6px rgba(0,0,0,0.4); overflow-x:hidden;"\n'
html = html .. '|-\n| colspan=2 style="background:#304060; color:white; font-weight:bold; font-size:110%; text-align:center; padding:6px;" | ' .. spell.name_fr .. '\n'
html = html .. '|-\n| colspan=2 align="center" style="padding:8px;" | [[File:' .. spellIcon .. '|64px]]\n'
html = html .. '|-\n| style="width:20%; font-weight:bold; text-align:left; background:#222;" | Ecole de magie || style="text-align:center;" | ' .. schoolName .. '\n'
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Rang || style="text-align:center;" | ' .. tier .. '\n'
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Mana || style="text-align:center;" | [[File:' .. manaIcon .. '|24px]] ' .. mana .. '\n'
-- Levels 1–4
for i = 1, 4 do
local key = "l" .. i .. "_fr"
if spell[key] then
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Niveau ' .. i ..
' || style="text-align:center;" | ' .. spell[key] .. '\n'
end
end
-- Masterful
if spell.masterful_fr then
html = html .. '|-\n| style="font-weight:bold; text-align:left; background:#222;" | Maîtrise || style="text-align:center;" | ' .. spell.masterful_fr .. '\n'
end
html = html .. '|}'
return html
end
-- Cette fonction fusionne les tables 'base' et 'translate' (pour la localisation)
function p.mergeSpellTables(base, translate)
local merged = {}
for key, spell in pairs(base) do
local s = {}
-- On copie toutes les données depuis base[key]
for k, v in pairs(spell) do
s[k] = v
end
-- On ajoute ou remplace par les données de translate[key], si elles existent
if translate[key] then
for k, v in pairs(translate[key]) do
s[k] = v
end
end
merged[key] = s
end
return merged
end
return p


