forked from poooi/plugin-exp-calculator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselectors.es
86 lines (76 loc) · 2.17 KB
/
selectors.es
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import _, { get, last } from 'lodash'
import { createSelector } from 'reselect'
import memoize from 'fast-memoize'
import { toRomaji } from 'wanakana'
import {
shipDataSelectorFactory,
constSelector,
shipsSelector,
stateSelector,
} from 'views/utils/selectors'
import { exp } from './constants'
const MAX_LEVEL = Object.keys(exp).length
export const remodelLvSelector = createSelector(
[constSelector],
({ $ships = {} }) =>
_($ships)
.filter(ship => typeof ship.api_aftershipid !== 'undefined') // filter enemies
.map(ship => {
let remodelLvs = [ship.api_afterlv]
let nextShipId = +ship.api_aftershipid
while (
nextShipId !== 0 &&
last(remodelLvs) < $ships[nextShipId].api_afterlv
) {
remodelLvs = [...remodelLvs, $ships[nextShipId].api_afterlv]
nextShipId = +get($ships, [nextShipId, 'api_aftershipid'], 0)
}
remodelLvs =
last(remodelLvs) < 100
? [...remodelLvs, 99, MAX_LEVEL]
: [...remodelLvs, MAX_LEVEL]
return [ship.api_id, remodelLvs]
})
.fromPairs()
.value(),
)
// const toRomaji = kana => wanakana.toRomaji(kana)
export const expInfoSelectorFactory = memoize(shipId =>
createSelector(
[shipDataSelectorFactory(shipId)],
([ship, $ship] = []) =>
typeof ship !== 'undefined' && typeof $ship !== 'undefined'
? {
...$ship,
...ship,
romaji: toRomaji($ship.api_yomi),
}
: undefined,
),
)
export const shipExpDataSelector = createSelector(
[stateSelector, shipsSelector],
(state, ships) =>
_(ships)
.mapValues(ship => expInfoSelectorFactory(ship.api_id)(state))
.value(),
)
export const mapDataSelctor = createSelector(
[constSelector],
({ $maps = {} } = {}) => $maps,
)
const fleetsSelector = state => state.info.fleets
export const shipFleetMapSelector = createSelector(
[fleetsSelector],
fleets =>
_(fleets)
.filter(Boolean)
.flatMap(fleet =>
_(fleet.api_ship)
.filter(id => id > 0)
.map(id => [id, fleet.api_id])
.value(),
)
.fromPairs()
.value(),
)