Module:HeroData: Difference between revisions
No edit summary |
mNo edit summary |
||
| Line 43: | Line 43: | ||
end | end | ||
-- 2. GESTION DES ALIAS VIRTUELS (DÉCOUPAGE DES SKILLS DE DÉPART) | -- 2. GESTION DES ALIAS VIRTUELS (DÉCOUPAGE DES SKILLS ET MAGIES DE DÉPART) | ||
local cargo_field = field | local cargo_field = field | ||
if field == 'start_skill_1' or field == 'start_skill_2' then | if field == 'start_skill_1' or field == 'start_skill_2' then | ||
cargo_field = 'start_skills' | cargo_field = 'start_skills' | ||
elseif field == 'start_magic_1' or field == 'start_magic_2' then | |||
cargo_field = 'start_magics' | |||
end | end | ||
| Line 59: | Line 60: | ||
local raw_value = heroRes[1][cargo_field] | local raw_value = heroRes[1][cargo_field] | ||
-- Traitement spécifique du découpage | -- Traitement spécifique du découpage (pour les skills OU les magies) | ||
if field == 'start_skill_1' or field == 'start_skill_2' then | if field == 'start_skill_1' or field == 'start_skill_2' or field == 'start_magic_1' or field == 'start_magic_2' then | ||
local | local items = {} | ||
for | for item in string.gmatch(raw_value, "([^,]+)") do | ||
table.insert( | table.insert(items, mw.text.trim(item)) | ||
end | end | ||
if field == 'start_skill_1' then | if field == 'start_skill_1' or field == 'start_magic_1' then | ||
return | return items[1] or "" | ||
elseif field == 'start_skill_2' then | elseif field == 'start_skill_2' or field == 'start_magic_2' then | ||
return | return items[2] or "" | ||
end | end | ||
end | end | ||
-- Comportement normal pour tous les autres champs Cargo d'origine | -- Comportement normal pour tous les autres champs Cargo d'origine (y compris start_magics brut) | ||
return raw_value | return raw_value | ||
end | end | ||
Latest revision as of 20:22, 25 May 2026
This module allows for the dynamic extraction of all hero data parameters, asset references, and translated profiles stored within the wiki's Cargo database (specifically from the Hero and Translation tables). It automatically handles localized fallback to English if a translation in the requested language is missing.
Basic Syntax
To fetch a data field, use the following syntax:
{{#invoke:HeroData|get|HERO_ID|VARIABLE|LANGUAGE_CODE}}
HERO_ID: The technical identifier of the hero (e.g.,dungeon_hero_3).VARIABLE: The keyword for the specific data field you want to display (see the full index below).LANGUAGE_CODE: (Optional) The localization code (e.g.,en,fr,pl). Defaults to English (en).
---
Technical Reference Index
📝 Text & Translations (Language-Dependent)
These fields query the Translation table. They dynamically adapt to the requested language code and fallback to English seamlessly if missing.
| Variable | Description | Database Filter Relation |
|---|---|---|
name |
The localized name of the hero. | type="hero"
|
description |
The localized official biography or lore text of the hero. | type="hero"
|
motto |
The hero's localized specific quote or battle motto. | type="hero_motto"
|
⚔️ Split Starting Skills (Virtual Fields)
Instead of returning a raw comma-separated string from the database, the module automatically slices the data array into distinct outputs for clean wiki markup nesting:
| Variable | Description | Fallback Behavior |
|---|---|---|
start_skill_1 |
Returns the technical ID of the hero's primary starting skill. | Always returns the first value found. |
start_skill_2 |
Returns the technical ID of the hero's secondary starting skill. | Returns an empty string ("") if the hero only has one starting skill.
|
start_magic_1 |
Returns the technical ID of the hero's primary starting spell/magic. | Returns an empty string ("") if the hero has no starting magic.
|
start_magic_2 |
Returns the technical ID of the hero's secondary starting spell/magic. | Returns an empty string ("") if the hero has fewer than two spells.
|
⚙️ Core Technical Properties
Standard database values extracted directly from the primary Hero table records.
| Variable | Description | Example Value |
|---|---|---|
class_id |
Technical ID linking to the hero's mechanical class archetype. | might_dungeon
|
faction |
The alignment group or city archetype the hero is drafted under. | dungeon
|
class_type |
Archetype category profiling orientation. | might or magic
|
icon |
The filename token assigned to the hero portrait graphic asset. | hero_dungeon_3_Stinger
|
specialization_id |
Points to the unique combat skill perk assigned to this specific hero unit. | dungeon_hero_3_specialization
|
source_path |
The file path location of the original repository data dump JSON. | DB/heroes/dungeon/dungeon_hero_3.json
|
start_skills |
Raw comma-separated list of all starting skill IDs. | skill_faction_dungeon,skill_battle_artistry
|
start_magics |
Raw comma-separated list of all starting spell or magic IDs. | day_16_magic_arinas_chosen_special
|
Practical Examples
Example 1: Rendering Hero Portrait Images Dynamically
To render a hero portrait using their explicit database-defined icon file:
[[File:{{#invoke:HeroData|get|dungeon_hero_3|icon}}.png|64px]]
Example 2: Parsing Layout Blocks Conditionals via Virtual Fields
You can use the native MediaWiki parser to change your layouts depending on whether a hero has a secondary starting skill or any starting magic:
{{#if:{{#invoke:HeroData|get|dungeon_hero_3|start_skill_2}}
| This hero starts with two skills. Secondary skill ID: {{#invoke:HeroData|get|dungeon_hero_3|start_skill_2}}
| This hero starts with a single skill only!
}}
{{#if:{{#invoke:HeroData|get|dungeon_hero_3|start_magic_1}}
| This hero has a starting spell: {{#invoke:HeroData|get|dungeon_hero_3|start_magic_1}}
| This hero does not know any magic at the start.
}}
Example 3: Cross-Module Integration Chaining
Pass the technical ID returned by this module directly into your skill formatting templates or modules to fetch human-readable information automatically:
The primary starting skill name is: {{#invoke:SkillData|get|{{#invoke:HeroData|get|dungeon_hero_3|start_skill_1}}|name|fr}}
local p = {}
-- Fonction principale pour récupérer une donnée
-- Syntaxe : {{#invoke:HeroData|get|ID_HEROS|CHAMP|LANGUE}}
function p.get(frame)
local args = frame.args[1] and frame.args or frame:getParent().args
local hero_id = args[1]
local field = args[2]
local lang = args[3] or 'en' -- Anglais par défaut
if not hero_id or not field then
return "Erreur : ID ou champ manquant."
end
-- 1. GESTION DES CHAMPS TEXTUELS TRADUITS (name, description, motto)
if field == 'name' or field == 'description' or field == 'motto' then
local target_type = 'hero'
if field == 'motto' then target_type = 'hero_motto' end
local target_field = (field == 'motto') and 'description' or field
-- Requête sur la table Translation
local queryOpts = {
where = string.format('target_id="%s" AND language="%s" AND type="%s"', hero_id, lang, target_type)
}
local res = mw.ext.cargo.query('Translation', target_field, queryOpts)
if res and res[1] and res[1][target_field] then
return res[1][target_field]
else
-- Système de secours (fallback) vers l'anglais si la langue voulue est absente
if lang ~= 'en' then
local fallbackOpts = {
where = string.format('target_id="%s" AND language="en" AND type="%s"', hero_id, target_type)
}
local fallbackRes = mw.ext.cargo.query('Translation', target_field, fallbackOpts)
if fallbackRes and fallbackRes[1] and fallbackRes[1][target_field] then
return fallbackRes[1][target_field]
end
end
return ""
end
end
-- 2. GESTION DES ALIAS VIRTUELS (DÉCOUPAGE DES SKILLS ET MAGIES DE DÉPART)
local cargo_field = field
if field == 'start_skill_1' or field == 'start_skill_2' then
cargo_field = 'start_skills'
elseif field == 'start_magic_1' or field == 'start_magic_2' then
cargo_field = 'start_magics'
end
-- 3. REQUÊTE SUR LA TABLE PRINCIPALE "Hero"
local heroOpts = {
where = string.format('id="%s"', hero_id)
}
local heroRes = mw.ext.cargo.query('Hero', cargo_field, heroOpts)
if heroRes and heroRes[1] and heroRes[1][cargo_field] then
local raw_value = heroRes[1][cargo_field]
-- Traitement spécifique du découpage (pour les skills OU les magies)
if field == 'start_skill_1' or field == 'start_skill_2' or field == 'start_magic_1' or field == 'start_magic_2' then
local items = {}
for item in string.gmatch(raw_value, "([^,]+)") do
table.insert(items, mw.text.trim(item))
end
if field == 'start_skill_1' or field == 'start_magic_1' then
return items[1] or ""
elseif field == 'start_skill_2' or field == 'start_magic_2' then
return items[2] or ""
end
end
-- Comportement normal pour tous les autres champs Cargo d'origine (y compris start_magics brut)
return raw_value
end
return ""
end
return p


