Add displaying rest of the requirements for buildings

This commit is contained in:
Aelita4 2024-06-28 16:52:47 +02:00
parent 25b7a01bd6
commit 4f10a18d33
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
5 changed files with 63 additions and 6 deletions

View File

@ -5,6 +5,7 @@
"gold-mine": "Gold mine", "gold-mine": "Gold mine",
"utilities": "Utilities", "utilities": "Utilities",
"research-lab": "Research lab" "research-lab": "Research lab",
"research-facility": "Research facility"
} }
} }

View File

@ -26,6 +26,10 @@
"terraforming": { "terraforming": {
"name": "Terraforming", "name": "Terraforming",
"description": "Allows for changing landscape of planets, making them habitable" "description": "Allows for changing landscape of planets, making them habitable"
},
"advanced-technologies": {
"name": "Advanced Technologies",
"description": "Various advanced technologies"
} }
} }
} }

View File

@ -74,6 +74,39 @@
}, },
"energy": 100, "energy": 100,
"multiplier": 3 "multiplier": 3
},
{
"id": "research-facility",
"requirements": {
"buildings": [
{
"id": "research-lab",
"level": 3
}
],
"research": [
{
"id": "advanced-technologies",
"level": 2
}
],
"resources": [
{
"name": "iron",
"amount": 1
},
{
"name": "gold",
"amount": 1
},
{
"name": "coal",
"amount": 1
}
]
},
"energy": 100,
"multiplier": 2
} }
] ]
} }

View File

@ -106,5 +106,22 @@
}, },
"time": 500, "time": 500,
"multiplier": 3 "multiplier": 3
}, {
"id": "advanced-technologies",
"requirements": {
"buildings": [
{
"id": "research-lab",
"level": 6
}
],
"research": [],
"resources": {
"iron": 1000,
"gold": 500
}
},
"time": 1500,
"multiplier": 4
} }
] ]

View File

@ -4,8 +4,6 @@ import NavBar from '../../components/NavBar.astro';
import { getUserByAccessToken } from '../../lib/db/users'; import { getUserByAccessToken } from '../../lib/db/users';
import { getHighestWeightedLanguage, getLocales } from '../../lib/utils/langDriver'; import { getHighestWeightedLanguage, getLocales } from '../../lib/utils/langDriver';
import ResourceBar from '../../components/ResourceBar.astro'; import ResourceBar from '../../components/ResourceBar.astro';
// import { calculateCurrentAvailableResources } from '../../lib/utils/resourceManager';
// import { getUserResources } from '../../lib/utils/resourceManager';
const buildingsList = (await import('../../lib/data/buildings.json')).default; const buildingsList = (await import('../../lib/data/buildings.json')).default;
@ -16,14 +14,12 @@ if(loggedToken === null || username === "") return Astro.redirect('/logout');
const checkUser = await getUserByAccessToken(loggedToken); const checkUser = await getUserByAccessToken(loggedToken);
if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout'); if(checkUser === null || checkUser.username !== username) return Astro.redirect('/logout');
// const resources = await getUserResources(checkUser._id);
const locale = await getHighestWeightedLanguage(Astro.request.headers.get('accept-language')); const locale = await getHighestWeightedLanguage(Astro.request.headers.get('accept-language'));
const langResources = await getLocales(locale, 'resources'); const langResources = await getLocales(locale, 'resources');
const langGame = await getLocales(locale, 'game'); const langGame = await getLocales(locale, 'game');
const langBuildings = await getLocales(locale, 'buildings'); const langBuildings = await getLocales(locale, 'buildings');
// console.log(await calculateCurrentAvailableResources(checkUser._id)); const langResearch = await getLocales(locale, 'research');
--- ---
<Layout title="Buildings"> <Layout title="Buildings">
@ -38,6 +34,12 @@ const langBuildings = await getLocales(locale, 'buildings');
{building.requirements.resources.map(res => ( {building.requirements.resources.map(res => (
<div>{langResources[`Label_${res.name}`]}: {res.amount}</div> <div>{langResources[`Label_${res.name}`]}: {res.amount}</div>
))} ))}
{building.requirements.buildings.map(b => (
<div>{langBuildings[`Label_${b.id}`]}: {b.level}</div>
))}
{building.requirements.research.map(t => (
<div>{langResearch[`Label_${t.id}`].name}: {t.level}</div>
))}
<a id={`build_${building.id}`} href="#" class="a-button">{langGame['Link_build']}</a> <a id={`build_${building.id}`} href="#" class="a-button">{langGame['Link_build']}</a>
</>))} </>))}
</div> </div>