poi-plugin-quest-info-2 0.7.2 → 0.7.3

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.
@@ -1,132 +0,0 @@
1
- /* eslint-disable no-console */
2
- import { existsSync, readFileSync, writeFileSync } from 'fs'
3
- import pangu from 'pangu'
4
- import path from 'path'
5
- import { fetch } from './proxyFetch'
6
- import { prepareDir } from './utils'
7
-
8
- // See https://github.com/antest1/kcanotify-gamedata
9
-
10
- const OUTPUT_PATH = path.resolve('build', 'kcanotifyGamedata')
11
- const URL_PREFIX =
12
- 'https://raw.githubusercontent.com/antest1/kcanotify-gamedata/master'
13
- const VERSION_URL = `${URL_PREFIX}/KCAINFO`
14
- const DATA_URL = `${URL_PREFIX}/files`
15
- const LANGS = ['scn', 'tcn', 'jp', 'en', 'ko'] as const
16
- const LOCALES = ['zh-CN', 'zh-TW', 'ja-JP', 'en-US', 'ko-KR'] as const
17
-
18
- const getRemoteVersion = async () => {
19
- const resp = await fetch(VERSION_URL)
20
- if (!resp.ok) {
21
- throw new Error(`Fetch Error!\nurl: ${resp.url}\nstatus: ${resp.status}`)
22
- }
23
- const KCAINFO: {
24
- version: string
25
- data_version: string
26
- kcadata_version: number
27
- kc_maintenance: string[]
28
- } = await resp.json()
29
-
30
- return String(KCAINFO.kcadata_version)
31
- }
32
-
33
- const getLocalVersion = () => {
34
- const localVersionFile = path.resolve(OUTPUT_PATH, 'DATA_VERSION')
35
- const version = existsSync(localVersionFile)
36
- ? readFileSync(localVersionFile).toString()
37
- : '0'
38
- return version
39
- }
40
-
41
- /**
42
- * @example
43
- * ```ts
44
- * import zh_CN from './quests-scn.json'
45
- * export default {
46
- * 'zh-CN': zh_CN,
47
- * }
48
- * export const version = '5.1.2.1'
49
- * ```
50
- */
51
- const genTS = (version: string) => {
52
- const importCode = LOCALES.map(
53
- (locale, idx) =>
54
- `import ${locale.replace('-', '_')} from './quests-${LANGS[idx]}.json'`
55
- ).join('\n')
56
-
57
- const exportCode =
58
- 'export const QuestData = {\n' +
59
- LOCALES.map((locale) => ` '${locale}': ${locale.replace('-', '_')},`).join(
60
- '\n'
61
- ) +
62
- '\n}'
63
-
64
- const versionCode = `export const version = '${version}'`
65
- return `${importCode}\n\n${exportCode}\n\n${versionCode}\n`
66
- }
67
-
68
- const main = async () => {
69
- const args = process.argv.slice(2)
70
-
71
- prepareDir(OUTPUT_PATH)
72
- const remoteVersion = await getRemoteVersion()
73
- const localVersion = getLocalVersion()
74
- if (remoteVersion === localVersion) {
75
- console.log('The local version is up to date. Version:', localVersion)
76
- if (!args.find((v) => v === '-f' || v === '--force')) {
77
- return
78
- }
79
- } else {
80
- console.log('New Version Detected. Version:', remoteVersion)
81
- }
82
-
83
- await Promise.all(
84
- LANGS.map(async (lang) => {
85
- const filename = `quests-${lang}.json`
86
- const fileURL = `${DATA_URL}/${filename}`
87
-
88
- console.log(`Download ${filename}...`)
89
- const resp = await fetch(fileURL)
90
- if (!resp.ok) {
91
- console.error(`Fetch Error!\nurl: ${resp.url}\nstatus: ${resp.status}`)
92
- return
93
- }
94
- let text = await resp.text()
95
- // TODO fix source file
96
- // Remove BOM(U+FEFF) from the header of the quests-ko.json
97
- text = text.trim()
98
-
99
- const json = JSON.parse(text) as {
100
- [gameId: string]: {
101
- code: string
102
- name: string
103
- desc: string
104
- memo?: string
105
- }
106
- }
107
- for (const gameId in json) {
108
- const { name, desc, memo } = json[gameId]
109
- json[gameId].name = pangu.spacing(name)
110
- json[gameId].desc = pangu.spacing(desc)
111
- if (memo) {
112
- json[gameId].memo = pangu.spacing(memo)
113
- }
114
- }
115
-
116
- const data = JSON.stringify(json, undefined, 2)
117
- writeFileSync(`${OUTPUT_PATH}/${filename}`, data)
118
- })
119
- )
120
-
121
- const ts = genTS(remoteVersion)
122
- writeFileSync(`${OUTPUT_PATH}/index.ts`, ts)
123
-
124
- // Finally record the version number
125
- writeFileSync(`${OUTPUT_PATH}/DATA_VERSION`, remoteVersion)
126
- }
127
-
128
- main()
129
-
130
- process.on('unhandledRejection', (up) => {
131
- throw up
132
- })
@@ -1,126 +0,0 @@
1
- /* eslint-disable no-console */
2
- import path from 'path'
3
- import fs from 'fs'
4
- import crypto from 'crypto'
5
- // See https://sharp.pixelplumbing.com/
6
- import sharp from 'sharp'
7
- import { fetch } from './proxyFetch'
8
- import { prepareDir } from './utils'
9
-
10
- const OUTPUT_PATH = path.resolve('build', 'dutySprites')
11
-
12
- const SERVER_URL = 'http://203.104.209.199'
13
- const JSON_PATH = '/kcs2/img/duty/duty_main.json'
14
- const SPRITES_PATH = '/kcs2/img/duty/duty_main.png'
15
- const VERSION = '5.1.2.0'
16
- const SPRITES_URL = `${SERVER_URL}${SPRITES_PATH}?version=${VERSION}`
17
- const META_URL = `${SERVER_URL}${JSON_PATH}?version=${VERSION}`
18
-
19
- const getFilename = (url: string) => {
20
- const pathname = new URL(url).pathname
21
- const index = pathname.lastIndexOf('/')
22
- return index !== -1 ? pathname.slice(index + 1) : pathname
23
- }
24
-
25
- const download = async (url: string, filename?: string) => {
26
- if (!filename) {
27
- filename = getFilename(url)
28
- }
29
- const filePath = path.resolve(OUTPUT_PATH, filename)
30
- const response = await fetch(url)
31
- const buffer = await response.buffer()
32
- await fs.writeFileSync(filePath, buffer)
33
- return { filePath, buffer }
34
- }
35
-
36
- const checksumFile = (algorithm: string, path: fs.PathLike) => {
37
- return new Promise<string>((resolve, reject) => {
38
- const hash = crypto.createHash(algorithm)
39
- const stream = fs.createReadStream(path)
40
- stream.on('error', (err) => reject(err))
41
- stream.on('data', (chunk) => hash.update(chunk))
42
- stream.on('end', () => resolve(hash.digest('hex')))
43
- })
44
- }
45
-
46
- const cropAndSaveImage = (
47
- img: Buffer,
48
- {
49
- name,
50
- format,
51
- x,
52
- y,
53
- w,
54
- h,
55
- }: {
56
- name: string
57
- format: string
58
- x: number
59
- y: number
60
- w: number
61
- h: number
62
- }
63
- ) => {
64
- const filename = `${name}.${format}`
65
- sharp(img)
66
- .extract({ left: x, top: y, width: w, height: h })
67
- .toFile(path.resolve(OUTPUT_PATH, filename))
68
- .catch((err) => {
69
- console.error('Failed to process image:', filename, err)
70
- })
71
- }
72
-
73
- type KCS2Meta = {
74
- frames: {
75
- [name: string]: {
76
- frame: {
77
- x: number
78
- y: number
79
- w: number
80
- h: number
81
- }
82
- rotated: boolean
83
- trimmed: boolean
84
- spriteSourceSize: {
85
- x: number
86
- y: number
87
- w: number
88
- h: number
89
- }
90
- sourceSize: {
91
- w: number
92
- h: number
93
- }
94
- }
95
- }
96
- meta: any
97
- }
98
-
99
- const parseSprites = (sprites: Buffer, meta: KCS2Meta) => {
100
- const { frames } = meta
101
- for (const [name, { frame }] of Object.entries(frames)) {
102
- cropAndSaveImage(sprites, { ...frame, name, format: 'png' })
103
- }
104
- }
105
-
106
- const main = async () => {
107
- prepareDir(OUTPUT_PATH)
108
- const [
109
- { buffer: metaBuffer },
110
- { filePath: spritesPath, buffer: spritesBuffer },
111
- ] = await Promise.all([download(META_URL), download(SPRITES_URL)])
112
-
113
- const spritesFilename = path.parse(spritesPath).base
114
- const md5 = await checksumFile('md5', spritesPath)
115
- fs.writeFileSync(path.resolve(OUTPUT_PATH, `${spritesFilename}.md5`), md5)
116
- console.log('File download complete')
117
- console.log(spritesFilename, 'MD5:', md5)
118
-
119
- parseSprites(spritesBuffer, JSON.parse(metaBuffer.toString()))
120
- }
121
-
122
- main()
123
-
124
- process.on('unhandledRejection', (up) => {
125
- throw up
126
- })
@@ -1,58 +0,0 @@
1
- import { writeFileSync } from 'fs'
2
- import path from 'path'
3
- import { QuestData } from '../build/kcanotifyGamedata'
4
- import { KcwikiQuestData } from '../build/kcQuestsData'
5
-
6
- const OUTPUT_PATH = path.resolve('build', 'questCategory.json')
7
-
8
- const kcaQuestStartsFilter = (str: string) =>
9
- Object.entries(QuestData['zh-CN'])
10
- .filter(([, quest]) => quest.name.startsWith(str))
11
- .map(([gameId]) => gameId)
12
-
13
- const kcwikiDataSelector = () => Object.entries(KcwikiQuestData['zh-CN'])
14
- const mergeDataSelector = () =>
15
- Object.entries({ ...QuestData['zh-CN'], ...KcwikiQuestData['zh-CN'] })
16
-
17
- const main = () => {
18
- const dailyQuest = kcaQuestStartsFilter('(日任)')
19
- const weeklyQuest = kcaQuestStartsFilter('(周任)')
20
- const monthlyQuest = kcaQuestStartsFilter('(月任)')
21
- const quarterlyQuest = [
22
- ...new Set([
23
- ...kcaQuestStartsFilter('(季任)'),
24
- ...kcwikiDataSelector()
25
- .filter(([, quest]) => quest.memo2.includes('季常任务'))
26
- .map(([gameId]) => gameId),
27
- ]),
28
- ].sort((a, b) => +a - +b)
29
- // (年任) (年任 / x 月)
30
- const yearlyQuest = kcwikiDataSelector()
31
- .filter(([, quest]) => quest.memo2.includes('年常任务'))
32
- .map(([gameId]) => gameId)
33
- const singleQuest = mergeDataSelector()
34
- .filter(
35
- ([gameId]) =>
36
- ![
37
- ...dailyQuest,
38
- ...weeklyQuest,
39
- ...monthlyQuest,
40
- ...quarterlyQuest,
41
- ...yearlyQuest,
42
- ].includes(gameId)
43
- )
44
- .map(([gameId]) => gameId)
45
-
46
- const data = {
47
- dailyQuest,
48
- weeklyQuest,
49
- monthlyQuest,
50
- quarterlyQuest,
51
- yearlyQuest,
52
- singleQuest,
53
- }
54
-
55
- writeFileSync(OUTPUT_PATH, JSON.stringify(data, null, 2))
56
- }
57
-
58
- main()
@@ -1,42 +0,0 @@
1
- /* eslint-disable no-console */
2
- import nodeFetch from 'node-fetch'
3
- import type { Request, RequestInfo } from 'node-fetch'
4
- import type { Agent } from 'http'
5
- import { HttpsProxyAgent } from 'https-proxy-agent'
6
-
7
- const withAgent =
8
- (agent: Agent) =>
9
- (fetch: typeof nodeFetch): typeof nodeFetch => {
10
- const isRequest = (input: RequestInfo): input is Request => {
11
- return typeof input === 'object' && !('href' in input)
12
- }
13
- return new Proxy(fetch, {
14
- apply(target, thisArg: unknown, argArray: Parameters<typeof nodeFetch>) {
15
- if (isRequest(argArray[0])) {
16
- // Request
17
- if (!argArray[0].agent) {
18
- argArray[0].agent = agent
19
- }
20
- } else {
21
- // URL or URLLike + ?RequestInit
22
- if (!argArray[1]) {
23
- argArray[1] = {}
24
- }
25
- if (!argArray[1].agent) {
26
- argArray[1].agent = agent
27
- }
28
- }
29
- return target.apply(thisArg, argArray)
30
- },
31
- })
32
- }
33
-
34
- let fetch = nodeFetch
35
- // HTTP/HTTPS proxy to connect to
36
- const proxy = process.env.https_proxy || process.env.http_proxy
37
- if (proxy) {
38
- console.log('using proxy server %j', proxy)
39
- fetch = withAgent(new HttpsProxyAgent(proxy))(nodeFetch)
40
- }
41
-
42
- export { fetch }
package/scripts/utils.ts DELETED
@@ -1,8 +0,0 @@
1
- import { existsSync, mkdirSync } from 'fs'
2
- import type { PathLike } from 'fs'
3
-
4
- export const prepareDir = (dir: PathLike) => {
5
- if (!existsSync(dir)) {
6
- mkdirSync(dir, { recursive: true })
7
- }
8
- }