Fix Animate order so that map draws properly

This commit is contained in:
Tyler Marques 2025-03-07 16:23:37 -05:00
parent f34ef44002
commit 4e73846dcf
No known key found for this signature in database
GPG key ID: 7672EFD79378341C

View file

@ -6,6 +6,7 @@ import { addMapMouseEvents } from "./map/mouseMovement"
import { createLabel } from "./map/labels" import { createLabel } from "./map/labels"
import "./style.css" import "./style.css"
const isDebugMode = process.env.NODE_ENV === 'development' || localStorage.getItem('debug') === 'true';
// --- CORE VARIABLES --- // --- CORE VARIABLES ---
let scene, camera, renderer, controls; let scene, camera, renderer, controls;
@ -114,12 +115,12 @@ function initScene() {
infoPanel.textContent = `Error loading coords: ${err.message}`; infoPanel.textContent = `Error loading coords: ${err.message}`;
}); });
// Kick off animation loop
animate();
// Handle resizing // Handle resizing
window.addEventListener('resize', onWindowResize); window.addEventListener('resize', onWindowResize);
addMapMouseEvents(mapView, infoPanel) addMapMouseEvents(mapView, infoPanel)
// Kick off animation loop
animate();
} }
@ -294,7 +295,7 @@ function loadCoordinateData() {
} }
// --- CREATE THE FALLBACK MAP AS A PLANE --- // --- CREATE THE FALLBACK MAP AS A PLANE ---
function drawMap(ownershipMap = null) { function drawMap() {
const loader = new SVGLoader(); const loader = new SVGLoader();
loader.load('assets/maps/standard/standard.svg', loader.load('assets/maps/standard/standard.svg',
function (data) { function (data) {
@ -317,7 +318,6 @@ function drawMap(ownershipMap = null) {
continue continue
} else if (provinceKey && coordinateData.provinces[provinceKey] && coordinateData.provinces[provinceKey].owner) { } else if (provinceKey && coordinateData.provinces[provinceKey] && coordinateData.provinces[provinceKey].owner) {
fillColor = getPowerHexColor(coordinateData.provinces[provinceKey].owner) fillColor = getPowerHexColor(coordinateData.provinces[provinceKey].owner)
} }
else { else {
fillColor = map_styles[path.userData.node.classList[0]].fill; fillColor = map_styles[path.userData.node.classList[0]].fill;
@ -473,7 +473,6 @@ function updateSupplyCenterOwnership(centers) {
// centers is typically { "AUSTRIA":["VIE","BUD"], "FRANCE":["PAR","MAR"], ... } // centers is typically { "AUSTRIA":["VIE","BUD"], "FRANCE":["PAR","MAR"], ... }
for (const [power, provinces] of Object.entries(centers)) { for (const [power, provinces] of Object.entries(centers)) {
provinces.forEach(p => { provinces.forEach(p => {
coordinateData.provinces[p.toUpperCase()].owner = power.toUpperCase();
// No messages, animate units immediately // No messages, animate units immediately
ownershipMap[p.toUpperCase()] = power.toUpperCase(); ownershipMap[p.toUpperCase()] = power.toUpperCase();
}); });
@ -674,6 +673,7 @@ function displayInitialPhase(index) {
} }
updateLeaderboard(phase); updateLeaderboard(phase);
updateMapOwnership(phase)
// DON'T show messages yet - skip updateChatWindows call // DON'T show messages yet - skip updateChatWindows call
@ -779,7 +779,6 @@ function advanceToNextPhase() {
// Display the new phase with animation // Display the new phase with animation
displayPhaseWithAnimation(currentPhaseIndex); displayPhaseWithAnimation(currentPhaseIndex);
drawMap()
} }
function displayPhaseWithAnimation(index) { function displayPhaseWithAnimation(index) {
@ -826,6 +825,7 @@ function displayPhaseWithAnimation(index) {
infoPanel.textContent = `Phase: ${currentPhase.name}\nSCs: ${currentPhase.state?.centers ? JSON.stringify(currentPhase.state.centers) : 'None' infoPanel.textContent = `Phase: ${currentPhase.name}\nSCs: ${currentPhase.state?.centers ? JSON.stringify(currentPhase.state.centers) : 'None'
}\nUnits: ${currentPhase.state?.units ? JSON.stringify(currentPhase.state.units) : 'None' }\nUnits: ${currentPhase.state?.units ? JSON.stringify(currentPhase.state.units) : 'None'
}`; }`;
drawMap()
} }
function updateMapOwnership(currentPhase) { function updateMapOwnership(currentPhase) {
@ -1201,13 +1201,12 @@ function updateChatWindows(phase, stepMessages = false) {
} }
const msg = relevantMessages[index]; const msg = relevantMessages[index];
const isNew = addMessageToChat(msg, phase.name); const isNew = addMessageToChat(msg, phase.name);
if (isNew) { if (isNew && !isDebugMode) {
animateHeadNod(msg); animateHeadNod(msg);
} }
index++; index++;
// Increase the delay between messages - 3x the playback speed gives more spacing // Increase the delay between messages - 3x the playback speed gives more spacing
// Remove the delay if we're developing // Remove the delay if we're developing
const isDebugMode = process.env.NODE_ENV === 'development' || localStorage.getItem('debug') === 'true';
if (isDebugMode) { if (isDebugMode) {
showNext() showNext()
} else { } else {