summaryrefslogtreecommitdiff
path: root/src/LivingVillage.Desktop
diff options
context:
space:
mode:
Diffstat (limited to 'src/LivingVillage.Desktop')
-rw-r--r--src/LivingVillage.Desktop/Game.fs26
-rw-r--r--src/LivingVillage.Desktop/M6Presentation.fs7
2 files changed, 22 insertions, 11 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs
index 4760d4e..765cea8 100644
--- a/src/LivingVillage.Desktop/Game.fs
+++ b/src/LivingVillage.Desktop/Game.fs
@@ -134,13 +134,16 @@ type LivingVillageGame() as this =
match Double.TryParse(value, Globalization.NumberStyles.Float, Globalization.CultureInfo.InvariantCulture) with
| true, hour -> Some hour
| _ -> None
+ // Single source of truth for the starting tick so the sample/autoplay path (which
+ // re-creates the world via StartNewGame) honours the evidence hour too.
+ let evidenceStartTick () =
+ M6Presentation.resolveStartTick startHourOverride daylightAutoplay
+ let withStartTick (world: World) : World =
+ let tick = evidenceStartTick ()
+ { world with Tick = tick; Time = float tick * Sim.dtSeconds }
let createInitialWorld () =
- let baseWorld = WorldBootstrap.initialWorldForDaylight daylightAutoplay 42UL Sim.npcCount
- match startHourOverride with
- | Some hour ->
- let tick = M6Presentation.startTickForHour hour
- { baseWorld with Tick = tick; Time = float tick * Sim.dtSeconds }
- | None -> baseWorld
+ WorldBootstrap.initialWorldForDaylight daylightAutoplay 42UL Sim.npcCount
+ |> withStartTick
let mutable world = createInitialWorld ()
let mutable camera = Vector2.Zero
let mutable avatarFacing = VillageArt.SouthFacing
@@ -223,17 +226,18 @@ type LivingVillageGame() as this =
this.CenterCamera()
member private this.StartNewGame (occupation: Occupation.Kind option) =
+ let startTick = evidenceStartTick ()
let state =
occupation
- |> Option.map (fun kind ->
- let startTick = if daylightAutoplay then 6L * Sim.ticksPerDay / 24L else 0L
- WorldBootstrap.occupationStateFor 42UL kind startTick)
- world <- WorldBootstrap.initialWorldWithOccupation daylightAutoplay 42UL Sim.npcCount state
+ |> Option.map (fun kind -> WorldBootstrap.occupationStateFor 42UL kind startTick)
+ world <-
+ WorldBootstrap.initialWorldWithOccupation daylightAutoplay 42UL Sim.npcCount state
+ |> withStartTick
this.ResetWorldView()
m5View <- { m5View with Task = state }
menu <- menu |> MenuState.setCurrentWorld true |> MenuState.enterGame
let occupationName = occupation |> Option.map Occupation.nameOf |> Option.defaultValue "none"
- printfn $"new-game=ok seed=42 npcs={Sim.npcCount} occupation={occupationName}"
+ printfn $"new-game=ok seed=42 npcs={Sim.npcCount} occupation={occupationName} tick={world.Tick}"
member private this.SaveWorld (prefix: string) : bool =
try
diff --git a/src/LivingVillage.Desktop/M6Presentation.fs b/src/LivingVillage.Desktop/M6Presentation.fs
index a64d494..752034a 100644
--- a/src/LivingVillage.Desktop/M6Presentation.fs
+++ b/src/LivingVillage.Desktop/M6Presentation.fs
@@ -104,6 +104,13 @@ module M6Presentation =
let startTickForHour (hour: float) : int64 =
int64 (hour * float (Sim.ticksPerDay / 24L))
+ /// Start-tick decision shared by bootstrap and new-game: an explicit evidence hour wins,
+ /// else daylight starts at 6:00, else midnight. Pure function, no side effects.
+ let resolveStartTick (startHour: float option) (startAtDaylight: bool) : int64 =
+ match startHour with
+ | Some hour -> startTickForHour hour
+ | None -> if startAtDaylight then 6L * Sim.ticksPerDay / 24L else 0L
+
let private hourOf (tick: int64) : int =
int ((tick / (Sim.ticksPerDay / 24L)) % 24L)