mirror of
https://github.com/GoodStartLabs/AI_Diplomacy.git
synced 2026-05-02 17:46:00 +00:00
WIP: Moment display at the end of the turn only
This commit is contained in:
parent
25c67cbf78
commit
8a3b6273cc
3 changed files with 37 additions and 50 deletions
|
|
@ -5,6 +5,8 @@ import { advanceToNextPhase } from "../phase";
|
||||||
import { getPowerDisplayName, getAllPowerDisplayNames } from '../utils/powerNames';
|
import { getPowerDisplayName, getAllPowerDisplayNames } from '../utils/powerNames';
|
||||||
import { PowerENUM } from '../types/map';
|
import { PowerENUM } from '../types/map';
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Sometimes the LLMs use lists, and they don't work in the chats. The just appear as bullets within a single line.
|
||||||
let faceIconCache = {}; // Cache for generated face icons
|
let faceIconCache = {}; // Cache for generated face icons
|
||||||
|
|
||||||
// Add a message counter to track sound effect frequency
|
// Add a message counter to track sound effect frequency
|
||||||
|
|
|
||||||
|
|
@ -172,24 +172,6 @@ function animate() {
|
||||||
gameState.camControls.update();
|
gameState.camControls.update();
|
||||||
gameState.renderer.render(gameState.scene, gameState.camera);
|
gameState.renderer.render(gameState.scene, gameState.camera);
|
||||||
|
|
||||||
|
|
||||||
// TODO: This needs to only occur at the end of a phase, not at the beginning during the animation loop.
|
|
||||||
// MOVE ME
|
|
||||||
//
|
|
||||||
const MOMENT_THRESHOLD = 9.0
|
|
||||||
if (!gameState.isDisplayingMoment && gameState.gameData && gameState.momentsData) {
|
|
||||||
let moment = gameState.checkPhaseHasMoment(gameState.gameData.phases[gameState.phaseIndex].name)
|
|
||||||
if (moment !== null && moment.interest_score >= MOMENT_THRESHOLD && moment.hasBeenDisplayed === undefined) {
|
|
||||||
gameState.isDisplayingMoment = true
|
|
||||||
moment.hasBeenDisplayed = true
|
|
||||||
showTwoPowerConversation({ power1: PowerENUM.AUSTRIA, power2: PowerENUM.FRANCE })
|
|
||||||
setTimeout(() => {
|
|
||||||
closeTwoPowerConversation()
|
|
||||||
gameState.isDisplayingMoment = false
|
|
||||||
}, 2000)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,10 @@ import { updateChatWindows, addToNewsBanner } from "./domElements/chatWindows";
|
||||||
import { createAnimationsForNextPhase } from "./units/animate";
|
import { createAnimationsForNextPhase } from "./units/animate";
|
||||||
import { speakSummary } from "./speech";
|
import { speakSummary } from "./speech";
|
||||||
import { config } from "./config";
|
import { config } from "./config";
|
||||||
import { updateNextMomentDisplay } from "./debug/nextMoment";
|
|
||||||
import { debugMenuInstance } from "./debug/debugMenu";
|
import { debugMenuInstance } from "./debug/debugMenu";
|
||||||
|
|
||||||
|
|
||||||
|
const MOMENT_THRESHOLD = 8.0
|
||||||
|
|
||||||
// FIXME: Going to previous phases is borked. Units do not animate properly, map doesn't update.
|
// FIXME: Going to previous phases is borked. Units do not animate properly, map doesn't update.
|
||||||
function _setPhase(phaseIndex: number) {
|
function _setPhase(phaseIndex: number) {
|
||||||
|
|
@ -28,23 +28,49 @@ function _setPhase(phaseIndex: number) {
|
||||||
initUnits(phaseIndex)
|
initUnits(phaseIndex)
|
||||||
displayPhase()
|
displayPhase()
|
||||||
} else {
|
} else {
|
||||||
|
// Clear any existing animations to prevent overlap
|
||||||
|
if (gameState.playbackTimer) {
|
||||||
|
clearTimeout(gameState.playbackTimer);
|
||||||
|
gameState.playbackTimer = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reset animation state
|
||||||
|
gameState.isAnimating = false;
|
||||||
|
gameState.messagesPlaying = false;
|
||||||
|
|
||||||
|
// Advance the phase index
|
||||||
|
gameState.phaseIndex++;
|
||||||
|
if (config.isDebugMode && gameState.gameData) {
|
||||||
|
console.log(`Moving to phase ${gameState.gameData.phases[gameState.phaseIndex].name}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Finally, update the gameState with the current phaseIndex
|
// Finally, update the gameState with the current phaseIndex
|
||||||
gameState.phaseIndex = phaseIndex
|
gameState.phaseIndex = phaseIndex
|
||||||
// If we're at the end of the game, don't attempt to animate.
|
// If we're at the end of the game, don't attempt to animate.
|
||||||
if (phaseIndex === gameLength - 1) {
|
if (phaseIndex === gameLength - 1) {
|
||||||
|
displayFinalPhase()
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
displayPhase()
|
displayPhase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
export function nextPhase() {
|
export function nextPhase() {
|
||||||
|
if (!gameState.isDisplayingMoment && gameState.gameData && gameState.momentsData) {
|
||||||
|
let moment = gameState.checkPhaseHasMoment(gameState.gameData.phases[gameState.phaseIndex].name)
|
||||||
|
if (moment !== null && moment.interest_score >= MOMENT_THRESHOLD && moment.hasBeenDisplayed === undefined) {
|
||||||
|
gameState.isDisplayingMoment = true
|
||||||
|
moment.hasBeenDisplayed = true
|
||||||
|
showTwoPowerConversation({ power1: PowerENUM.AUSTRIA, power2: PowerENUM.FRANCE })
|
||||||
|
setTimeout(() => {
|
||||||
|
closeTwoPowerConversation()
|
||||||
|
gameState.isDisplayingMoment = false
|
||||||
|
}, 2000)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
_setPhase(gameState.phaseIndex + 1)
|
_setPhase(gameState.phaseIndex + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -147,7 +173,7 @@ export function displayPhaseWithAnimation() {
|
||||||
export function advanceToNextPhase() {
|
export function advanceToNextPhase() {
|
||||||
// If we're not "playing" through the game, just skipping phases, move everything along
|
// If we're not "playing" through the game, just skipping phases, move everything along
|
||||||
if (!gameState.isPlaying) {
|
if (!gameState.isPlaying) {
|
||||||
moveToNextPhase()
|
nextPhase()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gameState.gameData || !gameState.gameData.phases || gameState.phaseIndex < 0) {
|
if (!gameState.gameData || !gameState.gameData.phases || gameState.phaseIndex < 0) {
|
||||||
|
|
@ -181,13 +207,13 @@ export function advanceToNextPhase() {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
console.log("Speech completed successfully");
|
console.log("Speech completed successfully");
|
||||||
if (gameState.isPlaying) {
|
if (gameState.isPlaying) {
|
||||||
moveToNextPhase();
|
nextPhase();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Speech failed with error:", error);
|
console.error("Speech failed with error:", error);
|
||||||
if (gameState.isPlaying) {
|
if (gameState.isPlaying) {
|
||||||
moveToNextPhase();
|
nextPhase();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -196,7 +222,7 @@ export function advanceToNextPhase() {
|
||||||
} else {
|
} else {
|
||||||
console.log("No summary available, skipping speech");
|
console.log("No summary available, skipping speech");
|
||||||
// No summary to speak, advance immediately
|
// No summary to speak, advance immediately
|
||||||
moveToNextPhase();
|
nextPhase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,26 +281,3 @@ function displayFinalPhase() {
|
||||||
logger.log("Could not determine game winner");
|
logger.log("Could not determine game winner");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Internal helper to handle the actual phase advancement
|
|
||||||
*/
|
|
||||||
function moveToNextPhase() {
|
|
||||||
// Clear any existing animations to prevent overlap
|
|
||||||
if (gameState.playbackTimer) {
|
|
||||||
clearTimeout(gameState.playbackTimer);
|
|
||||||
gameState.playbackTimer = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset animation state
|
|
||||||
gameState.isAnimating = false;
|
|
||||||
gameState.messagesPlaying = false;
|
|
||||||
|
|
||||||
// Advance the phase index
|
|
||||||
gameState.phaseIndex++;
|
|
||||||
if (config.isDebugMode && gameState.gameData) {
|
|
||||||
console.log(`Moving to phase ${gameState.gameData.phases[gameState.phaseIndex].name}`);
|
|
||||||
}
|
|
||||||
// Display the next phase and start showing its messages
|
|
||||||
displayPhaseWithAnimation();
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue