summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2022-01-30 00:37:05 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2022-01-30 00:37:05 +0100
commitb1d6d8af0e31123d46e102bc68fcfd02d3b51256 (patch)
tree9caad859acaf7481d248d3d5e0de9d3c9114a0b2
parent0705fbf7c20c5002c26a2c9faa9663b047189e39 (diff)
...
-rw-r--r--src/Struct/UI.elm9
-rw-r--r--src/Tonkadur/Compute.elm11
-rw-r--r--src/Tonkadur/Execute.elm40
-rw-r--r--src/Tonkadur/Json.elm46
-rw-r--r--src/Tonkadur/Types.elm24
-rw-r--r--src/Update/Story.elm62
-rw-r--r--src/View/PlayerInput.elm38
7 files changed, 193 insertions, 37 deletions
diff --git a/src/Struct/UI.elm b/src/Struct/UI.elm
index 108ab04..9f1ce8f 100644
--- a/src/Struct/UI.elm
+++ b/src/Struct/UI.elm
@@ -12,6 +12,7 @@ import Struct.Event
--------------------------------------------------------------------------------
type InputType =
NoInput
+ | FloatInput
| IntegerInput
| StringInput
| CommandInput
@@ -23,6 +24,8 @@ type alias Type =
displayed_choices : (List (Int, (Html.Html Struct.Event.Type))),
min : Int,
max : Int,
+ min_float : Float,
+ max_float : Float,
input : InputType
}
@@ -41,6 +44,8 @@ new =
displayed_choices = [],
min = -1,
max = -1,
+ min_float = -1.0,
+ max_float = -1.0,
input = NoInput
}
@@ -65,6 +70,10 @@ display_choice ix html ui =
prompt_string : Int -> Int -> Type -> Type
prompt_string min max ui = {ui | min = min, max = max, input = StringInput}
+prompt_float : Float -> Float -> Type -> Type
+prompt_float min max ui =
+ {ui | min_float = min, max_float = max, input = FloatInput}
+
prompt_integer : Int -> Int -> Type -> Type
prompt_integer min max ui = {ui | min = min, max = max, input = IntegerInput}
diff --git a/src/Tonkadur/Compute.elm b/src/Tonkadur/Compute.elm
index 149f37d..a75ef7c 100644
--- a/src/Tonkadur/Compute.elm
+++ b/src/Tonkadur/Compute.elm
@@ -108,6 +108,7 @@ cast state from to param =
)
"float" -> (Tonkadur.Types.FloatValue (toFloat int))
+ "bool" -> (Tonkadur.Types.BoolValue (not (int == 0)))
"int" -> (Tonkadur.Types.IntValue int)
_ -> (unsupported_cast from to)
@@ -130,6 +131,11 @@ cast state from to param =
Nothing -> (unsupported_cast from to)
(Just result) -> (Tonkadur.Types.IntValue result)
+ "bool" ->
+ (Tonkadur.Types.BoolValue
+ ((String.toLower (String.trim as_string)) == "true")
+ )
+
"text" -> (Tonkadur.Types.TextValue text_v)
_ -> (unsupported_cast from to)
@@ -146,6 +152,11 @@ cast state from to param =
Nothing -> (unsupported_cast from to)
(Just result) -> (Tonkadur.Types.IntValue result)
+ "bool" ->
+ (Tonkadur.Types.BoolValue
+ ((String.toLower (String.trim string)) == "true")
+ )
+
"text" ->
(Tonkadur.Types.TextValue (Tonkadur.Types.StringText string))
diff --git a/src/Tonkadur/Execute.elm b/src/Tonkadur/Execute.elm
index cf10833..a65df88 100644
--- a/src/Tonkadur/Execute.elm
+++ b/src/Tonkadur/Execute.elm
@@ -30,7 +30,7 @@ add_event_option : (
)
add_event_option name parameters state =
(Tonkadur.Types.append_option
- (Tonkadur.Types.Event
+ (Tonkadur.Types.EventOption
name
(List.map (Tonkadur.Compute.compute state) parameters)
)
@@ -44,7 +44,7 @@ add_text_option : (
)
add_text_option label state =
(Tonkadur.Types.append_option
- (Tonkadur.Types.Choice
+ (Tonkadur.Types.TextOption
(Tonkadur.Types.value_to_text_or_string
(Tonkadur.Compute.compute state label)
)
@@ -60,8 +60,7 @@ assert : (
)
assert condition label state =
if (Tonkadur.Types.value_to_bool (Tonkadur.Compute.compute state condition))
- then
- state
+ then state
else
{state |
last_instruction_effect =
@@ -168,16 +167,16 @@ prompt_command prompt_data state =
)
}
-prompt_string : (
+prompt_float : (
Tonkadur.Types.PromptInstructionData ->
Tonkadur.Types.State ->
Tonkadur.Types.State
)
-prompt_string prompt_data state =
+prompt_float prompt_data state =
{state |
memorized_target = (Tonkadur.Compute.compute state prompt_data.address),
last_instruction_effect =
- (Tonkadur.Types.MustPromptString
+ (Tonkadur.Types.MustPromptFloat
(Tonkadur.Compute.compute state prompt_data.min)
(Tonkadur.Compute.compute state prompt_data.max)
(Tonkadur.Compute.compute state prompt_data.label)
@@ -200,6 +199,22 @@ prompt_integer prompt_data state =
)
}
+prompt_string : (
+ Tonkadur.Types.PromptInstructionData ->
+ Tonkadur.Types.State ->
+ Tonkadur.Types.State
+ )
+prompt_string prompt_data state =
+ {state |
+ memorized_target = (Tonkadur.Compute.compute state prompt_data.address),
+ last_instruction_effect =
+ (Tonkadur.Types.MustPromptString
+ (Tonkadur.Compute.compute state prompt_data.min)
+ (Tonkadur.Compute.compute state prompt_data.max)
+ (Tonkadur.Compute.compute state prompt_data.label)
+ )
+ }
+
remove : (
Tonkadur.Types.Computation ->
Tonkadur.Types.State ->
@@ -286,13 +301,13 @@ set_random address min max state =
random_seed = next_random_seed
}
-set : (
+set_value : (
Tonkadur.Types.Computation ->
Tonkadur.Types.Computation ->
Tonkadur.Types.State ->
Tonkadur.Types.State
)
-set address value state =
+set_value address value state =
{state |
memory =
(Tonkadur.Types.set_at_address
@@ -347,6 +362,9 @@ execute instruction state =
(Tonkadur.Types.PromptCommand prompt_data) ->
(increment_program_counter (prompt_command prompt_data new_state))
+ (Tonkadur.Types.PromptFloat prompt_data) ->
+ (increment_program_counter (prompt_float prompt_data new_state))
+
(Tonkadur.Types.PromptInteger prompt_data) ->
(increment_program_counter (prompt_integer prompt_data new_state))
@@ -363,6 +381,6 @@ execute instruction state =
(Tonkadur.Types.SetRandom address min max) ->
(increment_program_counter (set_random address min max new_state))
- (Tonkadur.Types.Set address value) ->
- (increment_program_counter (set address value new_state))
+ (Tonkadur.Types.SetValue address value) ->
+ (increment_program_counter (set_value address value new_state))
diff --git a/src/Tonkadur/Json.elm b/src/Tonkadur/Json.elm
index 3860548..d7ae3b3 100644
--- a/src/Tonkadur/Json.elm
+++ b/src/Tonkadur/Json.elm
@@ -31,13 +31,13 @@ specific_computation_decoder name =
(\ename params content ->
(Tonkadur.Types.AddTextEffect ename params content)
)
- (Json.Decode.field "effect" (Json.Decode.string))
+ (Json.Decode.field "name" (Json.Decode.string))
(Json.Decode.field
"parameters"
(Json.Decode.list (computation_decoder))
)
(Json.Decode.field
- "content"
+ "values"
(Json.Decode.list (computation_decoder))
)
)
@@ -45,7 +45,7 @@ specific_computation_decoder name =
"address" ->
(Json.Decode.map
(\address -> (Tonkadur.Types.Address address))
- (Json.Decode.field "address" (computation_decoder))
+ (Json.Decode.field "value_or_target" (computation_decoder))
)
"cast" ->
@@ -105,15 +105,21 @@ specific_computation_decoder name =
"relative_address" ->
(Json.Decode.map2
(\base extra -> (Tonkadur.Types.RelativeAddress base extra))
- (Json.Decode.field "base" (computation_decoder))
+ (Json.Decode.field "target" (computation_decoder))
(Json.Decode.field "extra" (computation_decoder))
)
+ "size" ->
+ (Json.Decode.map
+ (\computation -> (Tonkadur.Types.Size computation))
+ (Json.Decode.field "target" (computation_decoder))
+ )
+
"text" ->
(Json.Decode.map
(\computation -> (Tonkadur.Types.Text computation))
(Json.Decode.field
- "content"
+ "values"
(Json.Decode.list (computation_decoder))
)
)
@@ -121,13 +127,13 @@ specific_computation_decoder name =
"value_of" ->
(Json.Decode.map
(\computation -> (Tonkadur.Types.ValueOf computation))
- (Json.Decode.field "reference" (computation_decoder))
+ (Json.Decode.field "target" (computation_decoder))
)
_ ->
(Json.Decode.map
(\params -> (Tonkadur.Types.ExtraComputation name params))
- (Json.Decode.field "params"
+ (Json.Decode.field "parameters"
(Json.Decode.list (computation_decoder))
)
)
@@ -156,7 +162,7 @@ prompt_instruction_data_decoder =
|> (Json.Decode.Pipeline.required "target" (computation_decoder))
-- label
- |> (Json.Decode.Pipeline.required "label" (computation_decoder))
+ |> (Json.Decode.Pipeline.required "message" (computation_decoder))
)
specific_instruction_decoder : (
@@ -167,9 +173,9 @@ specific_instruction_decoder name =
"add_event_option" ->
(Json.Decode.map2
(\oname params -> (Tonkadur.Types.AddEventOption oname params))
- (Json.Decode.field "event" (Json.Decode.string))
+ (Json.Decode.field "name" (Json.Decode.string))
(Json.Decode.field
- "reference"
+ "parameters"
(Json.Decode.list (computation_decoder))
)
)
@@ -177,7 +183,7 @@ specific_instruction_decoder name =
"add_text_option" ->
(Json.Decode.map
(\computation -> (Tonkadur.Types.AddTextOption computation))
- (Json.Decode.field "label" (computation_decoder))
+ (Json.Decode.field "value" (computation_decoder))
)
"assert" ->
@@ -190,7 +196,7 @@ specific_instruction_decoder name =
"display" ->
(Json.Decode.map
(\computation -> (Tonkadur.Types.Display computation))
- (Json.Decode.field "content" (computation_decoder))
+ (Json.Decode.field "value" (computation_decoder))
)
"end" -> (Json.Decode.succeed Tonkadur.Types.End)
@@ -198,7 +204,7 @@ specific_instruction_decoder name =
(Json.Decode.map2
(\type_name ref -> (Tonkadur.Types.Initialize type_name ref))
(Json.Decode.field "type" (Json.Decode.string))
- (Json.Decode.field "reference" (computation_decoder))
+ (Json.Decode.field "target" (computation_decoder))
)
"prompt_command" ->
@@ -207,6 +213,12 @@ specific_instruction_decoder name =
(prompt_instruction_data_decoder)
)
+ "prompt_float" ->
+ (Json.Decode.map
+ (\data -> (Tonkadur.Types.PromptFloat data))
+ (prompt_instruction_data_decoder)
+ )
+
"prompt_integer" ->
(Json.Decode.map
(\data -> (Tonkadur.Types.PromptInteger data))
@@ -222,7 +234,7 @@ specific_instruction_decoder name =
"remove" ->
(Json.Decode.map
(\computation -> (Tonkadur.Types.Remove computation))
- (Json.Decode.field "reference" (computation_decoder))
+ (Json.Decode.field "target" (computation_decoder))
)
"resolve_choice" -> (Json.Decode.succeed Tonkadur.Types.ResolveChoice)
@@ -242,15 +254,15 @@ specific_instruction_decoder name =
"set_value" ->
(Json.Decode.map2
- (\target value -> (Tonkadur.Types.Set target value))
- (Json.Decode.field "reference" (computation_decoder))
+ (\target value -> (Tonkadur.Types.SetValue target value))
+ (Json.Decode.field "target" (computation_decoder))
(Json.Decode.field "value" (computation_decoder))
)
_ ->
(Json.Decode.map
(\params -> (Tonkadur.Types.ExtraInstruction name params))
- (Json.Decode.field "params"
+ (Json.Decode.field "parameters"
(Json.Decode.list (computation_decoder))
)
)
diff --git a/src/Tonkadur/Types.elm b/src/Tonkadur/Types.elm
index 77cd707..2a4df76 100644
--- a/src/Tonkadur/Types.elm
+++ b/src/Tonkadur/Types.elm
@@ -33,8 +33,8 @@ type Value =
| StructureValue (Dict.Dict String Value)
type Option =
- Choice RichText
- | Event String (List Value)
+ TextOption RichText
+ | EventOption String (List Value)
type Computation =
AddTextEffect String (List Computation) (List Computation)
@@ -69,24 +69,25 @@ type Instruction =
| ExtraInstruction String (List Computation)
| Initialize String Computation
| PromptCommand PromptInstructionData
+ | PromptFloat PromptInstructionData
| PromptInteger PromptInstructionData
| PromptString PromptInstructionData
| Remove Computation
| ResolveChoice
| SetPC Computation
| SetRandom Computation Computation Computation
- | Set Computation Computation
+ | SetValue Computation Computation
type InstructionEffect =
MustContinue
| MustEnd
| MustPromptCommand Value Value Value
+ | MustPromptFloat Value Value Value
| MustPromptInteger Value Value Value
| MustPromptString Value Value Value
| MustPromptChoice
| MustDisplay Value
| MustDisplayError Value
- | MustExtraEffect String (List Value)
type alias State =
{
@@ -372,6 +373,9 @@ elm_list_to_wyrd_list elm_value_to_wyrd_value list =
set_last_choice_index : Int -> State -> State
set_last_choice_index ix state = {state | last_choice_index = ix}
+clear_all_options : State -> State
+clear_all_options state = {state | available_options = []}
+
set_target_from_string : String -> State -> State
set_target_from_string str state =
{state |
@@ -383,6 +387,18 @@ set_target_from_string str state =
)
}
+set_target_from_float : Float -> State -> State
+set_target_from_float float state =
+ {state |
+ memory =
+ (set_at_address
+ (value_to_address state.memorized_target)
+ (FloatValue float)
+ state.memory
+ )
+ }
+
+
set_target_from_integer : Int -> State -> State
set_target_from_integer int state =
{state |
diff --git a/src/Update/Story.elm b/src/Update/Story.elm
index 3c9d041..708f5a9 100644
--- a/src/Update/Story.elm
+++ b/src/Update/Story.elm
@@ -67,6 +67,17 @@ step model =
)
}
+ (Tonkadur.Types.MustPromptFloat min max label) ->
+ {model |
+ tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
+ ui =
+ (Struct.UI.prompt_float
+ (Tonkadur.Types.value_to_float min)
+ (Tonkadur.Types.value_to_float max)
+ model.ui
+ )
+ }
+
(Tonkadur.Types.MustPromptInteger min max label) ->
{model |
tonkadur = (Tonkadur.Types.allow_continuing model.tonkadur),
@@ -95,7 +106,7 @@ step model =
(List.foldl
(\option (ix, ui) ->
case option of
- (Tonkadur.Types.Choice rich_text) ->
+ (Tonkadur.Types.TextOption rich_text) ->
(
(ix + 1),
(Struct.UI.display_choice
@@ -142,7 +153,7 @@ step model =
}
)
- _ -> model
+-- _ -> model
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
@@ -155,9 +166,11 @@ select_choice ix model =
(step
{model |
tonkadur =
- (Tonkadur.Types.set_last_choice_index
- ix
- model.tonkadur
+ (Tonkadur.Types.clear_all_options
+ (Tonkadur.Types.set_last_choice_index
+ ix
+ model.tonkadur
+ )
)
}
)
@@ -191,6 +204,45 @@ input_string string model =
}
)
+input_float : String -> Struct.Model.Type -> Struct.Model.Type
+input_float string model =
+ case (String.toFloat string) of
+ Nothing ->
+ {model |
+ ui =
+ (Struct.UI.display_string_error
+ "Input expects a float."
+ model.ui
+ )
+ }
+
+ (Just float) ->
+ if ((float < model.ui.min_float) || (float > model.ui.max_float))
+ then
+ {model |
+ ui =
+ (Struct.UI.display_string_error
+ (
+ "Input float should be between "
+ ++ (String.fromFloat model.ui.min_float)
+ ++ " and "
+ ++ (String.fromFloat model.ui.max_float)
+ ++ "."
+ )
+ model.ui
+ )
+ }
+ else
+ (step
+ {model |
+ tonkadur =
+ (Tonkadur.Types.set_target_from_float
+ float
+ model.tonkadur
+ )
+ }
+ )
+
input_integer : String -> Struct.Model.Type -> Struct.Model.Type
input_integer string model =
case (String.toInt string) of
diff --git a/src/View/PlayerInput.elm b/src/View/PlayerInput.elm
index 01d926c..e8004f4 100644
--- a/src/View/PlayerInput.elm
+++ b/src/View/PlayerInput.elm
@@ -41,6 +41,44 @@ get_html model =
then
case model.ui.input of
Struct.UI.NoInput -> (Html.div [] [])
+ Struct.UI.FloatInput ->
+ (Html.div
+ [
+ (Html.Attributes.class "tonkadur-input")
+ ]
+ [
+ (Html.div
+ [
+ (Html.Attributes.class "tonkadur-input-instruction")
+ ]
+ [
+ (Html.text
+ (
+ "A number between "
+ ++ (String.fromFloat model.ui.min_float)
+ ++ " and "
+ ++ (String.fromFloat model.ui.max_float)
+ ++ " is expected:"
+ )
+ )
+ ]
+ ),
+ (Html.input
+ [
+ (Html.Attributes.class "tonkadur-input-field"),
+ (Html.Attributes.min
+ (String.fromFloat model.ui.min_float)
+ ),
+ (Html.Attributes.max
+ (String.fromFloat model.ui.max_float)
+ )
+ ]
+ [
+ ]
+ )
+ ]
+ )
+
Struct.UI.IntegerInput ->
(Html.div
[