Fix weapon icon mapping and local SVG assets

This commit is contained in:
devRaGonSa
2026-06-11 09:02:17 +02:00
parent 9809161aa6
commit 8f9084b8f2
140 changed files with 1367 additions and 325 deletions

View File

@@ -374,11 +374,13 @@ const CURRENT_MATCH_EXTRA_WEAPON_ALIASES = Object.freeze({
"dp 27 lmg": "DP-27",
"flammenwerfer 41": "FLAMMENWERFER 41",
flammenwerfer: "FLAMMENWERFER 41",
flammenwefer41: "FLAMMENWERFER 41",
"german flamethrower": "FLAMMENWERFER 41",
"gewehr 43": "GEWEHR 43",
gewehr43: "GEWEHR 43",
g43: "GEWEHR 43",
fg42x4: "FG42 x4",
"fg42 scoped": "FG42 x4",
"fg42 sniper": "FG42 x4",
kar98k: "KARABINER 98K",
"kar 98k": "KARABINER 98K",
kar98: "KARABINER 98K",
@@ -401,7 +403,6 @@ const CURRENT_MATCH_EXTRA_WEAPON_ALIASES = Object.freeze({
"us sniper springfield": "M1903 SPRINGFIELD",
"scoped springfield": "M1903 SPRINGFIELD",
"m1 carbine": "M1 CARBINE",
"m1 carabine": "M1 CARBINE",
"m1 garand": "M1 GARAND",
garand: "M1 GARAND",
"m2 flamethrower": "M2 FLAMETHROWER",
@@ -429,10 +430,10 @@ const CURRENT_MATCH_EXTRA_WEAPON_ALIASES = Object.freeze({
"mosin nagant m38": "MOSIN NAGANT M38",
"mosin m38": "MOSIN NAGANT M38",
m38: "MOSIN NAGANT M38",
"mp 40": "MP40",
"nagant m1895": "NAGANT M1895",
"nagant revolver": "NAGANT M1895",
panzerschreck: "PANZERSCHRECK",
panzerchreck: "PANZERSCHRECK",
raketenpanzerbuchse: "PANZERSCHRECK",
piat: "PIAT",
"ppsh 41": "PPSH 41",

View File

@@ -622,12 +622,18 @@ function renderNamedCountSection(title, items) {
return `
<article class="historical-player-stats-panel__section">
<h5>${escapeHtml(title)}</h5>
<ol>
<ol class="historical-weapon-stat-list">
${items
.map((stat) => {
const name = stat.name || stat.label || "Sin nombre";
const count = stat.count ?? stat.total ?? 0;
return `<li><span>${escapeHtml(name)}</span><strong>${escapeHtml(formatNumber(count))}</strong></li>`;
return `
<li>
${renderHistoricalWeaponIcon(name)}
<span>${escapeHtml(name)}</span>
<strong>${escapeHtml(formatNumber(count))}</strong>
</li>
`;
})
.join("")}
</ol>
@@ -635,6 +641,47 @@ function renderNamedCountSection(title, items) {
`;
}
function renderHistoricalWeaponIcon(name) {
const weapon = resolveHistoricalWeapon(name);
if (!weapon.icon) {
return `
<span class="historical-weapon-stat-list__icon-frame" aria-hidden="true">
<span class="historical-weapon-stat-list__fallback">?</span>
</span>
`;
}
return `
<span class="historical-weapon-stat-list__icon-frame" aria-hidden="true">
<img
class="historical-weapon-stat-list__icon"
src="${escapeHtml(weapon.icon)}"
alt=""
width="72"
height="26"
loading="lazy"
decoding="async"
onerror="this.hidden = true; this.nextElementSibling.hidden = false;"
/>
<span class="historical-weapon-stat-list__fallback" hidden>?</span>
</span>
`;
}
function resolveHistoricalWeapon(value) {
const runtimeWeaponIcons = globalThis.HLL_VIETNAM_CURRENT_MATCH_WEAPON_ICONS;
if (runtimeWeaponIcons?.lookup) {
const runtimeKey = runtimeWeaponIcons.normalize(value);
return runtimeWeaponIcons.lookup[runtimeKey] || {
label: String(value || runtimeWeaponIcons.unknown.label),
icon: runtimeWeaponIcons.unknown.icon,
};
}
return {
label: String(value || "Arma desconocida"),
icon: "",
};
}
function renderDirectMatchupsSection(matchups) {
if (!matchups.length) {
return `

View File

@@ -10,208 +10,6 @@ const CURRENT_MATCH_SCOREBOARDS = Object.freeze({
"comunidad-hispana-02": "https://scoreboard.comunidadhll.es:5443",
});
const CURRENT_MATCH_KILL_FEED_LIMIT = 18;
const CURRENT_MATCH_WHITE_WEAPON_ICON_PATH = "./assets/img/weapons/white/";
const CURRENT_MATCH_WHITE_WEAPON_ICON_FILES = Object.freeze([
"bazooka_white.svg",
"bren_gun_white.svg",
"browing_m1919_white.svg",
"colt_1911_white.svg",
"dp27_white.svg",
"flammenwefer41_white.svg",
"gewehr_white.svg",
"kar98k_white.svg",
"kar98k_x8_white.svg",
"lee_enfield_n4_white.svg",
"luger_p08_white.svg",
"m1903_springfield_white.svg",
"m1_carabine_white.svg",
"m1_garand_white.svg",
"m2_flamethrower_white.svg",
"m3_grease_gun_white.svg",
"m97_white.svg",
"mg34_white.svg",
"mg42_white.svg",
"mosing_nagant_1891_white.svg",
"mosing_nagant_9130_white.svg",
"mosing_nagant_m38_white.svg",
"mp40_white.svg",
"nagant_m1895_white.svg",
"panzerchreck_white.svg",
"piat_white.svg",
"ppsh41_white.svg",
"ppsh_41w_drum_white.svg",
"ptrs41_white.svg",
"scoped_mosin_nagant_9130_white.svg",
"scoped_svt40_white.svg",
"sten_mk_v_white.svg",
"stg44_white.svg",
"svt40_white.svg",
"thompson_white.svg",
"tokarev_tt33_white.svg",
"walther_p38_white.svg",
"webley_revolver_white.svg",
]);
const CURRENT_MATCH_WEAPONS = Object.freeze({
bazooka: currentMatchWeapon("Bazooka", "bazooka_white.svg"),
"m1 bazooka": currentMatchWeapon("M1 Bazooka", "bazooka_white.svg"),
"us bazooka": currentMatchWeapon("M1 Bazooka", "bazooka_white.svg"),
bren: currentMatchWeapon("Bren Gun", "bren_gun_white.svg"),
"bren gun": currentMatchWeapon("Bren Gun", "bren_gun_white.svg"),
m1919: currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"m1919 browning": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"browning m1919": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
browning: currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"us tank machine gun": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"us coaxial mg": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"us vehicle mg": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"coaxial m1919": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
"m1919 coaxial": currentMatchWeapon("Browning M1919", "browing_m1919_white.svg"),
colt: currentMatchWeapon("Colt 1911", "colt_1911_white.svg"),
"colt 1911": currentMatchWeapon("Colt 1911", "colt_1911_white.svg"),
"colt m1911": currentMatchWeapon("Colt 1911", "colt_1911_white.svg"),
m1911: currentMatchWeapon("Colt 1911", "colt_1911_white.svg"),
"m1911 pistol": currentMatchWeapon("Colt 1911", "colt_1911_white.svg"),
dp27: currentMatchWeapon("DP-27", "dp27_white.svg"),
"dp 27": currentMatchWeapon("DP-27", "dp27_white.svg"),
"dp 27 lmg": currentMatchWeapon("DP-27", "dp27_white.svg"),
"flammenwerfer 41": currentMatchWeapon("Flammenwerfer 41", "flammenwefer41_white.svg"),
flammenwerfer: currentMatchWeapon("Flammenwerfer 41", "flammenwefer41_white.svg"),
flammenwefer41: currentMatchWeapon("Flammenwerfer 41", "flammenwefer41_white.svg"),
"german flamethrower": currentMatchWeapon("Flammenwerfer 41", "flammenwefer41_white.svg"),
"gewehr 43": currentMatchWeapon("Gewehr 43", "gewehr_white.svg"),
gewehr43: currentMatchWeapon("Gewehr 43", "gewehr_white.svg"),
g43: currentMatchWeapon("Gewehr 43", "gewehr_white.svg"),
kar98k: currentMatchWeapon("KARABINER 98K", "kar98k_white.svg"),
"kar 98k": currentMatchWeapon("KARABINER 98K", "kar98k_white.svg"),
kar98: currentMatchWeapon("KARABINER 98K", "kar98k_white.svg"),
k98: currentMatchWeapon("KARABINER 98K", "kar98k_white.svg"),
"k98k": currentMatchWeapon("KARABINER 98K", "kar98k_white.svg"),
"scoped kar98k": currentMatchWeapon("Scoped Kar98k", "kar98k_x8_white.svg"),
"kar98k x8": currentMatchWeapon("Scoped Kar98k", "kar98k_x8_white.svg"),
"kar 98k x8": currentMatchWeapon("Scoped Kar98k", "kar98k_x8_white.svg"),
"german sniper kar98k": currentMatchWeapon("Scoped Kar98k", "kar98k_x8_white.svg"),
"sniper kar98k": currentMatchWeapon("Scoped Kar98k", "kar98k_x8_white.svg"),
"lee enfield no 4": currentMatchWeapon("Lee-Enfield No.4", "lee_enfield_n4_white.svg"),
"lee enfield no4": currentMatchWeapon("Lee-Enfield No.4", "lee_enfield_n4_white.svg"),
"lee enfield": currentMatchWeapon("Lee-Enfield No.4", "lee_enfield_n4_white.svg"),
enfield: currentMatchWeapon("Lee-Enfield No.4", "lee_enfield_n4_white.svg"),
luger: currentMatchWeapon("Luger P08", "luger_p08_white.svg"),
p08: currentMatchWeapon("Luger P08", "luger_p08_white.svg"),
"luger p08": currentMatchWeapon("Luger P08", "luger_p08_white.svg"),
"m1903 springfield": currentMatchWeapon("M1903 Springfield", "m1903_springfield_white.svg"),
springfield: currentMatchWeapon("M1903 Springfield", "m1903_springfield_white.svg"),
"us sniper springfield": currentMatchWeapon("M1903 Springfield", "m1903_springfield_white.svg"),
"scoped springfield": currentMatchWeapon("M1903 Springfield", "m1903_springfield_white.svg"),
"m1 carbine": currentMatchWeapon("M1 Carbine", "m1_carabine_white.svg"),
"m1 carabine": currentMatchWeapon("M1 Carbine", "m1_carabine_white.svg"),
"m1 garand": currentMatchWeapon("M1 Garand", "m1_garand_white.svg"),
garand: currentMatchWeapon("M1 Garand", "m1_garand_white.svg"),
"m2 flamethrower": currentMatchWeapon("M2 Flamethrower", "m2_flamethrower_white.svg"),
"us flamethrower": currentMatchWeapon("M2 Flamethrower", "m2_flamethrower_white.svg"),
"m3 grease gun": currentMatchWeapon("M3 Grease Gun", "m3_grease_gun_white.svg"),
"grease gun": currentMatchWeapon("M3 Grease Gun", "m3_grease_gun_white.svg"),
m97: currentMatchWeapon("Winchester M97", "m97_white.svg"),
"winchester m97": currentMatchWeapon("Winchester M97", "m97_white.svg"),
"trench gun": currentMatchWeapon("Winchester M97", "m97_white.svg"),
shotgun: currentMatchWeapon("Winchester M97", "m97_white.svg"),
mg34: currentMatchWeapon("MG34", "mg34_white.svg"),
"mg 34": currentMatchWeapon("MG34", "mg34_white.svg"),
"german tank machine gun": currentMatchWeapon("MG34", "mg34_white.svg"),
"german coaxial mg": currentMatchWeapon("MG34", "mg34_white.svg"),
"german vehicle mg": currentMatchWeapon("MG34", "mg34_white.svg"),
"coaxial mg34": currentMatchWeapon("MG34", "mg34_white.svg"),
"mg34 coaxial": currentMatchWeapon("MG34", "mg34_white.svg"),
mg42: currentMatchWeapon("MG42", "mg42_white.svg"),
"mg 42": currentMatchWeapon("MG42", "mg42_white.svg"),
"mosin nagant 1891": currentMatchWeapon("Mosin Nagant 1891", "mosing_nagant_1891_white.svg"),
"mosin 1891": currentMatchWeapon("Mosin Nagant 1891", "mosing_nagant_1891_white.svg"),
"mosin nagant 91 30": currentMatchWeapon("Mosin Nagant 91/30", "mosing_nagant_9130_white.svg"),
"mosin 9130": currentMatchWeapon("Mosin Nagant 91/30", "mosing_nagant_9130_white.svg"),
"mosin nagant 9130": currentMatchWeapon("Mosin Nagant 91/30", "mosing_nagant_9130_white.svg"),
"mosin nagant m38": currentMatchWeapon("Mosin Nagant M38", "mosing_nagant_m38_white.svg"),
"mosin m38": currentMatchWeapon("Mosin Nagant M38", "mosing_nagant_m38_white.svg"),
m38: currentMatchWeapon("Mosin Nagant M38", "mosing_nagant_m38_white.svg"),
mp40: currentMatchWeapon("MP40", "mp40_white.svg"),
"mp 40": currentMatchWeapon("MP40", "mp40_white.svg"),
"nagant m1895": currentMatchWeapon("Nagant M1895", "nagant_m1895_white.svg"),
"nagant revolver": currentMatchWeapon("Nagant M1895", "nagant_m1895_white.svg"),
panzerschreck: currentMatchWeapon("Panzerschreck", "panzerchreck_white.svg"),
panzerchreck: currentMatchWeapon("Panzerschreck", "panzerchreck_white.svg"),
raketenpanzerbuchse: currentMatchWeapon("Panzerschreck", "panzerchreck_white.svg"),
piat: currentMatchWeapon("PIAT", "piat_white.svg"),
"ppsh 41": currentMatchWeapon("PPSh-41", "ppsh41_white.svg"),
ppsh41: currentMatchWeapon("PPSh-41", "ppsh41_white.svg"),
ppsh: currentMatchWeapon("PPSh-41", "ppsh41_white.svg"),
"ppsh 41 drum": currentMatchWeapon("PPSh-41 Drum", "ppsh_41w_drum_white.svg"),
"ppsh 41 w drum": currentMatchWeapon("PPSh-41 Drum", "ppsh_41w_drum_white.svg"),
"ppsh drum": currentMatchWeapon("PPSh-41 Drum", "ppsh_41w_drum_white.svg"),
"ppsh41 drum": currentMatchWeapon("PPSh-41 Drum", "ppsh_41w_drum_white.svg"),
"ptrs 41": currentMatchWeapon("PTRS-41", "ptrs41_white.svg"),
ptrs41: currentMatchWeapon("PTRS-41", "ptrs41_white.svg"),
ptrs: currentMatchWeapon("PTRS-41", "ptrs41_white.svg"),
"scoped mosin nagant 91 30": currentMatchWeapon("Scoped Mosin Nagant 91/30", "scoped_mosin_nagant_9130_white.svg"),
"scoped mosin nagant 9130": currentMatchWeapon("Scoped Mosin Nagant 91/30", "scoped_mosin_nagant_9130_white.svg"),
"soviet sniper mosin": currentMatchWeapon("Scoped Mosin Nagant 91/30", "scoped_mosin_nagant_9130_white.svg"),
"sniper mosin": currentMatchWeapon("Scoped Mosin Nagant 91/30", "scoped_mosin_nagant_9130_white.svg"),
"scoped svt 40": currentMatchWeapon("Scoped SVT-40", "scoped_svt40_white.svg"),
"scoped svt40": currentMatchWeapon("Scoped SVT-40", "scoped_svt40_white.svg"),
"svt40 scoped": currentMatchWeapon("Scoped SVT-40", "scoped_svt40_white.svg"),
"sten mk v": currentMatchWeapon("Sten Mk V", "sten_mk_v_white.svg"),
sten: currentMatchWeapon("Sten Mk V", "sten_mk_v_white.svg"),
stg44: currentMatchWeapon("StG 44", "stg44_white.svg"),
"stg 44": currentMatchWeapon("StG 44", "stg44_white.svg"),
"sturmgewehr 44": currentMatchWeapon("StG 44", "stg44_white.svg"),
"svt 40": currentMatchWeapon("SVT-40", "svt40_white.svg"),
svt40: currentMatchWeapon("SVT-40", "svt40_white.svg"),
"m1a1 thompson": currentMatchWeapon("M1A1 Thompson", "thompson_white.svg"),
m1a1: currentMatchWeapon("M1A1 Thompson", "thompson_white.svg"),
"m1928 thompson": currentMatchWeapon("M1928 Thompson", "thompson_white.svg"),
thompson: currentMatchWeapon("Thompson", "thompson_white.svg"),
"tokarev tt 33": currentMatchWeapon("Tokarev TT-33", "tokarev_tt33_white.svg"),
"tokarev tt33": currentMatchWeapon("Tokarev TT-33", "tokarev_tt33_white.svg"),
tt33: currentMatchWeapon("Tokarev TT-33", "tokarev_tt33_white.svg"),
"walther p38": currentMatchWeapon("Walther P38", "walther_p38_white.svg"),
p38: currentMatchWeapon("Walther P38", "walther_p38_white.svg"),
webley: currentMatchWeapon("Webley Revolver", "webley_revolver_white.svg"),
"webley revolver": currentMatchWeapon("Webley Revolver", "webley_revolver_white.svg"),
unknown: { label: "Arma desconocida", icon: "" },
});
validateCurrentMatchWeaponMapping();
function currentMatchWeapon(label, fileName) {
return {
label,
icon: `${CURRENT_MATCH_WHITE_WEAPON_ICON_PATH}${fileName}`,
};
}
function validateCurrentMatchWeaponMapping() {
const expectedIcons = new Set(CURRENT_MATCH_WHITE_WEAPON_ICON_FILES);
const mappedIcons = new Set();
const invalidIcons = [];
Object.entries(CURRENT_MATCH_WEAPONS).forEach(([alias, weapon]) => {
if (!weapon.icon) {
return;
}
if (!weapon.icon.startsWith(CURRENT_MATCH_WHITE_WEAPON_ICON_PATH)) {
invalidIcons.push(`${alias}: ${weapon.icon}`);
return;
}
const fileName = weapon.icon.slice(CURRENT_MATCH_WHITE_WEAPON_ICON_PATH.length);
mappedIcons.add(fileName);
if (!expectedIcons.has(fileName)) {
invalidIcons.push(`${alias}: ${weapon.icon}`);
}
});
const unmappedIcons = [...expectedIcons].filter((fileName) => !mappedIcons.has(fileName));
if (unmappedIcons.length > 0 || invalidIcons.length > 0) {
console.warn("Current match weapon icon mapping needs review.", {
unmappedIcons,
invalidIcons,
});
}
}
document.addEventListener("DOMContentLoaded", () => {
const params = new URLSearchParams(window.location.search);
@@ -534,10 +332,9 @@ function resolveKillFeedWeapon(value) {
icon: runtimeWeaponIcons.unknown.icon,
};
}
const key = normalizeLookupText(value);
return CURRENT_MATCH_WEAPONS[key] || {
label: String(value || CURRENT_MATCH_WEAPONS.unknown.label),
icon: CURRENT_MATCH_WEAPONS.unknown.icon,
return {
label: String(value || "Arma desconocida"),
icon: "",
};
}