Add simple way to reset talent tree
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
REMOVE_POINT,
|
||||
SET_POINTS,
|
||||
Points,
|
||||
RESET_SPEC,
|
||||
} from './types'
|
||||
|
||||
export const setClass = (classId: number, points?: Points): CalculatorActionTypes => ({
|
||||
@@ -26,4 +27,9 @@ export const removePoint = (talentId: number): CalculatorActionTypes => ({
|
||||
export const setPoints = (points: Points): CalculatorActionTypes => ({
|
||||
type: SET_POINTS,
|
||||
points
|
||||
})
|
||||
|
||||
export const resetSpec = (specId: number): CalculatorActionTypes => ({
|
||||
type: RESET_SPEC,
|
||||
specId
|
||||
})
|
||||
@@ -5,10 +5,11 @@ import {
|
||||
SET_CLASS,
|
||||
ADD_POINT,
|
||||
REMOVE_POINT,
|
||||
SET_POINTS
|
||||
SET_POINTS,
|
||||
RESET_SPEC
|
||||
} from './types'
|
||||
import { canLearnTalent, canUnlearnTalent, encodeKnownTalents } from '../../lib/tree'
|
||||
import { talentsById } from '../../data/talents'
|
||||
import { talentsById, talentsBySpec } from '../../data/talents'
|
||||
|
||||
const initialState: CalculatorState = {
|
||||
classId: null,
|
||||
@@ -70,6 +71,15 @@ export default function(state = initialState, action: CalculatorActionTypes): Ca
|
||||
}
|
||||
}
|
||||
|
||||
case RESET_SPEC: {
|
||||
const resetIds = Object.values(talentsBySpec[action.specId]).map((t) => t.id)
|
||||
const nextPoints = points.filter((_, id) => resetIds.indexOf(id) === -1)
|
||||
return {
|
||||
...state,
|
||||
points: nextPoints
|
||||
}
|
||||
}
|
||||
|
||||
default:
|
||||
return state
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ export const SET_CLASS = 'SET_CLASS'
|
||||
export const ADD_POINT = 'ADD_POINT'
|
||||
export const REMOVE_POINT = 'REMOVE_POINT'
|
||||
export const SET_POINTS = 'SET_POINTS'
|
||||
export const RESET_SPEC = 'RESET_SPEC'
|
||||
|
||||
interface SetClassAction {
|
||||
type: typeof SET_CLASS
|
||||
@@ -34,5 +35,10 @@ interface SetPointsAction {
|
||||
points: Points
|
||||
}
|
||||
|
||||
interface ResetSpecAction {
|
||||
type: typeof RESET_SPEC
|
||||
specId: number
|
||||
}
|
||||
|
||||
export type CalculatorActionTypes = SetClassAction | AddPointAction | RemovePointAction |
|
||||
SetPointsAction
|
||||
SetPointsAction | ResetSpecAction
|
||||
Reference in New Issue
Block a user