diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-16 23:24:21 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-16 23:24:21 -0400 |
commit | 595ec01214bc1552bdc47b3212caeda274fc9d03 (patch) | |
tree | 810e112ab3e34a1ad500db85b6854b2d58f2a682 | |
parent | 0c809ee14c9acb07c927f1057c02bc0a91558034 (diff) |
implement calendar-entry-based time warping
-rw-r--r-- | CosmicCalendar.hs | 7 | ||||
-rwxr-xr-x | countdown.hs | 18 |
2 files changed, 19 insertions, 6 deletions
diff --git a/CosmicCalendar.hs b/CosmicCalendar.hs index 8def5b7..290fa3a 100644 --- a/CosmicCalendar.hs +++ b/CosmicCalendar.hs | |||
@@ -93,8 +93,11 @@ yearStart (LocalTime d _) = LocalTime d' t' | |||
93 | localTimeToYearElapsed :: LocalTime -> NominalDiffTime | 93 | localTimeToYearElapsed :: LocalTime -> NominalDiffTime |
94 | localTimeToYearElapsed t = t `diffLocalTime` yearStart t | 94 | localTimeToYearElapsed t = t `diffLocalTime` yearStart t |
95 | 95 | ||
96 | getLastCalendarEntry :: LocalTime -> Maybe CalendarEntry | 96 | getPreviousCalendarEntry :: LocalTime -> Maybe CalendarEntry |
97 | getLastCalendarEntry (localTimeToYearElapsed -> t) = snd <$> Map.lookupLE t theCalendar | 97 | getPreviousCalendarEntry (localTimeToYearElapsed -> t) = snd <$> Map.lookupLT t theCalendar |
98 | |||
99 | getCurrentCalendarEntry :: LocalTime -> Maybe CalendarEntry | ||
100 | getCurrentCalendarEntry (localTimeToYearElapsed -> t) = snd <$> Map.lookupLE t theCalendar | ||
98 | 101 | ||
99 | getNextCalendarEntry :: LocalTime -> Maybe CalendarEntry | 102 | getNextCalendarEntry :: LocalTime -> Maybe CalendarEntry |
100 | getNextCalendarEntry (localTimeToYearElapsed -> t) = snd <$> Map.lookupGT t theCalendar | 103 | getNextCalendarEntry (localTimeToYearElapsed -> t) = snd <$> Map.lookupGT t theCalendar |
diff --git a/countdown.hs b/countdown.hs index d630287..42675f6 100755 --- a/countdown.hs +++ b/countdown.hs | |||
@@ -210,15 +210,15 @@ countdownWidget isSimulated t = | |||
210 | str "\n" | 210 | str "\n" |
211 | <=> | 211 | <=> |
212 | hCenter (hBox [ | 212 | hCenter (hBox [ |
213 | vBox [ cosmicCalendarNext, str "\n", cosmicCalendarPrevious ], | 213 | vBox [ cosmicCalendarCurrent, txt "\n", cosmicCalendarNext ], |
214 | str " ", | 214 | str " ", |
215 | borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) | 215 | borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) |
216 | ]) | 216 | ]) |
217 | where | 217 | where |
218 | cosmicCalendarPrevious = borderWithLabel (str "Previously on the Cosmic Calendar") prevEntry | 218 | cosmicCalendarCurrent = borderWithLabel (str $ (if current then "Now" else "Previously") ++ " on the Cosmic Calendar") currentEntry |
219 | cosmicCalendarNext = borderWithLabel (str $ (if current then "Now" else "Next") ++ " on the Cosmic Calendar") nextEntry | ||
220 | where | 219 | where |
221 | current = True | 220 | current = True |
221 | cosmicCalendarNext = borderWithLabel (txt "Next on the Cosmic Calendar") nextEntry | ||
222 | 222 | ||
223 | -- TODO: We want to display "today" or "now" on the cosmic calendar; | 223 | -- TODO: We want to display "today" or "now" on the cosmic calendar; |
224 | -- We want to display what happened previously on the cosmic calendar | 224 | -- We want to display what happened previously on the cosmic calendar |
@@ -228,7 +228,7 @@ countdownWidget isSimulated t = | |||
228 | -- We also _may_ want to say the same thing for the current happening, depending on if it's an instant or a stage | 228 | -- We also _may_ want to say the same thing for the current happening, depending on if it's an instant or a stage |
229 | -- If it's a stage, we want to say how long it lasts; how long since it started, and how long until it ends | 229 | -- If it's a stage, we want to say how long it lasts; how long since it started, and how long until it ends |
230 | 230 | ||
231 | prevEntry = fromMaybe (str "none") $ calendarWidget <$> getLastCalendarEntry t | 231 | currentEntry = fromMaybe (str "none") $ calendarWidget <$> getCurrentCalendarEntry t |
232 | nextEntry = fromMaybe (str "none") $ calendarWidget <$> getNextCalendarEntry t | 232 | nextEntry = fromMaybe (str "none") $ calendarWidget <$> getNextCalendarEntry t |
233 | 233 | ||
234 | calendarWidget CalendarEntry{..} = vBox [eventCountdown, str "\n", box] | 234 | calendarWidget CalendarEntry{..} = vBox [eventCountdown, str "\n", box] |
@@ -371,6 +371,14 @@ queueNextEvent hyper chan = liftIO $ do | |||
371 | isSimulatedTime :: St -> Bool | 371 | isSimulatedTime :: St -> Bool |
372 | isSimulatedTime st = st ^. stDisplayTime /= st ^. stClockTime | 372 | isSimulatedTime st = st ^. stDisplayTime /= st ^. stClockTime |
373 | 373 | ||
374 | nextCalendarEntryTime :: LocalTime -> LocalTime | ||
375 | nextCalendarEntryTime t = fromMaybe t $ getNextCalendarEntry t <&> (`addLocalTime` yearStart t) . calBeginTime | ||
376 | |||
377 | previousCalendarEntryTime :: LocalTime -> LocalTime | ||
378 | previousCalendarEntryTime t = fromMaybe t $ goBack t | ||
379 | where | ||
380 | goBack t = getPreviousCalendarEntry t <&> (`addLocalTime` yearStart t) . calBeginTime | ||
381 | |||
374 | handleEvent :: BChan CustomEvent -> St -> BrickEvent () CustomEvent -> EventM () (Next St) | 382 | handleEvent :: BChan CustomEvent -> St -> BrickEvent () CustomEvent -> EventM () (Next St) |
375 | handleEvent chan st e = | 383 | handleEvent chan st e = |
376 | case e of | 384 | case e of |
@@ -391,6 +399,8 @@ handleEvent chan st e = | |||
391 | VtyEvent (V.EvKey V.KEnd [MShift]) -> cont $ st & stDisplayTime .~ (yearEnd $ st ^. stClockTime) | 399 | VtyEvent (V.EvKey V.KEnd [MShift]) -> cont $ st & stDisplayTime .~ (yearEnd $ st ^. stClockTime) |
392 | VtyEvent (V.EvKey V.KEnd [MCtrl]) -> cont $ st & stDisplayTime .~ (newYearsEveNoon $ st ^. stClockTime) | 400 | VtyEvent (V.EvKey V.KEnd [MCtrl]) -> cont $ st & stDisplayTime .~ (newYearsEveNoon $ st ^. stClockTime) |
393 | VtyEvent (V.EvKey (V.KChar 'p') []) -> cont $ st & stPaused %~ not | 401 | VtyEvent (V.EvKey (V.KChar 'p') []) -> cont $ st & stPaused %~ not |
402 | VtyEvent (V.EvKey (V.KChar ',') []) -> cont $ st & stDisplayTime %~ previousCalendarEntryTime | ||
403 | VtyEvent (V.EvKey (V.KChar '.') []) -> cont $ st & stDisplayTime %~ nextCalendarEntryTime | ||
394 | VtyEvent _ -> cont st | 404 | VtyEvent _ -> cont st |
395 | AppEvent (TimeChanged now) -> do | 405 | AppEvent (TimeChanged now) -> do |
396 | let hyper = isNewYearsEve $ st ^. stDisplayTime | 406 | let hyper = isNewYearsEve $ st ^. stDisplayTime |