Skip to content

Commit

Permalink
💄 Show rented hotel on the top
Browse files Browse the repository at this point in the history
sleepyfran committed Oct 30, 2023

Verified

This commit was signed with the committer’s verified signature.
sleepyfran Fran González
1 parent 03a8692 commit dcd6d15
Showing 1 changed file with 41 additions and 23 deletions.
64 changes: 41 additions & 23 deletions src/Duets.Cli/Components/Map.fs
Original file line number Diff line number Diff line change
@@ -9,12 +9,20 @@ open Duets.Entities
open Duets.Simulation
open Duets.Simulation.Navigation

let private placeWithOpenInfo place =
let private placeWithOpenInfo (city: City) (place: Place) =
let rentedPlaces = Queries.Rentals.allAsMap (State.get ())
let hasPlaceRented = rentedPlaces |> Map.containsKey (city.Id, place.Id)
let currentlyOpen = Queries.World.placeCurrentlyOpen' (State.get ()) place

let placeDetails =
match hasPlaceRented with
| true ->
$"""{World.placeWithZone place} ({"Rented" |> Styles.highlight})"""
| false -> World.placeWithZone place

match currentlyOpen with
| true -> World.placeWithZone place
| false -> Styles.faded $"{place.Name} ({place.Zone.Name}) - Closed"
| true -> placeDetails
| false -> Styles.faded $"{placeDetails}) - Closed"

let private showOpeningHours place =
match place.OpeningHours with
@@ -33,19 +41,20 @@ let private showOpeningHours place =
(* Obviously if it's always open this shouldn't happen :) *)
()

let private showPlaceChoice placesInCity places =
let private showPlaceChoice city placesInCity places =
let selectedPlace =
showOptionalChoicePrompt
Command.mapChoosePlace
Generic.back
placeWithOpenInfo
(placeWithOpenInfo city)
places

match selectedPlace with
| Some place -> Some place
| None -> showPlaceTypeChoice placesInCity
| None -> showPlaceTypeChoice city placesInCity

let private showPlaceTypeChoice
city
(placesInCity: Map<PlaceTypeIndex, Place list>)
=
let availablePlaceTypes =
@@ -57,9 +66,9 @@ let private showPlaceTypeChoice
World.placeTypeName
availablePlaceTypes
|> Option.bind (fun placeType ->
placesInCity |> Map.find placeType |> showPlaceChoice placesInCity)
placesInCity |> Map.find placeType |> showPlaceChoice city placesInCity)

let private moveToPlace availablePlaces (destination: Place) =
let private moveToPlace city availablePlaces (destination: Place) =
let currentPlace = State.get () |> Queries.World.currentPlace
let navigationResult = Navigation.moveTo destination.Id (State.get ())

@@ -84,7 +93,7 @@ let private moveToPlace availablePlaces (destination: Place) =

showSeparator None

askForPlace availablePlaces
askForPlace city availablePlaces
| Error PlaceEntranceError.CannotEnterWithoutRental ->
showSeparator None

@@ -97,15 +106,30 @@ let private moveToPlace availablePlaces (destination: Place) =

showSeparator None

askForPlace availablePlaces
askForPlace city availablePlaces

let private askForPlace availablePlaces =
let selectedPlace = availablePlaces |> showPlaceTypeChoice
let private askForPlace city availablePlaces =
let selectedPlace = availablePlaces |> showPlaceTypeChoice city

match selectedPlace with
| Some place -> moveToPlace availablePlaces place
| Some place -> moveToPlace city availablePlaces place
| None -> []

let private changePlace idxType fn (places: Map<PlaceTypeIndex, Place list>) =
Map.change idxType (Option.bind (fn >> Option.ofList)) places

let private filterRentedHomePlaces (currentCity: City) rentedPlaces =
changePlace
PlaceTypeIndex.Home
(List.filter (fun (place: Place) ->
rentedPlaces |> Map.containsKey (currentCity.Id, place.Id)))

let private sortHotels (currentCity: City) rentedPlaces =
changePlace
PlaceTypeIndex.Hotel
(List.sortByDescending (fun (place: Place) ->
rentedPlaces |> Map.containsKey (currentCity.Id, place.Id)))

/// Shows a list of all the place types in the current city and, upon selecting
/// one type, shows all the places of that specific type in the current city.
/// If the user selects one of the places, it will attempt to move the character
@@ -119,16 +143,10 @@ let showMap () =
(* Filter out homes that are not rented to not pollute the map. *)
let allAvailablePlaces =
Queries.World.allPlacesInCurrentCity state
|> Map.change PlaceTypeIndex.Home (fun places ->
places
|> Option.bind (fun places ->
places
|> List.filter (fun place ->
rentedPlaces
|> Map.containsKey (currentCity.Id, place.Id))
|> Option.ofList))

allAvailablePlaces |> askForPlace
|> filterRentedHomePlaces currentCity rentedPlaces
|> sortHotels currentCity rentedPlaces

allAvailablePlaces |> askForPlace currentCity

/// Shows the map, forcing the user to make a choice.
let showMapUntilChoice () =

0 comments on commit dcd6d15

Please sign in to comment.