poi-plugin-quest-info-2 0.5.0 → 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/poi.ts DELETED
@@ -1,211 +0,0 @@
1
- import { useTranslation } from 'react-i18next'
2
- import { name as PACKAGE_NAME } from '../package.json'
3
- import type { PluginState } from './reducer'
4
-
5
- // See https://github.com/poooi/poi/blob/master/views/redux/info/quests.es
6
- export type GameQuest = {
7
- // 1 Default
8
- // 2 In progress
9
- // 3 Completed
10
- api_state: 1 | 2 | 3
11
- api_no: number
12
- api_title: string
13
- api_detail: string
14
- /**
15
- * 任务类别
16
- *
17
- * 1. Composition
18
- * 1. Sortie
19
- * 1. Exercise
20
- * 1. Expedition
21
- * 1. Supply/Docking
22
- * 1. Arsenal
23
- * 1. Modernization
24
- *
25
- * @see https://github.com/poooi/plugin-quest/blob/master/index.es#L49-L57
26
- */
27
- api_category: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
28
- /**
29
- * 任务类型
30
- *
31
- * 1. One-time
32
- * 1. Daily
33
- * 1. Weekly
34
- * 1. -3rd/-7th/-0th
35
- * 1. -2nd/-8th
36
- * 1. Monthly
37
- * 1. Quarterly
38
- *
39
- * @see https://github.com/poooi/plugin-quest/blob/master/index.es#L69-L77
40
- */
41
- api_type: 1 | 2 | 3 | 4 | 5 | 6 | 7
42
- // Rewards 油弹钢铝
43
- api_get_material: [number, number, number, number]
44
- api_invalid_flag: 0
45
- api_label_type: 1
46
- // 0: Empty: [0.0, 0.5)
47
- // 1: 50%: [0.5, 0.8)
48
- // 2: 80%: [0.8, 1.0)
49
- api_progress_flag: 0 | 1 | 2
50
- api_select_rewards?: [
51
- {
52
- api_count: number
53
- api_kind: number
54
- api_mst_id: number
55
- api_no: number
56
- }[]
57
- ]
58
- api_voice_id: 0
59
- api_bonus_flag: 1
60
- }
61
-
62
- type QuestListAction = {
63
- type: '@@Response/kcsapi/api_get_member/questlist'
64
- path: '/kcsapi/api_get_member/questlist'
65
- postBody: {
66
- api_verno: '1'
67
- api_tab_id:
68
- | '0' // All
69
- | '9' // In progress
70
- | '1' // Daily
71
- | '2' // Weekly
72
- | '3' // Monthly
73
- | '4' // Once
74
- | '5' // Others
75
- }
76
- body: {
77
- api_completed_kind: number
78
- // api_list.length
79
- api_count: number
80
- // In progress count
81
- api_exec_count: number
82
- api_exec_type: number
83
- api_list: GameQuest[]
84
- }
85
- }
86
-
87
- type OtherAction = {
88
- type: 'otherString' // TODO fix me
89
- path?: string
90
- postBody?: unknown
91
- body?: unknown
92
- }
93
-
94
- export type PoiAction = QuestListAction | OtherAction
95
-
96
- export type PoiState = {
97
- ext: {
98
- // TODO fix use constant PACKAGE_NAME
99
- [packageName: string]: PluginState
100
- }
101
- plugins: { id: string; enabled: boolean; [x: string]: unknown }[]
102
- [x: string]: any
103
- }
104
-
105
- type Store<S> = {
106
- getState: () => S
107
- subscribe: (listener: () => void) => () => void
108
- }
109
-
110
- // state.info.quests.activeQuests
111
- export type PoiQuestState = Record<number, { time: number; detail: GameQuest }>
112
-
113
- export const IN_POI = 'POI_VERSION' in globalThis
114
-
115
- const noop = () => {}
116
- const id = <T>(x: T) => x
117
-
118
- /**
119
- * Prevent webpack early error
120
- * Module not found: Error: Can't resolve 'views/create-store'
121
- * TODO fix webpack warn
122
- * Critical dependency: the request of a dependency is an expression
123
- */
124
- export const importFromPoi = <T = any>(path: string): Promise<T> => {
125
- if (!IN_POI) {
126
- return new Promise(() => {
127
- // Never resolve
128
- })
129
- }
130
- return import(path)
131
- }
132
-
133
- /**
134
- * See https://redux.js.org/api/store#subscribelistener
135
- */
136
- const observeStore = <State, SelectedState = State>(
137
- store: Store<State>,
138
- onChange: (state: SelectedState) => void,
139
- selector: (s: State) => SelectedState = id as any
140
- ) => {
141
- let currentState: SelectedState
142
-
143
- const handleChange = () => {
144
- const nextState = selector(store.getState())
145
- if (nextState !== currentState) {
146
- currentState = nextState
147
- onChange(currentState)
148
- }
149
- }
150
-
151
- const unsubscribe = store.subscribe(handleChange)
152
- handleChange()
153
- return unsubscribe
154
- }
155
-
156
- export const observePoiStore = <SelectedState = PoiState>(
157
- onChange: (state: SelectedState) => void,
158
- selector: (state: PoiState) => SelectedState = id as any
159
- ) => {
160
- let valid = true
161
- let unsubscribe = noop
162
- getPoiStore().then((store) => {
163
- if (!valid) {
164
- return
165
- }
166
- unsubscribe = observeStore(store, onChange, selector)
167
- })
168
-
169
- return () => {
170
- valid = false
171
- unsubscribe()
172
- }
173
- }
174
-
175
- export const observePluginStore = <SelectedState = PluginState>(
176
- onChange: (state: SelectedState) => void,
177
- selector: (state: PluginState) => SelectedState = id as any
178
- ) => observePoiStore(onChange, (s) => selector(s?.ext[PACKAGE_NAME]))
179
-
180
- const fallbackStore: Store<PoiState> = {
181
- getState: noop as () => PoiState,
182
- subscribe: () => (() => {}) as () => () => void,
183
- }
184
-
185
- let globalStore: Store<PoiState> | null = null
186
- /**
187
- * Get poi global Store if in poi env
188
- */
189
- export const getPoiStore: () => Promise<Store<PoiState>> = async () => {
190
- if (globalStore !== null) {
191
- return globalStore
192
- }
193
- if (IN_POI) {
194
- try {
195
- const { store } = await importFromPoi('views/create-store')
196
- globalStore = store
197
- return store
198
- } catch (error) {
199
- console.warn('Load global store error', error)
200
- }
201
- }
202
- globalStore = fallbackStore
203
- return fallbackStore
204
- }
205
-
206
- export const activeQuestsSelector = (state: PoiState): PoiQuestState =>
207
- state?.info?.quests?.activeQuests ?? {}
208
-
209
- export const usePluginTranslation = () => {
210
- return useTranslation(PACKAGE_NAME)
211
- }