Include Talent component in the playground
This commit is contained in:
@@ -64,6 +64,24 @@ a {
|
|||||||
margin-right: 1em;
|
margin-right: 1em;
|
||||||
background-color: #111;
|
background-color: #111;
|
||||||
|
|
||||||
|
.talent {
|
||||||
|
position: absolute;
|
||||||
|
|
||||||
|
// Rows
|
||||||
|
@for $i from 0 through 6 {
|
||||||
|
&[data-row="#{$i}"] {
|
||||||
|
top: $row-offset + (($i) * $row-distance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Columns
|
||||||
|
@for $i from 0 through 3 {
|
||||||
|
&[data-col="#{$i}"] {
|
||||||
|
left: $col-offset + ($col-distance * $i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
&:last-child {
|
&:last-child {
|
||||||
margin-right: 0;
|
margin-right: 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const Icon: FC<Props> = ({ name: defaultName, size = 'medium', golden = f
|
|||||||
}
|
}
|
||||||
img.onerror = () => setName(NOT_FOUND_ICON)
|
img.onerror = () => setName(NOT_FOUND_ICON)
|
||||||
img.src = url
|
img.src = url
|
||||||
}, [name, url])
|
}, [name, url, start])
|
||||||
|
|
||||||
const className = classNames('icon', `icon--${size}`, {
|
const className = classNames('icon', `icon--${size}`, {
|
||||||
'icon--golden': golden,
|
'icon--golden': golden,
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import { ClassPicker } from './ClassPicker'
|
|||||||
import { RouteComponentProps } from 'react-router'
|
import { RouteComponentProps } from 'react-router'
|
||||||
import { Icon } from './Icon';
|
import { Icon } from './Icon';
|
||||||
import { Tooltip } from './Tooltip';
|
import { Tooltip } from './Tooltip';
|
||||||
|
import { TalentSlot } from './TalentSlot';
|
||||||
|
import { talentsById } from '../data/talents';
|
||||||
|
|
||||||
interface Props extends RouteComponentProps {
|
interface Props extends RouteComponentProps {
|
||||||
//
|
//
|
||||||
@@ -66,6 +68,35 @@ export class Playground extends React.PureComponent<Props> {
|
|||||||
</div>
|
</div>
|
||||||
</Section>
|
</Section>
|
||||||
|
|
||||||
|
<Section title="TalentSlot">
|
||||||
|
<div className="inline-items">
|
||||||
|
<TalentSlot
|
||||||
|
talent={talentsById[181]}
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TalentSlot
|
||||||
|
talent={talentsById[181]}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TalentSlot
|
||||||
|
talent={talentsById[181]}
|
||||||
|
points={3}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TalentSlot
|
||||||
|
talent={talentsById[181]}
|
||||||
|
points={5}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<TalentSlot
|
||||||
|
talent={talentsById[181]}
|
||||||
|
points={3}
|
||||||
|
disabled
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</Section>
|
||||||
|
|
||||||
<Section title="Tooltips">
|
<Section title="Tooltips">
|
||||||
<h3>No params</h3>
|
<h3>No params</h3>
|
||||||
<Tooltip />
|
<Tooltip />
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
@import "../sass/config";
|
@import "../sass/config";
|
||||||
|
|
||||||
.talent {
|
.talent {
|
||||||
position: absolute;
|
position: relative;
|
||||||
width: 40px;
|
width: 40px;
|
||||||
height: 40px;
|
height: 40px;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
&--available {
|
&--available {
|
||||||
.talent__status::after {
|
.talent__status::after {
|
||||||
// background-color: rgba($color-green, .8);
|
|
||||||
box-shadow: inset 0px 0px 6px 3px rgba($color-green, .8);
|
box-shadow: inset 0px 0px 6px 3px rgba($color-green, .8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,20 +37,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rows
|
|
||||||
@for $i from 0 through 6 {
|
|
||||||
&[data-row="#{$i}"] {
|
|
||||||
top: $row-offset + (($i) * $row-distance);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Columns
|
|
||||||
@for $i from 0 through 3 {
|
|
||||||
&[data-col="#{$i}"] {
|
|
||||||
left: $col-offset + ($col-distance * $i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&__status {
|
&__status {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 48px;
|
width: 48px;
|
||||||
|
|||||||
@@ -2,45 +2,31 @@ import './TalentSlot.scss'
|
|||||||
import React, { FC } from 'react'
|
import React, { FC } from 'react'
|
||||||
import { Icon } from './Icon'
|
import { Icon } from './Icon'
|
||||||
import classNames from 'classnames'
|
import classNames from 'classnames'
|
||||||
import { Map } from 'immutable';
|
|
||||||
import { getPointsInSpec, calcMeetsRequirements } from '../lib/tree';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
talent: TalentData
|
talent: TalentData
|
||||||
specId: number
|
specId?: number
|
||||||
availablePoints: number
|
points?: number
|
||||||
/** All spent talents */
|
|
||||||
knownTalents: Map<number, number>
|
|
||||||
/** Disabled override */
|
|
||||||
disabled?: boolean
|
disabled?: boolean
|
||||||
onClick?: (talentId: number) => void
|
onClick?: (talentId: number) => void
|
||||||
onRightClick?: (talentId: number) => void
|
onRightClick?: (talentId: number) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultProps: Partial<Props> = {
|
const defaultProps: Partial<Props> = {
|
||||||
|
points: 0,
|
||||||
|
disabled: false,
|
||||||
onClick: () => undefined,
|
onClick: () => undefined,
|
||||||
onRightClick: () => undefined
|
onRightClick: () => undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
const isAvailable = (talent: TalentData, specId: number, knownTalents: Map<number, number>): boolean => {
|
|
||||||
// Dependent on other talents?
|
|
||||||
if (!calcMeetsRequirements(talent, knownTalents)) {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
const pointsInSpec = getPointsInSpec(specId, knownTalents)
|
|
||||||
return talent.row * 5 <= pointsInSpec
|
|
||||||
}
|
|
||||||
|
|
||||||
export const TalentSlot: FC<Props> = (props) => {
|
export const TalentSlot: FC<Props> = (props) => {
|
||||||
const { talent, specId, knownTalents, availablePoints } = props
|
const { talent, points, disabled } = props
|
||||||
const points = knownTalents.get(talent.id, 0)
|
const showPoints = !disabled || points > 0
|
||||||
const showPoints = points > 0 || availablePoints > 0
|
|
||||||
const disabled = props.disabled || !showPoints || !isAvailable(talent, specId, knownTalents)
|
|
||||||
|
|
||||||
const containerClassNames = classNames('talent', {
|
const containerClassNames = classNames('talent', {
|
||||||
'talent--disabled': !!disabled,
|
'talent--disabled': disabled && points === 0,
|
||||||
'talent--available': !disabled && points < talent.ranks.length,
|
'talent--available': !disabled && points < talent.ranks.length,
|
||||||
'talent--maxed': points >= talent.ranks.length || (points > 0 && availablePoints === 0)
|
'talent--maxed': points >= talent.ranks.length || (points > 0 && disabled)
|
||||||
})
|
})
|
||||||
|
|
||||||
const pointsClassNames = classNames('point-label', {
|
const pointsClassNames = classNames('point-label', {
|
||||||
@@ -65,7 +51,7 @@ export const TalentSlot: FC<Props> = (props) => {
|
|||||||
<div className="talent__status" />
|
<div className="talent__status" />
|
||||||
<Icon name={talent.icon} size="medium" />
|
<Icon name={talent.icon} size="medium" />
|
||||||
|
|
||||||
{showPoints && !disabled &&
|
{showPoints &&
|
||||||
<div className={pointsClassNames}>
|
<div className={pointsClassNames}>
|
||||||
{points}
|
{points}
|
||||||
/{talent.ranks.length}
|
/{talent.ranks.length}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
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, canLearnTalent } from '../lib/tree';
|
import { getPointsInSpec, canLearnTalent, calcMeetsRequirements } from '../lib/tree';
|
||||||
import { talentsBySpec, specNames, talentsById } from '../data/talents'
|
import { talentsBySpec, specNames, talentsById, talentToSpec } from '../data/talents'
|
||||||
import { Arrow } from './Arrow'
|
import { Arrow } from './Arrow'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
@@ -46,12 +46,11 @@ export const TalentTree: React.FC<Props> = ({ specId, knownTalents, availablePoi
|
|||||||
{talents.map((talent) =>
|
{talents.map((talent) =>
|
||||||
<TalentSlot
|
<TalentSlot
|
||||||
key={talent.id}
|
key={talent.id}
|
||||||
specId={specId}
|
|
||||||
talent={talent}
|
talent={talent}
|
||||||
availablePoints={availablePoints}
|
points={knownTalents.get(talent.id, 0)}
|
||||||
knownTalents={knownTalents}
|
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
onRightClick={handleRightClick}
|
onRightClick={handleRightClick}
|
||||||
|
disabled={availablePoints === 0 || !isAvailable(talent, knownTalents)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -61,4 +60,15 @@ export const TalentTree: React.FC<Props> = ({ specId, knownTalents, availablePoi
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// move this somewhere else/revise this
|
||||||
|
export const isAvailable = (talent: TalentData, knownTalents: Map<number, number>): boolean => {
|
||||||
|
// Dependent on other talents?
|
||||||
|
if (!calcMeetsRequirements(talent, knownTalents)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const specId = talentToSpec[talent.id]
|
||||||
|
const pointsInSpec = getPointsInSpec(specId, knownTalents)
|
||||||
|
return talent.row * 5 <= pointsInSpec
|
||||||
|
}
|
||||||
|
|
||||||
;(TalentTree as any).whyDidYouRender = true
|
;(TalentTree as any).whyDidYouRender = true
|
||||||
+4
-1
@@ -10,7 +10,7 @@
|
|||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
"strict": true,
|
"strict": false,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"module": "esnext",
|
"module": "esnext",
|
||||||
"moduleResolution": "node",
|
"moduleResolution": "node",
|
||||||
@@ -21,5 +21,8 @@
|
|||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src"
|
"src"
|
||||||
|
],
|
||||||
|
"exclude": [
|
||||||
|
"src/lib/foo.ts"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user