refactor(tools): rename fetchGamedataConfig
This commit is contained in:
parent
4f6b2045f2
commit
cb66593b2c
@ -1,55 +0,0 @@
|
||||
import { downloadDir } from '@tauri-apps/api/path'
|
||||
import { XMLParser } from 'fast-xml-parser'
|
||||
import { writeTextFile } from '@tauri-apps/api/fs'
|
||||
|
||||
import { PROD_VERSION } from '../config/Endpoints'
|
||||
import { FigureMap } from '../controllers/FigureMap'
|
||||
import { EffectMap } from '../controllers/EffectMap'
|
||||
import type { GameEndPointsTypes, IEffectMap, IFigureData, IFigureMap } from '../types'
|
||||
import { parseData } from './parseData'
|
||||
import { convertTXT } from './convertTXT'
|
||||
import { FigureData } from '../controllers/FigureData'
|
||||
import { FurniData } from '../controllers/FurniData'
|
||||
|
||||
export const fetchGamedata = async (data: string, endpoint: GameEndPointsTypes[number]): Promise<void> => {
|
||||
const subDir = '/config'
|
||||
|
||||
const outputDir = async (path: string): Promise<string> => {
|
||||
return (await downloadDir()).concat(String(PROD_VERSION) + path)
|
||||
}
|
||||
|
||||
switch (endpoint.convert) {
|
||||
case 'XML':
|
||||
const convertedData = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '' }).parse(data)
|
||||
|
||||
const XML2JSON = () => {
|
||||
if (endpoint.fileName === 'FigureData') {
|
||||
return new FigureData(convertedData).data
|
||||
} else if (endpoint.fileName === 'FigureMap') {
|
||||
return new FigureMap(convertedData).data
|
||||
} else if (endpoint.fileName === 'EffectMap') {
|
||||
return new EffectMap(convertedData)
|
||||
}
|
||||
}
|
||||
|
||||
XML2JSON()
|
||||
|
||||
break
|
||||
|
||||
/* return await parseData(await outputDir(subDir), endpoint.fileName, XML2JSON) */
|
||||
case 'TXT':
|
||||
return await convertTXT(await outputDir(subDir), data)
|
||||
|
||||
default:
|
||||
const handleJSON = () => {
|
||||
if (endpoint.fileName === 'FurniData') {
|
||||
return new FurniData(JSON.parse(data))
|
||||
}
|
||||
}
|
||||
|
||||
handleJSON()
|
||||
break
|
||||
|
||||
/* return await parseData(await outputDir(subDir), endpoint.fileName, data) */
|
||||
}
|
||||
}
|
33
src/tools/fetchGamedataConfig.ts
Normal file
33
src/tools/fetchGamedataConfig.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import { XMLParser } from 'fast-xml-parser'
|
||||
|
||||
import { FigureMap } from '../controllers/FigureMap'
|
||||
import { EffectMap } from '../controllers/EffectMap'
|
||||
import type { GameEndPointsTypes } from '../types'
|
||||
import { convertTXT } from './convertTXT'
|
||||
import { FigureData } from '../controllers/FigureData'
|
||||
import { FurniData } from '../controllers/FurniData'
|
||||
import { Convertion } from '../config/Convertion'
|
||||
|
||||
export const fetchGamedataConfig = async (data: string, endpoint: GameEndPointsTypes[number]): Promise<unknown> => {
|
||||
switch (endpoint.convert) {
|
||||
case 'XML':
|
||||
const convertedData = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: '' }).parse(data)
|
||||
|
||||
if (endpoint.fileName === 'FigureData') {
|
||||
return new FigureData(convertedData, endpoint.fileName)
|
||||
} else if (endpoint.fileName === 'FigureMap') {
|
||||
return new FigureMap(convertedData, endpoint.fileName)
|
||||
} else if (endpoint.fileName === 'EffectMap') {
|
||||
return new EffectMap(convertedData, endpoint.fileName)
|
||||
}
|
||||
|
||||
break
|
||||
case 'TXT':
|
||||
return await convertTXT(Convertion.gamedataDir, data)
|
||||
|
||||
default:
|
||||
if (endpoint.fileName === 'FurniData') {
|
||||
return new FurniData(JSON.parse(data), endpoint.fileName)
|
||||
}
|
||||
}
|
||||
}
|
@ -2,23 +2,23 @@ import { ResponseType } from '@tauri-apps/api/http'
|
||||
|
||||
import { GAME_ENDPOINTS, client } from '../config/Endpoints'
|
||||
import type { DomainTypes } from '../types/Domain'
|
||||
import { fetchGamedata } from './fetchGamedata'
|
||||
import type { StateTypes } from '../types/global'
|
||||
import { fetchGamedataConfig } from './fetchGamedataConfig'
|
||||
import type { ConvertionHandler } from '../types/global'
|
||||
|
||||
export const handleConvertion = async (
|
||||
domain: DomainTypes,
|
||||
callback: (message: string, state: StateTypes) => void,
|
||||
callback: ConvertionHandler,
|
||||
assetsOption = false
|
||||
): Promise<void> => {
|
||||
if (!assetsOption) {
|
||||
callback('Converting Gamedata configuration...', 'loading')
|
||||
callback('Initializing Gamedata configuration...', 'loading')
|
||||
|
||||
await Promise.all(
|
||||
GAME_ENDPOINTS(domain).map(async (endpoint) => {
|
||||
await client
|
||||
.get(endpoint.src, { responseType: ResponseType.Text })
|
||||
.then(async ({ data }) => {
|
||||
return await fetchGamedata(data as string, endpoint)
|
||||
return await fetchGamedataConfig(data as string, endpoint)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(error)
|
||||
@ -28,6 +28,9 @@ export const handleConvertion = async (
|
||||
)
|
||||
|
||||
callback('Converting shockwave files...', 'loading')
|
||||
|
||||
// fetch, read and convert the files from the production folder in the user downloads' folder
|
||||
// write the files into a seperate folder
|
||||
} else {
|
||||
/* ASSETS_ENDPOINTS(domain).map((endpoint) => {
|
||||
client.get()
|
||||
|
Loading…
Reference in New Issue
Block a user