mirror of
https://github.com/an-anime-team/an-anime-game-launcher.git
synced 2024-12-23 18:20:19 +03:00
Proper TS
This commit is contained in:
parent
bf3e57a7dd
commit
182cddb006
9 changed files with 29 additions and 27 deletions
|
@ -42,8 +42,8 @@ export default class Configs
|
|||
public static set(name: string, value: scalar|scalar[]): Promise<void>
|
||||
{
|
||||
const getUpdatedArray = (path: string[], array: scalar|scalar[], value: scalar|scalar[]): scalar|scalar[] => {
|
||||
array[path[0]] = path.length > 1 ?
|
||||
getUpdatedArray(path.slice(1), array[path[0]] ?? {}, value) : value;
|
||||
array![path[0]] = path.length > 1 ?
|
||||
getUpdatedArray(path.slice(1), array![path[0]] ?? {}, value) : value;
|
||||
|
||||
return array;
|
||||
};
|
||||
|
@ -74,14 +74,14 @@ export default class Configs
|
|||
return new Promise(async (resolve) => {
|
||||
const setDefaults = async (current: scalar) => {
|
||||
const updateDefaults = (current: scalar, defaults: scalar) => {
|
||||
Object.keys(defaults).forEach((key) => {
|
||||
Object.keys(defaults!).forEach((key) => {
|
||||
// If the field exists in defaults and doesn't exist in current
|
||||
if (current[key] === undefined)
|
||||
current[key] = defaults[key];
|
||||
if (current![key] === undefined)
|
||||
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]);
|
||||
else if (typeof current![key] == 'object' && typeof defaults![key] == 'object')
|
||||
current![key] = updateDefaults(current![key], defaults![key]);
|
||||
});
|
||||
|
||||
return current;
|
||||
|
|
|
@ -6,6 +6,7 @@ import type {
|
|||
} from './types/GameData';
|
||||
|
||||
import constants from './Constants';
|
||||
import fetch from './core/Fetch';
|
||||
|
||||
declare const Neutralino;
|
||||
|
||||
|
@ -48,7 +49,7 @@ export default class Game
|
|||
|
||||
if (response.ok)
|
||||
{
|
||||
const json: ServerResponse = await response.json();
|
||||
const json: ServerResponse = await (response as any).json();
|
||||
|
||||
if (json.message == 'OK')
|
||||
resolve(json.data);
|
||||
|
|
|
@ -74,7 +74,7 @@ export default class Voice
|
|||
{
|
||||
return new Promise((resolve, reject) => {
|
||||
Game.getDiff(version)
|
||||
.then((data) => resolve(data.voice_packs ?? null))
|
||||
.then((data) => resolve(data!.voice_packs ?? null))
|
||||
.catch((error) => reject(error));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ class Stream
|
|||
protected unpackDir: string|null;
|
||||
protected unpacked: number = 0;
|
||||
|
||||
protected archive: ArchiveInfo;
|
||||
protected archive?: ArchiveInfo;
|
||||
|
||||
protected onStart?: () => void;
|
||||
protected onProgress?: (current: number, total: number, difference: number) => void;
|
||||
|
@ -59,7 +59,7 @@ class Stream
|
|||
const command = {
|
||||
tar: `tar -xvf "${path}"${unpackDir ? ` -C "${unpackDir}"` : ''}`,
|
||||
zip: `unzip -o "${path}"${unpackDir ? ` -d "${unpackDir}"` : ''}`
|
||||
}[this.archive.type];
|
||||
}[this.archive.type!];
|
||||
|
||||
let remainedFiles = this.archive.files;
|
||||
|
||||
|
@ -77,8 +77,8 @@ class Stream
|
|||
{
|
||||
Neutralino.filesystem.getStats(`${baseDir}/${file.path}`)
|
||||
.then(() => {
|
||||
this.unpacked += file.size.uncompressed;
|
||||
difference += file.size.uncompressed;
|
||||
this.unpacked += file.size.uncompressed!;
|
||||
difference += file.size.uncompressed!;
|
||||
|
||||
file.path = '#unpacked#';
|
||||
})
|
||||
|
@ -89,9 +89,9 @@ class Stream
|
|||
remainedFiles = remainedFiles.filter((file) => file.path != '#unpacked#');
|
||||
|
||||
if (this.onProgress)
|
||||
this.onProgress(this.unpacked, this.archive.size.uncompressed, difference);
|
||||
this.onProgress(this.unpacked, this.archive!.size.uncompressed!, difference);
|
||||
|
||||
if (this.unpacked >= this.archive.size.uncompressed)
|
||||
if (this.unpacked >= this.archive!.size.uncompressed!)
|
||||
{
|
||||
this.finished = true;
|
||||
|
||||
|
@ -204,7 +204,7 @@ export default class Archive
|
|||
{
|
||||
let fileSize = parseInt(match[1]);
|
||||
|
||||
archive.size.uncompressed += fileSize;
|
||||
archive.size.uncompressed! += fileSize;
|
||||
|
||||
archive.files.push({
|
||||
path: match[2],
|
||||
|
@ -227,8 +227,8 @@ export default class Archive
|
|||
let uncompressedSize = parseInt(match[1]),
|
||||
compressedSize = parseInt(match[2]);
|
||||
|
||||
archive.size.compressed += compressedSize;
|
||||
archive.size.uncompressed += uncompressedSize;
|
||||
archive.size.compressed! += compressedSize;
|
||||
archive.size.uncompressed! += uncompressedSize;
|
||||
|
||||
archive.files.push({
|
||||
path: match[3],
|
||||
|
|
|
@ -59,7 +59,7 @@ export default class DXVK
|
|||
// then we should find this DXVK version and call this method for it
|
||||
if (typeof dxvk == 'string')
|
||||
{
|
||||
let foundDXVK = null;
|
||||
let foundDXVK;
|
||||
|
||||
(await this.get()).forEach((currDxvk) => {
|
||||
if (currDxvk.version == dxvk)
|
||||
|
|
|
@ -110,14 +110,14 @@ export default class Downloader
|
|||
{
|
||||
return new Promise(async (resolve) => {
|
||||
fetch(uri).then((response) => {
|
||||
resolve(new Stream(uri, output ?? this.fileFromUri(uri), response.length));
|
||||
resolve(new Stream(uri, output ?? this.fileFromUri(uri), response.length!));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static fileFromUri(uri: string): string
|
||||
{
|
||||
const file = uri.split('/').pop().split('#')[0].split('?')[0];
|
||||
const file = uri.split('/').pop()!.split('#')[0].split('?')[0];
|
||||
|
||||
if (file === '')
|
||||
return 'index.html';
|
||||
|
@ -125,7 +125,7 @@ export default class Downloader
|
|||
else if (`https://${file}` != uri && `http://${file}` != uri)
|
||||
return file;
|
||||
|
||||
else 'index.html';
|
||||
else return 'index.html';
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class Response
|
|||
this.length = length;
|
||||
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
|
||||
this.ok = status >= 200 && status <= 299;
|
||||
this.ok = status! >= 200 && status! <= 299;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -71,7 +71,7 @@ class Runners
|
|||
// then we should find this runner and call this method for it
|
||||
if (typeof runner == 'string')
|
||||
{
|
||||
let foundRunner = null;
|
||||
let foundRunner;
|
||||
|
||||
(await this.get()).forEach((family) => {
|
||||
family.runners.forEach((familyRunner) => {
|
||||
|
|
7
src/ts/types/Archive.d.ts
vendored
7
src/ts/types/Archive.d.ts
vendored
|
@ -1,10 +1,11 @@
|
|||
type ArchiveType =
|
||||
| 'tar'
|
||||
| 'zip';
|
||||
| 'zip'
|
||||
| null;
|
||||
|
||||
type Size = {
|
||||
compressed?: number;
|
||||
uncompressed?: number;
|
||||
compressed?: number | null;
|
||||
uncompressed?: number | null;
|
||||
};
|
||||
|
||||
type File = {
|
||||
|
|
Loading…
Reference in a new issue