Skip to content

Commit

Permalink
🎨 The great cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepyfran committed Jul 7, 2024
1 parent 2f2741b commit 4898aa8
Show file tree
Hide file tree
Showing 91 changed files with 428 additions and 514 deletions.
45 changes: 23 additions & 22 deletions src/Duets.Agents/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ type StateAgent() =
let state =
MailboxProcessor.Start
<| fun inbox ->
let rec loop (state, listeners) = async {
let! msg = inbox.Receive()

let notifyAll value =
listeners |> Map.iter (fun _ handler -> handler value)

match msg with
| Get channel ->
channel.Reply state
return! loop (state, listeners)
| Set value ->
notifyAll value
return! loop (value, listeners)
| Subscribe (id, handler) ->
let updated = listeners |> Map.add id handler

handler state
return! loop (state, updated)
| Unsubscribe id ->
let updated = listeners |> Map.remove id
return! loop (state, updated)
}
let rec loop (state, listeners) =
async {
let! msg = inbox.Receive()

let notifyAll value =
listeners |> Map.iter (fun _ handler -> handler value)

match msg with
| Get channel ->
channel.Reply state
return! loop (state, listeners)
| Set value ->
notifyAll value
return! loop (value, listeners)
| Subscribe(id, handler) ->
let updated = listeners |> Map.add id handler

handler state
return! loop (state, updated)
| Unsubscribe id ->
let updated = listeners |> Map.remove id
return! loop (state, updated)
}

loop (State.empty, Map.empty)

Expand Down
3 changes: 1 addition & 2 deletions src/Duets.Agents/Stats.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let private addElapsedToStats (elapsed: TimeSpan) =
let stats = loadStats ()
let elapsedSeconds = elapsed.Seconds |> (*) 1<second>

{ SecondsPlayed = stats.SecondsPlayed + elapsedSeconds }
|> writeStats
{ SecondsPlayed = stats.SecondsPlayed + elapsedSeconds } |> writeStats

let private startTracking (sw: Stopwatch) =
if sw.IsRunning then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ module WaitForLandingCommand =
Airport.passingPassportControl ]
5<second>

leavePlane (State.get ()) flight
|> Effect.applyMultiple
leavePlane (State.get ()) flight |> Effect.applyMultiple

Scene.WorldAfterMovement }
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace Duets.Cli.Components.Commands.Cheats

open System
open Duets.Agents
open Duets.Cli
open Duets.Cli.Components
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Time.AdvanceTime
open FSharpx

[<RequireQualifiedAccess>]
module LifeCommands =
Expand Down
4 changes: 1 addition & 3 deletions src/Duets.Cli/Components/Commands/Concert/ConcertCommon.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Entities
open FSharp.Data.UnitSystems.SI.UnitNames
open Duets.Simulation
open Duets.Simulation.Concerts.Live

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -67,8 +66,7 @@ module Concert =
| AveragePerformance reasons ->
Concert.soloResultAveragePerformance reasons points
| GoodPerformance _
| GreatPerformance ->
Concert.soloResultGreatPerformance points
| GreatPerformance -> Concert.soloResultGreatPerformance points
| _ -> Concert.tooManySolos points
|> showMessage)
ongoingConcert
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ module FinishConcertCommand =
Description = Command.finishConcertDescription
Handler =
(fun _ ->
Concerts.Live.Finish.finishConcert (State.get ()) ongoingConcert
Concerts.Live.Finish.finishConcert
(State.get ())
ongoingConcert
|> Duets.Cli.Effect.applyMultiple

Scene.World) }
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace Duets.Cli.Components.Commands
open Duets.Cli.Components
open Duets.Cli.Components.Commands
open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation.Concerts.Live.Encore

[<RequireQualifiedAccess>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ module MakeCrowdSingCommand =
makeCrowdSing
(fun result points ->
match result with
| LowPerformance _ -> Concert.makeCrowdSingLowPerformance points
| LowPerformance _ ->
Concert.makeCrowdSingLowPerformance points
| AveragePerformance _ ->
Concert.makeCrowdSingLowPerformance points
| GoodPerformance _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ open Duets.Cli.Components
open Duets.Cli.Components.Commands
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Concerts
open Duets.Simulation.Merchandise.SetPrice
open Microsoft.FSharp.Data.UnitSystems.SI.UnitNames

[<RequireQualifiedAccess>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open Duets.Cli.Components
open Duets.Cli.Components.Commands
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Concerts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Duets.Cli
open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Simulation
open Duets.Simulation.Bank.Operations
open Duets.Simulation.Gym

Expand Down
4 changes: 1 addition & 3 deletions src/Duets.Cli/Components/Commands/Inventory.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ module InventoryCommand =
else
Items.itemsCurrentlyCarrying |> showMessage

inventory
|> List.map Items.itemRow
|> List.iter showMessage
inventory |> List.map Items.itemRow |> List.iter showMessage

Scene.World }
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/Items/Consume.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation.Interactions

[<RequireQualifiedAccess>]
module ConsumeCommands =
Expand Down
3 changes: 1 addition & 2 deletions src/Duets.Cli/Components/Commands/Items/Cook.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Duets.Agents
open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open Duets.Simulation
open FSharp.Data.UnitSystems.SI.UnitNames
Expand Down Expand Up @@ -35,7 +34,7 @@ module CookCommand =
$"{Generic.itemDetailedName item} ({Styles.money price} for ingredients)"

let toReferenceName (item: Item, _) = item.Name

let recipe =
Selection.fromArgsOrInteractive
args
Expand Down
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/Items/Open.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Simulation
open Duets.Simulation.Interactions

[<RequireQualifiedAccess>]
module rec OpenCommand =
Expand Down
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/Items/Sleep.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Duets.Agents
open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Interactions
Expand Down
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/MiniGame/Bet.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.MiniGames

[<RequireQualifiedAccess>]
Expand Down
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/Movement.Command.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Cli.Text.World
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Navigation

[<RequireQualifiedAccess>]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ module DiscardSongCommand =
unfinishedSongs

match selectedSong with
| Some song -> discardSong currentBand song |> Duets.Cli.Effect.apply
| Some song ->
discardSong currentBand song |> Duets.Cli.Effect.apply
| None -> ()

Scene.World) }
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Entities
open Duets.Entities.Lenses
open Duets.Simulation
open Duets.Simulation.Songs.Composition.FinishSong

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ module HireMemberCommand =
let instrument = Instrument.createInstrument role

let availableMember =
membersForHire state band instrument.Type
|> Seq.head
membersForHire state band instrument.Type |> Seq.head

showMemberForHire role band availableMember

Expand Down Expand Up @@ -51,10 +50,7 @@ module HireMemberCommand =
Rehearsal.hireMemberContinueConfirmation
)

if continueHiring then
promptForMemberSelection role
else
()
if continueHiring then promptForMemberSelection role else ()

let private roleText instrumentType = Generic.role instrumentType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ module ListSongsCommand =

showTableWithTitle "Unfinished songs" columns rows

let private showFinishedTable
columns
(finishedSongs: Finished<Song> list)
=
let private showFinishedTable columns (finishedSongs: Finished<Song> list) =
let rows =
finishedSongs
|> List.map (fun (Finished(song, quality)) ->
Expand Down
1 change: 0 additions & 1 deletion src/Duets.Cli/Components/Commands/Studio/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Duets.Agents
open Duets.Cli.Components
open Duets.Cli.Text
open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Studio.ReleaseAlbum

module Studio =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ open Duets.Agents
open Duets.Cli.Components
open Duets.Cli.SceneIndex
open Duets.Cli.Text
open Duets.Common
open Duets.Entities
open FSharp.Data.UnitSystems.SI.UnitNames
open Duets.Simulation
Expand Down
9 changes: 3 additions & 6 deletions src/Duets.Cli/Components/Table.fs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ let private createTable
| Some title -> table.Title <- TableTitle(title)
| None -> ()

columns
|> List.iter (fun column -> table <- table.AddColumn(column))
columns |> List.iter (fun column -> table <- table.AddColumn(column))

rows
|> List.iter (fun row -> table <- row |> Array.ofList |> table.AddRow)
rows |> List.iter (fun row -> table <- row |> Array.ofList |> table.AddRow)

table

Expand Down Expand Up @@ -47,5 +45,4 @@ let showTable columns rows =
/// Row text to be shown. Each field in the list correspond with each column
/// </param>
let showTableWithTitle title columns rows =
createTable (Some title) columns rows
|> AnsiConsole.Write
createTable (Some title) columns rows |> AnsiConsole.Write
Loading

0 comments on commit 4898aa8

Please sign in to comment.