| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2022-01-01 16:32:45 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2022-01-01 16:32:45 +0100 | 
| commit | f86032ff459f57c8cda368b48888a39c848d263b (patch) | |
| tree | 682ee08cf60baebfc62b3c7cdaf4e715e1bbc635 /src/Tonkadur | |
| parent | 17903cc8333e0f50d3b4e3567f52a8de92101ad3 (diff) | |
Adds JSON decoding.
Diffstat (limited to 'src/Tonkadur')
| -rw-r--r-- | src/Tonkadur/Types.elm | 31 | 
1 files changed, 19 insertions, 12 deletions
| diff --git a/src/Tonkadur/Types.elm b/src/Tonkadur/Types.elm index 929d848..bf8ae56 100644 --- a/src/Tonkadur/Types.elm +++ b/src/Tonkadur/Types.elm @@ -17,7 +17,6 @@ type alias TextData =        effect_parameters : (List Value)     } -  type RichText =     StringText String     | AugmentedText TextData @@ -252,18 +251,26 @@ append_option option state =  get_default : State -> String -> Value  get_default state type_name = -   case type_name of -      "bool" -> (BoolValue False) -      "float" -> (FloatValue 0.0) -      "int" -> (IntValue 0) -      "text" -> (TextValue (StringText "")) -      "string" -> (StringValue "") -      "list" -> (ListValue (Dict.empty)) -      "ptr" -> (PointerValue []) -      other -> -         case (Dict.get other state.user_types) of +   case (maybe_get_default_primitive type_name) of +      (Just value) -> value +      Nothing -> +         case (Dict.get type_name state.user_types) of              (Just default) -> default -            Nothing -> (StringValue ("Unknown type '" ++ other ++ "'")) +            Nothing -> (StringValue ("Unknown type '" ++ type_name ++ "'")) + +-- Used during the decoding process, prior to 'state' being available, hence +-- its separation from 'get_default'. +maybe_get_default_primitive : String -> (Maybe Value) +maybe_get_default_primitive type_name = +   case type_name of +      "bool" -> (Just (BoolValue False)) +      "float" -> (Just (FloatValue 0.0)) +      "int" -> (Just (IntValue 0)) +      "text" -> (Just (TextValue (StringText ""))) +      "string" -> (Just (StringValue "")) +      "list" -> (Just (ListValue (Dict.empty))) +      "ptr" -> (Just (PointerValue [])) +      _ -> Nothing  apply_at_address : (        (List String) -> | 


