diff --git a/public/main.js b/public/main.js index e52c1204d5d2c112b6767f615cc9e41db36da36d..047f4a9a70d8c0554c939402479a1b0ca76bc7ca 100644 --- a/public/main.js +++ b/public/main.js @@ -5166,9 +5166,10 @@ 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 = { arete: A3($author$project$BoundedInt$new, 1, 0, 10), - creationPoints: {freebie: 15, spheres: 6}, + creationPoints: $author$project$Creation$new, name: 'Default Name', spheres: _List_fromArray( [ @@ -5237,15 +5238,25 @@ var $author$project$Character$changeName = F2( character, {name: newName}); }); +var $author$project$Creation$buySphere = F2( + function (cp, value) { + return _Utils_update( + cp, + {spheres: cp.spheres - value}); + }); var $author$project$BoundedInt$changeTo = F2( function (boundedInt, value) { return ((_Utils_cmp(value, boundedInt.min) < 0) || (_Utils_cmp(value, boundedInt.max) > 0)) ? boundedInt : _Utils_update( boundedInt, {value: value}); }); -var $author$project$BoundedInt$changeBy = F2( - function (boundedInt, value) { - return A2($author$project$BoundedInt$changeTo, boundedInt, boundedInt.value + value); +var $author$project$Sphere$changeDotsOfSphereTo = F2( + function (sphere, value) { + return _Utils_update( + sphere, + { + dots: A2($author$project$BoundedInt$changeTo, sphere.dots, value) + }); }); var $author$project$Sphere$isSphere = F2( function (name, sphere) { @@ -5262,8 +5273,6 @@ var $author$project$Sphere$changeSphereInList = F2( $author$project$Sphere$changeSphere(sphere), spheres); }); -var $author$project$Sphere$freebieCost = 7; -var $elm$core$Basics$ge = _Utils_ge; var $elm$core$List$filter = F2( function (isGood, list) { return A3( @@ -5302,9 +5311,6 @@ var $elm$core$Basics$min = F2( function (x, y) { return (_Utils_cmp(x, y) < 0) ? x : y; }); -var $elm$core$Basics$negate = function (n) { - return -n; -}; var $author$project$Character$changeSphere = F2( function (character, sphere) { var maybeOldDots = A2($author$project$Sphere$getDotsOfSphereInList, character.spheres, sphere.name); @@ -5313,38 +5319,23 @@ var $author$project$Character$changeSphere = F2( return 0; } else { var oldDots = maybeOldDots.a; - return (_Utils_cmp(sphere.dots.value, character.arete.value) > 0) ? character.arete.value : (sphere.dots.value - oldDots.value); + return (_Utils_cmp(sphere.dots.value, character.arete.value) > 0) ? (character.arete.value - oldDots.value) : (sphere.dots.value - oldDots.value); } }(); if (maybeOldDots.$ === 'Nothing') { return character; } else { var oldDots = maybeOldDots.a; - if (difference >= 0) { - var sA = (character.creationPoints.spheres > 0) ? A2($elm$core$Basics$min, difference, character.creationPoints.spheres) : 0; - var fA = A2($elm$core$Basics$min, difference - sA, (character.creationPoints.freebie / $author$project$Sphere$freebieCost) | 0); - return _Utils_update( - character, - { - creationPoints: {freebie: character.creationPoints.freebie - (fA * $author$project$Sphere$freebieCost), spheres: (character.creationPoints.spheres - sA) - fA}, - spheres: A2( - $author$project$Sphere$changeSphereInList, - character.spheres, - _Utils_update( - sphere, - { - dots: A2($author$project$BoundedInt$changeBy, oldDots, fA + sA) - })) - }); - } else { - var fA = (character.creationPoints.spheres < 0) ? (-A2($elm$core$Basics$max, difference, character.creationPoints.spheres)) : 0; - return _Utils_update( - character, - { - creationPoints: {freebie: character.creationPoints.freebie + (fA * $author$project$Sphere$freebieCost), spheres: character.creationPoints.spheres - difference}, - spheres: A2($author$project$Sphere$changeSphereInList, character.spheres, sphere) - }); - } + var buyAmount = A2($elm$core$Basics$min, difference, character.creationPoints.spheres); + return _Utils_update( + character, + { + creationPoints: A2($author$project$Creation$buySphere, character.creationPoints, buyAmount), + spheres: A2( + $author$project$Sphere$changeSphereInList, + character.spheres, + A2($author$project$Sphere$changeDotsOfSphereTo, sphere, oldDots.value + buyAmount)) + }); } }); var $author$project$Main$modalValue = F2( diff --git a/src/Character.elm b/src/Character.elm index 849a3db5cbdd99672c6f903c81b1dbbb9757f299..d1a0aee41acdbdf5e83abc2af6690d6ce70cb0dd 100644 --- a/src/Character.elm +++ b/src/Character.elm @@ -1,8 +1,8 @@ module Character exposing (..) import Sphere exposing (Sphere) -import Sphere exposing (getDotsOfSphereInList) import BoundedInt exposing (BoundedInt) +import Creation exposing (CreationPoints) type alias Character = { name : String @@ -11,74 +11,10 @@ type alias Character = , arete : BoundedInt } -type alias CreationPoints = - { freebie : Int - , spheres : Int - } - -changeName : Character -> String -> Character -changeName character newName = - if ( newName == "") - then - character - else - { character | name = newName } - -changeSphere : Character -> Sphere -> Character -changeSphere character sphere = - let - maybeOldDots = getDotsOfSphereInList character.spheres sphere.name - difference = case maybeOldDots of - Nothing -> 0 - Just oldDots -> - if sphere.dots.value > character.arete.value - then character.arete.value - else sphere.dots.value - oldDots.value - in - case maybeOldDots of - Nothing -> character - Just oldDots -> - if difference >= 0 - then - let - sA = - if character.creationPoints.spheres > 0 - then min difference character.creationPoints.spheres - else 0 - fA = min ( difference - sA ) ( character.creationPoints.freebie // Sphere.freebieCost ) - in - { character - | spheres = Sphere.changeSphereInList character.spheres - { sphere - | dots = BoundedInt.changeBy oldDots ( fA + sA ) - } - , creationPoints = - { freebie = character.creationPoints.freebie - fA * Sphere.freebieCost - , spheres = character.creationPoints.spheres - sA - fA - } - } - else - let - fA = - if character.creationPoints.spheres < 0 - then negate ( max difference character.creationPoints.spheres ) - else 0 - in - { character - | spheres = Sphere.changeSphereInList character.spheres sphere - , creationPoints = - { freebie = character.creationPoints.freebie + fA * Sphere.freebieCost - , spheres = character.creationPoints.spheres - difference - } - } - new : Character new = - { name = "Default Name" - , creationPoints = - { freebie = 15 - , spheres = 6 - } + { name = "Default Name" + , creationPoints = Creation.new , spheres = [ { name = "Correspondence" , dots = Sphere.dots 0 @@ -118,4 +54,34 @@ new = } ] , arete = BoundedInt.new 1 0 10 - } \ No newline at end of file + } + +changeName : Character -> String -> Character +changeName character newName = + if ( newName == "") + then + character + else + { character | name = newName } + +changeSphere : Character -> Sphere -> Character +changeSphere character sphere = + let + maybeOldDots = Sphere.getDotsOfSphereInList character.spheres sphere.name + difference = case maybeOldDots of + Nothing -> 0 + Just oldDots -> + if sphere.dots.value > character.arete.value + then character.arete.value - oldDots.value + else sphere.dots.value - oldDots.value + in + case maybeOldDots of + Nothing -> character + Just oldDots -> + let + buyAmount = min difference character.creationPoints.spheres + in + { character + | creationPoints = Creation.buySphere character.creationPoints buyAmount + , spheres = Sphere.changeSphereInList character.spheres ( Sphere.changeDotsOfSphereTo sphere ( oldDots.value + buyAmount ) ) + } \ No newline at end of file diff --git a/src/Creation.elm b/src/Creation.elm new file mode 100644 index 0000000000000000000000000000000000000000..96288f3349eea65a9dc8ce141184b514ff1bad23 --- /dev/null +++ b/src/Creation.elm @@ -0,0 +1,25 @@ +module Creation exposing (..) + +import Sphere exposing (Sphere) + +type alias CreationPoints = + { freebie : Int + , spheres : Int + } + +new : CreationPoints +new = + { freebie = 15 + , spheres = 6 + } + +cost : + { sphere : Int + } +cost = + { sphere = 7 + } + +buySphere : CreationPoints -> Int -> CreationPoints +buySphere cp value = + { cp | spheres = cp.spheres - value } diff --git a/src/Sphere.elm b/src/Sphere.elm index 1e551f0fc7919029dc955ad1bdb14103c08f6233..eb577579a06c1ddd30286b1849d33d965c7f39af 100644 --- a/src/Sphere.elm +++ b/src/Sphere.elm @@ -8,9 +8,6 @@ type alias Sphere = , affinity : Bool } -freebieCost : Int -freebieCost = 7 - changeSphereInList : List Sphere -> Sphere -> List Sphere changeSphereInList spheres sphere = List.map ( changeSphere sphere ) spheres @@ -23,6 +20,10 @@ changeSphere newSphere sphere = else sphere +changeDotsOfSphereTo : Sphere -> Int -> Sphere +changeDotsOfSphereTo sphere value = + { sphere | dots = BoundedInt.changeTo sphere.dots value } + isSphere : String -> Sphere -> Bool isSphere name sphere = sphere.name == name