Skip to content

Instantly share code, notes, and snippets.

@bryanedds
Created June 11, 2019 01:48
Show Gist options
  • Save bryanedds/52819583dffa72389b48dd3f377eed3d to your computer and use it in GitHub Desktop.
Save bryanedds/52819583dffa72389b48dd3f377eed3d to your computer and use it in GitHub Desktop.
namespace OmniBlade
open System
open FSharpx.Collections
open Prime
open Nu
open Nu.Declarative
open OmniBlade
[<AutoOpen>]
module OmniGame =
type [<NoComparison>] Simulants =
{ Splash : Screen
Title : Screen
TitleGui : Layer
TitlePlay : Entity
TitleCredits : Entity
TitleExit : Entity
Credits : Screen
CreditsGui : Layer
CreditsBack : Entity
Battle : Screen
BattleGui : Layer
BattleBack : Entity }
type OmniCommand =
| PlayTitleSong
| PlaySplashSound
| FadeSong
| ShowTitle
| ShowCredits
| ShowBattle
| ExitGame
type Game with
member this.GetSimulants world : Simulants = this.Get Property? Simulants world
member internal this.SetSimulants (value : Simulants) world = this.Set Property? SetSimulants value world
member this.Simulants = PropertyTag.make this Property? Simulants this.GetSimulants this.SetSimulants
type OmniDispatcher () =
inherit GameDispatcher<Simulants, unit, OmniCommand> (Game.Simulants)
static member Properties =
[define Game.Simulants
{ Splash = !! "Splash"
Title = !! "Title"
TitleGui = !! "Title/Gui"
TitlePlay = !! "Title/Gui/Play"
TitleCredits = !! "Title/Gui/Credits"
TitleExit = !! "Title/Gui/Exit"
Credits = !! "Credits"
CreditsGui = !! "Credits/Gui"
CreditsBack = !! "Credits/Gui/Back"
Battle = !! "Battle"
BattleGui = !! "Battle/Gui"
BattleBack = !! "Battle/Gui/Back" }]
override this.Register (game, world) =
let world = World.hintRenderPackageUse Assets.DefaultPackageName world
let world = World.hintAudioPackageUse Assets.DefaultPackageName world
let world = World.hintRenderPackageUse Assets.GuiPackage world
let world = World.hintAudioPackageUse Assets.GuiPackage world
base.Register (game, world)
override this.Bindings (simulants, _, _) =
[simulants.Title.IncomingStartEvent ==>! PlayTitleSong
simulants.Title.OutgoingStartEvent ==>! FadeSong
simulants.TitleCredits.ClickEvent ==>! ShowCredits
simulants.TitlePlay.ClickEvent ==>! ShowBattle
simulants.TitleExit.ClickEvent ==>! ExitGame
simulants.CreditsBack.ClickEvent ==>! ShowTitle
simulants.Battle.OutgoingStartEvent ==>! FadeSong
simulants.BattleBack.ClickEvent ==>! ShowTitle
simulants.Splash.RegisterEvent ==>! PlaySplashSound]
override this.Update (_, simulants, _, _) =
just simulants
override this.Command (command, simulants, _, world) =
match command with
| PlayTitleSong -> World.playSong 0 (1.0f * Constants.Audio.MasterSongVolume) Assets.TitleSong world
| PlaySplashSound -> World.playSound 1.0f Assets.NuSplashSound world
| FadeSong -> World.fadeOutSong Constants.Audio.DefaultTimeToFadeOutSongMs world
| ShowTitle -> World.transitionScreen simulants.Title world
| ShowCredits -> World.transitionScreen simulants.Credits world
| ShowBattle -> World.transitionScreen simulants.Battle world
| ExitGame -> World.exit world
override this.Layout (simulants, _, _) =
[Layout.screen simulants.Splash (Splash (Constants.OmniBlade.DissolveData, Constants.OmniBlade.SplashData, simulants.Title)) [] []
Layout.screenFromLayerFile simulants.Title (Dissolve Constants.OmniBlade.DissolveData) Assets.TitleLayerFilePath
Layout.screenFromLayerFile simulants.Credits (Dissolve Constants.OmniBlade.DissolveData) Assets.CreditsLayerFilePath
Layout.screenFromLayerFile<BattleDispatcher> simulants.Battle (Dissolve Constants.OmniBlade.DissolveData) Assets.BattleLayerFilePath]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment