Aller au contenu

« Module:Ligne apparition » : différence entre les versions

De Stargate Wiki Sémantique
Contenu supprimé Contenu ajouté
mAucun résumé des modifications
Aucun résumé des modifications
 
(Une version intermédiaire par le même utilisateur non affichée)
Ligne 203 : Ligne 203 :
-- Affichage
-- Affichage
------------------------------------------------------------------
------------------------------------------------------------------
local titleEpFr = frame:preprocess(Episode.getEpisodeTitle{ args = { ep } })
local propLabel = appearancePropertyLabel(typeApp)
local propLabel = appearancePropertyLabel(typeApp)
local linkFull = Episode.getEpisodeFullLink{ args = { ep } }
local linkFull = Episode.getEpisodeFullLink{ args = { ep } }
Ligne 209 : Ligne 210 :
if typeApp ~= "" then
if typeApp ~= "" then
display = string.format("'''[[%s::%s|%s]]'''%s",
display = string.format("'''[[%s::%s|%s]]'''%s",
propLabel, linkFull, titleEp, suffix)
propLabel, linkFull, titleEpFr, suffix)
else
else
display = string.format("<span style=\"color:#555555;\">%s</span>%s",
display = string.format("<span style=\"color:#555555;\">%s</span>%s",
titleEp, suffix)
titleEpFr, suffix)
end
end



Dernière version du 18 juin 2026 à 16:34

Documentation icon Documentation module[créer]
local p = {}

local Episode = require("Module:Episode")

----------------------------------------------------------------------
-- Nettoyage UTF‑8
----------------------------------------------------------------------
local function safe_utf8(str)
    if type(str) ~= "string" then return "" end
    return mw.ustring.gsub(str, "[^\0-\x7F\xC2-\xF4][\x80-\xBF]*", " ")
end

----------------------------------------------------------------------
-- Normalisation
----------------------------------------------------------------------
local function normalize(str)
    str = safe_utf8(str or "")
    str = mw.text.trim(str)
    str = mw.ustring.lower(str)
    str = str:gsub("[%-%_]", " ")
    str = mw.ustring.toNFD(str)
    str = str:gsub("[%pM]", "")
    str = str:gsub("%s+", " ")
    return str
end

----------------------------------------------------------------------
-- Types d’apparition → propriété SMW
----------------------------------------------------------------------
local types = {
    main = "Personnage principal de ",
    m = "Personnage principal de ",
    principal = "Personnage principal de ",

    supporting = "Personnage secondaire de ",
    s = "Personnage secondaire de ",
    secondaire = "Personnage secondaire de ",

    recurring = "Personnage récurrent de ",
    re = "Personnage récurrent de ",

    ["one shot"] = "Personnage one shot de ",
    os = "Personnage one shot de ",

    minor = "Personnage mineur de ",
    mi = "Personnage mineur de ",

    yes = "Apparaît dans ",
    y = "Apparaît dans ",
    vrai = "Apparaît dans ",

    mention = "Mentionné dans ",
    me = "Mentionné dans ",

    picture = "Photo seule dans ",
    photo = "Photo seule dans ",

    voice = "Voix seule dans ",
    voix = "Voix seule dans ",

    body = "Corps visible dans ",
    corps = "Corps visible dans ",

    deleted = "Apparaît uniquement dans les scènes supprimées de ",
    flashback = "Apparaît uniquement dans des flashbacks de ",

    nom = "Nom visible dans ",

    ["#default"] = "Apparaît dans "
}

local function appearancePropertyLabel(typeApp)
    local key = normalize(typeApp)
    return types[key] or types["#default"]
end

----------------------------------------------------------------------
-- Alias → catégories
----------------------------------------------------------------------
local alias = {
    m="principal", main="principal", principal="principal",
    s="secondaire", secondaire="secondaire",
    re="recurrent", recurring="recurrent",
    os="oneshot", ["one shot"]="oneshot",
    mi="mineur", minor="mineur",
    y="true", yes="true", vrai="true",
    me="mention", mention="mention",
    picture="photo", photo="photo",
    voice="voix", voix="voix",
    body="corps", corps="corps",
    del="deleted", deleted="deleted",
    flash="flashback", flashback="flashback",
    nom="nom"
}

local messages = {
    principal="", secondaire="", recurrent="", oneshot="", mineur="", ["true"]="",
    mention=" (mention)", photo=" (photo seule)", voix=" (voix seule)",
    deleted=" (scenes supprimees)", flashback=" (flashbacks)",
    nom=" (nom uniquement)", corps=" (corps)"
}

----------------------------------------------------------------------
-- Suffixe d’apparition (type + décès)
-- Règle :
-- - principal / one shot / récurrent / mineur → pas de type, mais (décédé) si mort
-- - autres types → suffixe normal, et ", décédé" si mort
----------------------------------------------------------------------

local invisibleTypes = {
    principal = true,
    oneshot   = true,
    recurrent = true,
    mineur    = true,
    ["true"]  = true,  -- "Apparaît dans"
}

local function appearanceSuffix(typeApp, isDead)
    local norm = normalize(typeApp)
    local key = alias[norm]

    -- Si type inconnu → on ne montre rien, sauf décès
    if not key then
        if isDead then return " (décédé)" end
        return ""
    end

    -- Si type invisible (principal, mineur, etc.)
    if invisibleTypes[key] then
        if isDead then return " (décédé)" end
        return ""
    end

    -- Type visible (mention, photo, voix, etc.)
    local base = messages[key] or ""

    if isDead then
        return base:gsub("%)$", ", décédé)")
    end

    return base
end

local function buildDisplaySuffix(raw)
    if raw == "" then return "" end
    return " ''" .. raw .. "''"
end


----------------------------------------------------------------------
-- Nom du personnage (SMW)
----------------------------------------------------------------------
local function setCharacterName(ep, name)
    if ep == "" or name == "" then return "" end
    local fullName = Episode.getEpisodeTitle{ args = { ep } }
    if not fullName or fullName == "" then return "" end
    return string.format("{{#set: Nom du personnage dans %s = %s}}", fullName, name)
end

----------------------------------------------------------------------
-- Fonction principale
----------------------------------------------------------------------
function p.main(frame)
    local args = frame.args

    local ep      = safe_utf8(args[1] or "")
    local typeApp = safe_utf8(args[2] or "")
    local order   = safe_utf8(args[3] or "")
    local name    = safe_utf8(args[4] or "")
    local deathEp = safe_utf8(args[5] or "")

    if ep == "" then return "" end

    ------------------------------------------------------------------
    -- TITRES
    ------------------------------------------------------------------
    local titleEp = Episode.getEpisodeLink{ args = { ep } }
    local titleDeath = Episode.getEpisodeLink{ args = { deathEp } }

    if (not titleDeath or titleDeath == "") and deathEp ~= "" then
        local full = Episode.getEpisodeFullLink{ args = { deathEp } }
        if full and full ~= "" then
            titleDeath = Episode.getEpisodeLink{ args = { full } }
        end
    end

    if (not titleDeath or titleDeath == "") and deathEp ~= "" then
        titleDeath = Episode.getEpisodeLink{ args = { deathEp } }
    end

    ------------------------------------------------------------------
    -- DÉTECTION DU DÉCÈS PAR TITRE
    ------------------------------------------------------------------
    local isDead = (titleEp ~= "" and titleDeath ~= "" and titleEp == titleDeath)

    ------------------------------------------------------------------
    -- Suffixe
    ------------------------------------------------------------------
    local rawSuffix = appearanceSuffix(typeApp, isDead)
    local suffix = buildDisplaySuffix(rawSuffix)

    ------------------------------------------------------------------
    -- Affichage
    ------------------------------------------------------------------
    local titleEpFr = frame:preprocess(Episode.getEpisodeTitle{ args = { ep } })
    local propLabel = appearancePropertyLabel(typeApp)
    local linkFull  = Episode.getEpisodeFullLink{ args = { ep } }

    local display
    if typeApp ~= "" then
        display = string.format("'''[[%s::%s|%s]]'''%s",
            propLabel, linkFull, titleEpFr, suffix)
    else
        display = string.format("<span style=\"color:#555555;\">%s</span>%s",
            titleEpFr, suffix)
    end

    ------------------------------------------------------------------
    -- SMW
    ------------------------------------------------------------------
    local smw = ""

    if isDead then
        smw = smw .. string.format("{{#set: Décédé dans = %s}}", linkFull)
    end

    if order ~= "" then
        smw = smw .. string.format("{{#set: Ordre d'apparition dans %s = %s}}",
            titleEp, order)
    end

    if name ~= "" then
        smw = smw .. setCharacterName(ep, name)
    end

    if smw ~= "" then
        frame:preprocess(smw)
    end

    return display
end

return p