diff options
Diffstat (limited to 'src/LivingVillage.Desktop/Game.fs')
| -rw-r--r-- | src/LivingVillage.Desktop/Game.fs | 53 |
1 files changed, 41 insertions, 12 deletions
diff --git a/src/LivingVillage.Desktop/Game.fs b/src/LivingVillage.Desktop/Game.fs index 3bb43f8..3f3a1d8 100644 --- a/src/LivingVillage.Desktop/Game.fs +++ b/src/LivingVillage.Desktop/Game.fs @@ -97,6 +97,7 @@ type LivingVillageGame() as this = let autoplay = (Environment.GetEnvironmentVariable("LV_AUTOPLAY") = "1") || (Environment.GetEnvironmentVariable("LV_MAP_TOUR") = "1") let autoplayFlow = Environment.GetEnvironmentVariable("LV_AUTOPLAY_FLOW") = "1" let sampleMode = Environment.GetEnvironmentVariable("LV_AUTOPLAY_SAMPLE") = "1" + let menuShotMode = Environment.GetEnvironmentVariable("LV_AUTOPLAY_MENU_SHOT") = "1" let daylightAutoplay = Environment.GetEnvironmentVariable("LV_AUTOPLAY_DAYLIGHT") = "1" let automated = autoplay || autoplayFlow let modeName = @@ -143,6 +144,7 @@ type LivingVillageGame() as this = let mutable splashActive = true let mutable splashFrame = 0L let mutable menuEntranceFrame = 0L + let mutable menuShotFrame = 0L let mutable autoplayFrames = 0 let mutable flowStep = 0 let mutable flowHold = 0 @@ -316,6 +318,12 @@ type LivingVillageGame() as this = printfn (if nextState.TimedOut then "sample result=timeout" else "sample result=ok") this.Exit() + /// P16-FIX:菜单截图模式。停在开始界面,按确定性帧表向下切到「读档」,帧表见 MenuShotScript。 + member private this.RunMenuShot () = + menuShotFrame <- menuShotFrame + 1L + if menuShotFrame = MenuShotScript.downFrame then + this.DispatchMenuInput Down + member private this.RunMapTour () = let (tileX, tileY) = tourWaypoints.[tourIndex % tourWaypoints.Length] let position : Vec2 = @@ -542,6 +550,8 @@ type LivingVillageGame() as this = this.RunAutoplayFlow() elif menu.Page = Playing then this.UpdatePlaying gameTime kb pressed pressedAny + elif menuShotMode then + this.RunMenuShot() else this.UpdateMenu pressed if menu.Page <> Playing then @@ -605,6 +615,33 @@ type LivingVillageGame() as this = | None -> () spriteBatch.End() + /// 将当前后台缓冲存为 PNG(取证用;record 与菜单截图共用)。 + member private this.SaveBackBuffer (path: string) = + let width = this.GraphicsDevice.PresentationParameters.BackBufferWidth + let height = this.GraphicsDevice.PresentationParameters.BackBufferHeight + let buffer = Array.zeroCreate<Color> (width * height) + this.GraphicsDevice.GetBackBufferData<Color>(buffer) + use texture = new Texture2D(this.GraphicsDevice, width, height) + texture.SetData(buffer) + use stream = System.IO.File.Create(path) + texture.SaveAsPng(stream, width, height) + + /// P16-FIX:按 MenuShotScript 帧表落菜单/启动画面截图,拍完即退出。 + member private this.CaptureMenuShot () = + let save name = + System.IO.Directory.CreateDirectory recordDirectory |> ignore + this.SaveBackBuffer(sprintf "%s/%s.png" recordDirectory name) + if splashActive then + if splashFrame = MenuShotScript.splashMidFrame then + save MenuShotScript.splashMidName + elif menuShotFrame = MenuShotScript.initialFrame then + save MenuShotScript.initialName + elif menuShotFrame = MenuShotScript.loadFrame then + save MenuShotScript.loadName + elif menuShotFrame = MenuShotScript.exitFrame then + printfn "menu-shot=done frames=%d" menuShotFrame + this.Exit() + override this.Draw(gameTime: GameTime) = if splashActive then this.DrawSplash() @@ -618,18 +655,10 @@ type LivingVillageGame() as this = if recordMode && sampleMode then recordIndex <- recordIndex + 1 if recordIndex % recordEvery = 0 then - let directory = recordDirectory - System.IO.Directory.CreateDirectory directory |> ignore - let width, height = - this.GraphicsDevice.PresentationParameters.BackBufferWidth, - this.GraphicsDevice.PresentationParameters.BackBufferHeight - let buffer = Array.zeroCreate<Color> (width * height) - this.GraphicsDevice.GetBackBufferData<Color>(buffer) - use texture = new Texture2D(this.GraphicsDevice, width, height) - texture.SetData(buffer) - let path = sprintf "%s/rec-frame-%04d.png" directory recordIndex - use stream = System.IO.File.Create(path) - texture.SaveAsPng(stream, width, height) + System.IO.Directory.CreateDirectory recordDirectory |> ignore + this.SaveBackBuffer(sprintf "%s/rec-frame-%04d.png" recordDirectory recordIndex) + if menuShotMode then + this.CaptureMenuShot() /// 启动画面:分层天色 + 屋脊/水面剪影 + 标题淡入上浮 + 跳过提示,全部为帧计数纯函数。 member private this.DrawSplash() = |
