From 494e208ad5610f0c4ae9eeaea689936836924024 Mon Sep 17 00:00:00 2001 From: Oskar Marquardt <oskar.marquardt@student.uni-halle.de> Date: Fri, 28 Jun 2024 19:52:23 +0200 Subject: [PATCH] Added changing Attributes --- public/main.js | 121 ++++++++++++++++++++++++++++++---------------- src/Character.elm | 35 +++++++++----- src/Creation.elm | 4 -- src/Main.elm | 59 +++++++++++++--------- src/Stats.elm | 9 +++- 5 files changed, 145 insertions(+), 83 deletions(-) diff --git a/public/main.js b/public/main.js index bd2a6f6..ae5f7df 100644 --- a/public/main.js +++ b/public/main.js @@ -5362,12 +5362,17 @@ var $author$project$Stats$areteInList = function (stats) { return $author$project$Stats$newArete; } }; -var $author$project$Creation$buySphere = F2( - function (cp, value) { - return _Utils_update( - cp, - {spheres: cp.spheres - value}); - }); +var $author$project$Stats$isAttribute = function (stat) { + var _v0 = stat.statType; + if (_v0.$ === 'Attribute') { + return true; + } else { + return false; + } +}; +var $author$project$Stats$attributesInList = function (stats) { + return A2($elm$core$List$filter, $author$project$Stats$isAttribute, stats); +}; 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( @@ -5419,38 +5424,52 @@ var $author$project$Stats$spheresInList = function (stats) { }; var $author$project$Character$changeStat = F2( function (character, stat) { - var _v0 = stat.statType; - switch (_v0.$) { - case 'Arete': - return character; - case 'Sphere': - var spheres = $author$project$Stats$spheresInList(character.stats); - var maybeOldDots = A2($author$project$Stats$dotsOfStatInList, spheres, stat.name); - var arete = $author$project$Stats$areteInList(character.stats); - var difference = function () { - if (maybeOldDots.$ === 'Nothing') { + var statType = stat.statType; + if (statType.$ === 'Arete') { + return character; + } else { + var stats = function () { + switch (statType.$) { + case 'Sphere': + return $author$project$Stats$spheresInList(character.stats); + case 'Attribute': + return $author$project$Stats$attributesInList(character.stats); + default: + return _List_Nil; + } + }(); + var maybeOldDots = A2($author$project$Stats$dotsOfStatInList, stats, stat.name); + var max = function () { + switch (statType.$) { + case 'Sphere': + return $author$project$Stats$areteInList(character.stats).dots.value; + case 'Attribute': + return stat.dots.max; + default: return 0; - } else { - var oldDots = maybeOldDots.a; - return (_Utils_cmp(stat.dots.value, arete.dots.value) > 0) ? (arete.dots.value - oldDots.value) : (stat.dots.value - oldDots.value); - } - }(); + } + }(); + var difference = function () { if (maybeOldDots.$ === 'Nothing') { - return character; + return 0; } else { var oldDots = maybeOldDots.a; - return _Utils_update( - character, - { - creationPoints: A2($author$project$Creation$buySphere, character.creationPoints, difference), - stats: A2( - $author$project$Stats$changeStatInList, - character.stats, - A2($author$project$Stats$changeDotsTo, stat, oldDots.value + difference)) - }); + return (_Utils_cmp(stat.dots.value, max) > 0) ? (max - oldDots.value) : (stat.dots.value - oldDots.value); } - default: + }(); + if (maybeOldDots.$ === 'Nothing') { return character; + } else { + var oldDots = maybeOldDots.a; + return _Utils_update( + character, + { + stats: A2( + $author$project$Stats$changeStatInList, + character.stats, + A2($author$project$Stats$changeDotsTo, stat, oldDots.value + difference)) + }); + } } }); var $author$project$Main$modalValue = F2( @@ -5560,6 +5579,23 @@ var $author$project$OrderedAttributeCategories$categoryValue = F2( }, A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, oac.points)))).b; }); +var $elm$core$List$sum = function (numbers) { + return A3($elm$core$List$foldl, $elm$core$Basics$add, 0, numbers); +}; +var $author$project$Stats$count = function (stats) { + return $elm$core$List$sum( + A2( + $elm$core$List$map, + function ($) { + return $.value; + }, + A2( + $elm$core$List$map, + function ($) { + return $.dots; + }, + stats))); +}; var $elm$core$Basics$compare = _Utils_compare; var $author$project$Main$creationInfo = function (points) { var notificationColor = function () { @@ -5793,8 +5829,10 @@ var $author$project$Main$viewStat = function (stat) { }; var $author$project$Main$viewAttributeCol = F4( function (oac, name, category, attributes) { - var priority = A2($author$project$OrderedAttributeCategories$indexOf, oac.order, category); - var points = A2($author$project$OrderedAttributeCategories$categoryValue, oac, category); + var index = A2($author$project$OrderedAttributeCategories$indexOf, oac.order, category); + var categoryAttributes = A2($author$project$Stats$attributesOfCategoryInList, category, attributes); + var basePoints = A2($author$project$OrderedAttributeCategories$categoryValue, oac, category); + var points = (basePoints - $author$project$Stats$count(categoryAttributes)) + $elm$core$List$length(categoryAttributes); return A2( $elm$html$Html$div, _List_fromArray( @@ -5833,7 +5871,7 @@ var $author$project$Main$viewAttributeCol = F4( _List_fromArray( [ $elm$html$Html$Attributes$class( - 'button is-small is-fullwidth' + ((!priority) ? ' is-primary' : '')), + 'button is-small is-fullwidth' + ((!index) ? ' is-primary' : '')), $elm$html$Html$Events$onClick( A2($author$project$Main$ChangePriority, category, 0)) ]), @@ -5855,7 +5893,7 @@ var $author$project$Main$viewAttributeCol = F4( _List_fromArray( [ $elm$html$Html$Attributes$class( - 'button is-small is-fullwidth' + ((priority === 1) ? ' is-primary' : '')), + 'button is-small is-fullwidth' + ((index === 1) ? ' is-primary' : '')), $elm$html$Html$Events$onClick( A2($author$project$Main$ChangePriority, category, 1)) ]), @@ -5877,7 +5915,7 @@ var $author$project$Main$viewAttributeCol = F4( _List_fromArray( [ $elm$html$Html$Attributes$class( - 'button is-small is-fullwidth' + ((priority === 2) ? ' is-primary' : '')), + 'button is-small is-fullwidth' + ((index === 2) ? ' is-primary' : '')), $elm$html$Html$Events$onClick( A2($author$project$Main$ChangePriority, category, 2)) ]), @@ -5888,10 +5926,7 @@ var $author$project$Main$viewAttributeCol = F4( ])) ])) ]), - A2( - $elm$core$List$map, - $author$project$Main$viewStat, - A2($author$project$Stats$attributesOfCategoryInList, category, attributes)))); + A2($elm$core$List$map, $author$project$Main$viewStat, categoryAttributes))); }); var $author$project$Main$viewAttributes = F3( function (cp, oac, attributes) { @@ -6167,6 +6202,8 @@ var $author$project$Stats$everyThirdStat = F2( }); var $author$project$Main$viewSpheres = F2( function (cp, spheres) { + var basePoints = cp.spheres; + var points = basePoints - $author$project$Stats$count(spheres); return A2( $elm$html$Html$div, _List_fromArray( @@ -6198,7 +6235,7 @@ var $author$project$Main$viewSpheres = F2( ]), _List_fromArray( [ - $author$project$Main$creationInfo(cp.spheres) + $author$project$Main$creationInfo(points) ])) ])), A2( diff --git a/src/Character.elm b/src/Character.elm index 13522eb..96325d1 100644 --- a/src/Character.elm +++ b/src/Character.elm @@ -1,8 +1,8 @@ module Character exposing (..) import Creation exposing (CreationPoints) -import Stats exposing (Stat) -import Stats exposing (AttributeCategory) +import Stats exposing (Stat, AttributeCategory) +import BoundedInt exposing (BoundedInt) type alias Character = { name : String @@ -27,30 +27,39 @@ changeName character newName = changeStat : Character -> Stat -> Character changeStat character stat = - case stat.statType of + let statType = stat.statType in + case statType of Stats.Arete -> character - Stats.Sphere -> + _ -> let - spheres = Stats.spheresInList character.stats - arete = Stats.areteInList character.stats + stats : List Stat + stats = case statType of + Stats.Sphere -> Stats.spheresInList character.stats + Stats.Attribute _ -> Stats.attributesInList character.stats + _ -> [] + + max : Int + max = case statType of + Stats.Sphere -> ( Stats.areteInList character.stats ).dots.value + Stats.Attribute _ -> stat.dots.max + _ -> 0 - maybeOldDots = Stats.dotsOfStatInList spheres stat.name + maybeOldDots : Maybe BoundedInt + maybeOldDots = Stats.dotsOfStatInList stats stat.name + difference : Int difference = case maybeOldDots of Nothing -> 0 Just oldDots -> - if stat.dots.value > arete.dots.value - then arete.dots.value - oldDots.value + if stat.dots.value > max + then max - oldDots.value else stat.dots.value - oldDots.value in case maybeOldDots of Nothing -> character Just oldDots -> { character - | creationPoints = Creation.buySphere character.creationPoints difference - , stats = Stats.changeStatInList character.stats ( Stats.changeDotsTo stat ( oldDots.value + difference ) ) + | stats = Stats.changeStatInList character.stats ( Stats.changeDotsTo stat ( oldDots.value + difference ) ) } - Stats.Attribute _ -> - character changePriority : Character -> AttributeCategory -> Int -> Character changePriority character category value = diff --git a/src/Creation.elm b/src/Creation.elm index a3b63e4..5e86cbb 100644 --- a/src/Creation.elm +++ b/src/Creation.elm @@ -23,10 +23,6 @@ cost = { sphere = 7 } -buySphere : CreationPoints -> Int -> CreationPoints -buySphere cp value = - { cp | spheres = cp.spheres - value } - changeOrder : CreationPoints -> AttributeCategory -> Int -> CreationPoints changeOrder cp category index = { cp | attributes = OrderedAttributeCategories.changeOrder cp.attributes category index } \ No newline at end of file diff --git a/src/Main.elm b/src/Main.elm index b45e694..6b9d3a7 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -134,8 +134,15 @@ viewAttributes cp oac attributes = viewAttributeCol : OAC -> String -> AttributeCategory -> List Stat -> Html Msg viewAttributeCol oac name category attributes = let - priority = OAC.indexOf oac.order category - points = OAC.categoryValue oac category + categoryAttributes : List Stat + categoryAttributes = Stats.attributesOfCategoryInList category attributes + + index : Int + index = OAC.indexOf oac.order category + basePoints : Int + basePoints = OAC.categoryValue oac category + points : Int + points = basePoints - ( Stats.count categoryAttributes ) + ( List.length categoryAttributes ) in div [ class "column is-one-fifth" ] ( [ p [] [ text name ] @@ -143,50 +150,56 @@ viewAttributeCol oac name category attributes = , div [ class "field has-addons is-fullwidth" ] [ p [ class "control is-expanded" ] [ button - [ class ( "button is-small is-fullwidth" ++ if priority == 0 then " is-primary" else "" ) + [ class ( "button is-small is-fullwidth" ++ if index == 0 then " is-primary" else "" ) , onClick ( ChangePriority category 0 ) ] [ text "I" ] ] , p [ class "control is-expanded" ] [ button - [ class ( "button is-small is-fullwidth" ++ if priority == 1 then " is-primary" else "" ) + [ class ( "button is-small is-fullwidth" ++ if index == 1 then " is-primary" else "" ) , onClick ( ChangePriority category 1 ) ] [ text "II" ] ] , p [ class "control is-expanded" ] [ button - [ class ( "button is-small is-fullwidth" ++ if priority == 2 then " is-primary" else "" ) + [ class ( "button is-small is-fullwidth" ++ if index == 2 then " is-primary" else "" ) , onClick ( ChangePriority category 2 ) ] [ text "III" ] ] ] ] ++ - ( List.map viewStat ( Stats.attributesOfCategoryInList category attributes ) + ( List.map viewStat categoryAttributes ) ) viewSpheres : CreationPoints -> List Stat -> Html Msg viewSpheres cp spheres = - div [ class "has-text-centered" ] - [ p [] [ text "Spheres" ] - , div [ class "columns is-centered" ] - [ div [ class "column is-three-fifths" ] - [ creationInfo cp.spheres + let + basePoints : Int + basePoints = cp.spheres + points : Int + points = basePoints - ( Stats.count spheres ) + in + div [ class "has-text-centered" ] + [ p [] [ text "Spheres" ] + , div [ class "columns is-centered" ] + [ div [ class "column is-three-fifths" ] + [ creationInfo points + ] + ] + , div [ class "columns is-centered" ] + [ div [ class "column is-one-fifth" ] + ( List.map viewStat ( Stats.everyThirdStat spheres 0 ) + ) + , div [ class "column is-one-fifth" ] + ( List.map viewStat ( Stats.everyThirdStat spheres 1 ) + ) + , div [ class "column is-one-fifth" ] + ( List.map viewStat ( Stats.everyThirdStat spheres 2 ) + ) ] ] - , div [ class "columns is-centered" ] - [ div [ class "column is-one-fifth" ] - ( List.map viewStat ( Stats.everyThirdStat spheres 0 ) - ) - , div [ class "column is-one-fifth" ] - ( List.map viewStat ( Stats.everyThirdStat spheres 1 ) - ) - , div [ class "column is-one-fifth" ] - ( List.map viewStat ( Stats.everyThirdStat spheres 2 ) - ) - ] - ] creationInfo : Int -> Html Msg creationInfo points = diff --git a/src/Stats.elm b/src/Stats.elm index 9ee89af..6ed4512 100644 --- a/src/Stats.elm +++ b/src/Stats.elm @@ -138,4 +138,11 @@ everyThirdStat stats offset = stats |> List.indexedMap Tuple.pair |> List.filter ( \x -> ( Tuple.first x ) // 3 == offset ) - |> List.map Tuple.second \ No newline at end of file + |> List.map Tuple.second + +count : List Stat -> Int +count stats = + stats + |> List.map .dots + |> List.map .value + |> List.sum \ No newline at end of file -- GitLab