Skip to content

Commit

Permalink
Some API and code clean-up.
Browse files Browse the repository at this point in the history
Former-commit-id: a0cfe45
  • Loading branch information
bryanedds committed Oct 2, 2016
1 parent b98b4ca commit 6aea7af
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 63 deletions.
6 changes: 3 additions & 3 deletions Nu/Nu/WorldGame.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ module WorldGameModule =
static member isEntitySelected entity world =
let screenName = Address.head entity.EntityAddress
match World.getOptSelectedScreen world with
| Some selectedScreen -> screenName = selectedScreen.ScreenName
| Some selectedScreen -> screenName = Address.getName selectedScreen.ScreenAddress
| None -> false

/// Determine if a group is selected by being in the currently selected screeen.
static member isGroupSelected group world =
let screenName = Address.head group.GroupAddress
match World.getOptSelectedScreen world with
| Some selectedScreen -> screenName = selectedScreen.ScreenName
| Some selectedScreen -> screenName = Address.getName selectedScreen.ScreenAddress
| None -> false

/// Determine if a screen is the currently selected screeen.
Expand All @@ -151,7 +151,7 @@ module WorldGameModule =
| [] -> true
| screenName :: _ ->
match World.getOptSelectedScreen world with
| Some screen -> screen.ScreenName = screenName
| Some screen -> Address.getName screen.ScreenAddress = screenName
| None -> false

/// Write a game to a game descriptor.
Expand Down
2 changes: 1 addition & 1 deletion Nu/Nu/WorldModule.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ module WorldModule =
// OPTIMIZATION: assumes a valid entity address with List.head on its names
let screen =
match (World.getGameState world).OptSelectedScreen with
| Some screen when screen.ScreenName = List.head ^ Address.getNames entity.EntityAddress -> screen
| Some screen when Address.getName screen.ScreenAddress = List.head ^ Address.getNames entity.EntityAddress -> screen
| Some _ | None -> entity.EntityAddress |> Address.getNames |> List.head |> ntoa<Screen> |> Screen.proxy

// proceed with updating entity in entity tree
Expand Down
28 changes: 14 additions & 14 deletions Nu/Nu/WorldTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ module WorldTests =

let [<Fact>] entitySubscribeWorks () =
let world = World.makeEmpty ()
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some Simulants.DefaultScreen.ScreenName) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some Simulants.DefaultGroup.GroupName) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Simulants.DefaultEntity.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultScreen.ScreenAddress) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultGroup.GroupAddress) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultEntity.EntityAddress) Simulants.DefaultGroup world |> snd
let handleEvent = fun evt world -> (Cascade, World.updateUserState (fun _ -> evt.Subscriber) world)
let world = World.subscribe handleEvent StringEvent Simulants.DefaultEntity world
let world = World.publish String.Empty StringEvent EventTrace.empty Simulants.Game world
Assert.Equal<Simulant> (Simulants.DefaultEntity :> Simulant, World.getUserState world)

let [<Fact>] gameSerializationWorks () =
let world = World.makeEmpty ()
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some Simulants.DefaultScreen.ScreenName) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some Simulants.DefaultGroup.GroupName) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Simulants.DefaultEntity.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultScreen.ScreenAddress) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultGroup.GroupAddress) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultEntity.EntityAddress) Simulants.DefaultGroup world |> snd
let oldWorld = world
World.writeGameToFile TestFilePath world
let world = World.readGameFromFile TestFilePath world
Expand All @@ -42,21 +42,21 @@ module WorldTests =

let [<Fact>] iterativeFrpWorks () =
let world = World.makeEmpty ()
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some Simulants.DefaultScreen.ScreenName) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some Simulants.DefaultGroup.GroupName) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Jim.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Bob.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultScreen.ScreenAddress) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultGroup.GroupAddress) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Jim.EntityAddress) Simulants.DefaultGroup world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Bob.EntityAddress) Simulants.DefaultGroup world |> snd
let world = !-- Bob.TagVisible --- map not --> Jim.TagVisible ^ world
let world = Bob.SetVisible false world
Assert.False (Bob.GetVisible world)
Assert.True (Jim.GetVisible world)

let [<Fact>] iterativeFrpCyclicWorks () =
let world = World.makeEmpty ()
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some Simulants.DefaultScreen.ScreenName) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some Simulants.DefaultGroup.GroupName) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Jim.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some Bob.EntityName) Simulants.DefaultGroup world |> snd
let world = World.createScreen typeof<ScreenDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultScreen.ScreenAddress) world |> snd
let world = World.createGroup typeof<GroupDispatcher>.Name None (Some ^ Address.getName Simulants.DefaultGroup.GroupAddress) Simulants.DefaultScreen world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Jim.EntityAddress) Simulants.DefaultGroup world |> snd
let world = World.createEntity typeof<EntityDispatcher>.Name None (Some ^ Address.getName Bob.EntityAddress) Simulants.DefaultGroup world |> snd
let world = !-- Bob.TagVisible --> Jim.TagVisible ^ world
let world = !-- Jim.TagVisible -/> Bob.TagVisible ^ world
let world = Bob.SetVisible false world
Expand Down
78 changes: 33 additions & 45 deletions Nu/Nu/WorldTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,6 @@ type [<StructuralEquality; NoComparison>] TileData =
[<AutoOpen>]
module WorldTypes =

/// A simulant in the world.
type Simulant =
interface
inherit Participant
abstract member SimulantAddress : Simulant Address
end

/// Operators for the Simulant type.
type SimulantOperators =
private
| SimulantOperators

/// Concatenate two addresses, forcing the type of first address.
static member acatf<'a> (address : 'a Address) (simulant : Simulant) = acatf address (atooa simulant.SimulantAddress)

/// Concatenate two addresses, takings the type of first address.
static member (->-) (address, simulant : Simulant) = SimulantOperators.acatf address simulant

/// The data for a change in the world's ambient state.
type [<StructuralEquality; NoComparison>] AmbientChangeData =
{ OldWorldWithOldState : World }
Expand Down Expand Up @@ -283,6 +265,24 @@ module WorldTypes =

interface Dispatcher

/// A simulant in the world.
and Simulant =
interface
inherit Participant
abstract member SimulantAddress : Simulant Address
end

/// Operators for the Simulant type.
and SimulantOperators =
private
| SimulantOperators

/// Concatenate two addresses, forcing the type of first address.
static member acatf<'a> (address : 'a Address) (simulant : Simulant) = acatf address (atooa simulant.SimulantAddress)

/// Concatenate two addresses, takings the type of first address.
static member (->-) (address, simulant : Simulant) = SimulantOperators.acatf address simulant

/// Generalized interface for simulant state.
and SimulantState =
interface
Expand Down Expand Up @@ -477,7 +477,7 @@ module WorldTypes =

interface SimulantState with
member this.GetXtension () = this.Xtension

/// Hosts the ongoing state of an entity. The end-user of this engine should never touch this
/// type, and it's public _only_ to make [<CLIMutable>] work.
and [<CLIMutable; NoEquality; NoComparison>] EntityState =
Expand Down Expand Up @@ -645,9 +645,6 @@ module WorldTypes =
/// View as address string.
override this.ToString () = scstring this.GameAddress

/// Get the full name of a game proxy.
member this.GameFullName = atos this.GameAddress

/// Get the latest value of a game's properties.
[<DebuggerBrowsable (DebuggerBrowsableState.RootHidden)>]
member private this.View = Debug.World.viewGame Debug.World.Chosen
Expand Down Expand Up @@ -681,12 +678,6 @@ module WorldTypes =
/// View as address string.
override this.ToString () = scstring this.ScreenAddress

/// Get the full name of a screen proxy.
member this.ScreenFullName = atos this.ScreenAddress

/// Get the name of a screen proxy.
member this.ScreenName = Address.getName this.ScreenAddress

/// Get the latest value of a screen's properties.
[<DebuggerBrowsable (DebuggerBrowsableState.RootHidden)>]
member private this.View = Debug.World.viewScreen (this :> obj) Debug.World.Chosen
Expand Down Expand Up @@ -728,12 +719,6 @@ module WorldTypes =
/// View as address string.
override this.ToString () = scstring this.GroupAddress

/// Get the full name of a group proxy.
member this.GroupFullName = atos this.GroupAddress

/// Get the name of a group proxy.
member this.GroupName = Address.getName this.GroupAddress

/// Get the latest value of a group's properties.
[<DebuggerBrowsable (DebuggerBrowsableState.RootHidden)>]
member private this.View = Debug.World.viewGroup (this :> obj) Debug.World.Chosen
Expand Down Expand Up @@ -780,12 +765,6 @@ module WorldTypes =
/// View as address string.
override this.ToString () = scstring this.EntityAddress

/// Get the name of an entity proxy.
member this.EntityFullName = atos this.EntityAddress

/// Get the name of an entity proxy.
member this.EntityName = Address.getName this.EntityAddress

/// Get the latest value of an entity's properties.
[<DebuggerBrowsable (DebuggerBrowsableState.RootHidden)>]
member private this.View = Debug.World.viewEntity (this :> obj) Debug.World.Chosen
Expand Down Expand Up @@ -899,12 +878,15 @@ module WorldTypes =
abstract MakeOverlayRoutes : unit -> (string * OverlayDescriptor) list
default this.MakeOverlayRoutes () = []

/// A simulant in the world.
type Simulant = WorldTypes.Simulant

/// The data for a change in the world's ambient state.
type AmbientChangeData = WorldTypes.AmbientChangeData

/// Generalized interface tag for dispatchers.
type Dispatcher = WorldTypes.Dispatcher

/// Generalized interface tag for simulant dispatchers.
type SimulantDispatcher = WorldTypes.SimulantDispatcher

/// The default dispatcher for games.
type GameDispatcher = WorldTypes.GameDispatcher

Expand All @@ -917,6 +899,9 @@ type GroupDispatcher = WorldTypes.GroupDispatcher
/// The default dispatcher for entities.
type EntityDispatcher = WorldTypes.EntityDispatcher

/// Dynamically augments an entity's behavior in a composable way.
type Facet = WorldTypes.Facet

/// Describes a game value independent of the engine.
type GameDescriptor = WorldTypes.GameDescriptor

Expand All @@ -929,8 +914,11 @@ type GroupDescriptor = WorldTypes.GroupDescriptor
/// Describes an entity value independent of the engine.
type EntityDescriptor = WorldTypes.EntityDescriptor

/// Dynamically augments an entity's behavior in a composable way.
type Facet = WorldTypes.Facet
/// A simulant in the world.
type Simulant = WorldTypes.Simulant

/// Operators for the Simulant type.
type SimulantOperators = WorldTypes.SimulantOperators

/// The game type that hosts the various screens used to navigate through a game.
type Game = WorldTypes.Game
Expand Down

0 comments on commit 6aea7af

Please sign in to comment.