summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop/Game.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-21 02:10:02 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-21 02:10:02 +0800
commitdd0907573e13981035a5ff264831edb0534e3496 (patch)
tree8ecd0fa3db6c3d084f064f6f9c96009f3c7f12fd /src/LivingVillage.Desktop/Game.fs
parentfc77481196aaea817eec991bdcf4dc22bb1d245c (diff)
downloadliving-village-dd0907573e13981035a5ff264831edb0534e3496.tar.gz
feat(desktop): LV_AUTOPLAY_SAMPLE 情境演示脚本
新增 SampleScript 状态机:进门→内景驻留→出门→走向 NPC →打开对话→发送意图→关闭面板→走开,超时兜底进 SampleComplete。 Game.fs 读取 LV_AUTOPLAY_SAMPLE=1 切换 sample 模式(2x 模拟、 关闭旧 step 倍率、UpdateMenu 常开、独立 UpdatePlaying 分发)。 SampleTests 覆盖首步行走、进门、完整巡游(42/42 通过)。
Diffstat (limited to 'src/LivingVillage.Desktop/Game.fs')
-rw-r--r--src/LivingVillage.Desktop/Game.fs34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs
index 514928f..1245e02 100644
--- a/src/LivingVillage.Desktop/Game.fs
+++ b/src/LivingVillage.Desktop/Game.fs
@@ -96,9 +96,11 @@ type LivingVillageGame() as this =
let autoplay = Environment.GetEnvironmentVariable("LV_AUTOPLAY") = "1"
let autoplayFlow = Environment.GetEnvironmentVariable("LV_AUTOPLAY_FLOW") = "1"
+ let sampleMode = Environment.GetEnvironmentVariable("LV_AUTOPLAY_SAMPLE") = "1"
let automated = autoplay || autoplayFlow
let modeName =
- if autoplayFlow then "autoplay-flow"
+ if sampleMode then "sample"
+ elif autoplayFlow then "autoplay-flow"
elif autoplay then "autoplay"
else "keyboard"
let configuredStepsPerFrame =
@@ -110,6 +112,8 @@ type LivingVillageGame() as this =
| _ -> 1
let initialSimulationControl, initialLegacyStepsPerFrame =
SimulationControl.initialForConfiguredSteps configuredStepsPerFrame
+ let startSimulationControl =
+ if sampleMode then SimulationControl.setSpeed TwoX initialSimulationControl else initialSimulationControl
let savePath =
match Environment.GetEnvironmentVariable("LV_SAVE_PATH") with
| null | "" -> "living-village.save"
@@ -129,11 +133,12 @@ type LivingVillageGame() as this =
let mutable relationView = false
let mutable relationSnapshot: float32[,] option = None
let mutable m5View = M5Interaction.initial
- let mutable simulationControl = initialSimulationControl
- let mutable legacyStepsPerFrame = initialLegacyStepsPerFrame
- let mutable menu = MenuState.create initialSimulationControl false
+ let mutable simulationControl = startSimulationControl
+ let mutable legacyStepsPerFrame = (if sampleMode then None else initialLegacyStepsPerFrame)
+ let mutable menu = MenuState.create startSimulationControl false
let mutable autoplayFrames = 0
let mutable flowStep = 0
+ let mutable sampleState = SampleScript.initial
do
graphics.PreferredBackBufferWidth <- 1280
@@ -235,13 +240,32 @@ type LivingVillageGame() as this =
else None
match input with
| Some nextInput -> this.DispatchMenuInput nextInput
- | None when autoplay && not autoplayFlow && menu.Page = MainMenu && not menu.HasCurrentWorld ->
+ | None when (autoplay || sampleMode) && not autoplayFlow && menu.Page = MainMenu && not menu.HasCurrentWorld ->
autoplayFrames <- autoplayFrames + 1
if autoplayFrames >= 15 then
this.DispatchMenuInput Confirm
| None -> ()
+ member private this.RunSampleMode () =
+ let stageBefore = sampleState.Stage
+ let positionBefore = world.Avatar.Pos
+ let nextWorld, nextView, nextState = SampleScript.runFrame world m5View sampleState
+ if nextWorld.Avatar.Pos <> positionBefore then
+ avatarFacing <- VillageArt.facingAfterMovement positionBefore nextWorld.Avatar.Pos avatarFacing
+ world <- nextWorld
+ m5View <- nextView
+ sampleState <- nextState
+ this.CenterCamera()
+ if nextState.Stage <> stageBefore then
+ printfn $"sample stage={nextState.Stage} tick={nextWorld.Tick} pos=({nextWorld.Avatar.Pos.X:F0},{nextWorld.Avatar.Pos.Y:F0})"
+
member private this.UpdatePlaying (gameTime: GameTime) (kb: KeyboardState) (pressed: Keys -> bool) (pressedAny: Keys list -> bool) =
+ if sampleMode then
+ this.RunSampleMode()
+ else
+ this.UpdatePlayingManual gameTime kb pressed pressedAny
+
+ member private this.UpdatePlayingManual (gameTime: GameTime) (kb: KeyboardState) (pressed: Keys -> bool) (pressedAny: Keys list -> bool) =
let mutable loadFailed = false
let mutable leftGame = false
let lPressed = pressed Keys.L