Add arrow active state

This commit is contained in:
Melvin Valster
2019-07-22 22:58:32 +02:00
parent 1866951986
commit 0b4af07407
9 changed files with 40 additions and 17 deletions

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

+15 -3
View File
@@ -24,9 +24,13 @@
} }
&--right { &--right {
background: url('/images/arrows/right.png'); background-image: url('/images/arrows/right.png');
background-position: center right; background-position: center right;
&.arrow--active {
background-image: url('/images/arrows/right-active.png');
}
// Cols // Cols
@for $i from 0 through 3 { @for $i from 0 through 3 {
&[data-col="#{$i}"] { &[data-col="#{$i}"] {
@@ -36,9 +40,13 @@
} }
&--left { &--left {
background: url('/images/arrows/left.png'); background-image: url('/images/arrows/left.png');
background-position: center left; background-position: center left;
&.arrow--active {
background-image: url('/images/arrows/left-active.png');
}
// Cols // Cols
@for $i from 0 through 3 { @for $i from 0 through 3 {
&[data-col="#{$i}"] { &[data-col="#{$i}"] {
@@ -49,9 +57,13 @@
&--down { &--down {
width: $arrow-width; width: $arrow-width;
background: url('/images/arrows/down.png'); background-image: url('/images/arrows/down.png');
background-position: center bottom; background-position: center bottom;
&.arrow--active {
background-image: url('/images/arrows/down-active.png');
}
// Rows // Rows
@for $i from 0 through 6 { @for $i from 0 through 6 {
&[data-row="#{$i}"] { &[data-row="#{$i}"] {
+3 -1
View File
@@ -5,9 +5,10 @@ import classNames from 'classnames'
interface Props { interface Props {
from: TalentData from: TalentData
to: TalentData to: TalentData
active?: boolean
} }
export const Arrow: FC<Props> = ({ from, to }) => { export const Arrow: FC<Props> = ({ from, to, active = false }) => {
const length = to.row === from.row const length = to.row === from.row
? Math.abs(to.col - from.col) ? Math.abs(to.col - from.col)
: to.row - from.row : to.row - from.row
@@ -19,6 +20,7 @@ export const Arrow: FC<Props> = ({ from, to }) => {
} }
const className = classNames('arrow', { const className = classNames('arrow', {
'arrow--active': active,
'arrow--down': to.row > from.row, 'arrow--down': to.row > from.row,
'arrow--right': to.row === from.row && to.col > from.col, 'arrow--right': to.row === from.row && to.col > from.col,
'arrow--left': to.row === from.row && to.col < from.col, 'arrow--left': to.row === from.row && to.col < from.col,
+2 -1
View File
@@ -1,7 +1,7 @@
import React, { useCallback } from 'react' import React, { useCallback } from 'react'
import { Map } from 'immutable' import { Map } from 'immutable'
import { TalentSlot } from './TalentSlot'; import { TalentSlot } from './TalentSlot';
import { getPointsInSpec } from '../lib/tree'; import { getPointsInSpec, canLearnTalent } from '../lib/tree';
import { talentsBySpec, specNames, talentsById } from '../data/talents' import { talentsBySpec, specNames, talentsById } from '../data/talents'
import { Arrow } from './Arrow' import { Arrow } from './Arrow'
@@ -35,6 +35,7 @@ export const TalentTree: React.FC<Props> = ({ specId, knownTalents, availablePoi
key={talent.id} key={talent.id}
from={talentsById[talent.requires[0].id]} from={talentsById[talent.requires[0].id]}
to={talent} to={talent}
active={knownTalents.get(talent.id, 0) > 0 || canLearnTalent(knownTalents, talent)}
/> />
}) })
+19 -11
View File
@@ -43,31 +43,39 @@ export function calcMeetsRequirements(talent: TalentData, known: Map<number, num
}, true) }, true)
} }
/** export const canLearnTalent = (known: Map<number, number>, talent: TalentData): boolean => {
* Adds a single talent point to the Map, if possible. // Reached the max rank?
*/ if (known.get(talent.id, 0) >= talent.ranks.length) {
export const addTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => { return false
const currentPoints = known.get(talent.id, 0)
// Reached the max rank?
if (currentPoints >= talent.ranks.length) {
return known
} }
// Spend a maximum of 51 points // Spend a maximum of 51 points
if (calcAvailablePoints(known) === 0) { if (calcAvailablePoints(known) === 0) {
return known return false
} }
// Support for specific Talent dependency requirement. // Support for specific Talent dependency requirement.
if (talent.requires.length > 0 && !calcMeetsRequirements(talent, known)) { 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 // Check we have the required amount of points spent in the tree for this talent
const requiredPoints = talent.row * 5 const requiredPoints = talent.row * 5
const pointsInSpec = getPointsInSpec(talentToSpec[talent.id], known) const pointsInSpec = getPointsInSpec(talentToSpec[talent.id], known)
if (requiredPoints > pointsInSpec) { if (requiredPoints > pointsInSpec) {
return false
}
return true
}
/**
* Adds a single talent point to the Map, if possible.
*/
export const addTalentPoint = (known: Map<number, number>, talent: TalentData): Map<number, number> => {
const currentPoints = known.get(talent.id, 0)
if (!canLearnTalent(known, talent)) {
return known return known
} }