fix: prevent game from auto-starting to avoid stale initialization events

Problem:
When loading a save (e.g., from year 106), events from year 100 would appear.
This happened because the game auto-started on server startup and client
connection, generating initialization events before the user could load a save.

Solution:
1. Backend: Keep game paused on startup even if LLM check passes
2. Backend: Remove auto-resume on first WebSocket connection
3. Frontend: Start with game paused (isManualPaused = true)

Now the user must explicitly click 'resume' to start a new game, or load a
save first. This prevents the race condition where game_loop generates events
with stale world state.
This commit is contained in:
Zihao Xu
2026-01-07 23:41:25 -08:00
committed by bridge
parent 624f697bee
commit 8631be501b
3 changed files with 141 additions and 4 deletions

View File

@@ -126,9 +126,10 @@ class ConnectionManager:
await websocket.accept()
self.active_connections.append(websocket)
# 当第一个客户端连接时,自动恢复游戏
# 不再自动恢复游戏,让用户明确选择"新游戏"或"加载存档"。
# 这样可以避免在用户加载存档前就生成初始化事件。
if len(self.active_connections) == 1:
self._set_pause_state(False, "检测到客户端连接,自动恢复游戏运行")
print("[Auto-Control] 检测到客户端连接,游戏保持暂停状态,等待用户操作")
def disconnect(self, websocket: WebSocket):
if websocket in self.active_connections:
@@ -367,7 +368,10 @@ def init_game():
print("LLM 连通性检测通过 ✓")
game_instance["llm_check_failed"] = False
game_instance["llm_error_message"] = ""
game_instance["is_paused"] = False
# 即使 LLM 检测通过,也保持暂停状态。
# 等待用户选择"新游戏"或"加载存档"后再开始运行。
# 这样可以避免在用户加载存档前就生成初始化事件(如长期目标)。
game_instance["is_paused"] = True
# ===== LLM 检测结束 =====
async def game_loop():