diff --git a/public/main.js b/public/main.js index c8c482b880fe97c34d5d468b1ac781979129f330..b09c9d851bbedac09bd0767da41c4cd0cff1b270 100644 --- a/public/main.js +++ b/public/main.js @@ -5410,10 +5410,6 @@ var $author$project$Stats$dotsOfStatInList = F2( return $elm$core$Maybe$Just(stat.dots); } }); -var $elm$core$Basics$min = F2( - function (x, y) { - return (_Utils_cmp(x, y) < 0) ? x : y; - }); var $author$project$Stats$isSphere = function (stat) { return _Utils_eq(stat.statType, $author$project$Stats$Sphere); }; @@ -5442,15 +5438,14 @@ var $author$project$Character$changeStat = F2( return character; } else { var oldDots = maybeOldDots.a; - var buyAmount = A2($elm$core$Basics$min, difference, character.creationPoints.spheres); return _Utils_update( character, { - creationPoints: A2($author$project$Creation$buySphere, character.creationPoints, buyAmount), + 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 + buyAmount)) + A2($author$project$Stats$changeDotsTo, stat, oldDots.value + difference)) }); } default: @@ -5550,6 +5545,45 @@ var $author$project$Stats$attributesOfCategoryInList = F2( stats); }); var $elm$html$Html$button = _VirtualDom_node('button'); +var $author$project$Creation$categoryValue = F2( + function (priorities, category) { + var priority = A2( + $elm$core$Maybe$withDefault, + {category: $author$project$Stats$Physical, value: 0}, + $elm$core$List$head( + A2( + $elm$core$List$filter, + function (x) { + return _Utils_eq(x.category, category); + }, + priorities))); + return priority.value; + }); +var $elm$core$Basics$compare = _Utils_compare; +var $author$project$Main$creationInfo = function (points) { + var notificationColor = function () { + var _v0 = A2($elm$core$Basics$compare, points, 0); + switch (_v0.$) { + case 'GT': + return 'is-warning'; + case 'EQ': + return 'is-success'; + default: + return 'is-danger'; + } + }(); + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('notification ' + notificationColor) + ]), + _List_fromArray( + [ + $elm$html$Html$text( + $elm$core$String$fromInt(points) + ' remaining') + ])); +}; var $elm$virtual_dom$VirtualDom$Normal = function (a) { return {$: 'Normal', a: a}; }; @@ -5759,6 +5793,7 @@ var $author$project$Main$viewStat = function (stat) { var $author$project$Main$viewAttributeCol = F4( function (priorities, name, category, attributes) { var priority = A2($author$project$Creation$attributeCategoryPriority, priorities, category); + var points = A2($author$project$Creation$categoryValue, priorities, category); return A2( $elm$html$Html$div, _List_fromArray( @@ -5775,6 +5810,7 @@ var $author$project$Main$viewAttributeCol = F4( [ $elm$html$Html$text(name) ])), + $author$project$Main$creationInfo(points), A2( $elm$html$Html$div, _List_fromArray( @@ -5856,8 +5892,8 @@ var $author$project$Main$viewAttributeCol = F4( $author$project$Main$viewStat, A2($author$project$Stats$attributesOfCategoryInList, category, attributes)))); }); -var $author$project$Main$viewAttributes = F2( - function (priorities, attributes) { +var $author$project$Main$viewAttributes = F3( + function (cp, priorities, attributes) { return A2( $elm$html$Html$div, _List_fromArray( @@ -6128,63 +6164,83 @@ var $author$project$Stats$everyThirdStat = F2( }, A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, stats))); }); -var $author$project$Main$viewSpheres = function (spheres) { - return A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('has-text-centered') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$p, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Spheres') - ])), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('columns is-centered') - ]), - _List_fromArray( - [ - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('column is-one-fifth') - ]), - A2( - $elm$core$List$map, - $author$project$Main$viewStat, - A2($author$project$Stats$everyThirdStat, spheres, 0))), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('column is-one-fifth') - ]), - A2( - $elm$core$List$map, - $author$project$Main$viewStat, - A2($author$project$Stats$everyThirdStat, spheres, 1))), - A2( - $elm$html$Html$div, - _List_fromArray( - [ - $elm$html$Html$Attributes$class('column is-one-fifth') - ]), - A2( - $elm$core$List$map, - $author$project$Main$viewStat, - A2($author$project$Stats$everyThirdStat, spheres, 2))) - ])) - ])); -}; +var $author$project$Main$viewSpheres = F2( + function (cp, spheres) { + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('has-text-centered') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text('Spheres') + ])), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('columns is-centered') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('column is-three-fifths') + ]), + _List_fromArray( + [ + $author$project$Main$creationInfo(cp.spheres) + ])) + ])), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('columns is-centered') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('column is-one-fifth') + ]), + A2( + $elm$core$List$map, + $author$project$Main$viewStat, + A2($author$project$Stats$everyThirdStat, spheres, 0))), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('column is-one-fifth') + ]), + A2( + $elm$core$List$map, + $author$project$Main$viewStat, + A2($author$project$Stats$everyThirdStat, spheres, 1))), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('column is-one-fifth') + ]), + A2( + $elm$core$List$map, + $author$project$Main$viewStat, + A2($author$project$Stats$everyThirdStat, spheres, 2))) + ])) + ])); + }); var $author$project$Main$view = function (model) { return { body: _List_fromArray( @@ -6198,8 +6254,10 @@ var $author$project$Main$view = function (model) { _List_fromArray( [ A2($author$project$Main$viewEditableText, $author$project$Main$Name, model.character.name), - A2($author$project$Main$viewAttributes, model.character.creationPoints.attributes, model.character.stats), - $author$project$Main$viewSpheres( + A3($author$project$Main$viewAttributes, model.character.creationPoints, model.character.creationPoints.attributes, model.character.stats), + A2( + $author$project$Main$viewSpheres, + model.character.creationPoints, $author$project$Stats$spheresInList(model.character.stats)), $author$project$Main$viewStat( $author$project$Stats$areteInList(model.character.stats)), diff --git a/src/Character.elm b/src/Character.elm index bcd99d58610e5922950bcec4569e32c6df062435..4ea2003f7ed6e2fc73e6fe3a5e69e58e46551167 100644 --- a/src/Character.elm +++ b/src/Character.elm @@ -45,13 +45,10 @@ changeStat character stat = case maybeOldDots of Nothing -> character Just oldDots -> - let - buyAmount = min difference character.creationPoints.spheres - in - { character - | creationPoints = Creation.buySphere character.creationPoints buyAmount - , stats = Stats.changeStatInList character.stats ( Stats.changeDotsTo stat ( oldDots.value + buyAmount ) ) - } + { character + | creationPoints = Creation.buySphere character.creationPoints difference + , stats = Stats.changeStatInList character.stats ( Stats.changeDotsTo stat ( oldDots.value + difference ) ) + } Stats.Attribute _ -> character diff --git a/src/Creation.elm b/src/Creation.elm index db5a18890634adb512c9b67526fee0db7faa1ac7..4776e5b64b1e0d966581b2d411fb056130bce31b 100644 --- a/src/Creation.elm +++ b/src/Creation.elm @@ -77,4 +77,16 @@ changePriority cp category value = |> List.sortBy Tuple.first |> List.map Tuple.second in - { cp | attributes = newPriorities } \ No newline at end of file + { cp | attributes = newPriorities } + +categoryValue : List Priority -> AttributeCategory -> Int +categoryValue priorities category = + let + priority : Priority + priority = + priorities + |> List.filter ( \x -> x.category == category ) + |> List.head + |> Maybe.withDefault { value = 0, category = Stats.Physical } + in + priority.value \ No newline at end of file diff --git a/src/Main.elm b/src/Main.elm index b1ea016cda2d2962561755eba083499aa3e995a3..62c88d2f689950b4870a31101b17eb302a9b34f5 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -10,7 +10,7 @@ import Character exposing (Character) import Stats exposing (Stat) import BoundedInt exposing (BoundedInt) import Stats exposing (AttributeCategory) -import Creation exposing (Priority) +import Creation exposing (CreationPoints, Priority) main : Program () Model Msg main = @@ -93,8 +93,8 @@ view model = , body = [ div [ class "container is-max-desktop" ] [ viewEditableText Name model.character.name - , viewAttributes model.character.creationPoints.attributes model.character.stats - , viewSpheres ( Stats.spheresInList model.character.stats ) + , viewAttributes model.character.creationPoints model.character.creationPoints.attributes model.character.stats + , viewSpheres model.character.creationPoints ( Stats.spheresInList model.character.stats ) , viewStat ( Stats.areteInList model.character.stats ) , viewModal model , div [] [ text ( "freebie: " ++ String.fromInt model.character.creationPoints.freebie ) ] @@ -119,8 +119,8 @@ viewEditableText modalType content = ] ] -viewAttributes : List Priority -> List Stat -> Html Msg -viewAttributes priorities attributes = +viewAttributes : CreationPoints -> List Priority -> List Stat -> Html Msg +viewAttributes cp priorities attributes = div [ class "has-text-centered" ] [ p [] [ text "Attributes" ] , div [ class "columns is-centered" ] @@ -134,9 +134,11 @@ viewAttributeCol : List Priority -> String -> AttributeCategory -> List Stat -> viewAttributeCol priorities name category attributes = let priority = Creation.attributeCategoryPriority priorities category + points = Creation.categoryValue priorities category in div [ class "column is-one-fifth" ] ( [ p [] [ text name ] + , creationInfo points , div [ class "field has-addons is-fullwidth" ] [ p [ class "control is-expanded" ] [ button @@ -163,10 +165,15 @@ viewAttributeCol priorities name category attributes = ) ) -viewSpheres : List Stat -> Html Msg -viewSpheres spheres = +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 + ] + ] , div [ class "columns is-centered" ] [ div [ class "column is-one-fifth" ] ( List.map viewStat ( Stats.everyThirdStat spheres 0 ) @@ -178,7 +185,21 @@ viewSpheres spheres = ( List.map viewStat ( Stats.everyThirdStat spheres 2 ) ) ] - ] + ] + +creationInfo : Int -> Html Msg +creationInfo points = + let + notificationColor : String + notificationColor = + case compare points 0 of + GT -> "is-warning" + EQ -> "is-success" + LT -> "is-danger" + in + div [ class ( "notification " ++ notificationColor ) ] + [ text ( ( String.fromInt points ) ++ " remaining" ) + ] viewStat : Stat -> Html Msg viewStat stat =