Map-Bilder und Seitenwahl mit Emblemen

Map-Bilder aus ghostcap-gaming/cs2-map-images lokal als WebP gespeichert
(npm run images lädt und verkleinert sie). Bilder in Veto-Kacheln,
Pool-Vorschau, Serie und Seitenwahl; CT/T-Embleme aus client/public/sides
mit Ersatzsymbol, falls die Dateien fehlen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SPP UserandClaude Opus 5.5 committed 2026-10-25 17:23:55 +01:00
1 parent 3a790ce0b1
commit 54168ae763
21 files changed
+701 -27

No files matched your search

+56
View File
@@ -0,0 +1,56 @@
// Lädt für alle Maps aus server/config/map-pools.json ein Bild herunter, verkleinert es
// und speichert es als WebP unter client/public/maps/<map>.webp. Danach zeigt "image" in
// der Konfiguration auf die lokale Datei.
//
// Aufruf: npm run images fehlende Bilder laden
// npm run images -- --force alle Bilder neu laden
//
// Quelle: https://github.com/ghostcap-gaming/cs2-map-images (Bilder aus dem Spiel, Rechte bei Valve)
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import sharp from 'sharp';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const poolFile = path.join(root, 'server', 'config', 'map-pools.json');
const outDir = path.join(root, 'client', 'public', 'maps');
const SOURCE = 'https://cdn.jsdelivr.net/gh/ghostcap-gaming/cs2-map-images@main/cs2/';
const WIDTH = 960;
const force = process.argv.includes('--force');
const config = JSON.parse(fs.readFileSync(poolFile, 'utf8'));
fs.mkdirSync(outDir, { recursive: true });
const ids = [...new Set(Object.values(config.pools).flatMap((p) => p.maps.map((m) => m.id)))];
const saved = new Set();
let failed = 0;
for (const id of ids) {
const target = path.join(outDir, `${id}.webp`);
if (!force && fs.existsSync(target)) {
console.log(`= ${id} (vorhanden)`);
saved.add(id);
continue;
}
try {
const res = await fetch(`${SOURCE}${id}.png`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const input = Buffer.from(await res.arrayBuffer());
const info = await sharp(input).resize({ width: WIDTH, withoutEnlargement: true }).webp({ quality: 78 }).toFile(target);
console.log(`+ ${id}: ${Math.round(input.length / 1024)} KB -> ${Math.round(info.size / 1024)} KB`);
saved.add(id);
} catch (err) {
failed++;
console.warn(`! ${id}: kein Bild (${err.message}) – Map behält das Farbmuster`);
}
}
// Konfiguration auf lokale Dateien umstellen (nur für Maps mit gespeichertem Bild).
let text = fs.readFileSync(poolFile, 'utf8');
for (const id of saved) {
const entry = new RegExp(`("id": "${id}"[^}]*?"image": ")[^"]*(")`, 'g');
text = text.replace(entry, `$1/maps/${id}.webp$2`);
}
fs.writeFileSync(poolFile, text);
console.log(`Fertig: ${saved.size} Bilder in client/public/maps${failed ? `, ${failed} fehlgeschlagen` : ''}.`);