More separation and typing

This commit is contained in:
Tyler Marques 2025-03-12 11:05:15 -04:00
parent 44204f77dd
commit f3b7067182
No known key found for this signature in database
GPG key ID: 7672EFD79378341C
4 changed files with 160 additions and 158 deletions

View file

@ -0,0 +1,34 @@
function hashStringToPosition(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = (hash << 5) - hash + str.charCodeAt(i);
hash |= 0;
}
const x = (hash % 800) - 400;
const z = ((hash >> 8) % 800) - 400;
return { x, y: 0, z };
}
//TODO: Make coordinateData come from gameState
export function getProvincePosition(coordinateData, loc) {
// Convert e.g. "Spa/sc" to "SPA_SC" if needed
const normalized = loc.toUpperCase().replace('/', '_');
const base = normalized.split('_')[0];
if (coordinateData && coordinateData.provinces) {
if (coordinateData.provinces[normalized]) {
return {
"x": coordinateData.provinces[normalized].label.x,
"y": 10,
"z": coordinateData.provinces[normalized].label.y
};
}
if (coordinateData.provinces[base]) {
return coordinateData.provinces[base].label;
}
}
// Fallback with offset
const pos = hashStringToPosition(loc);
return { x: pos.x, y: pos.y, z: pos.z + 100 };
}