Module:Donnees jeu : Différence entre versions

De X-Wing 2.0 - Le wiki des figurines
Aller à : navigation, rechercher
 
(29 révisions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
 
local p = {}
 
local p = {}
  
local Data = mw.loadData('Module:Donnees jeu/Data')
+
local DataLoad = mw.loadData('Module:Donnees jeu/Data')
 +
local AmeliorationType = mw.loadData('Module:Donnees jeu/AmeliorationType')
 +
 
 +
local Data = {}
 +
for key,value in pairs(DataLoad) do
 +
  if type(value) ~= "table" then
 +
    Data[key] = mw.loadData(value)
 +
  else
 +
    Data[key] = value
 +
  end
 +
end
  
 
function trim(s)
 
function trim(s)
 
   return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
 
   return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
 +
end
 +
 +
function version(faction)
 +
  return mw.getCurrentFrame():preprocess("<ref name=\"" .. faction .. "\">Données en version " .. Data["Version"][faction]["version"] .. " (" .. Data["Version"][faction]["periode"] .. ")</ref>")
 
end
 
end
  
Ligne 10 : Ligne 24 :
 
     local typeCarteStr = trim(frame.args[1]) or ""
 
     local typeCarteStr = trim(frame.args[1]) or ""
 
     local nomCarteStr = trim(frame.args[2]) or ""
 
     local nomCarteStr = trim(frame.args[2]) or ""
     local typeDonnees = trim(frame.args[3]) or "Cout"
+
    local formationStr = trim(frame.args[3]) or "Generique"
    if typeDonnees == "Cout" then
+
     local typeDonnees = trim(frame.args[4]) or "Cout"
         return Data[typeCarteStr][nomCarteStr][typeDonnees]
+
    local typeAmeliorationStr = ""
 +
    if typeCarteStr == "Amelioration" then
 +
        typeAmeliorationStr = trim(frame.args[2]) or ""
 +
        formationStr = trim(frame.args[3]) or "Generique"
 +
        nomCarteStr = trim(frame.args[4]) or ""
 +
        typeDonnees = trim(frame.args[5]) or ""
 +
    end
 +
    if typeDonnees == "Cout" or typeDonnees == "Hyperespace" then
 +
        if Data[typeCarteStr] == nil then
 +
            return typeCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
        if typeCarteStr == "Amelioration" then
 +
            local texteRetour = ""
 +
            if Data[typeCarteStr][typeAmeliorationStr] == nil then
 +
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
            end
 +
            if Data[typeCarteStr][typeAmeliorationStr][formationStr] == nil then
 +
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
            end
 +
            if Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr] == nil then
 +
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " - " .. nomCarteStr.. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
            end
 +
            if Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr][typeDonnees] == nil then
 +
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " - " .. nomCarteStr.. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
            end
 +
            texteRetour = Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr][typeDonnees] .. version(formationStr)
 +
            if typeDonnees == "Cout" and Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr]["Ref"] ~= nil then
 +
                texteRetour = texteRetour .. mw.getCurrentFrame():preprocess("<ref>" .. Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr]["Ref"] .. "</ref>")
 +
            end
 +
            return texteRetour
 +
        end
 +
        if Data[typeCarteStr][formationStr] == nil then
 +
            return typeCarteStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
        if Data[typeCarteStr][formationStr][nomCarteStr] == nil then
 +
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
        if Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] == nil then
 +
            return typeCarteStr .. " - " .. formationStr  .. " - " .. nomCarteStr .. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
         return Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] .. version(formationStr)
 
     end
 
     end
 
     if typeDonnees == "Amelioration" then
 
     if typeDonnees == "Amelioration" then
         retour = "== Améliorations ==\n"
+
         retour = "== Améliorations " .. version(formationStr) .. " ==\n"
         for k, a in pairs (Data[typeCarteStr][nomCarteStr][typeDonnees]) do
+
        if Data[typeCarteStr] == nil then
             retour = retour .. "* [[" .. k "]] x " .. a .. "\n"
+
            return typeCarteStr .. " : non défini"
 +
        end
 +
        if Data[typeCarteStr][formationStr] == nil then
 +
            return typeCarteStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
        if Data[typeCarteStr][formationStr][nomCarteStr] == nil then
 +
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
        if Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] == nil then
 +
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
 +
        end
 +
         for k, a in pairs (Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees]) do
 +
             retour = retour .. "* " .. AmeliorationType[k].icone .. " " .. AmeliorationType[k].lien .. " x " .. a .. "\n"
 +
        end
 +
        if retour == "== Améliorations ==\n" then
 +
            retour = retour .. "* Aucune\n"
 
         end
 
         end
 +
        -- retour = retour .. version(formationStr) .. "\n"
 
         return retour
 
         return retour
 
     end
 
     end
 
end
 
end
 
return p
 
return p

Version actuelle datée du 19 mars 2021 à 21:06

La documentation pour ce module peut être créée à Module:Donnees jeu/doc

local p = {}

local DataLoad = mw.loadData('Module:Donnees jeu/Data')
local AmeliorationType = mw.loadData('Module:Donnees jeu/AmeliorationType')

local Data = {}
for key,value in pairs(DataLoad) do
  if type(value) ~= "table" then
    Data[key] = mw.loadData(value)
  else
    Data[key] = value
  end
end

function trim(s)
  return (string.gsub(s, "^%s*(.-)%s*$", "%1"))
end

function version(faction)
   return mw.getCurrentFrame():preprocess("<ref name=\"" .. faction .. "\">Données en version " .. Data["Version"][faction]["version"] .. " (" .. Data["Version"][faction]["periode"] .. ")</ref>")
end

function p.affichage(frame)
    local typeCarteStr = trim(frame.args[1]) or ""
    local nomCarteStr = trim(frame.args[2]) or ""
    local formationStr = trim(frame.args[3]) or "Generique"
    local typeDonnees = trim(frame.args[4]) or "Cout"
    local typeAmeliorationStr = ""
    if typeCarteStr == "Amelioration" then
        typeAmeliorationStr = trim(frame.args[2]) or ""
        formationStr = trim(frame.args[3]) or "Generique"
        nomCarteStr = trim(frame.args[4]) or ""
        typeDonnees = trim(frame.args[5]) or ""
    end
    if typeDonnees == "Cout" or typeDonnees == "Hyperespace" then
        if Data[typeCarteStr] == nil then
            return typeCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        if typeCarteStr == "Amelioration" then
            local texteRetour = ""
            if Data[typeCarteStr][typeAmeliorationStr] == nil then
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
            end
            if Data[typeCarteStr][typeAmeliorationStr][formationStr] == nil then
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
            end
            if Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr] == nil then
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " - " .. nomCarteStr.. " : non défini [[Catégorie:Données de jeu manquantes]]"
            end
            if Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr][typeDonnees] == nil then
                return typeCarteStr .. " - " .. typeAmeliorationStr .. " - " .. formationStr .. " - " .. nomCarteStr.. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
            end
            texteRetour = Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr][typeDonnees] .. version(formationStr)
            if typeDonnees == "Cout" and Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr]["Ref"] ~= nil then
                texteRetour = texteRetour .. mw.getCurrentFrame():preprocess("<ref>" .. Data[typeCarteStr][typeAmeliorationStr][formationStr][nomCarteStr]["Ref"] .. "</ref>")
            end
            return texteRetour
        end
        if Data[typeCarteStr][formationStr] == nil then
            return typeCarteStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        if Data[typeCarteStr][formationStr][nomCarteStr] == nil then
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        if Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] == nil then
            return typeCarteStr .. " - " .. formationStr  .. " - " .. nomCarteStr .. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        return Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] .. version(formationStr)
    end
    if typeDonnees == "Amelioration" then
        retour = "== Améliorations " .. version(formationStr) .. " ==\n"
        if Data[typeCarteStr] == nil then
            return typeCarteStr .. " : non défini"
        end
        if Data[typeCarteStr][formationStr] == nil then
            return typeCarteStr .. " - " .. formationStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        if Data[typeCarteStr][formationStr][nomCarteStr] == nil then
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        if Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees] == nil then
            return typeCarteStr .. " - " .. formationStr .. " - " .. nomCarteStr .. " - " .. typeDonnees .. " : non défini [[Catégorie:Données de jeu manquantes]]"
        end
        for k, a in pairs (Data[typeCarteStr][formationStr][nomCarteStr][typeDonnees]) do
            retour = retour .. "* " .. AmeliorationType[k].icone .. " " .. AmeliorationType[k].lien .. " x " .. a .. "\n"
        end
        if retour == "== Améliorations ==\n" then
            retour = retour .. "* Aucune\n"
        end
        -- retour = retour .. version(formationStr) .. "\n"
        return retour
    end
end
return p