+94
-1
@@ -8,12 +8,28 @@ const auth = require("./src/auth");
|
||||
const labels = require("./src/labels");
|
||||
const fmt = require("./src/format");
|
||||
|
||||
const inventory = require("./src/inventory");
|
||||
const itemIcons = require("./src/itemIcons");
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3000;
|
||||
|
||||
app.set("view engine", "ejs");
|
||||
app.set("views", path.join(__dirname, "views"));
|
||||
app.use(express.static(path.join(__dirname, "public")));
|
||||
|
||||
app.get("/icons/items/:itemId.png", (req, res) => {
|
||||
const itemId = decodeURIComponent(req.params.itemId);
|
||||
const data = itemIcons.getIconData(itemId);
|
||||
if (!data) {
|
||||
res.type("image/svg+xml");
|
||||
return res.sendFile(path.join(__dirname, "public/icons/unknown.svg"));
|
||||
}
|
||||
res.set("Content-Type", "image/png");
|
||||
res.set("Cache-Control", "public, max-age=86400");
|
||||
res.send(data);
|
||||
});
|
||||
|
||||
app.use(express.urlencoded({ extended: false }));
|
||||
|
||||
app.use(
|
||||
@@ -38,6 +54,8 @@ app.use((req, res, next) => {
|
||||
];
|
||||
res.locals.fmt = fmt;
|
||||
res.locals.auth = auth;
|
||||
res.locals.db = db;
|
||||
res.locals.itemIcons = itemIcons;
|
||||
res.locals.dbStatus = db.getDbStatus();
|
||||
res.locals.sessionUser = req.session.playerUuid
|
||||
? {
|
||||
@@ -48,6 +66,67 @@ app.use((req, res, next) => {
|
||||
next();
|
||||
});
|
||||
|
||||
function loadPlayerInventory(player) {
|
||||
const characterId = inventory.resolveCharacterId(player);
|
||||
const slots = db.getCharacterInventory(characterId);
|
||||
return inventory.buildInventoryView(slots);
|
||||
}
|
||||
|
||||
function enrichCharacter(character) {
|
||||
if (!character) return null;
|
||||
|
||||
const classLabel = labels.labelClass(
|
||||
character.class_id,
|
||||
db.getReferenceLabel("classes", character.class_id),
|
||||
);
|
||||
const raceLabel = labels.labelRace(
|
||||
character.race_id,
|
||||
db.getReferenceLabel("races", character.race_id),
|
||||
);
|
||||
const jobs = labels.parseJsonArray(character.jobs).map(labels.labelJob);
|
||||
const powers = labels.parseJsonArray(character.powers).map(labels.labelPower);
|
||||
|
||||
return {
|
||||
...character,
|
||||
display_name: character.name ?? character.display_name,
|
||||
classLabel,
|
||||
raceLabel,
|
||||
jobs,
|
||||
powers,
|
||||
};
|
||||
}
|
||||
|
||||
function loadAccountCharacters(accountUuid) {
|
||||
if (db.hasCharactersTable()) {
|
||||
const activeCharacterId = db.getActiveCharacterId(accountUuid);
|
||||
return db.getCharactersByAccountUuid(accountUuid).map((character) => {
|
||||
const enriched = enrichCharacter(character);
|
||||
return {
|
||||
...enriched,
|
||||
character_id: character.id,
|
||||
isActive: character.id === activeCharacterId,
|
||||
playerInventory: inventory.buildInventoryView(
|
||||
db.getCharacterInventory(character.id),
|
||||
),
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
const player = enrichPlayer(db.getPlayerByUuid(accountUuid));
|
||||
if (!player) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
{
|
||||
...player,
|
||||
character_id: inventory.resolveCharacterId(player),
|
||||
isActive: true,
|
||||
playerInventory: loadPlayerInventory(player),
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
function enrichPlayer(player) {
|
||||
if (!player) return null;
|
||||
|
||||
@@ -120,7 +199,7 @@ app.get("/players/:uuid", (req, res) => {
|
||||
title: player.display_name,
|
||||
player,
|
||||
group,
|
||||
comingSoon: true,
|
||||
comingSoon: false,
|
||||
isOwner: req.session.playerUuid === player.uuid,
|
||||
});
|
||||
});
|
||||
@@ -146,12 +225,14 @@ app.get("/profile", (req, res) => {
|
||||
}
|
||||
|
||||
const group = db.getGroupForPlayer(player.uuid);
|
||||
const characters = loadAccountCharacters(req.session.playerUuid);
|
||||
|
||||
return res.render("profile/account", {
|
||||
page: "profile",
|
||||
title: "Mon profil",
|
||||
player,
|
||||
group,
|
||||
characters,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -256,4 +337,16 @@ app.listen(PORT, () => {
|
||||
console.warn(`Base SQLite introuvable : ${status.path}`);
|
||||
console.warn("Lancez le serveur Hytale pour créer mmorpg.db à la racine du monorepo.");
|
||||
}
|
||||
const icons = itemIcons.getStatus();
|
||||
if (!icons.available) {
|
||||
console.warn("Icônes Hytale indisponibles.");
|
||||
if (icons.error) {
|
||||
console.warn(` → ${icons.error}`);
|
||||
}
|
||||
console.warn(" → Définissez HYTALE_ASSETS_ZIP dans Webapp/.env si besoin.");
|
||||
} else {
|
||||
console.log(
|
||||
`Icônes Hytale (${icons.backend}) : ${icons.indexedIcons} PNG indexés, ${icons.indexedItems} items — ${icons.assetsZip}`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user