summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/Update/Story.elm')
-rw-r--r--src/Update/Story.elm139
1 files changed, 139 insertions, 0 deletions
diff --git a/src/Update/Story.elm b/src/Update/Story.elm
new file mode 100644
index 0000000..bee5cc8
--- /dev/null
+++ b/src/Update/Story.elm
@@ -0,0 +1,139 @@
+module Update.Story exposing
+ (
+ new,
+ select_choice,
+ input_string,
+ input_integer,
+ input_command
+ )
+
+-- Elm -------------------------------------------------------------------------
+import Html
+
+-- Local Module ----------------------------------------------------------------
+import Struct.Event
+import Struct.Model
+
+import Util.TonkadurToHtml
+
+import Tonkadur.Execute
+
+--------------------------------------------------------------------------------
+-- TYPES -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+step : Struct.Model.Type -> Struct.Model.Type
+step model =
+ case model.tonkadur.last_instruction_effect of
+ MustContinue ->
+ (step
+ {model |
+ tonkadur =
+ (Tonkadur.Execute.execute
+ model.tonkadur.code[model.tonkadur.program_counter]
+ model.tonkadur
+ )
+ }
+ )
+
+ MustEnd -> model -- TODO
+
+ (MustPromptCommand min max label) ->
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.prompt_command
+ (Tonkadur.Types.value_to_int min)
+ (Tonkadur.Types.value_to_int max)
+ model.ui
+ )
+ }
+
+ (MustPromptInteger min max label) ->
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.prompt_integer
+ (Tonkadur.Types.value_to_int min)
+ (Tonkadur.Types.value_to_int max)
+ model.ui
+ )
+ }
+
+ (MustPromptString min max label) ->
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.prompt_string
+ (Tonkadur.Types.value_to_int min)
+ (Tonkadur.Types.value_to_int max)
+ model.ui
+ )
+ }
+
+ MustPromptChoice ->
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (List.foldl
+ (\option (ix, ui) ->
+ case option of
+ (Choice rich_text) ->
+ (
+ (ix + 1),
+ (Struct.UI.display_choice
+ ix
+ (Util.TonkadurToHtml.convert
+ (TextValue rich_text)
+ )
+ )
+ )
+
+ _ -> ((ix + 1), ui)
+ )
+ (0, model.ui)
+ model.tonkadur.available_options
+ )
+ }
+
+ (MustDisplay text) ->
+ (step
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.display_text
+ (Util.TonkadurToHtml.convert text)
+ model.ui
+ )
+ }
+ )
+
+ (MustDisplayError text) ->
+ (step
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.display_error
+ (Util.TonkadurToHtml.convert text)
+ model.ui
+ )
+ }
+ )
+
+ _ -> model
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+new : Type
+new =
+ {
+ displayed_text = [],
+ displayed_options = []
+ }
+
+