summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-11-07 18:34:47 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-11-07 18:34:47 +0100
commit2c4b6a7248d62530edc8896e48799dac3c1c1b61 (patch)
tree1ab4a6cc7f4cfe05b72fb57f48ab0c8f7ae23e0f /src/roster-editor
parent602f67b09d1eb77532641a52d0e885688352e231 (diff)
Adds encoder for characters.
Diffstat (limited to 'src/roster-editor')
-rw-r--r--src/roster-editor/src/Struct/Character.elm46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/roster-editor/src/Struct/Character.elm b/src/roster-editor/src/Struct/Character.elm
index ab0e452..19663f1 100644
--- a/src/roster-editor/src/Struct/Character.elm
+++ b/src/roster-editor/src/Struct/Character.elm
@@ -17,7 +17,8 @@ module Struct.Character exposing
set_glyph_board,
get_glyphs,
set_glyph,
- decoder
+ decoder,
+ encode
)
-- Elm -------------------------------------------------------------------------
@@ -25,6 +26,7 @@ import Array
import Json.Decode
import Json.Decode.Pipeline
+import Json.Encode
-- Roster Editor ---------------------------------------------------------------
import Struct.Armor
@@ -206,3 +208,45 @@ decoder =
|> (Json.Decode.Pipeline.hardcoded (Struct.Omnimods.none))
)
)
+
+encode : Type -> Json.Encode.Value
+encode char =
+ (Json.Encode.object
+ [
+ ("ix", (Json.Encode.int char.ix)),
+ ("nam", (Json.Encode.string char.name)),
+ ("prt", (Json.Encode.string (Struct.Portrait.get_id char.portrait))),
+ (
+ "awp",
+ (Json.Encode.int
+ (Struct.Weapon.get_id
+ (Struct.WeaponSet.get_active_weapon char.weapons)
+ )
+ )
+ ),
+ (
+ "swp",
+ (Json.Encode.int
+ (Struct.Weapon.get_id
+ (Struct.WeaponSet.get_active_weapon char.weapons)
+ )
+ )
+ ),
+ ("ar", (Json.Encode.int (Struct.Armor.get_id char.armor))),
+ (
+ "gb",
+ (Json.Encode.string (Struct.GlyphBoard.get_id char.glyph_board))
+ ),
+ (
+ "gls",
+ (Json.Encode.list
+ (Array.toList
+ (Array.map
+ ((Struct.Glyph.get_id) >> Json.Encode.string)
+ char.glyphs
+ )
+ )
+ )
+ )
+ ]
+ )