diff --git a/src/tools/fetchGamedata.ts b/src/tools/fetchGamedata.ts deleted file mode 100644 index 24ade8b..0000000 --- a/src/tools/fetchGamedata.ts +++ /dev/null @@ -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 => { - const subDir = '/config' - - const outputDir = async (path: string): Promise => { - 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) */ - } -} diff --git a/src/tools/fetchGamedataConfig.ts b/src/tools/fetchGamedataConfig.ts new file mode 100644 index 0000000..9687e75 --- /dev/null +++ b/src/tools/fetchGamedataConfig.ts @@ -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 => { + 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) + } + } +} diff --git a/src/tools/handleConvertion.ts b/src/tools/handleConvertion.ts index 45e2347..f03fd34 100644 --- a/src/tools/handleConvertion.ts +++ b/src/tools/handleConvertion.ts @@ -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 => { 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()