diff --git a/static/js/app.js b/static/js/app.js
index e29d5b2..935856a 100644
--- a/static/js/app.js
+++ b/static/js/app.js
@@ -1,4 +1,21 @@
document.addEventListener("DOMContentLoaded", () => {
+ let buildingNames = {};
+ let unitNames = {};
+
+ // Fetch building names first
+ fetch("/api/buildings")
+ .then(res => res.json())
+ .then(data => {
+ buildingNames = data;
+ });
+
+ // Fetch unit names
+ fetch("/api/units")
+ .then(res => res.json())
+ .then(data => {
+ unitNames = data;
+ });
+
fetch("/api/data")
.then(res => res.json())
.then(data => {
@@ -51,29 +68,80 @@ document.addEventListener("DOMContentLoaded", () => {
item.addEventListener("click", () => {
const townId = parseInt(item.dataset.townid);
const selectedTown = player.towns.find(t => t.town_id === townId);
- showTownDetails(selectedTown);
+ showTownMenu(selectedTown);
});
});
}
- // Step 2: Show town data
- function showTownDetails(town) {
+ // Step 2: Show town menu
+ function showTownMenu(town) {
let html = `
${town.town_name}
`;
- html += `Points: ${town.points} | Population: ${town.population}
`;
- html += `Resources
-
+ html += `Select info to view:
`;
+ html += `
+
+
+ `;
+ playerDetails.innerHTML = html;
+
+ const infoSelect = document.getElementById("town-info-select");
+ const infoDisplay = document.getElementById("town-info-display");
+
+ function renderInfo(option) {
+ let displayHTML = "";
+ if (option === "main") {
+ displayHTML += `Main Info
`;
+ displayHTML += `
+ - Sea: ${town.sea}
- Wood: ${town.wood}
- Stone: ${town.stone}
- Iron: ${town.iron}
-
`;
- html += `Buildings
`;
- Object.entries(town.buildings).forEach(([b, lvl]) => {
- if (b !== "id") {
- html += `- ${b}: ${lvl}
`;
+ - Population: ${town.population}
+ - Points: ${town.points}
+
`;
+ displayHTML += `Buildings
`;
+ Object.entries(town.buildings).forEach(([b, lvl]) => {
+ if (b !== "id") {
+ const name = buildingNames[b]?.name || b;
+ displayHTML += `- ${name}: ${lvl}
`;
+ }
+ });
+ displayHTML += `
`;
+ } else if (option === "buildingOrder") {
+ displayHTML += `Building Order
`;
+ town.buildingOrder.forEach(b => {
+ const name = buildingNames[b.building_type]?.name || b.building_type;
+ displayHTML += `- ${name} (ID: ${b.id}) - To complete at: ${b.to_be_completed_at}
`;
+ });
+ displayHTML += `
`;
+ } else if (option === "researches") {
+ displayHTML += `Researches
`;
+ Object.entries(town.researches).forEach(([r, val]) => {
+ if (r !== "id" && val) displayHTML += `- ${r}
`;
+ });
+ displayHTML += `
`;
+ } else if (option === "units") {
+ displayHTML += `Units
`;
+ Object.entries(town.units).forEach(([u, val]) => {
+ const name = unitNames[u]?.name || u; // <-- Use Greek name mapping
+ displayHTML += `- ${name}: ${val}
`;
+ });
+ displayHTML += `
`;
}
+ infoDisplay.innerHTML = displayHTML;
+ }
+
+ // Initial render
+ renderInfo(infoSelect.value);
+
+ // Update on selection change
+ infoSelect.addEventListener("change", () => {
+ renderInfo(infoSelect.value);
});
- html += `
`;
- playerDetails.innerHTML = html;
}
});
});