aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-05-03 17:23:24 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-05-03 17:23:24 +0200
commitc14e56360447d5581913d5a535b0540378f04a04 (patch)
tree1db4c28de2df71bc575b8a2704551a2b72e7d25d
parent5b60ea80b8e3f4c0fcfe8764f37e54a8e6f4d9bb (diff)
downloadtacticians-client-c14e56360447d5581913d5a535b0540378f04a04.zip
tacticians-client-c14e56360447d5581913d5a535b0540378f04a04.tar.bz2
Adds partial Marker edition (no permissions yet).
-rw-r--r--src/map-editor/src/ElmModule/Update.elm16
-rw-r--r--src/map-editor/src/Struct/Event.elm5
-rw-r--r--src/map-editor/src/Struct/Toolbox.elm4
-rw-r--r--src/map-editor/src/Struct/UI.elm24
-rw-r--r--src/map-editor/src/Update/Markers.elm160
-rw-r--r--src/map-editor/src/View/SubMenu/Markers.elm79
-rw-r--r--src/map-editor/src/View/Toolbox.elm10
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Map.elm4
-rw-r--r--src/shared/battle-map/BattleMap/Struct/Marker.elm4
9 files changed, 282 insertions, 24 deletions
diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm
index 095c049..944108a 100644
--- a/src/map-editor/src/ElmModule/Update.elm
+++ b/src/map-editor/src/ElmModule/Update.elm
@@ -8,6 +8,7 @@ import Update.ChangeScale
import Update.ClearToolboxSelection
import Update.GoToMainMenu
import Update.HandleServerReply
+import Update.Markers
import Update.PrettifySelectedTiles
import Update.SelectTab
import Update.SelectTile
@@ -76,5 +77,20 @@ update event model =
Struct.Event.SendMapUpdateRequested ->
(Update.SendMapUpdate.apply_to new_model)
+ (Struct.Event.SetMarkerName name) ->
+ (Update.Markers.set_name new_model name)
+
+ Struct.Event.LoadMarker ->
+ (Update.Markers.load new_model)
+
+ Struct.Event.SaveMarker ->
+ (Update.Markers.save new_model)
+
+ Struct.Event.RemoveMarker ->
+ (Update.Markers.remove new_model)
+
+ Struct.Event.NewMarker ->
+ (Update.Markers.new new_model)
+
Struct.Event.GoToMainMenu ->
(Update.GoToMainMenu.apply_to new_model)
diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm
index fd7a1ee..af59184 100644
--- a/src/map-editor/src/Struct/Event.elm
+++ b/src/map-editor/src/Struct/Event.elm
@@ -33,6 +33,11 @@ type Type =
| PrettifySelectionRequested
| SendMapUpdateRequested
| GoToMainMenu
+ | SetMarkerName String
+ | NewMarker
+ | RemoveMarker
+ | LoadMarker
+ | SaveMarker
attempted : (Result.Result err val) -> Type
attempted act =
diff --git a/src/map-editor/src/Struct/Toolbox.elm b/src/map-editor/src/Struct/Toolbox.elm
index 8a05fc2..fcd3b58 100644
--- a/src/map-editor/src/Struct/Toolbox.elm
+++ b/src/map-editor/src/Struct/Toolbox.elm
@@ -16,6 +16,7 @@ module Struct.Toolbox exposing
get_shape,
get_shapes,
get_selection,
+ set_selection,
default
)
@@ -238,6 +239,9 @@ get_shapes mode =
get_selection : Type -> (List BattleMap.Struct.Location.Type)
get_selection tb = tb.selection
+set_selection : (List BattleMap.Struct.Location.Type) -> Type -> Type
+set_selection location_list tb = {tb | selection = location_list}
+
set_template : BattleMap.Struct.TileInstance.Type -> Type -> Type
set_template template tb =
{tb |
diff --git a/src/map-editor/src/Struct/UI.elm b/src/map-editor/src/Struct/UI.elm
index a027b26..f295e19 100644
--- a/src/map-editor/src/Struct/UI.elm
+++ b/src/map-editor/src/Struct/UI.elm
@@ -16,7 +16,11 @@ module Struct.UI exposing
get_all_tabs,
-- Previous Action
get_previous_action,
- set_previous_action
+ set_previous_action,
+ -- Marker Name
+ get_marker_name,
+ reset_marker_name,
+ set_marker_name
)
-- Battle Map ------------------------------------------------------------------
@@ -29,7 +33,7 @@ type Tab =
StatusTab
| TilesTab
| SettingsTab
- | MarkersTab
+ | MarkersTab
type Action =
SelectedLocation BattleMap.Struct.Location.Ref
@@ -38,7 +42,8 @@ type alias Type =
{
zoom_level : Float,
displayed_tab : (Maybe Tab),
- previous_action : (Maybe Action)
+ previous_action : (Maybe Action),
+ marker_name : String
}
--------------------------------------------------------------------------------
@@ -53,7 +58,8 @@ default =
{
zoom_level = 1.0,
displayed_tab = (Just TilesTab),
- previous_action = Nothing
+ previous_action = Nothing,
+ marker_name = ""
}
-- Zoom ------------------------------------------------------------------------
@@ -94,3 +100,13 @@ set_previous_action act ui = {ui | previous_action = act}
get_previous_action : Type -> (Maybe Action)
get_previous_action ui = ui.previous_action
+
+-- Marker Name -----------------------------------------------------------------
+set_marker_name : String -> Type -> Type
+set_marker_name name ui = {ui | marker_name = name}
+
+reset_marker_name : Type -> Type
+reset_marker_name ui = {ui | marker_name = ""}
+
+get_marker_name : Type -> String
+get_marker_name ui = ui.marker_name
diff --git a/src/map-editor/src/Update/Markers.elm b/src/map-editor/src/Update/Markers.elm
new file mode 100644
index 0000000..e5d64ea
--- /dev/null
+++ b/src/map-editor/src/Update/Markers.elm
@@ -0,0 +1,160 @@
+module Update.Markers exposing (set_name, load, save, new, remove)
+
+-- Elm -------------------------------------------------------------------------
+import Dict
+import Set
+
+-- Battle Map ------------------------------------------------------------------
+import BattleMap.Struct.Map
+import BattleMap.Struct.Location
+import BattleMap.Struct.Marker
+
+-- Local Module ----------------------------------------------------------------
+import Struct.Error
+import Struct.Event
+import Struct.Model
+import Struct.UI
+import Struct.Toolbox
+
+--------------------------------------------------------------------------------
+-- LOCAL -----------------------------------------------------------------------
+--------------------------------------------------------------------------------
+
+--------------------------------------------------------------------------------
+-- EXPORTED --------------------------------------------------------------------
+--------------------------------------------------------------------------------
+set_name : (
+ Struct.Model.Type ->
+ String ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+set_name model name =
+ (
+ {model | ui = (Struct.UI.set_marker_name name model.ui)},
+ Cmd.none
+ )
+
+load : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+load model =
+ (
+ (
+ case
+ (Dict.get
+ (Struct.UI.get_marker_name model.ui)
+ (BattleMap.Struct.Map.get_markers model.map)
+ )
+ of
+ (Just marker) ->
+ {model |
+ toolbox =
+ (Struct.Toolbox.set_selection
+ (List.map
+ (BattleMap.Struct.Location.from_ref)
+ (Set.toList
+ (BattleMap.Struct.Marker.get_locations marker)
+ )
+ )
+ model.toolbox
+ )
+ }
+
+ Nothing ->
+ (Struct.Model.invalidate
+ (Struct.Error.new
+ Struct.Error.Programming
+ (
+ "Cannot load unknown marker \""
+ ++ (Struct.UI.get_marker_name model.ui)
+ ++ "\"."
+ )
+ )
+ model
+ )
+ ),
+ Cmd.none
+ )
+
+save : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+save model =
+ (
+ (
+ {model |
+ map =
+ (BattleMap.Struct.Map.set_markers
+ (Dict.insert
+ (Struct.UI.get_marker_name model.ui)
+ (BattleMap.Struct.Marker.set_locations
+ (Set.fromList
+ (List.map
+ (BattleMap.Struct.Location.get_ref)
+ (Struct.Toolbox.get_selection model.toolbox)
+ )
+ )
+ (BattleMap.Struct.Marker.new)
+ )
+ (BattleMap.Struct.Map.get_markers model.map)
+ )
+ model.map
+ )
+ }
+ ),
+ Cmd.none
+ )
+
+new : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+new model =
+ (
+ (
+ {model |
+ map =
+ (BattleMap.Struct.Map.set_markers
+ (Dict.insert
+ (Struct.UI.get_marker_name model.ui)
+ (BattleMap.Struct.Marker.set_locations
+ (Set.fromList
+ (List.map
+ (BattleMap.Struct.Location.get_ref)
+ (Struct.Toolbox.get_selection model.toolbox)
+ )
+ )
+ (BattleMap.Struct.Marker.new)
+ )
+ (BattleMap.Struct.Map.get_markers model.map)
+ )
+ model.map
+ )
+ }
+ ),
+ Cmd.none
+ )
+
+remove : (
+ Struct.Model.Type ->
+ (Struct.Model.Type, (Cmd Struct.Event.Type))
+ )
+remove model =
+ (
+ (
+ {model |
+ map =
+ (BattleMap.Struct.Map.set_markers
+ (Dict.remove
+ (Struct.UI.get_marker_name model.ui)
+ (BattleMap.Struct.Map.get_markers model.map)
+ )
+ model.map
+ )
+ }
+ ),
+ Cmd.none
+ )
+
diff --git a/src/map-editor/src/View/SubMenu/Markers.elm b/src/map-editor/src/View/SubMenu/Markers.elm
index 62aa89f..b5f6b77 100644
--- a/src/map-editor/src/View/SubMenu/Markers.elm
+++ b/src/map-editor/src/View/SubMenu/Markers.elm
@@ -8,29 +8,88 @@ import Html.Attributes
import Html.Events
-- Battle Map ------------------------------------------------------------------
-import BattleMap.Struct.Tile
import BattleMap.Struct.Map
import BattleMap.Struct.Marker
-import BattleMap.Struct.TileInstance
-
-import BattleMap.View.Tile
-- Local Module ----------------------------------------------------------------
import Struct.Event
import Struct.Model
+import Struct.UI
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
get_marker_html : (
+ String ->
(String, BattleMap.Struct.Marker.Type)
-> (Html.Html Struct.Event.Type)
)
-get_marker_html (ref, marker) =
+get_marker_html current_selection (ref, marker) =
+ (Html.option
+ [
+ (Html.Attributes.value ref),
+ (Html.Attributes.selected (ref == current_selection))
+ ]
+ [ (Html.text ref) ]
+ )
+
+get_selector_html : Struct.Model.Type -> (Html.Html Struct.Event.Type)
+get_selector_html model =
+ (Html.div
+ [
+ ]
+ [
+ (Html.select
+ [
+ (Html.Events.onInput Struct.Event.SetMarkerName)
+ ]
+ (List.map
+ (get_marker_html (Struct.UI.get_marker_name model.ui))
+ (Dict.toList (BattleMap.Struct.Map.get_markers model.map))
+ )
+ ),
+ (Html.button
+ [
+ (Html.Events.onClick Struct.Event.LoadMarker)
+ ]
+ [(Html.text "Load")]
+ ),
+ (Html.button
+ [
+ (Html.Events.onClick Struct.Event.SaveMarker)
+ ]
+ [(Html.text "Save")]
+ ),
+ (Html.button
+ [
+ (Html.Events.onClick Struct.Event.RemoveMarker)
+ ]
+ [(Html.text "Remove")]
+ )
+ ]
+ )
+
+new_marker_menu : (Html.Html Struct.Event.Type)
+new_marker_menu =
(Html.div
+ []
[
+ (Html.input
+ [
+ (Html.Events.onInput Struct.Event.SetMarkerName)
+ ]
+ [
+ ]
+ ),
+ (Html.button
+ [
+ (Html.Events.onClick Struct.Event.NewMarker)
+ ]
+ [
+ (Html.text "Add")
+ ]
+ )
]
- [(Html.text ref)]
)
--------------------------------------------------------------------------------
@@ -43,8 +102,8 @@ get_html model =
(Html.Attributes.class "tabmenu-content"),
(Html.Attributes.class "tabmenu-markers-tab")
]
- (List.map
- (get_marker_html)
- (Dict.toList (BattleMap.Struct.Map.get_markers model.map))
- )
+ [
+ (new_marker_menu),
+ (get_selector_html model)
+ ]
)
diff --git a/src/map-editor/src/View/Toolbox.elm b/src/map-editor/src/View/Toolbox.elm
index c9711d4..be29e44 100644
--- a/src/map-editor/src/View/Toolbox.elm
+++ b/src/map-editor/src/View/Toolbox.elm
@@ -19,7 +19,6 @@ import Struct.Event
import Struct.Model
import Struct.Toolbox
-
--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -122,14 +121,6 @@ get_others_menu_html =
]
)
-get_markers_html : (List String) -> (Html.Html Struct.Event.Type)
-get_markers_html markers_name =
- (Html.select
- [
- ]
- (List.map (Html.text) markers_name)
- )
-
--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
@@ -142,7 +133,6 @@ get_html model =
(get_template_icon_html (Struct.Toolbox.get_template tb)),
(get_modes_menu_html tb),
(get_shapes_menu_html tb),
- (get_markers_html (Dict.keys (BattleMap.Struct.Map.get_markers model.map))),
(get_others_menu_html)
]
)
diff --git a/src/shared/battle-map/BattleMap/Struct/Map.elm b/src/shared/battle-map/BattleMap/Struct/Map.elm
index 97f0ae8..fb3f8fb 100644
--- a/src/shared/battle-map/BattleMap/Struct/Map.elm
+++ b/src/shared/battle-map/BattleMap/Struct/Map.elm
@@ -5,6 +5,7 @@ module BattleMap.Struct.Map exposing
empty,
get_height,
get_markers,
+ set_markers,
get_movement_cost_function,
get_omnimods_at,
get_tiles,
@@ -76,6 +77,9 @@ get_tiles map = map.content
get_markers : Type -> (Dict.Dict String BattleMap.Struct.Marker.Type)
get_markers map = map.markers
+set_markers : (Dict.Dict String BattleMap.Struct.Marker.Type) -> Type -> Type
+set_markers markers map = {map | markers = markers}
+
set_tile_to : BattleMap.Struct.Location.Type -> BattleMap.Struct.TileInstance.Type -> Type -> Type
set_tile_to loc tile_inst map =
{map |
diff --git a/src/shared/battle-map/BattleMap/Struct/Marker.elm b/src/shared/battle-map/BattleMap/Struct/Marker.elm
index 9af3ece..2493b5e 100644
--- a/src/shared/battle-map/BattleMap/Struct/Marker.elm
+++ b/src/shared/battle-map/BattleMap/Struct/Marker.elm
@@ -3,6 +3,7 @@ module BattleMap.Struct.Marker exposing
Type,
new,
get_locations,
+ set_locations,
is_in_locations,
decoder,
encode
@@ -44,6 +45,9 @@ new =
get_locations : Type -> (Set.Set BattleMap.Struct.Location.Ref)
get_locations marker = marker.locations
+set_locations : (Set.Set BattleMap.Struct.Location.Ref) -> Type -> Type
+set_locations locations marker = {marker | locations = locations}
+
is_in_locations : BattleMap.Struct.Location.Ref -> Type -> Bool
is_in_locations loc_ref marker =
(Set.member loc_ref marker.locations)