import React from 'react' import { Map } from 'immutable' import { TalentTree } from './TalentTree' import { modifyTalentPoint, calcAvailablePoints, encodeKnownTalents, } from '../lib/tree' import { talentsBySpec } from '../data/talents' import { classByName } from '../data/classes' import { History } from 'history' // import { debugPrintKnown } from '../lib/debug' import { Link } from 'react-router-dom'; interface Props { selectedClass: string history: History initialTalents?: Map } const EMPTY_TALENTS = Map() export class Calculator extends React.PureComponent { static whyDidYouRender = true state = { knownTalents: EMPTY_TALENTS } componentDidMount() { if (this.props.initialTalents) { this.setState({ knownTalents: this.props.initialTalents }) this.updateURL(this.props.initialTalents) } } componentDidUpdate(prevProps: Props) { if (prevProps.selectedClass !== this.props.selectedClass) { this.setState({ knownTalents: EMPTY_TALENTS }) } } updateURL(knownTalents: Map) { const { selectedClass } = this.props const pointString = encodeKnownTalents(knownTalents, selectedClass) this.props.history.replace(`/${selectedClass}` + (pointString ? `/${pointString}` : '')) } handleTalentPress = (specId: number, talentId: number, modifier: 1 | -1) => { const talent = talentsBySpec[specId][talentId] console.log('Clicked talent: ', talentId) const newKnownTalents = modifyTalentPoint(this.state.knownTalents, talent, modifier) if (newKnownTalents !== this.state.knownTalents) { this.updateURL(newKnownTalents) } this.setState({ knownTalents: newKnownTalents }) // Debug // debugPrintKnown(newKnownTalents) } render() { const { selectedClass } = this.props const { knownTalents } = this.state const classData = classByName[selectedClass] const availablePoints = calcAvailablePoints(knownTalents) return (
{classData.specs.map((specId) => ( ))}
Points: {availablePoints}

Quick links

  • Shaman test
  • Shaman test broken
  • Full Rogue (shouldn't be possible)
) } }