API improvements

- added `Game.getDiff()` method to the difference between specified
  version and the latest one
- added `Voice.latest` field
- added `Voice.getDiff()` method
- updated comments
This commit is contained in:
Observer KRypt0n_ 2021-12-22 11:51:25 +02:00
parent 180db65ecc
commit 9e6672c797
No known key found for this signature in database
GPG key ID: DC5D4EC1303465DA
3 changed files with 58 additions and 21 deletions

View file

@ -1,6 +1,7 @@
import * as Vue from 'vue/dist/vue.esm-bundler';
import Window from '../ts/neutralino/Window';
import Voice from '../ts/Voice';
const app = Vue.createApp({
data: () => ({
@ -14,6 +15,9 @@ const app = Vue.createApp({
mounted: () => {
Window.current.show();
Voice.getDiff('2.1.0')
.then((data) => console.log(data));
/*Downloader.download('https://github.com/GloriousEggroll/wine-ge-custom/releases/download/6.20-GE-1/wine-lutris-ge-6.20-1-x86_64.tar.xz', '123.tar.xz').then((stream) => {
stream.start(() => console.log('Downloading started'));
stream.finish(() => console.log('Downloading finished'));

View file

@ -1,7 +1,8 @@
import type {
ServerResponse,
Data,
Latest
Latest,
Diff
} from './types/GameData';
import constants from './Constants';
@ -38,7 +39,7 @@ 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
* @returns rejects Error object if company's servers are unreachable or they responded with an error
*/
public static getLatestData(): Promise<Data>
{
@ -62,14 +63,38 @@ export default class Game
/**
* Get latest game version data
*
* @returns Error object if company's servers are unreachable or they responded with an error
* @returns rejects 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) => {
return new Promise((resolve, reject) => {
this.getLatestData()
.then((data) => resolve(data.game.latest))
.catch((error) => reject(error));
});
}
/**
* Get updated game data from the specified version to the latest
*
* @returns null if the difference can't be calculated
*/
public static getDiff(version: string): Promise<Diff|null>
{
return new Promise(async (resolve, reject) => {
this.getLatestData()
.then((data) => {
for (const diff of data.game.diffs)
if (diff.version == version)
{
resolve(diff);
return;
}
resolve(null);
})
.catch((error) => reject(error));
});
}
}

View file

@ -1,15 +1,8 @@
import type {
ServerResponse,
Data,
Latest
} from './types/GameData';
import type {
VoiceLang,
InstalledVoice
} from './types/Voice';
import type { VoicePack } from './types/GameData';
import type { InstalledVoice } from './types/Voice';
import constants from './Constants';
import Game from './Game';
declare const Neutralino;
@ -58,16 +51,31 @@ export default class Voice
}
/**
* Get latest game version data
* Get latest voice data info
*
* @returns Error object if company's servers are unreachable or they responded with an error
* @returns rejects Error object if company's servers are unreachable or they responded with an error
*/
/*public static get latest(): Promise<Latest>
public static get latest(): Promise<VoicePack[]>
{
return new Promise(async (resolve, reject) => {
this.getLatestData()
.then((data) => resolve(data.game.latest))
return new Promise((resolve, reject) => {
Game.getLatestData()
.then((data) => resolve(data.game.latest.voice_packs))
.catch((error) => reject(error));
});
}*/
}
/**
* Get updated voice data from the specified version to the latest
*
* @returns null if the difference can't be calculated
* @returns rejects Error object if company's servers are unreachable or they responded with an error
*/
public static getDiff(version: string): Promise<VoicePack[]|null>
{
return new Promise((resolve, reject) => {
Game.getDiff(version)
.then((data) => resolve(data.voice_packs ?? null))
.catch((error) => reject(error));
});
}
}