From c4091e47c7f0624f98286238e5ab57597cfa266d Mon Sep 17 00:00:00 2001
From: Oskar Marquardt <oskar.marquardt@student.uni-halle.de>
Date: Tue, 18 Jun 2024 15:50:50 +0200
Subject: [PATCH] Moved character stats into dedicated module

---
 public/main.js    | 27 ++++++++++++++---------
 src/Character.elm | 52 ++++++-------------------------------------
 src/Main.elm      |  2 +-
 src/Stats.elm     | 56 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+), 56 deletions(-)
 create mode 100644 src/Stats.elm

diff --git a/public/main.js b/public/main.js
index 047f4a9..676d0e2 100644
--- a/public/main.js
+++ b/public/main.js
@@ -5159,6 +5159,7 @@ var $elm$core$Task$perform = F2(
 				A2($elm$core$Task$map, toMessage, task)));
 	});
 var $elm$browser$Browser$document = _Browser_document;
+var $author$project$Creation$new = {freebie: 15, spheres: 6};
 var $author$project$BoundedInt$new = F3(
 	function (value, min, max) {
 		return ((_Utils_cmp(value, min) < 0) || ((_Utils_cmp(value, max) > 0) || (_Utils_cmp(min, max) > 0))) ? {max: 0, min: 0, value: 0} : {max: max, min: min, value: value};
@@ -5166,11 +5167,8 @@ var $author$project$BoundedInt$new = F3(
 var $author$project$Sphere$dots = function (value) {
 	return A3($author$project$BoundedInt$new, value, 0, 5);
 };
-var $author$project$Creation$new = {freebie: 15, spheres: 6};
-var $author$project$Character$new = {
+var $author$project$Stats$new = {
 	arete: A3($author$project$BoundedInt$new, 1, 0, 10),
-	creationPoints: $author$project$Creation$new,
-	name: 'Default Name',
 	spheres: _List_fromArray(
 		[
 			{
@@ -5220,6 +5218,7 @@ var $author$project$Character$new = {
 		}
 		])
 };
+var $author$project$Character$new = {creationPoints: $author$project$Creation$new, name: 'Default Name', stats: $author$project$Stats$new};
 var $elm$core$Platform$Cmd$batch = _Platform_batch;
 var $elm$core$Platform$Cmd$none = $elm$core$Platform$Cmd$batch(_List_Nil);
 var $author$project$Main$init = function (_v0) {
@@ -5273,6 +5272,14 @@ var $author$project$Sphere$changeSphereInList = F2(
 			$author$project$Sphere$changeSphere(sphere),
 			spheres);
 	});
+var $author$project$Stats$changeSphere = F2(
+	function (stats, sphere) {
+		return _Utils_update(
+			stats,
+			{
+				spheres: A2($author$project$Sphere$changeSphereInList, stats.spheres, sphere)
+			});
+	});
 var $elm$core$List$filter = F2(
 	function (isGood, list) {
 		return A3(
@@ -5313,13 +5320,13 @@ var $elm$core$Basics$min = F2(
 	});
 var $author$project$Character$changeSphere = F2(
 	function (character, sphere) {
-		var maybeOldDots = A2($author$project$Sphere$getDotsOfSphereInList, character.spheres, sphere.name);
+		var maybeOldDots = A2($author$project$Sphere$getDotsOfSphereInList, character.stats.spheres, sphere.name);
 		var difference = function () {
 			if (maybeOldDots.$ === 'Nothing') {
 				return 0;
 			} else {
 				var oldDots = maybeOldDots.a;
-				return (_Utils_cmp(sphere.dots.value, character.arete.value) > 0) ? (character.arete.value - oldDots.value) : (sphere.dots.value - oldDots.value);
+				return (_Utils_cmp(sphere.dots.value, character.stats.arete.value) > 0) ? (character.stats.arete.value - oldDots.value) : (sphere.dots.value - oldDots.value);
 			}
 		}();
 		if (maybeOldDots.$ === 'Nothing') {
@@ -5331,9 +5338,9 @@ var $author$project$Character$changeSphere = F2(
 				character,
 				{
 					creationPoints: A2($author$project$Creation$buySphere, character.creationPoints, buyAmount),
-					spheres: A2(
-						$author$project$Sphere$changeSphereInList,
-						character.spheres,
+					stats: A2(
+						$author$project$Stats$changeSphere,
+						character.stats,
 						A2($author$project$Sphere$changeDotsOfSphereTo, sphere, oldDots.value + buyAmount))
 				});
 		}
@@ -5851,7 +5858,7 @@ var $author$project$Main$view = function (model) {
 		body: _List_fromArray(
 			[
 				A2($author$project$Main$viewEditableText, $author$project$Main$Name, model.character.name),
-				$author$project$Main$viewSpheres(model.character.spheres),
+				$author$project$Main$viewSpheres(model.character.stats.spheres),
 				$author$project$Main$viewModal(model),
 				A2(
 				$elm$html$Html$div,
diff --git a/src/Character.elm b/src/Character.elm
index d1a0aee..006d7c8 100644
--- a/src/Character.elm
+++ b/src/Character.elm
@@ -3,57 +3,19 @@ module Character exposing (..)
 import Sphere exposing (Sphere)
 import BoundedInt exposing (BoundedInt)
 import Creation exposing (CreationPoints)
+import Stats exposing (Stats)
 
 type alias Character =
     { name : String
     , creationPoints : CreationPoints
-    , spheres : List Sphere
-    , arete : BoundedInt
+    , stats : Stats
     }
 
 new : Character
 new =
     { name = "Default Name"
     , creationPoints = Creation.new
-    , spheres = 
-        [   { name = "Correspondence"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Entropy"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Forces"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Life"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Matter"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Mind"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Prime"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Spirit"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ,   { name = "Time"
-            , dots = Sphere.dots 0
-            , affinity = False
-            }
-        ]
-    , arete = BoundedInt.new 1 0 10
+    , stats = Stats.new
     }
 
 changeName : Character -> String -> Character
@@ -67,12 +29,12 @@ changeName character newName =
 changeSphere : Character -> Sphere -> Character
 changeSphere character sphere =
     let
-        maybeOldDots = Sphere.getDotsOfSphereInList character.spheres sphere.name
+        maybeOldDots = Sphere.getDotsOfSphereInList character.stats.spheres sphere.name
         difference = case maybeOldDots of
             Nothing -> 0
             Just oldDots ->
-                if sphere.dots.value > character.arete.value
-                then character.arete.value - oldDots.value
+                if sphere.dots.value > character.stats.arete.value
+                then character.stats.arete.value - oldDots.value
                 else sphere.dots.value - oldDots.value
     in
         case maybeOldDots of
@@ -83,5 +45,5 @@ changeSphere character sphere =
                 in
                     { character
                     | creationPoints = Creation.buySphere character.creationPoints buyAmount
-                    , spheres = Sphere.changeSphereInList character.spheres ( Sphere.changeDotsOfSphereTo sphere ( oldDots.value + buyAmount ) )
+                    , stats = Stats.changeSphere character.stats ( Sphere.changeDotsOfSphereTo sphere ( oldDots.value + buyAmount ) )
                     }
\ No newline at end of file
diff --git a/src/Main.elm b/src/Main.elm
index 8f114ef..020fbd3 100644
--- a/src/Main.elm
+++ b/src/Main.elm
@@ -83,7 +83,7 @@ view model =
     { title = "Character Sheet"
     , body = 
         [ viewEditableText Name model.character.name
-        , viewSpheres model.character.spheres
+        , viewSpheres model.character.stats.spheres
         , viewModal model
         , div [] [ text ( "freebie: " ++ String.fromInt model.character.creationPoints.freebie ) ]
         , div [] [ text ( "spheres: " ++ String.fromInt model.character.creationPoints.spheres ) ]
diff --git a/src/Stats.elm b/src/Stats.elm
new file mode 100644
index 0000000..992d8df
--- /dev/null
+++ b/src/Stats.elm
@@ -0,0 +1,56 @@
+module Stats exposing (..)
+
+import Sphere exposing (Sphere)
+import BoundedInt exposing (BoundedInt)
+
+type alias Stats =
+    { spheres : List Sphere
+    , arete : BoundedInt
+    }
+
+new : Stats
+new =
+    { spheres = 
+        [   { name = "Correspondence"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Entropy"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Forces"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Life"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Matter"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Mind"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Prime"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Spirit"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ,   { name = "Time"
+            , dots = Sphere.dots 0
+            , affinity = False
+            }
+        ]
+    , arete = BoundedInt.new 1 0 10
+    }
+
+changeSphere : Stats -> Sphere -> Stats
+changeSphere stats sphere =
+    { stats | spheres = Sphere.changeSphereInList stats.spheres sphere }
\ No newline at end of file
-- 
GitLab