API improvements

- fixed `Configs.defaults()` settings overwriting
- added `Game.getLatestData()` and `Game.latest` to get latest game's version
- added `Voice` class to work with installed voice packages
- some classes were moved to the `core` folder
This commit is contained in:
Observer KRypt0n_ 2021-12-22 11:35:10 +02:00
parent 3f72b5c598
commit 180db65ecc
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
11 changed files with 221 additions and 21 deletions

View file

@ -2,12 +2,6 @@ import * as Vue from 'vue/dist/vue.esm-bundler';
import Window from '../ts/neutralino/Window';
import Downloader from '../ts/Downloader';
import Archive from '../ts/Archive';
import Configs from '../ts/Configs';
import Runners from '../ts/Runners';
import DXVK from '../ts/DXVK';
const app = Vue.createApp({
data: () => ({
progress: '0%'

View file

@ -80,14 +80,6 @@ export default class Configs
if (current[key] === undefined)
current[key] = defaults[key];
// If default is scalar and current object
else if (typeof current[key] == 'object' && typeof defaults[key] != 'object')
current[key] = defaults[key];
// If default is object and current scalar
else if (typeof current[key] != 'object' && typeof defaults[key] == 'object')
current[key] = defaults[key];
// If both of default and current are objects
else if (typeof current[key] == 'object' && typeof defaults[key] == 'object')
current[key] = updateDefaults(current[key], defaults[key]);

View file

@ -1,3 +1,9 @@
import type {
ServerResponse,
Data,
Latest
} from './types/GameData';
import constants from './Constants';
declare const Neutralino;
@ -28,4 +34,42 @@ export default class Game
});
});
}
/**
* Get latest game data, including voice data and packages difference
*
* @returns Error object if company's servers are unreachable or they responded with an error
*/
public static getLatestData(): Promise<Data>
{
return new Promise(async (resolve, reject) => {
const response = await fetch(constants.versionsUri);
if (response.ok)
{
const json: ServerResponse = await response.json();
if (json.message == 'OK')
resolve(json.data);
else reject(new Error(`${constants.placeholders.uppercase.company}'s versions server responds with an error: [${json.retcode}] ${json.message}`));
}
else reject(new Error(`${constants.placeholders.uppercase.company}'s versions server is unreachable`));
});
}
/**
* Get latest game version data
*
* @returns Error object if company's servers are unreachable or they responded with an error
*/
public static get latest(): Promise<Latest>
{
return new Promise(async (resolve, reject) => {
this.getLatestData()
.then((data) => resolve(data.game.latest))
.catch((error) => reject(error));
});
}
}

73
src/ts/Voice.ts Normal file
View file

@ -0,0 +1,73 @@
import type {
ServerResponse,
Data,
Latest
} from './types/GameData';
import type {
VoiceLang,
InstalledVoice
} from './types/Voice';
import constants from './Constants';
declare const Neutralino;
export default class Voice
{
/**
* Get current installed voice data info
*/
public static get current(): Promise<InstalledVoice>
{
return new Promise(async (resolve) => {
const persistentPath = `${await constants.paths.gameDataDir}/Persistent/audio_lang_14`;
// TODO: more langs folders
const langs = {
'English(US)': 'en-us',
'Japanese': 'ja-jp'
};
let installedVoice: InstalledVoice = {
installed: [],
active: null
};
// Parse installed voice packages
Neutralino.filesystem.readDirectory(await constants.paths.voiceDir)
.then((files) => {
files = files
.filter((file) => file.type == 'DIRECTORY')
.map((file) => file.entry);
Object.keys(langs).forEach((folder) => {
if (files.includes(folder) && langs[folder] !== undefined)
installedVoice.installed.push(langs[folder]);
});
})
.catch(() => {});
// Parse active voice package
Neutralino.filesystem.readFile(persistentPath)
.then((lang) => installedVoice.active = langs[lang] ?? null)
.catch(() => {});
resolve(installedVoice);
});
}
/**
* Get latest game version data
*
* @returns Error object if company's servers are unreachable or they responded with an error
*/
/*public static get latest(): Promise<Latest>
{
return new Promise(async (resolve, reject) => {
this.getLatestData()
.then((data) => resolve(data.game.latest))
.catch((error) => reject(error));
});
}*/
}

View file

@ -1,4 +1,4 @@
import constants from './Constants';
import constants from '../Constants';
import Downloader from './Downloader';
import Archive from './Archive';

View file

@ -3,7 +3,7 @@ import type {
Size,
File,
ArchiveInfo
} from './types/Archive';
} from '../types/Archive';
declare const Neutralino;
declare const NL_CWD;

View file

@ -1,6 +1,6 @@
import type { DXVK as TDXVK } from './types/DXVK';
import type { DXVK as TDXVK } from '../types/DXVK';
import constants from './Constants';
import constants from '../Constants';
import AbstractInstaller from './AbstractInstaller';
declare const Neutralino;

View file

@ -1,5 +1,4 @@
declare const Neutralino;
declare const NL_CWD;
class Stream
{

View file

@ -1,9 +1,9 @@
import {
Runner,
RunnerFamily
} from './types/Runners';
} from '../types/Runners';
import constants from './Constants';
import constants from '../Constants';
import AbstractInstaller from './AbstractInstaller';
declare const Neutralino;

83
src/ts/types/GameData.d.ts vendored Normal file
View file

@ -0,0 +1,83 @@
type VoicePack = {
language: string;
name: string;
path: string;
size: string;
md5: string;
}
type Latest = {
name: string;
version: string;
path: string;
size: string;
md5: string;
entry: string;
voice_packs: VoicePack[];
decompressed_path: string;
segments: any[];
}
type Diff = {
name: string;
version: string;
path: string;
size: string;
md5: string;
is_recommended_update: boolean;
voice_packs: VoicePack[];
}
type Game = {
latest: Latest;
diffs: Diff[];
}
type Plugins = {
name: string;
version: string;
path: string;
size: string;
md5: string;
entry: string;
}
type Plugin = {
plugins: Plugins[];
version: string;
}
type DeprecatedPackage = {
name: string;
md5: string;
}
type Data = {
game: Game;
plugin: Plugin;
web_url: string;
force_update?: any;
pre_download_game?: any;
deprecated_packages: DeprecatedPackage[];
sdk?: any;
}
type ServerResponse = {
retcode: number;
message: string;
data: Data;
};
export default ServerResponse;
export type {
VoicePack,
Latest,
Diff,
Game,
Plugins,
Plugin,
DeprecatedPackage,
Data,
ServerResponse
};

15
src/ts/types/Voice.d.ts vendored Normal file
View file

@ -0,0 +1,15 @@
type VoiceLang =
| 'en-us'
| 'zh-cn'
| 'ja-jp'
| 'ko-kr';
type InstalledVoice = {
installed: VoiceLang[];
active: VoiceLang|null;
};
export type {
VoiceLang,
InstalledVoice
};