about summary refs log tree commit diff
path: root/users/grfn/xanthous/src/Xanthous/App
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2021-11-06T15·44-0400
committergrfn <grfn@gws.fyi>2021-11-06T15·52+0000
commitff6c008d7884975f3dc0295a75b9383fd2c3a2ed (patch)
tree7b84c368db6c152f9e871cae8b9faa676262e1a1 /users/grfn/xanthous/src/Xanthous/App
parent099f36e5ee8b18126e006219153e3cf6fb6e7a50 (diff)
feat(gs/xanthous): Default to the current save file r/3008
When saving, default to the save file that was loaded for the game if
any. To support this, this also makes text prompts support a default,
which will be used if no value is input.

Change-Id: I72a826499d6e987b939e3465a2d29167e53416be
Reviewed-on: https://cl.tvl.fyi/c/depot/+/3801
Reviewed-by: grfn <grfn@gws.fyi>
Tested-by: BuildkiteCI
Diffstat (limited to 'users/grfn/xanthous/src/Xanthous/App')
-rw-r--r--users/grfn/xanthous/src/Xanthous/App/Prompt.hs25
1 files changed, 24 insertions, 1 deletions
diff --git a/users/grfn/xanthous/src/Xanthous/App/Prompt.hs b/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
index 911f8696123a..0397e590e760 100644
--- a/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
+++ b/users/grfn/xanthous/src/Xanthous/App/Prompt.hs
@@ -5,6 +5,8 @@ module Xanthous.App.Prompt
   , clearPrompt
   , prompt
   , prompt_
+  , stringPromptWithDefault
+  , stringPromptWithDefault_
   , confirm_
   , confirm
   , menu
@@ -123,7 +125,7 @@ prompt msgPath params cancellable cb = do
     SPointOnMap -> do
       charPos <- use characterPosition
       pure . Just $ mkPointOnMapPrompt cancellable charPos cb
-    SStringPrompt -> pure . Just $ mkPrompt cancellable pt cb
+    SStringPrompt -> pure . Just $ mkStringPrompt cancellable cb
     SConfirm -> pure . Just $ mkPrompt cancellable pt cb
     SDirectionPrompt -> pure . Just $ mkPrompt cancellable pt cb
     SContinue -> pure . Just $ mkPrompt cancellable pt cb
@@ -138,6 +140,27 @@ prompt_
   -> AppM ()
 prompt_ msg = prompt msg $ object []
 
+stringPromptWithDefault
+  :: forall (params :: Type). (ToJSON params)
+  => [Text]                                -- ^ Message key
+  -> params                                -- ^ Message params
+  -> PromptCancellable
+  -> Text                                  -- ^ Prompt default
+  -> (PromptResult 'StringPrompt -> AppM ()) -- ^ Prompt promise handler
+  -> AppM ()
+stringPromptWithDefault msgPath params cancellable def cb = do
+  msg <- Messages.message msgPath params
+  let p = mkStringPromptWithDefault cancellable def cb
+  promptState .= WaitingPrompt msg p
+
+stringPromptWithDefault_
+  :: [Text]                                -- ^ Message key
+  -> PromptCancellable
+  -> Text                                  -- ^ Prompt default
+  -> (PromptResult 'StringPrompt -> AppM ()) -- ^ Prompt promise handler
+  -> AppM ()
+stringPromptWithDefault_ msg = stringPromptWithDefault msg $ object []
+
 confirm
   :: ToJSON params
   => [Text] -- ^ Message key