summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop.Tests/DesktopTests.fs
diff options
context:
space:
mode:
authorSomhairle H. Marisol <[email protected]>2026-09-21 22:57:50 +0800
committerSomhairle H. Marisol <[email protected]>2026-09-21 22:57:50 +0800
commit60bbc83d9a1d047933e4128e7b48e1c61c925a14 (patch)
treec41b351535add285f8644d8703fa6c4f1799eeb3 /src/LivingVillage.Desktop.Tests/DesktopTests.fs
parente1d8d45cf08b4f30e33299eb40e865729e7adfd2 (diff)
downloadliving-village-60bbc83d9a1d047933e4128e7b48e1c61c925a14.tar.gz
feat(desktop): P15 开局职业选择页——新档四选一+暂不选择,接入 v3 存档与当日任务
- MenuState:新增 OccupationSelect 页与 StartNewGameWith 命令;occupationOptions=农夫/渔夫/货郎/书生/暂不选择, 默认高亮「暂不选择」= 不写职业的旧行为;四选一确认后发 StartNewGameWith,ESC 返回主菜单(既有 MainMenu 行为与测试不变)。 - WorldBootstrap.occupationStateFor/refreshOccupationToday:按 seed+职业种子生成/跨日刷新当日 Offered 任务。 - Game:主菜单「开始新游戏」→ 职业选择页;选定后 initialWorldWithOccupation 注入 Money/Energy 与 Today, m5View.Task 随之写入 v3 存档;游玩中按日刷新;autoplay/flow 默认走「暂不选择」保持旧演示行为;DrawMenu 渲染职业页。 - 测试 Desktop 93(新增 6):职业页选项顺序/默认 None/标签、确认命令与返回、bootstrap 四职业 Money/Energy+当日池内 Offered 任务、四职业 v3 round-trip(职业+任务逐字段)、T 面板显示所选职业的模板名与「待接受」、跨日刷新保持同日。
Diffstat (limited to 'src/LivingVillage.Desktop.Tests/DesktopTests.fs')
-rw-r--r--src/LivingVillage.Desktop.Tests/DesktopTests.fs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/DesktopTests.fs b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
index 52443e9..5f2d6df 100644
--- a/src/LivingVillage.Desktop.Tests/DesktopTests.fs
+++ b/src/LivingVillage.Desktop.Tests/DesktopTests.fs
@@ -208,3 +208,72 @@ type TaskPanelTests () =
Assert.AreEqual<M5View>(dialogueView, afterTask)
let _, closed = M5Interaction.apply ClosePanel world { dialogueView with Panel = TaskPanel }
Assert.AreEqual<M5Panel>(WorldPanel, closed.Panel)
+
+// ---- P15 开局职业选择接入:bootstrap 职业状态 / 存档 round-trip / 面板联调 ----
+
+module private OccupationFlowHarness =
+
+ let withTempSave (action: string -> unit) =
+ let id = System.Guid.NewGuid().ToString("N")
+ let path = System.IO.Path.Combine(System.IO.Path.GetTempPath(), $"living-village-p15-{id}.save")
+ try
+ action path
+ finally
+ if System.IO.File.Exists path then System.IO.File.Delete path
+
+[<TestClass>]
+type OccupationFlowTests () =
+
+ [<TestMethod>]
+ member _.BootstrapStampsOccupationMoneyEnergyAndTodaysOfferedTask () =
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind 0L
+ let task = state.Today.Value
+ Assert.AreEqual<Occupation.TaskState>(Occupation.Offered, task.State)
+ Assert.IsTrue(Occupation.taskPoolOf kind |> List.contains task.TemplateId)
+ Assert.AreEqual<Occupation.DailyTask>(
+ (Occupation.dailyTaskOf 42UL (Occupation.occupationSeedOf kind) 0L kind).Value,
+ task)
+ let world = WorldBootstrap.initialWorldWithOccupation true 42UL 4 (Some state)
+ Assert.AreEqual<float32>(float32 state.Profile.InitialMoney, world.Avatar.Mind.Needs.Money)
+ Assert.AreEqual<float32>(state.Profile.InitialEnergy, world.Avatar.Mind.Needs.Energy)
+
+ [<TestMethod>]
+ member _.ChosenOccupationAndTodaysTaskRoundTripThroughV3Save () =
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind (3L * Sim.ticksPerDay + 120L)
+ let world = WorldBootstrap.initialWorldWithOccupation false 42UL 4 (Some state)
+ OccupationFlowHarness.withTempSave (fun path ->
+ WorldSave.saveToFileWith (Some state) path world
+ let text = System.IO.File.ReadAllText path
+ Assert.IsTrue(text.StartsWith("LV_WORLD_SAVE_V3"), "chosen occupation must save as v3")
+ match WorldSave.loadFromFileWith path with
+ | Ok (restoredWorld, Some restoredState) ->
+ Assert.AreEqual<Occupation.Kind>(kind, restoredState.Profile.Kind)
+ Assert.AreEqual<Occupation.State>(state, restoredState)
+ Assert.AreEqual<string>(text, WorldSave.saveWith (Some restoredState) restoredWorld)
+ | Ok (_, None) -> Assert.Fail($"v3 occupation lost for {kind}")
+ | Error message -> Assert.Fail($"v3 round trip failed for {kind}: {message}"))
+
+ [<TestMethod>]
+ member _.TaskPanelShowsTheChosenOccupationsOfferedTask () =
+ let world = Sim.initialWorldN 42UL 4
+ for kind in Occupation.all do
+ let state = WorldBootstrap.occupationStateFor 42UL kind 0L
+ let view = { M5Interaction.initial with Task = Some state }
+ let _, taskView = M5Interaction.apply ShowTaskPanel world view
+ let lines = M5Interaction.panelLines world taskView
+ Assert.IsTrue(lines |> List.contains (Occupation.nameOf kind), $"occupation name missing for {kind}")
+ Assert.IsTrue(
+ lines |> List.exists (fun line -> line.Contains(Occupation.taskNameOf state.Today.Value.TemplateId)),
+ $"task name missing for {kind}")
+ Assert.IsTrue(lines |> List.exists (fun line -> line.Contains("待接受")), $"offered state missing for {kind}")
+
+ [<TestMethod>]
+ member _.RefreshOccupationTodayKeepsSameDayAndRegeneratesForTheNewDay () =
+ let state = WorldBootstrap.occupationStateFor 42UL Occupation.Farmer 0L
+ Assert.AreEqual<Occupation.State>(state, WorldBootstrap.refreshOccupationToday 42UL state (Sim.ticksPerDay - 1L))
+ let day1 = WorldBootstrap.refreshOccupationToday 42UL state Sim.ticksPerDay
+ Assert.AreEqual<Occupation.DailyTask option>(
+ Some (Occupation.dailyTaskOf 42UL (Occupation.occupationSeedOf Occupation.Farmer) 1L Occupation.Farmer).Value,
+ day1.Today)