diff options
Diffstat (limited to 'src/LivingVillage.Desktop.Tests')
| -rw-r--r-- | src/LivingVillage.Desktop.Tests/PrototypeTests.fs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs index af34802..7e4ce5f 100644 --- a/src/LivingVillage.Desktop.Tests/PrototypeTests.fs +++ b/src/LivingVillage.Desktop.Tests/PrototypeTests.fs @@ -630,6 +630,46 @@ type PrototypeTests () = CollectionAssert.AreEqual(snapshot, tieWorld.Npcs) [<TestMethod>] + member _.FloatingPromptStaysInViewportAndClearOfHudBands () = + for (width, height) in [ (1280, 720); (1920, 1080) ] do + let anchors : (float32 * float32) list = + [ (100.0f, 100.0f) // near top-left + (float32 width / 2.0f, float32 height / 2.0f) + (float32 width - 60.0f, 120.0f) // near top-right strip + (200.0f, float32 height - 200.0f) // above bottom-left HUD band + (float32 width - 100.0f, float32 height - 120.0f) ] + for (anchorX, anchorY) in anchors do + for text in [ "E 交谈"; "E 进屋"; "E 出屋" ] do + let rect = FloatingPrompt.layout width height anchorX anchorY 0.0f 0.0f 2 text + let textWidth = FloatingPrompt.measureWidth text 2 + Assert.AreEqual<int>(textWidth, rect.Width) + Assert.IsTrue(rect.Width > 0, "prompt must not be truncated to zero width") + Assert.IsTrue(rect.X >= 0 && rect.X + rect.Width <= width, sprintf "x overflow %A %A" (anchorX, anchorY) rect) + Assert.IsTrue(rect.Y >= 0 && rect.Y + rect.Height <= height, sprintf "y overflow %A %A" (anchorX, anchorY) rect) + // Never cover the bottom-left HUD band (camera 0: band starts at height - 160). + Assert.IsTrue(rect.Y + rect.Height <= height - FloatingPrompt.hudBottomBandHeight + 8, sprintf "bottom HUD overlap %A %A" (anchorX, anchorY) rect) + // Never cover the top-right status strip. + if rect.X + rect.Width >= width - FloatingPrompt.hudTopRightWidth then + Assert.IsTrue(rect.Y >= FloatingPrompt.hudTopRightHeight, sprintf "top-right HUD overlap %A %A" (anchorX, anchorY) rect) + + [<TestMethod>] + member _.FloatingPromptMeasureMatchesPixelTextAdvances () = + // E(12) space(8) 交(16) 谈(16) at scale 2. + Assert.AreEqual<int>(52, FloatingPrompt.measureWidth "E 交谈" 2) + Assert.AreEqual<int>(20, FloatingPrompt.measureWidth "E " 2) + + [<TestMethod>] + member _.FloatingPromptHiddenWhilePanelsOrMenusAreOpen () = + let world = Sim.initialWorldN 42UL 2 + let dialogueView = { M5Interaction.initial with Panel = DialoguePanel } + let cleared = M5Interaction.refreshPrompt world dialogueView + Assert.AreEqual<string option>(None, cleared.Prompt) + Assert.IsFalse(M5Interaction.worldInputAllowed dialogueView) + + let needsView = { M5Interaction.initial with Panel = NeedsPanel } + Assert.AreEqual<string option>(None, M5Interaction.refreshPrompt world needsView |> fun value -> value.Prompt) + + [<TestMethod>] member _.WorldPanelDoesNotRenderA永久KeyList () = let world = Sim.initialWorldN 42UL 0 let lines = M5Interaction.panelLines world M5Interaction.initial |
