diff --git a/public/images/arrows/down2.png b/public/images/arrows/down-active.png similarity index 100% rename from public/images/arrows/down2.png rename to public/images/arrows/down-active.png diff --git a/public/images/arrows/left-active.png b/public/images/arrows/left-active.png new file mode 100644 index 0000000..c11d7d5 Binary files /dev/null and b/public/images/arrows/left-active.png differ diff --git a/public/images/arrows/leftdown-active.png b/public/images/arrows/leftdown-active.png new file mode 100644 index 0000000..5a908db Binary files /dev/null and b/public/images/arrows/leftdown-active.png differ diff --git a/public/images/arrows/right-active.png b/public/images/arrows/right-active.png new file mode 100644 index 0000000..44934a9 Binary files /dev/null and b/public/images/arrows/right-active.png differ diff --git a/public/images/arrows/rightdown-active.png b/public/images/arrows/rightdown-active.png new file mode 100644 index 0000000..135dc5c Binary files /dev/null and b/public/images/arrows/rightdown-active.png differ diff --git a/src/components/Arrow.scss b/src/components/Arrow.scss index 9237f1d..306ef98 100644 --- a/src/components/Arrow.scss +++ b/src/components/Arrow.scss @@ -24,9 +24,13 @@ } &--right { - background: url('/images/arrows/right.png'); + background-image: url('/images/arrows/right.png'); background-position: center right; + &.arrow--active { + background-image: url('/images/arrows/right-active.png'); + } + // Cols @for $i from 0 through 3 { &[data-col="#{$i}"] { @@ -36,9 +40,13 @@ } &--left { - background: url('/images/arrows/left.png'); + background-image: url('/images/arrows/left.png'); background-position: center left; + &.arrow--active { + background-image: url('/images/arrows/left-active.png'); + } + // Cols @for $i from 0 through 3 { &[data-col="#{$i}"] { @@ -49,9 +57,13 @@ &--down { width: $arrow-width; - background: url('/images/arrows/down.png'); + background-image: url('/images/arrows/down.png'); background-position: center bottom; + &.arrow--active { + background-image: url('/images/arrows/down-active.png'); + } + // Rows @for $i from 0 through 6 { &[data-row="#{$i}"] { diff --git a/src/components/Arrow.tsx b/src/components/Arrow.tsx index 1304284..3795df1 100644 --- a/src/components/Arrow.tsx +++ b/src/components/Arrow.tsx @@ -5,9 +5,10 @@ import classNames from 'classnames' interface Props { from: TalentData to: TalentData + active?: boolean } -export const Arrow: FC = ({ from, to }) => { +export const Arrow: FC = ({ from, to, active = false }) => { const length = to.row === from.row ? Math.abs(to.col - from.col) : to.row - from.row @@ -19,6 +20,7 @@ export const Arrow: FC = ({ from, to }) => { } const className = classNames('arrow', { + 'arrow--active': active, 'arrow--down': to.row > from.row, 'arrow--right': to.row === from.row && to.col > from.col, 'arrow--left': to.row === from.row && to.col < from.col, diff --git a/src/components/TalentTree.tsx b/src/components/TalentTree.tsx index 4706c14..6d72720 100644 --- a/src/components/TalentTree.tsx +++ b/src/components/TalentTree.tsx @@ -1,7 +1,7 @@ import React, { useCallback } from 'react' import { Map } from 'immutable' import { TalentSlot } from './TalentSlot'; -import { getPointsInSpec } from '../lib/tree'; +import { getPointsInSpec, canLearnTalent } from '../lib/tree'; import { talentsBySpec, specNames, talentsById } from '../data/talents' import { Arrow } from './Arrow' @@ -34,7 +34,8 @@ export const TalentTree: React.FC = ({ specId, knownTalents, availablePoi return 0 || canLearnTalent(knownTalents, talent)} /> }) diff --git a/src/lib/tree.ts b/src/lib/tree.ts index efc7483..ddaf6bf 100644 --- a/src/lib/tree.ts +++ b/src/lib/tree.ts @@ -43,31 +43,39 @@ export function calcMeetsRequirements(talent: TalentData, known: Map, talent: TalentData): Map => { - const currentPoints = known.get(talent.id, 0) - - // Reached the max rank? - if (currentPoints >= talent.ranks.length) { - return known +export const canLearnTalent = (known: Map, talent: TalentData): boolean => { + // Reached the max rank? + if (known.get(talent.id, 0) >= talent.ranks.length) { + return false } // Spend a maximum of 51 points if (calcAvailablePoints(known) === 0) { - return known + return false } // Support for specific Talent dependency requirement. if (talent.requires.length > 0 && !calcMeetsRequirements(talent, known)) { - return known + return false } // Check we have the required amount of points spent in the tree for this talent const requiredPoints = talent.row * 5 const pointsInSpec = getPointsInSpec(talentToSpec[talent.id], known) if (requiredPoints > pointsInSpec) { + return false + } + + return true +} + +/** + * Adds a single talent point to the Map, if possible. + */ +export const addTalentPoint = (known: Map, talent: TalentData): Map => { + const currentPoints = known.get(talent.id, 0) + + if (!canLearnTalent(known, talent)) { return known }