diff --git a/public/main.js b/public/main.js index b09c9d851bbedac09bd0767da41c4cd0cff1b270..bd2a6f67695f5af6f5c708477712b926c4da1258 100644 --- a/public/main.js +++ b/public/main.js @@ -5162,16 +5162,13 @@ var $elm$browser$Browser$document = _Browser_document; var $author$project$Stats$Mental = {$: 'Mental'}; var $author$project$Stats$Physical = {$: 'Physical'}; var $author$project$Stats$Social = {$: 'Social'}; -var $author$project$Creation$new = { - 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 +var $author$project$OrderedAttributeCategories$new = { + order: _List_fromArray( + [$author$project$Stats$Physical, $author$project$Stats$Social, $author$project$Stats$Mental]), + points: _List_fromArray( + [7, 5, 3]) }; +var $author$project$Creation$new = {attributes: $author$project$OrderedAttributeCategories$new, freebie: 15, spheres: 6}; var $author$project$Stats$Arete = {$: 'Arete'}; var $author$project$BoundedInt$new = F3( function (value, min, max) { @@ -5282,43 +5279,39 @@ var $elm$core$Maybe$withDefault = F2( return _default; } }); -var $author$project$Creation$attributeCategoryPriority = F2( - function (priorities, category) { +var $author$project$OrderedAttributeCategories$categoryAtPosition = F2( + function (order, value) { return A2( $elm$core$Maybe$withDefault, - _Utils_Tuple2( - -1, - {category: $author$project$Stats$Physical, value: 0}), + _Utils_Tuple2(-1, $author$project$Stats$Physical), $elm$core$List$head( A2( $elm$core$List$filter, function (x) { - return _Utils_eq(x.b.category, category); + return _Utils_eq(x.a, value); }, - A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, priorities)))).a; + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, order)))).b; }); -var $author$project$Creation$priorityAtPosition = F2( - function (priorities, value) { +var $author$project$OrderedAttributeCategories$indexOf = F2( + function (order, category) { return A2( $elm$core$Maybe$withDefault, - _Utils_Tuple2( - -1, - {category: $author$project$Stats$Physical, value: 0}), + _Utils_Tuple2(-1, $author$project$Stats$Physical), $elm$core$List$head( A2( $elm$core$List$filter, function (x) { - return _Utils_eq(x.a, value); + return _Utils_eq(x.b, category); }, - A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, priorities)))).b; + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, order)))).a; }); 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( +var $author$project$OrderedAttributeCategories$changeOrder = F3( + function (oac, category, newIndex) { + var order = oac.order; + var currentIndex = A2($author$project$OrderedAttributeCategories$indexOf, order, category); + var unchangedIndex = 3 - (newIndex + currentIndex); + var newOrder = _Utils_eq(currentIndex, newIndex) ? order : A2( $elm$core$List$map, $elm$core$Tuple$second, A2( @@ -5327,25 +5320,33 @@ var $author$project$Creation$changePriority = F3( _List_fromArray( [ _Utils_Tuple2( - unchangedPrio, - A2($author$project$Creation$priorityAtPosition, priorities, unchangedPrio)), + unchangedIndex, + A2($author$project$OrderedAttributeCategories$categoryAtPosition, order, unchangedIndex)), _Utils_Tuple2( - currentPrio, - A2($author$project$Creation$priorityAtPosition, priorities, value)), + currentIndex, + A2($author$project$OrderedAttributeCategories$categoryAtPosition, order, newIndex)), _Utils_Tuple2( - value, - A2($author$project$Creation$priorityAtPosition, priorities, currentPrio)) + newIndex, + A2($author$project$OrderedAttributeCategories$categoryAtPosition, order, currentIndex)) ]))); + return _Utils_update( + oac, + {order: newOrder}); + }); +var $author$project$Creation$changeOrder = F3( + function (cp, category, index) { return _Utils_update( cp, - {attributes: newPriorities}); + { + attributes: A3($author$project$OrderedAttributeCategories$changeOrder, cp.attributes, category, index) + }); }); var $author$project$Character$changePriority = F3( function (character, category, value) { return _Utils_update( character, { - creationPoints: A3($author$project$Creation$changePriority, character.creationPoints, category, value) + creationPoints: A3($author$project$Creation$changeOrder, character.creationPoints, category, value) }); }); var $author$project$Stats$isArete = function (stat) { @@ -5545,19 +5546,19 @@ 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( +var $author$project$OrderedAttributeCategories$categoryValue = F2( + function (oac, category) { + var index = A2($author$project$OrderedAttributeCategories$indexOf, oac.order, category); + return A2( $elm$core$Maybe$withDefault, - {category: $author$project$Stats$Physical, value: 0}, + _Utils_Tuple2(0, 0), $elm$core$List$head( A2( $elm$core$List$filter, function (x) { - return _Utils_eq(x.category, category); + return _Utils_eq(x.a, index); }, - priorities))); - return priority.value; + A2($elm$core$List$indexedMap, $elm$core$Tuple$pair, oac.points)))).b; }); var $elm$core$Basics$compare = _Utils_compare; var $author$project$Main$creationInfo = function (points) { @@ -5791,9 +5792,9 @@ 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); + function (oac, name, category, attributes) { + var priority = A2($author$project$OrderedAttributeCategories$indexOf, oac.order, category); + var points = A2($author$project$OrderedAttributeCategories$categoryValue, oac, category); return A2( $elm$html$Html$div, _List_fromArray( @@ -5893,7 +5894,7 @@ var $author$project$Main$viewAttributeCol = F4( A2($author$project$Stats$attributesOfCategoryInList, category, attributes)))); }); var $author$project$Main$viewAttributes = F3( - function (cp, priorities, attributes) { + function (cp, oac, attributes) { return A2( $elm$html$Html$div, _List_fromArray( @@ -5917,9 +5918,9 @@ var $author$project$Main$viewAttributes = F3( ]), _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) + A4($author$project$Main$viewAttributeCol, oac, 'Physical', $author$project$Stats$Physical, attributes), + A4($author$project$Main$viewAttributeCol, oac, 'Social', $author$project$Stats$Social, attributes), + A4($author$project$Main$viewAttributeCol, oac, 'Mental', $author$project$Stats$Mental, attributes) ])) ])); }); diff --git a/src/Character.elm b/src/Character.elm index 4ea2003f7ed6e2fc73e6fe3a5e69e58e46551167..13522eb021d491bd674ef5074f824e7c1e8f2986 100644 --- a/src/Character.elm +++ b/src/Character.elm @@ -55,5 +55,5 @@ changeStat character stat = changePriority : Character -> AttributeCategory -> Int -> Character changePriority character category value = { character - | creationPoints = Creation.changePriority character.creationPoints category value + | creationPoints = Creation.changeOrder character.creationPoints category value } \ No newline at end of file diff --git a/src/Creation.elm b/src/Creation.elm index 4776e5b64b1e0d966581b2d411fb056130bce31b..a3b63e45bb4b54ed36340578f112dd8b54ab63fc 100644 --- a/src/Creation.elm +++ b/src/Creation.elm @@ -1,27 +1,19 @@ module Creation exposing (..) +import OrderedAttributeCategories exposing (OAC) import Stats exposing (AttributeCategory) type alias CreationPoints = { freebie : Int , spheres : Int - , attributes : List Priority - } - -type alias Priority = - { value : Int - , category : AttributeCategory + , attributes : OAC } new : CreationPoints new = { freebie = 15 , spheres = 6 - , attributes = - [ { value = 7, category = Stats.Physical } - , { value = 5, category = Stats.Social } - , { value = 3, category = Stats.Mental } - ] + , attributes = OrderedAttributeCategories.new } cost : @@ -35,58 +27,6 @@ buySphere : CreationPoints -> Int -> CreationPoints buySphere cp value = { 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 } - -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 +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 62c88d2f689950b4870a31101b17eb302a9b34f5..b45e69481cc193fac6665256d7a49bed04436b20 100644 --- a/src/Main.elm +++ b/src/Main.elm @@ -10,7 +10,8 @@ import Character exposing (Character) import Stats exposing (Stat) import BoundedInt exposing (BoundedInt) import Stats exposing (AttributeCategory) -import Creation exposing (CreationPoints, Priority) +import Creation exposing (CreationPoints) +import OrderedAttributeCategories as OAC exposing (OAC) main : Program () Model Msg main = @@ -119,22 +120,22 @@ viewEditableText modalType content = ] ] -viewAttributes : CreationPoints -> List Priority -> List Stat -> Html Msg -viewAttributes cp priorities attributes = +viewAttributes : CreationPoints -> OAC -> List Stat -> Html Msg +viewAttributes cp oac 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 + [ viewAttributeCol oac "Physical" Stats.Physical attributes + , viewAttributeCol oac "Social" Stats.Social attributes + , viewAttributeCol oac "Mental" Stats.Mental attributes ] ] -viewAttributeCol : List Priority -> String -> AttributeCategory -> List Stat -> Html Msg -viewAttributeCol priorities name category attributes = +viewAttributeCol : OAC -> String -> AttributeCategory -> List Stat -> Html Msg +viewAttributeCol oac name category attributes = let - priority = Creation.attributeCategoryPriority priorities category - points = Creation.categoryValue priorities category + priority = OAC.indexOf oac.order category + points = OAC.categoryValue oac category in div [ class "column is-one-fifth" ] ( [ p [] [ text name ] diff --git a/src/OrderedAttributeCategories.elm b/src/OrderedAttributeCategories.elm new file mode 100644 index 0000000000000000000000000000000000000000..d5a444cbb90a7972d6657a56f0bd01ce8c292b3a --- /dev/null +++ b/src/OrderedAttributeCategories.elm @@ -0,0 +1,80 @@ +module OrderedAttributeCategories exposing (..) + +import Stats exposing (AttributeCategory) + +type alias OrderedAttributeCategories = + { points : List Int + , order : List AttributeCategory + } +type alias OAC = OrderedAttributeCategories + +new : OAC +new = + { points = [ 7, 5, 3 ] + , order = + [ Stats.Physical + , Stats.Social + , Stats.Mental + ] + } + +type alias Priority = + { value : Int + , category : AttributeCategory + } +indexOf : List AttributeCategory -> AttributeCategory -> Int +indexOf order category = + order + |> List.indexedMap Tuple.pair + |> List.filter ( \x -> ( Tuple.second x ) == category ) + |> List.head + |> Maybe.withDefault ( -1, Stats.Physical ) + |> Tuple.first + +categoryAtPosition : List AttributeCategory -> Int -> AttributeCategory +categoryAtPosition order value = + order + |> List.indexedMap Tuple.pair + |> List.filter ( \x -> Tuple.first x == value ) + |> List.head + |> Maybe.withDefault ( -1, Stats.Physical ) + |> Tuple.second + +changeOrder : OAC -> AttributeCategory -> Int -> OAC +changeOrder oac category newIndex = + let + order : List AttributeCategory + order = oac.order + + currentIndex : Int + currentIndex = indexOf order category + + unchangedIndex : Int + unchangedIndex = 3 - ( newIndex + currentIndex ) + + newOrder : List AttributeCategory + newOrder = + if currentIndex == newIndex + then order + else + [ ( unchangedIndex, categoryAtPosition order unchangedIndex ) + , ( currentIndex, categoryAtPosition order newIndex ) + , ( newIndex, categoryAtPosition order currentIndex ) + ] + |> List.sortBy Tuple.first + |> List.map Tuple.second + in + { oac | order = newOrder } + +categoryValue : OAC -> AttributeCategory -> Int +categoryValue oac category = + let + index : Int + index = indexOf oac.order category + in + oac.points + |> List.indexedMap Tuple.pair + |> List.filter ( \x -> Tuple.first x == index ) + |> List.head + |> Maybe.withDefault ( 0, 0 ) + |> Tuple.second \ No newline at end of file