poi-plugin-quest-info-2
Advanced tools
Comparing version 0.7.4 to 0.8.0
@@ -22,4 +22,2 @@ // https://eslint.org/docs/user-guide/configuring | ||
'prettier', | ||
'prettier/react', | ||
'prettier/@typescript-eslint', | ||
], | ||
@@ -26,0 +24,0 @@ parser: '@typescript-eslint/parser', |
@@ -7,2 +7,2 @@ import zh_CN from './quests-scn.json' | ||
export const version = '433261cf82381efd22702e882ad359bf426695b5' | ||
export const version = 'cf24003d54c1b9cb2f6a76cdd670de717de0886c' |
{ | ||
"name": "poi-plugin-quest-info-2", | ||
"version": "0.7.4", | ||
"version": "0.8.0", | ||
"private": false, | ||
@@ -47,3 +47,3 @@ "description": "show quest info", | ||
"@storybook/react": "^6.3.4", | ||
"@types/jest": "^26.0.20", | ||
"@types/jest": "^27.4.1", | ||
"@types/pangu": "^3.3.0", | ||
@@ -53,10 +53,10 @@ "@types/react-virtualized": "^9.21.11", | ||
"@types/styled-components": "^5.1.7", | ||
"@typescript-eslint/eslint-plugin": "^4.14.1", | ||
"@typescript-eslint/parser": "^4.14.1", | ||
"@typescript-eslint/eslint-plugin": "^5.22.0", | ||
"@typescript-eslint/parser": "^5.22.0", | ||
"babel-loader": "^8.2.2", | ||
"eslint": "^7.18.0", | ||
"eslint-config-prettier": "^7.2.0", | ||
"eslint-plugin-prettier": "^3.3.1", | ||
"eslint-plugin-react": "^7.22.0", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"eslint": "^8.14.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-react": "^7.29.4", | ||
"eslint-plugin-react-hooks": "^4.5.0", | ||
"https-proxy-agent": "^5.0.0", | ||
@@ -67,3 +67,3 @@ "i18next": "^19.8.5", | ||
"poi-asset-themes": "^4.2.0", | ||
"prettier": "^2.3.2", | ||
"prettier": "^2.6.2", | ||
"react": "^17.0.1", | ||
@@ -74,5 +74,5 @@ "react-dom": "^17.0.1", | ||
"styled-components": "^5.3.3", | ||
"ts-jest": "^27.0.3", | ||
"ts-node": "^9.1.1", | ||
"typescript": "^4.4.4" | ||
"ts-jest": "^27.1.4", | ||
"ts-node": "^10.7.0", | ||
"typescript": "^4.5.5" | ||
}, | ||
@@ -79,0 +79,0 @@ "poiPlugin": { |
@@ -7,3 +7,3 @@ import { version, KcwikiQuestData } from '../../build/kcQuestsData' | ||
expect(version).toMatchInlineSnapshot( | ||
`"433261cf82381efd22702e882ad359bf426695b5"` | ||
`"cf24003d54c1b9cb2f6a76cdd670de717de0886c"` | ||
) | ||
@@ -10,0 +10,0 @@ }) |
@@ -6,3 +6,7 @@ import { useState, useEffect } from 'react' | ||
import { GameQuest, PoiQuestState, PoiState, QuestTab } from './types' | ||
import { createGlobalState } from 'react-use' | ||
export const activeQuestsSelector = (state: PoiState): PoiQuestState => | ||
state?.info?.quests?.activeQuests ?? {} | ||
export const useActiveQuest = () => { | ||
@@ -21,5 +25,2 @@ const [activeQuests, setActiveQuests] = useState<PoiQuestState>({}) | ||
export const activeQuestsSelector = (state: PoiState): PoiQuestState => | ||
state?.info?.quests?.activeQuests ?? {} | ||
export const usePluginTranslation = () => { | ||
@@ -29,4 +30,6 @@ return useTranslation(PACKAGE_NAME) | ||
const useGlobalGameQuest = createGlobalState<GameQuest[]>([]) | ||
export const useGameQuest = () => { | ||
const [quests, setQuests] = useState<GameQuest[]>([]) | ||
const [quests, setQuests] = useGlobalGameQuest() | ||
useEffect(() => { | ||
@@ -36,3 +39,3 @@ const listener = (quests: GameQuest[] | null) => setQuests(quests ?? []) | ||
return observePluginStore(listener, (i) => i?._?.questList) | ||
}, []) | ||
}, [setQuests]) | ||
return quests | ||
@@ -39,0 +42,0 @@ } |
@@ -1,7 +0,10 @@ | ||
import questCategory from '../build/questCategory.json' | ||
import { QuestData } from '../build/kcanotifyGamedata' | ||
import { KcwikiQuestData } from '../build/kcQuestsData' | ||
import newQuestData from '../build/kcQuestsData/quests-scn-new.json' | ||
import prePostQuest from '../build/prePostQuest.json' | ||
import questCategory from '../build/questCategory.json' | ||
import questCodeMap from '../build/questCodeMap.json' | ||
import { GameQuest, QUEST_API_STATE } from './poi/types' | ||
type DocQuest = { | ||
export type DocQuest = { | ||
code: string | ||
@@ -38,2 +41,5 @@ name: string | ||
export const getKcwikiQuestData = () => KcwikiQuestData | ||
export const getKcanotifyQuestData = () => QuestData | ||
const dailyQuest = new Set(questCategory.dailyQuest) | ||
@@ -201,3 +207,3 @@ const weeklyQuest = new Set(questCategory.weeklyQuest) | ||
export const getPrePost = (gameId: number) => { | ||
export const getQuestPrePost = (gameId: number) => { | ||
if (!(gameId in prePostQuest)) { | ||
@@ -209,2 +215,9 @@ return { pre: [], post: [] } | ||
export const getQuestIdByCode = (code: string) => { | ||
if (code in questCodeMap) { | ||
return questCodeMap[code as keyof typeof questCodeMap] | ||
} | ||
return null | ||
} | ||
export enum QUEST_STATUS { | ||
@@ -211,0 +224,0 @@ LOCKED, |
@@ -1,3 +0,3 @@ | ||
import { KcwikiQuestData } from '../../build/kcQuestsData' | ||
import { useStore } from '.' | ||
import { getKcwikiQuestData } from '../questHelper' | ||
@@ -16,3 +16,6 @@ export const usePreferKcwiki = () => { | ||
lang: string | ||
): lang is keyof typeof KcwikiQuestData => lang in KcwikiQuestData | ||
): lang is keyof typeof kcwikiQuestData => { | ||
const kcwikiQuestData = getKcwikiQuestData() | ||
return lang in kcwikiQuestData | ||
} | ||
@@ -29,3 +32,4 @@ export const useKcwikiData = (lang: string) => { | ||
} | ||
return KcwikiQuestData[lang] | ||
const kcwikiQuestData = getKcwikiQuestData() | ||
return kcwikiQuestData[lang] | ||
} |
import { useCallback } from 'react' | ||
import { QuestData } from '../../build/kcanotifyGamedata' | ||
import { useGameQuest, usePluginTranslation } from '../poi/hooks' | ||
import { getCategory } from '../questHelper' | ||
import { | ||
DocQuest, | ||
getCategory, | ||
getKcanotifyQuestData, | ||
getQuestIdByCode, | ||
getQuestPrePost, | ||
QUEST_STATUS, | ||
} from '../questHelper' | ||
import type { UnionQuest } from '../questHelper' | ||
@@ -11,9 +17,12 @@ import { useKcwikiData, checkIsKcwikiSupportedLanguages } from './kcwiki' | ||
export const checkIsKcanotifySupportedLanguages = ( | ||
const checkIsKcanotifySupportedLanguages = ( | ||
lang: string | ||
): lang is keyof typeof QuestData => lang in QuestData | ||
): lang is keyof typeof kcaQuestData => { | ||
const kcaQuestData = getKcanotifyQuestData() | ||
return lang in kcaQuestData | ||
} | ||
export const isSupportedLanguages = ( | ||
lang: string | ||
): lang is keyof typeof QuestData => | ||
): lang is keyof ReturnType<typeof getKcanotifyQuestData> => | ||
checkIsKcanotifySupportedLanguages(lang) || | ||
@@ -32,3 +41,3 @@ checkIsKcwikiSupportedLanguages(lang) | ||
const useQuestMap = () => { | ||
const useQuestMap = (): Record<string, DocQuest> => { | ||
const lang = useLanguage() | ||
@@ -39,3 +48,4 @@ const kcwikiData = useKcwikiData(lang) | ||
} | ||
return QuestData[lang] | ||
const kcaQuestData = getKcanotifyQuestData() | ||
return kcaQuestData[lang] | ||
} | ||
@@ -82,2 +92,73 @@ | ||
export const useQuestByCode = (code: string): UnionQuest | null => { | ||
const questMap = useQuestMap() | ||
const gameId = getQuestIdByCode(code) | ||
if (gameId && gameId in questMap) { | ||
return { | ||
gameId, | ||
docQuest: questMap[String(gameId) as keyof typeof questMap], | ||
} | ||
} | ||
return null | ||
} | ||
const useCompletedQuest = () => { | ||
const completedQuest: Record<number, true> = {} | ||
const gameQuest = useGameQuest() | ||
const queue: number[] = gameQuest.map((quest) => quest.api_no) | ||
while (queue.length) { | ||
const gameId = queue.shift()! | ||
if (gameId in completedQuest) { | ||
continue | ||
} | ||
completedQuest[gameId] = true | ||
const prePostQuests = getQuestPrePost(gameId) | ||
prePostQuests.pre.forEach((nextCode) => { | ||
const nextGameId = getQuestIdByCode(nextCode) | ||
if (nextGameId) { | ||
queue.push(nextGameId) | ||
} | ||
}) | ||
} | ||
return completedQuest | ||
} | ||
const useLockedQuest = () => { | ||
const lockedQuest: Record<number, true> = {} | ||
const gameQuest = useGameQuest() | ||
const queue: number[] = gameQuest.map((quest) => quest.api_no) | ||
while (queue.length) { | ||
const gameId = queue.shift()! | ||
if (gameId in lockedQuest) { | ||
continue | ||
} | ||
lockedQuest[gameId] = true | ||
const prePostQuests = getQuestPrePost(gameId) | ||
prePostQuests.post.forEach((nextCode) => { | ||
const nextGameId = getQuestIdByCode(nextCode) | ||
if (nextGameId) { | ||
queue.push(nextGameId) | ||
} | ||
}) | ||
} | ||
return lockedQuest | ||
} | ||
export const useQuestStatus = (gameId: number | null) => { | ||
const completedQuest = useCompletedQuest() | ||
const lockedQuest = useLockedQuest() | ||
if (!gameId) { | ||
return QUEST_STATUS.DEFAULT | ||
} | ||
if (gameId in completedQuest) { | ||
return QUEST_STATUS.ALREADY_COMPLETED | ||
} | ||
if (gameId in lockedQuest) { | ||
return QUEST_STATUS.LOCKED | ||
} | ||
return QUEST_STATUS.DEFAULT | ||
} | ||
/** | ||
@@ -84,0 +165,0 @@ * @deprecated Not large card now |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1593478
32550