Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryanedds/14ca89803b1c57b701540343a42e1c5d to your computer and use it in GitHub Desktop.
Save bryanedds/14ca89803b1c57b701540343a42e1c5d to your computer and use it in GitHub Desktop.
namespace OmniBlade
open Prime
open Nu
open OmniBlade
[<AutoOpen>]
module OmniGame =
type [<NoComparison>] OmniModel =
{ Omniscreen : Screen
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 OmniEffect =
| InitializeGame
| PlayTitleSong
| FadeSong
| ShowTitle
| ShowCredits
| ShowBattle
| ExitGame
type Game with
member this.GetOmniModel world : OmniModel = this.Get Property? OmniModel world
member this.SetOmniModel (value : OmniModel) world = this.Set Property? OmniModel value world
member this.OmniModel = PropertyTag.make this Property? OmniModel this.GetOmniModel this.SetOmniModel
type OmniDispatcher () =
inherit GameDispatcher<OmniModel, unit, OmniEffect> (fun game -> game.OmniModel)
static member PropertyDefinitions =
[Define? OmniModel
{ Omniscreen = Screen "OmniScreen"
Splash = Screen "Splash"
Title = Screen "Title"
TitleGui = Layer "Title/Gui"
TitlePlay = Entity "Title/Gui/Play"
TitleCredits = Entity "Title/Gui/Credits"
TitleExit = Entity "Title/Gui/Exit"
Credits = Screen "Credits"
CreditsGui = Layer "Credits/Gui"
CreditsBack = Entity "Credits/Gui/Back"
Battle = Screen "Battle"
BattleGui = Layer "Battle/Gui"
BattleBack = Entity "Battle/Gui/Back" }]
override this.Binding (model, game, _) =
[game.RegisterEvent ==>! InitializeGame
model.Title.IncomingStartEvent ==>! PlayTitleSong
model.Title.OutgoingStartEvent ==>! FadeSong
model.TitleCredits.ClickEvent ==>! ShowCredits
model.TitlePlay.ClickEvent ==>! ShowBattle
model.TitleExit.ClickEvent ==>! ExitGame
model.CreditsBack.ClickEvent ==>! ShowTitle
model.Battle.OutgoingStartEvent ==>! FadeSong
model.BattleBack.ClickEvent ==>! ShowTitle]
override this.Message (_, model, _, _) =
just model
override this.Command (command, model, _, world) =
match command with
| InitializeGame ->
// hint to the renderer and audio systems
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
// create screens
let world = World.createScreen (Some model.Omniscreen.ScreenName) world |> snd
let world = World.setOmniscreen model.Omniscreen world
let world = World.createDissolveScreenFromLayerFile (Some model.Title.ScreenName) Constants.OmniBlade.DissolveData Assets.TitleLayerFilePath world |> snd
let world = World.createDissolveScreenFromLayerFile (Some model.Credits.ScreenName) Constants.OmniBlade.DissolveData Assets.CreditsLayerFilePath world |> snd
let world = World.createDissolveScreenFromLayerFile<BattleDispatcher> (Some model.Battle.ScreenName) Constants.OmniBlade.DissolveData Assets.BattleLayerFilePath world |> snd
let world = World.createSplashScreen (Some model.Splash.ScreenName) Constants.OmniBlade.SplashData model.Title world |> snd
// play the splash sound effect, select the splash screen, and we're off!
let world = World.playSound 1.0f Assets.NuSplashSound world
World.selectScreen model.Splash world
| PlayTitleSong -> World.playSong 0 (1.0f * Constants.Audio.MasterSongVolume) Assets.TitleSong world
| FadeSong -> World.fadeOutSong Constants.Audio.DefaultTimeToFadeOutSongMs world
| ShowTitle -> World.transitionScreen model.Title world
| ShowCredits -> World.transitionScreen model.Credits world
| ShowBattle -> World.transitionScreen model.Battle world
| ExitGame -> World.exit world
override this.View (_, _, world) =
world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment