From 47eaa2a613177e182b321f4fdd642333ff514ec3 Mon Sep 17 00:00:00 2001 From: sleepyfran Date: Sat, 6 Apr 2024 14:09:44 +0200 Subject: [PATCH] :sparkles: Allow to compose songs with vocals only if band has vocalist --- .../RehearsalRoom/ComposeSong.Command.fs | 16 +++++++++++++++- src/Duets.Simulation/Queries/Bands.fs | 9 +++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Duets.Cli/Components/Commands/RehearsalRoom/ComposeSong.Command.fs b/src/Duets.Cli/Components/Commands/RehearsalRoom/ComposeSong.Command.fs index c4943aee..9b1f62e6 100644 --- a/src/Duets.Cli/Components/Commands/RehearsalRoom/ComposeSong.Command.fs +++ b/src/Duets.Cli/Components/Commands/RehearsalRoom/ComposeSong.Command.fs @@ -38,11 +38,25 @@ module ComposeSongCommand = (showLengthError >> fun _ -> promptForLength name) and private promptForVocalStyle name length = + let hasVocalist = + Queries.Bands.currentBandHasAnyMemberWithRole (State.get ()) Vocals + + if not hasVocalist then + "To compose songs with vocals, you need to have a vocalist in your band. You can hire a new member from the rehearsal room." + |> Styles.hint + |> showMessage + + let vocalStyles = + if hasVocalist then + Data.VocalStyles.allNames + else + [ (Instrumental, Instrumental.ToString()) ] + let vocalStyle = showChoicePrompt Rehearsal.composeSongVocalStylePrompt snd - Data.VocalStyles.allNames + vocalStyles |> fst Song.from name length vocalStyle |> composeWithProgressbar diff --git a/src/Duets.Simulation/Queries/Bands.fs b/src/Duets.Simulation/Queries/Bands.fs index c191dd95..2de4ceff 100644 --- a/src/Duets.Simulation/Queries/Bands.fs +++ b/src/Duets.Simulation/Queries/Bands.fs @@ -104,3 +104,12 @@ module Bands = Lenses.State.bands_ >-> Lenses.Bands.simulatedBands_ Optic.get simulatedLens_ state + + /// Returns whether the given band has any member with the given role. + let hasAnyMemberWithRole (band: Band) (role: InstrumentType) = + band.Members |> List.exists (fun bandMember -> bandMember.Role = role) + + /// Returns whether the current band has any member with the given role. + let currentBandHasAnyMemberWithRole state role = + let band = currentBand state + hasAnyMemberWithRole band role