From 224d73e56e72fe0aa584230e0769ddcb16e1efa3 Mon Sep 17 00:00:00 2001 From: Oskar Marquardt <oskar.marquardt@student.uni-halle.de> Date: Fri, 28 Jun 2024 18:02:46 +0200 Subject: [PATCH] Added switching attribute priorities - Added basic website layout --- public/main.js | 463 ++++++++++++++++++++++++++++++++--------- src/Character.elm | 9 +- src/Creation.elm | 75 +++++-- src/Main.elm | 124 ++++++++--- src/Stats.elm | 11 +- zzz_elm_make_debug.bat | 1 + 6 files changed, 541 insertions(+), 142 deletions(-) create mode 100644 zzz_elm_make_debug.bat diff --git a/public/main.js b/public/main.js index 46dae53..c8c482b 100644 --- a/public/main.js +++ b/public/main.js @@ -5163,12 +5163,12 @@ var $author$project$Stats$Mental = {$: 'Mental'}; var $author$project$Stats$Physical = {$: 'Physical'}; var $author$project$Stats$Social = {$: 'Social'}; var $author$project$Creation$new = { - attributes: { - primary: 7, - priority: _Utils_Tuple3($author$project$Stats$Physical, $author$project$Stats$Social, $author$project$Stats$Mental), - secondary: 5, - tertiary: 3 - }, + attributes: _List_fromArray( + [ + {category: $author$project$Stats$Physical, value: 7}, + {category: $author$project$Stats$Social, value: 5}, + {category: $author$project$Stats$Mental, value: 3} + ]), freebie: 15, spheres: 6 }; @@ -5178,7 +5178,7 @@ var $author$project$BoundedInt$new = F3( 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}; }); var $author$project$Stats$newArete = { - dots: A3($author$project$BoundedInt$new, 1, 0, 10), + dots: A3($author$project$BoundedInt$new, 1, 1, 10), name: 'Arete', statType: $author$project$Stats$Arete }; @@ -5262,6 +5262,92 @@ var $elm$core$List$head = function (list) { return $elm$core$Maybe$Nothing; } }; +var $elm$core$Basics$negate = function (n) { + return -n; +}; +var $elm$core$Tuple$pair = F2( + function (a, b) { + return _Utils_Tuple2(a, b); + }); +var $elm$core$Tuple$second = function (_v0) { + var y = _v0.b; + return y; +}; +var $elm$core$Maybe$withDefault = F2( + function (_default, maybe) { + if (maybe.$ === 'Just') { + var value = maybe.a; + return value; + } else { + return _default; + } + }); +var $author$project$Creation$attributeCategoryPriority = F2( + function (priorities, category) { + return A2( + $elm$core$Maybe$withDefault, + _Utils_Tuple2( + -1, + {category: $author$project$Stats$Physical, value: 0}), + $elm$core$List$head( + A2( + $elm$core$List$filter, + function (x) { + return _Utils_eq(x.b.category, category); + }, + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, priorities)))).a; + }); +var $author$project$Creation$priorityAtPosition = F2( + function (priorities, value) { + return A2( + $elm$core$Maybe$withDefault, + _Utils_Tuple2( + -1, + {category: $author$project$Stats$Physical, value: 0}), + $elm$core$List$head( + A2( + $elm$core$List$filter, + function (x) { + return _Utils_eq(x.a, value); + }, + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, priorities)))).b; + }); +var $elm$core$List$sortBy = _List_sortBy; +var $author$project$Creation$changePriority = F3( + function (cp, category, value) { + var priorities = cp.attributes; + var currentPrio = A2($author$project$Creation$attributeCategoryPriority, priorities, category); + var unchangedPrio = 3 - (value + currentPrio); + var newPriorities = _Utils_eq(currentPrio, value) ? priorities : A2( + $elm$core$List$map, + $elm$core$Tuple$second, + A2( + $elm$core$List$sortBy, + $elm$core$Tuple$first, + _List_fromArray( + [ + _Utils_Tuple2( + unchangedPrio, + A2($author$project$Creation$priorityAtPosition, priorities, unchangedPrio)), + _Utils_Tuple2( + currentPrio, + A2($author$project$Creation$priorityAtPosition, priorities, value)), + _Utils_Tuple2( + value, + A2($author$project$Creation$priorityAtPosition, priorities, currentPrio)) + ]))); + return _Utils_update( + cp, + {attributes: newPriorities}); + }); +var $author$project$Character$changePriority = F3( + function (character, category, value) { + return _Utils_update( + character, + { + creationPoints: A3($author$project$Creation$changePriority, character.creationPoints, category, value) + }); + }); var $author$project$Stats$isArete = function (stat) { return _Utils_eq(stat.statType, $author$project$Stats$Arete); }; @@ -5411,7 +5497,7 @@ var $author$project$Main$update = F2( modal: $elm$core$Maybe$Nothing }), $elm$core$Platform$Cmd$none); - default: + case 'ChangeStat': var stat = msg.a; return _Utils_Tuple2( _Utils_update( @@ -5420,23 +5506,36 @@ var $author$project$Main$update = F2( character: A2($author$project$Character$changeStat, model.character, stat) }), $elm$core$Platform$Cmd$none); + default: + var category = msg.a; + var value = msg.b; + return _Utils_Tuple2( + _Utils_update( + model, + { + character: A3($author$project$Character$changePriority, model.character, category, value) + }), + $elm$core$Platform$Cmd$none); } }); var $author$project$Main$Name = {$: 'Name'}; -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 $elm$json$Json$Encode$string = _Json_wrap; +var $elm$html$Html$Attributes$stringProperty = F2( + function (key, string) { + return A2( + _VirtualDom_property, + key, + $elm$json$Json$Encode$string(string)); + }); +var $elm$html$Html$Attributes$class = $elm$html$Html$Attributes$stringProperty('className'); var $elm$html$Html$div = _VirtualDom_node('div'); var $elm$virtual_dom$VirtualDom$text = _VirtualDom_text; var $elm$html$Html$text = $elm$virtual_dom$VirtualDom$text; +var $elm$html$Html$p = _VirtualDom_node('p'); +var $author$project$Main$ChangePriority = F2( + function (a, b) { + return {$: 'ChangePriority', a: a, b: b}; + }); var $author$project$Stats$isAttributeOfCategory = F2( function (category, stat) { return _Utils_eq( @@ -5450,7 +5549,24 @@ var $author$project$Stats$attributesOfCategoryInList = F2( $author$project$Stats$isAttributeOfCategory(category), stats); }); -var $elm$html$Html$span = _VirtualDom_node('span'); +var $elm$html$Html$button = _VirtualDom_node('button'); +var $elm$virtual_dom$VirtualDom$Normal = function (a) { + return {$: 'Normal', a: a}; +}; +var $elm$virtual_dom$VirtualDom$on = _VirtualDom_on; +var $elm$html$Html$Events$on = F2( + function (event, decoder) { + return A2( + $elm$virtual_dom$VirtualDom$on, + event, + $elm$virtual_dom$VirtualDom$Normal(decoder)); + }); +var $elm$html$Html$Events$onClick = function (msg) { + return A2( + $elm$html$Html$Events$on, + 'click', + $elm$json$Json$Decode$succeed(msg)); +}; var $elm$core$String$fromFloat = _String_fromNumber; var $elm$svg$Svg$Attributes$height = _VirtualDom_attribute('height'); var $elm$core$List$map3 = _List_map3; @@ -5516,29 +5632,8 @@ var $elm$core$Tuple$mapSecond = F2( x, func(y)); }); -var $elm$virtual_dom$VirtualDom$Normal = function (a) { - return {$: 'Normal', a: a}; -}; -var $elm$virtual_dom$VirtualDom$on = _VirtualDom_on; -var $elm$html$Html$Events$on = F2( - function (event, decoder) { - return A2( - $elm$virtual_dom$VirtualDom$on, - event, - $elm$virtual_dom$VirtualDom$Normal(decoder)); - }); -var $elm$html$Html$Events$onClick = function (msg) { - return A2( - $elm$html$Html$Events$on, - 'click', - $elm$json$Json$Decode$succeed(msg)); -}; var $elm$svg$Svg$Attributes$points = _VirtualDom_attribute('points'); var $elm$svg$Svg$polygon = $elm$svg$Svg$trustedNode('polygon'); -var $elm$core$Tuple$second = function (_v0) { - var y = _v0.b; - return y; -}; var $elm$svg$Svg$Attributes$stroke = _VirtualDom_attribute('stroke'); var $elm$svg$Svg$Attributes$strokeWidth = _VirtualDom_attribute('stroke-width'); var $author$project$Main$tupleToString = function (tuple) { @@ -5639,18 +5734,21 @@ var $author$project$Main$viewDots = function (stat) { var $author$project$Main$viewStat = function (stat) { return A2( $elm$html$Html$div, - _List_Nil, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('notification') + ]), _List_fromArray( [ A2( - $elm$html$Html$span, + $elm$html$Html$p, _List_Nil, _List_fromArray( [ $elm$html$Html$text(stat.name) ])), A2( - $elm$html$Html$span, + $elm$html$Html$p, _List_Nil, _List_fromArray( [ @@ -5658,42 +5756,142 @@ var $author$project$Main$viewStat = function (stat) { ])) ])); }; -var $author$project$Main$viewStats = function (stats) { - return A2( - $elm$html$Html$div, - _List_Nil, - A2($elm$core$List$map, $author$project$Main$viewStat, stats)); -}; -var $author$project$Main$viewAttributes = function (stats) { - return A2( - $elm$html$Html$div, - _List_Nil, - _List_fromArray( - [ - $elm$html$Html$text('Physical'), - $author$project$Main$viewStats( - A2($author$project$Stats$attributesOfCategoryInList, $author$project$Stats$Physical, stats)), - $elm$html$Html$text('Social'), - $author$project$Main$viewStats( - A2($author$project$Stats$attributesOfCategoryInList, $author$project$Stats$Social, stats)), - $elm$html$Html$text('Mental'), - $author$project$Main$viewStats( - A2($author$project$Stats$attributesOfCategoryInList, $author$project$Stats$Mental, stats)) - ])); -}; +var $author$project$Main$viewAttributeCol = F4( + function (priorities, name, category, attributes) { + var priority = A2($author$project$Creation$attributeCategoryPriority, priorities, category); + return A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('column is-one-fifth') + ]), + _Utils_ap( + _List_fromArray( + [ + A2( + $elm$html$Html$p, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text(name) + ])), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('field has-addons is-fullwidth') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('control is-expanded') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$button, + _List_fromArray( + [ + $elm$html$Html$Attributes$class( + 'button is-small is-fullwidth' + ((!priority) ? ' is-primary' : '')), + $elm$html$Html$Events$onClick( + A2($author$project$Main$ChangePriority, category, 0)) + ]), + _List_fromArray( + [ + $elm$html$Html$text('I') + ])) + ])), + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('control is-expanded') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$button, + _List_fromArray( + [ + $elm$html$Html$Attributes$class( + 'button is-small is-fullwidth' + ((priority === 1) ? ' is-primary' : '')), + $elm$html$Html$Events$onClick( + A2($author$project$Main$ChangePriority, category, 1)) + ]), + _List_fromArray( + [ + $elm$html$Html$text('II') + ])) + ])), + A2( + $elm$html$Html$p, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('control is-expanded') + ]), + _List_fromArray( + [ + A2( + $elm$html$Html$button, + _List_fromArray( + [ + $elm$html$Html$Attributes$class( + 'button is-small is-fullwidth' + ((priority === 2) ? ' is-primary' : '')), + $elm$html$Html$Events$onClick( + A2($author$project$Main$ChangePriority, category, 2)) + ]), + _List_fromArray( + [ + $elm$html$Html$text('III') + ])) + ])) + ])) + ]), + A2( + $elm$core$List$map, + $author$project$Main$viewStat, + A2($author$project$Stats$attributesOfCategoryInList, category, attributes)))); + }); +var $author$project$Main$viewAttributes = F2( + function (priorities, attributes) { + 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('Attributes') + ])), + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('columns is-centered') + ]), + _List_fromArray( + [ + A4($author$project$Main$viewAttributeCol, priorities, 'Physical', $author$project$Stats$Physical, attributes), + A4($author$project$Main$viewAttributeCol, priorities, 'Social', $author$project$Stats$Social, attributes), + A4($author$project$Main$viewAttributeCol, priorities, 'Mental', $author$project$Stats$Mental, attributes) + ])) + ])); + }); var $author$project$Main$OpenModal = function (a) { return {$: 'OpenModal', a: a}; }; -var $elm$json$Json$Encode$string = _Json_wrap; -var $elm$html$Html$Attributes$stringProperty = F2( - function (key, string) { - return A2( - _VirtualDom_property, - key, - $elm$json$Json$Encode$string(string)); - }); -var $elm$html$Html$Attributes$class = $elm$html$Html$Attributes$stringProperty('className'); var $elm$html$Html$i = _VirtualDom_node('i'); +var $elm$html$Html$span = _VirtualDom_node('span'); var $author$project$Main$viewEditableText = F2( function (modalType, content) { return A2( @@ -5744,7 +5942,6 @@ var $author$project$Main$CloseModal = {$: 'CloseModal'}; var $author$project$Main$SaveModalChange = function (a) { return {$: 'SaveModalChange', a: a}; }; -var $elm$html$Html$button = _VirtualDom_node('button'); var $elm$html$Html$footer = _VirtualDom_node('footer'); var $elm$html$Html$header = _VirtualDom_node('header'); var $elm$html$Html$input = _VirtualDom_node('input'); @@ -5784,7 +5981,6 @@ var $elm$html$Html$Events$onInput = function (tagger) { $elm$html$Html$Events$alwaysStop, A2($elm$json$Json$Decode$map, tagger, $elm$html$Html$Events$targetValue))); }; -var $elm$html$Html$p = _VirtualDom_node('p'); var $elm$html$Html$Attributes$placeholder = $elm$html$Html$Attributes$stringProperty('placeholder'); var $elm$html$Html$section = _VirtualDom_node('section'); var $elm$html$Html$Attributes$type_ = $elm$html$Html$Attributes$stringProperty('type'); @@ -5920,33 +6116,110 @@ var $author$project$Main$viewModal = function (model) { ])); } }; -var $author$project$Main$view = function (model) { - return { - body: _List_fromArray( +var $author$project$Stats$everyThirdStat = F2( + function (stats, offset) { + return A2( + $elm$core$List$map, + $elm$core$Tuple$second, + A2( + $elm$core$List$filter, + function (x) { + return _Utils_eq((x.a / 3) | 0, offset); + }, + 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($author$project$Main$viewEditableText, $author$project$Main$Name, model.character.name), - $author$project$Main$viewAttributes( - $author$project$Stats$attributesInList(model.character.stats)), - $author$project$Main$viewStats( - $author$project$Stats$spheresInList(model.character.stats)), - $author$project$Main$viewStat( - $author$project$Stats$areteInList(model.character.stats)), - $author$project$Main$viewModal(model), A2( - $elm$html$Html$div, + $elm$html$Html$p, _List_Nil, _List_fromArray( [ - $elm$html$Html$text( - 'freebie: ' + $elm$core$String$fromInt(model.character.creationPoints.freebie)) + $elm$html$Html$text('Spheres') ])), A2( $elm$html$Html$div, - _List_Nil, _List_fromArray( [ - $elm$html$Html$text( - 'spheres: ' + $elm$core$String$fromInt(model.character.creationPoints.spheres)) + $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( + [ + A2( + $elm$html$Html$div, + _List_fromArray( + [ + $elm$html$Html$Attributes$class('container is-max-desktop') + ]), + _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( + $author$project$Stats$spheresInList(model.character.stats)), + $author$project$Main$viewStat( + $author$project$Stats$areteInList(model.character.stats)), + $author$project$Main$viewModal(model), + A2( + $elm$html$Html$div, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text( + 'freebie: ' + $elm$core$String$fromInt(model.character.creationPoints.freebie)) + ])), + A2( + $elm$html$Html$div, + _List_Nil, + _List_fromArray( + [ + $elm$html$Html$text( + 'spheres: ' + $elm$core$String$fromInt(model.character.creationPoints.spheres)) + ])) ])) ]), title: 'Character Sheet' diff --git a/src/Character.elm b/src/Character.elm index ec80334..bcd99d5 100644 --- a/src/Character.elm +++ b/src/Character.elm @@ -2,6 +2,7 @@ module Character exposing (..) import Creation exposing (CreationPoints) import Stats exposing (Stat) +import Stats exposing (AttributeCategory) type alias Character = { name : String @@ -52,4 +53,10 @@ changeStat character stat = , stats = Stats.changeStatInList character.stats ( Stats.changeDotsTo stat ( oldDots.value + buyAmount ) ) } Stats.Attribute _ -> - character \ No newline at end of file + character + +changePriority : Character -> AttributeCategory -> Int -> Character +changePriority character category value = + { character + | creationPoints = Creation.changePriority character.creationPoints category value + } \ No newline at end of file diff --git a/src/Creation.elm b/src/Creation.elm index 796e009..db5a188 100644 --- a/src/Creation.elm +++ b/src/Creation.elm @@ -5,16 +5,12 @@ import Stats exposing (AttributeCategory) type alias CreationPoints = { freebie : Int , spheres : Int - , attributes : - { primary : Int - , secondary : Int - , tertiary : Int - , priority : - ( AttributeCategory - , AttributeCategory - , AttributeCategory - ) - } + , attributes : List Priority + } + +type alias Priority = + { value : Int + , category : AttributeCategory } new : CreationPoints @@ -22,15 +18,10 @@ new = { freebie = 15 , spheres = 6 , attributes = - { primary = 7 - , secondary = 5 - , tertiary = 3 - , priority = - ( Stats.Physical - , Stats.Social - , Stats.Mental - ) - } + [ { value = 7, category = Stats.Physical } + , { value = 5, category = Stats.Social } + , { value = 3, category = Stats.Mental } + ] } cost : @@ -42,4 +33,48 @@ cost = buySphere : CreationPoints -> Int -> CreationPoints buySphere cp value = - { cp | spheres = cp.spheres - value } \ No newline at end of file + { cp | spheres = cp.spheres - value } + +attributeCategoryPriority : List Priority -> AttributeCategory -> Int +attributeCategoryPriority priorities category = + priorities + |> List.indexedMap Tuple.pair + |> List.filter ( \x -> ( Tuple.second x ).category == category ) + |> List.head + |> Maybe.withDefault ( -1, { value = 0, category = Stats.Physical } ) + |> Tuple.first + +priorityAtPosition : List Priority -> Int -> Priority +priorityAtPosition priorities value = + priorities + |> List.indexedMap Tuple.pair + |> List.filter ( \x -> Tuple.first x == value ) + |> List.head + |> Maybe.withDefault ( -1, { value = 0, category = Stats.Physical } ) + |> Tuple.second + +changePriority : CreationPoints -> AttributeCategory -> Int -> CreationPoints +changePriority cp category value = + let + priorities : List Priority + priorities = cp.attributes + + currentPrio : Int + currentPrio = attributeCategoryPriority priorities category + + unchangedPrio : Int + unchangedPrio = 3 - ( value + currentPrio ) + + newPriorities : List Priority + newPriorities = + if currentPrio == value + then priorities + else + [ ( unchangedPrio, priorityAtPosition priorities unchangedPrio ) + , ( currentPrio, priorityAtPosition priorities value ) + , ( value, priorityAtPosition priorities currentPrio ) + ] + |> List.sortBy Tuple.first + |> List.map Tuple.second + in + { cp | attributes = newPriorities } \ No newline at end of file diff --git a/src/Main.elm b/src/Main.elm index a901974..b1ea016 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -9,6 +9,8 @@ import Svg.Attributes import Character exposing (Character) import Stats exposing (Stat) import BoundedInt exposing (BoundedInt) +import Stats exposing (AttributeCategory) +import Creation exposing (Priority) main : Program () Model Msg main = @@ -40,6 +42,7 @@ type Msg | ChangeModalValue String | SaveModalChange ModalType | ChangeStat Stat + | ChangePriority AttributeCategory Int type ModalType = Name @@ -77,18 +80,26 @@ update msg model = } , Cmd.none ) + ChangePriority category value -> + ( { model + | character = Character.changePriority model.character category value + } + , Cmd.none + ) view : Model -> Browser.Document Msg view model = { title = "Character Sheet" - , body = - [ viewEditableText Name model.character.name - , viewAttributes ( Stats.attributesInList model.character.stats ) - , viewStats ( Stats.spheresInList model.character.stats ) - , viewStat ( Stats.areteInList model.character.stats ) - , viewModal model - , div [] [ text ( "freebie: " ++ String.fromInt model.character.creationPoints.freebie ) ] - , div [] [ text ( "spheres: " ++ String.fromInt model.character.creationPoints.spheres ) ] + , 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 ) + , viewStat ( Stats.areteInList model.character.stats ) + , viewModal model + , div [] [ text ( "freebie: " ++ String.fromInt model.character.creationPoints.freebie ) ] + , div [] [ text ( "spheres: " ++ String.fromInt model.character.creationPoints.spheres ) ] + ] ] } @@ -108,27 +119,74 @@ viewEditableText modalType content = ] ] -viewAttributes : List Stat -> Html Msg -viewAttributes stats = - div [] - [ text "Physical" - , viewStats ( Stats.attributesOfCategoryInList Stats.Physical stats ) - , text "Social" - , viewStats ( Stats.attributesOfCategoryInList Stats.Social stats ) - , text "Mental" - , viewStats ( Stats.attributesOfCategoryInList Stats.Mental stats ) +viewAttributes : List Priority -> List Stat -> Html Msg +viewAttributes priorities attributes = + div [ class "has-text-centered" ] + [ p [] [ text "Attributes" ] + , div [ class "columns is-centered" ] + [ viewAttributeCol priorities "Physical" Stats.Physical attributes + , viewAttributeCol priorities "Social" Stats.Social attributes + , viewAttributeCol priorities "Mental" Stats.Mental attributes + ] ] -viewStats : List Stat -> Html Msg -viewStats stats = - div [] ( List.map viewStat stats ) +viewAttributeCol : List Priority -> String -> AttributeCategory -> List Stat -> Html Msg +viewAttributeCol priorities name category attributes = + let + priority = Creation.attributeCategoryPriority priorities category + in + div [ class "column is-one-fifth" ] + ( [ p [] [ text name ] + , 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 "" ) + , 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 "" ) + , 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 "" ) + , onClick ( ChangePriority category 2 ) + ] [ text "III" ] + ] + ] + ] + ++ + ( List.map viewStat ( Stats.attributesOfCategoryInList category attributes ) + ) + ) + +viewSpheres : List Stat -> Html Msg +viewSpheres spheres = + div [ class "has-text-centered" ] + [ p [] [ text "Spheres" ] + , 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 ) + ) + ] + ] viewStat : Stat -> Html Msg viewStat stat = - div [] - [ span [] [ text stat.name ] - , span [] [ viewDots stat ] + div [ class "notification" ] + [ p [] [ text stat.name ] + , p [] [ viewDots stat ] ] + viewDots : Stat -> Html Msg viewDots stat = @@ -258,6 +316,24 @@ subscriptions : Model -> Sub Msg subscriptions _ = Sub.none +-- aria functions + ariaLabel : String -> Attribute msg ariaLabel value = - Html.Attributes.attribute "aria-label" value \ No newline at end of file + Html.Attributes.attribute "aria-label" value + +ariaHaspopup : String -> Attribute msg +ariaHaspopup value = + Html.Attributes.attribute "aria-haspopup" value + +ariaControls : String -> Attribute msg +ariaControls value = + Html.Attributes.attribute "aria-controls" value + +ariaHidden : String -> Attribute msg +ariaHidden value = + Html.Attributes.attribute "aria-hidden" value + +ariaRole : String -> Attribute msg +ariaRole value = + Html.Attributes.attribute "role" value \ No newline at end of file diff --git a/src/Stats.elm b/src/Stats.elm index bd392f3..9ee89af 100644 --- a/src/Stats.elm +++ b/src/Stats.elm @@ -51,7 +51,7 @@ newSphere name = newArete : Stat newArete = { name = "Arete" - , dots = BoundedInt.new 1 0 10 + , dots = BoundedInt.new 1 1 10 , statType = Arete } @@ -131,4 +131,11 @@ changeStatIfSame newStat oldStat = changeDotsTo : Stat -> Int -> Stat changeDotsTo stat value = - { stat | dots = BoundedInt.changeTo stat.dots value } \ No newline at end of file + { stat | dots = BoundedInt.changeTo stat.dots value } + +everyThirdStat : List Stat -> Int -> List Stat +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 diff --git a/zzz_elm_make_debug.bat b/zzz_elm_make_debug.bat new file mode 100644 index 0000000..e9f093a --- /dev/null +++ b/zzz_elm_make_debug.bat @@ -0,0 +1 @@ +elm make src/Main.elm --output=public/main.js --debug \ No newline at end of file -- GitLab