summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-11-10 00:25:20 +0100
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-11-10 00:25:20 +0100
commitf76ee59d32b60f2728abd1eb3ac4169c92b2b5ba (patch)
tree802be8c3ca0d0c38585db2b90fddd43d45fdcf74
parent25e3a440f35cecb2f235442acbe1667fcf19d6da (diff)
Looks like it doesn't work, dunno why though...
-rw-r--r--src/roster-editor/src/Comm/AddChar.elm11
-rw-r--r--src/roster-editor/src/Comm/UpdateRoster.elm6
-rw-r--r--src/roster-editor/src/Struct/Armor.elm4
-rw-r--r--src/roster-editor/src/Struct/Character.elm5
-rw-r--r--src/roster-editor/src/Struct/CharacterRecord.elm12
-rw-r--r--src/roster-editor/src/Struct/Glyph.elm13
-rw-r--r--src/roster-editor/src/Struct/GlyphBoard.elm6
-rw-r--r--src/roster-editor/src/Struct/Model.elm35
-rw-r--r--src/roster-editor/src/Struct/Weapon.elm6
-rw-r--r--src/roster-editor/src/Update/HandleServerReply.elm35
10 files changed, 89 insertions, 44 deletions
diff --git a/src/roster-editor/src/Comm/AddChar.elm b/src/roster-editor/src/Comm/AddChar.elm
index 21cbb77..a546bf0 100644
--- a/src/roster-editor/src/Comm/AddChar.elm
+++ b/src/roster-editor/src/Comm/AddChar.elm
@@ -4,7 +4,7 @@ module Comm.AddChar exposing (decode)
import Json.Decode
-- Roster Editor ---------------------------------------------------------------
-import Struct.Character
+import Struct.CharacterRecord
import Struct.ServerReply
--------------------------------------------------------------------------------
@@ -15,14 +15,11 @@ import Struct.ServerReply
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
-internal_decoder : (
- (Struct.Character.Type, String, Int, Int, Int) ->
- Struct.ServerReply.Type
- )
-internal_decoder char_and_refs = (Struct.ServerReply.AddCharacter char_and_refs)
+internal_decoder : Struct.CharacterRecord.Type -> Struct.ServerReply.Type
+internal_decoder char= (Struct.ServerReply.AddCharacter char)
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
decode : (Json.Decode.Decoder Struct.ServerReply.Type)
-decode = (Json.Decode.map (internal_decoder) (Struct.Character.decoder))
+decode = (Json.Decode.map (internal_decoder) (Struct.CharacterRecord.decoder))
diff --git a/src/roster-editor/src/Comm/UpdateRoster.elm b/src/roster-editor/src/Comm/UpdateRoster.elm
index eabdd5e..ff31ad0 100644
--- a/src/roster-editor/src/Comm/UpdateRoster.elm
+++ b/src/roster-editor/src/Comm/UpdateRoster.elm
@@ -13,6 +13,7 @@ import Comm.Send
import Constants.IO
import Struct.Character
+import Struct.CharacterRecord
import Struct.Event
import Struct.Model
@@ -34,7 +35,10 @@ try_encoding model =
"rst",
(Json.Encode.list
(List.map
- (Struct.Character.encode)
+ (
+ (Struct.CharacterRecord.from_character)
+ >> (Struct.CharacterRecord.encode)
+ )
(List.filter
(Struct.Character.get_was_edited)
(Array.toList model.characters)
diff --git a/src/roster-editor/src/Struct/Armor.elm b/src/roster-editor/src/Struct/Armor.elm
index 659f2c3..5f163fe 100644
--- a/src/roster-editor/src/Struct/Armor.elm
+++ b/src/roster-editor/src/Struct/Armor.elm
@@ -8,6 +8,7 @@ module Struct.Armor exposing
get_image_id,
get_omnimods,
decoder,
+ default,
none
)
@@ -68,3 +69,6 @@ decoder =
none : Type
none = (new 0 "None" (Struct.Omnimods.new [] [] [] []))
+
+default : Type
+default = (none)
diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm
index a589fcc..796f85f 100644
--- a/src/roster-editor/src/Struct/Character.elm
+++ b/src/roster-editor/src/Struct/Character.elm
@@ -120,7 +120,7 @@ new index name m_portrait m_main_wp m_sec_wp m_armor m_board m_glyphs =
Nothing -> (Struct.Portrait.default)
),
attributes = (Struct.Attributes.default),
- statistics = (Struct.Statistics.default),
+ statistics = (Struct.Statistics.new_raw (Struct.Attributes.default)),
weapons =
(Struct.WeaponSet.new
(
@@ -155,7 +155,8 @@ new index name m_portrait m_main_wp m_sec_wp m_armor m_board m_glyphs =
Nothing -> (Struct.Glyph.default)
)
m_glyphs
- )
+ )
+ ),
current_omnimods = (Struct.Omnimods.none),
was_edited = False
}
diff --git a/src/roster-editor/src/Struct/CharacterRecord.elm b/src/roster-editor/src/Struct/CharacterRecord.elm
index c92014d..7784499 100644
--- a/src/roster-editor/src/Struct/CharacterRecord.elm
+++ b/src/roster-editor/src/Struct/CharacterRecord.elm
@@ -24,6 +24,7 @@ import Json.Encode
-- Roster Editor ---------------------------------------------------------------
import Struct.Armor
import Struct.Attributes
+import Struct.Character
import Struct.Glyph
import Struct.GlyphBoard
import Struct.Omnimods
@@ -44,7 +45,7 @@ type alias Type =
secondary_weapon_id : Int,
armor_id : Int,
glyph_board_id : String,
- glyph_ids : (List Int)
+ glyph_ids : (List String)
}
--------------------------------------------------------------------------------
@@ -75,7 +76,7 @@ get_armor_id char = char.armor_id
get_glyph_board_id : Type -> String
get_glyph_board_id char = char.glyph_board_id
-get_glyph_ids : Type -> (List Int)
+get_glyph_ids : Type -> (List String)
get_glyph_ids char = char.glyph_ids
from_character : Struct.Character.Type -> Type
@@ -107,7 +108,7 @@ from_character char =
decoder : (Json.Decode.Decoder Type)
decoder =
(Json.Decode.Pipeline.decode
- PartiallyDecoded
+ Type
|> (Json.Decode.Pipeline.required "ix" Json.Decode.int)
|> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
|> (Json.Decode.Pipeline.required "prt" Json.Decode.string)
@@ -117,7 +118,7 @@ decoder =
|> (Json.Decode.Pipeline.required "gb" Json.Decode.string)
|> (Json.Decode.Pipeline.required
"gls"
- (Json.Decode.list Json.Decode.int)
+ (Json.Decode.list Json.Decode.string)
)
)
@@ -135,7 +136,8 @@ encode char =
(
"gls",
(Json.Encode.list
- (List.map (Json.Encode.string)
+ (List.map
+ (Json.Encode.string)
char.glyph_ids
)
)
diff --git a/src/roster-editor/src/Struct/Glyph.elm b/src/roster-editor/src/Struct/Glyph.elm
index cd8329b..a5ff408 100644
--- a/src/roster-editor/src/Struct/Glyph.elm
+++ b/src/roster-editor/src/Struct/Glyph.elm
@@ -5,6 +5,8 @@ module Struct.Glyph exposing
get_name,
get_id,
get_omnimods,
+ none,
+ default,
decoder
)
@@ -51,3 +53,14 @@ decoder =
|> (Json.Decode.Pipeline.required "nam" Json.Decode.string)
|> (Json.Decode.Pipeline.required "omni" Struct.Omnimods.decoder)
)
+
+none : Type
+none =
+ {
+ id = "0",
+ name = "Empty",
+ omnimods = (Struct.Omnimods.none)
+ }
+
+default : Type
+default = (none)
diff --git a/src/roster-editor/src/Struct/GlyphBoard.elm b/src/roster-editor/src/Struct/GlyphBoard.elm
index 27ecfeb..3221a4e 100644
--- a/src/roster-editor/src/Struct/GlyphBoard.elm
+++ b/src/roster-editor/src/Struct/GlyphBoard.elm
@@ -7,7 +7,8 @@ module Struct.GlyphBoard exposing
get_omnimods,
get_omnimods_with_glyphs,
decoder,
- none
+ none,
+ default
)
-- Elm -------------------------------------------------------------------------
@@ -71,3 +72,6 @@ none =
name = "None",
omnimods = (Struct.Omnimods.none)
}
+
+default : Type
+default = (none)
diff --git a/src/roster-editor/src/Struct/Model.elm b/src/roster-editor/src/Struct/Model.elm
index 3dd5c3c..e796df7 100644
--- a/src/roster-editor/src/Struct/Model.elm
+++ b/src/roster-editor/src/Struct/Model.elm
@@ -3,6 +3,7 @@ module Struct.Model exposing
Type,
new,
add_character_record,
+ enable_character_records,
update_character,
update_character_fun,
save_character,
@@ -18,6 +19,8 @@ module Struct.Model exposing
-- Elm -------------------------------------------------------------------------
import Array
+import List
+
import Dict
-- Shared ----------------------------------------------------------------------
@@ -103,6 +106,20 @@ add_character char_rec model =
)
}
+has_loaded_data : Type -> Bool
+has_loaded_data model =
+ (
+ ((Array.length model.characters) > 0)
+ ||
+ (
+ (model.portraits /= (Dict.empty))
+ && (model.weapons /= (Dict.empty))
+ && (model.armors /= (Dict.empty))
+ && (model.glyph_boards /= (Dict.empty))
+ && (model.glyphs /= (Dict.empty))
+ )
+ )
+
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -134,9 +151,21 @@ new flags =
add_character_record : Struct.CharacterRecord.Type -> Type -> Type
add_character_record char model =
- if (condition)
- then {model | stalled_characters = (char :: model.stalled_characters)}
- else (add_character char model)
+ if (has_loaded_data model)
+ then (add_character char model)
+ else {model | stalled_characters = (char :: model.stalled_characters)}
+
+enable_character_records : Type -> Type
+enable_character_records model =
+ if (has_loaded_data model)
+ then
+ (List.foldr
+ (add_character)
+ {model | stalled_characters = []}
+ model.stalled_characters
+ )
+ else
+ model
add_weapon : Struct.Weapon.Type -> Type -> Type
add_weapon wp model =
diff --git a/src/roster-editor/src/Struct/Weapon.elm b/src/roster-editor/src/Struct/Weapon.elm
index 2035fe4..eb1f2e4 100644
--- a/src/roster-editor/src/Struct/Weapon.elm
+++ b/src/roster-editor/src/Struct/Weapon.elm
@@ -10,6 +10,7 @@ module Struct.Weapon exposing
get_omnimods,
get_damage_sum,
decoder,
+ default,
none
)
@@ -96,4 +97,7 @@ decoder =
)
none : Type
-none = (new 0 "None" 0 0 (Struct.Omnimods.new [] [] [] []))
+none = (new 0 "None" 0 0 (Struct.Omnimods.none))
+
+default : Type
+default = (none)
diff --git a/src/roster-editor/src/Update/HandleServerReply.elm b/src/roster-editor/src/Update/HandleServerReply.elm
index c5ad496..b1369de 100644
--- a/src/roster-editor/src/Update/HandleServerReply.elm
+++ b/src/roster-editor/src/Update/HandleServerReply.elm
@@ -15,6 +15,7 @@ import Constants.IO
import Struct.Armor
import Struct.Character
+import Struct.CharacterRecord
import Struct.Error
import Struct.Event
import Struct.Glyph
@@ -137,33 +138,14 @@ set_inventory inv current_state =
({model | inventory = inv}, cmds)
add_character : (
- (Struct.Character.Type, String, Int, Int, Int) ->
+ Struct.CharacterRecord.Type ->
(Struct.Model.Type, (List (Cmd Struct.Event.Type))) ->
(Struct.Model.Type, (List (Cmd Struct.Event.Type)))
)
-add_character char_and_refs current_state =
- let
- (model, cmds) = current_state
- (char, prt_ref, awp_ref, swp_ref, ar_ref) = char_and_refs
- prt = (portrait_getter model prt_ref)
- awp = (weapon_getter model awp_ref)
- swp = (weapon_getter model swp_ref)
- ar = (armor_getter model ar_ref)
- in
+add_character char current_state =
+ let (model, cmds) = current_state in
(
- (Struct.Model.add_character
- (Struct.Character.set_armor
- ar
- (Struct.Character.set_weapons
- (Struct.WeaponSet.new awp swp)
- (Struct.Character.set_portrait
- prt
- char
- )
- )
- )
- model
- ),
+ (Struct.Model.add_character_record char model),
cmds
)
@@ -197,7 +179,12 @@ apply_command command current_state =
(Struct.ServerReply.AddCharacter char) ->
(add_character char current_state)
- Struct.ServerReply.Okay -> current_state
+ Struct.ServerReply.Okay ->
+ let (model, cmds) = current_state in
+ (
+ (Struct.Model.enable_character_records model),
+ cmds
+ )
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------