mirror of
https://github.com/LostCityRS/Client-TS.git
synced 2026-05-06 08:56:53 -04:00
chore: Organized imports
This commit is contained in:
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"printWidth": 250,
|
||||
"tabWidth": 4,
|
||||
"semi": true,
|
||||
"singleQuote": true,
|
||||
"quoteProps": "as-needed",
|
||||
"trailingComma": "none",
|
||||
"bracketSpacing": true,
|
||||
"arrowParens": "avoid",
|
||||
"endOfLine": "auto"
|
||||
}
|
||||
+15
-10
@@ -1,11 +1,16 @@
|
||||
{
|
||||
"name": "client2",
|
||||
"module": "src/client/Client.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
"name": "client2",
|
||||
"module": "src/client/Client.ts",
|
||||
"type": "module",
|
||||
"imports": {
|
||||
"#3rdparty/*": "./src/3rdparty/*",
|
||||
"#/*": "./src/*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest",
|
||||
"prettier": "^3.4.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+5
-30
@@ -35,9 +35,7 @@ class BZ2Wasm {
|
||||
|
||||
ensureInitialized() {
|
||||
if (!this.wasmModule) {
|
||||
throw new Error(
|
||||
`${this.constructor.name} not initalized. call .init()`
|
||||
);
|
||||
throw new Error(`${this.constructor.name} not initalized. call .init()`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,20 +111,9 @@ class BZ2Wasm {
|
||||
|
||||
this.ensureInitialized();
|
||||
|
||||
const {
|
||||
sourcePtr: compressedPtr,
|
||||
destPtr: decompressedPtr,
|
||||
destLengthPtr: decompressedLengthPtr
|
||||
} = this.createWASMBuffers(compressed, decompressedLength);
|
||||
const { sourcePtr: compressedPtr, destPtr: decompressedPtr, destLengthPtr: decompressedLengthPtr } = this.createWASMBuffers(compressed, decompressedLength);
|
||||
|
||||
const returnValue = this.wasmModule._BZ2_bzBuffToBuffDecompress(
|
||||
decompressedPtr,
|
||||
decompressedLengthPtr,
|
||||
compressedPtr,
|
||||
compressed.length,
|
||||
0,
|
||||
0
|
||||
);
|
||||
const returnValue = this.wasmModule._BZ2_bzBuffToBuffDecompress(decompressedPtr, decompressedLengthPtr, compressedPtr, compressed.length, 0, 0);
|
||||
|
||||
this.wasmModule._free(compressedPtr);
|
||||
|
||||
@@ -150,21 +137,9 @@ class BZ2Wasm {
|
||||
throw new RangeError('blockSize should be between 1-9');
|
||||
}
|
||||
|
||||
const {
|
||||
sourcePtr: decompressedPtr,
|
||||
destPtr: compressedPtr,
|
||||
destLengthPtr: compressedLengthPtr
|
||||
} = this.createWASMBuffers(decompressed, compressedLength);
|
||||
const { sourcePtr: decompressedPtr, destPtr: compressedPtr, destLengthPtr: compressedLengthPtr } = this.createWASMBuffers(decompressed, compressedLength);
|
||||
|
||||
const returnValue = this.wasmModule._BZ2_bzBuffToBuffCompress(
|
||||
compressedPtr,
|
||||
compressedLengthPtr,
|
||||
decompressedPtr,
|
||||
decompressed.length,
|
||||
blockSize,
|
||||
0,
|
||||
30
|
||||
);
|
||||
const returnValue = this.wasmModule._BZ2_bzBuffToBuffCompress(compressedPtr, compressedLengthPtr, decompressedPtr, decompressed.length, blockSize, 0, 30);
|
||||
|
||||
this.wasmModule._free(decompressedPtr);
|
||||
|
||||
|
||||
Vendored
+1670
-1639
File diff suppressed because it is too large
Load Diff
Vendored
+7
-32
@@ -57,34 +57,23 @@ class TinyMidiPCM {
|
||||
|
||||
ensureInitialized() {
|
||||
if (!this.wasmModule) {
|
||||
throw new Error(
|
||||
`${this.constructor.name} not initalized. call .init()`
|
||||
);
|
||||
throw new Error(`${this.constructor.name} not initalized. call .init()`);
|
||||
}
|
||||
}
|
||||
|
||||
setSoundfont(buffer) {
|
||||
this.ensureInitialized();
|
||||
|
||||
const { _malloc, _free, _tsf_load_memory, _tsf_set_output } =
|
||||
this.wasmModule;
|
||||
const { _malloc, _free, _tsf_load_memory, _tsf_set_output } = this.wasmModule;
|
||||
|
||||
_free(this.soundfontBufferPtr);
|
||||
|
||||
this.soundfontBufferPtr = _malloc(buffer.length);
|
||||
this.wasmModule.HEAPU8.set(buffer, this.soundfontBufferPtr);
|
||||
|
||||
this.soundfontPtr = _tsf_load_memory(
|
||||
this.soundfontBufferPtr,
|
||||
buffer.length
|
||||
);
|
||||
this.soundfontPtr = _tsf_load_memory(this.soundfontBufferPtr, buffer.length);
|
||||
|
||||
_tsf_set_output(
|
||||
this.soundfontPtr,
|
||||
this.channels === 2 ? 0 : 2,
|
||||
this.sampleRate,
|
||||
this.gain
|
||||
);
|
||||
_tsf_set_output(this.soundfontPtr, this.channels === 2 ? 0 : 2, this.sampleRate, this.gain);
|
||||
}
|
||||
|
||||
getPCMBuffer() {
|
||||
@@ -92,12 +81,7 @@ class TinyMidiPCM {
|
||||
|
||||
const pcm = new Uint8Array(this.bufferSize);
|
||||
|
||||
pcm.set(
|
||||
this.wasmModule.HEAPU8.subarray(
|
||||
this.pcmBufferPtr,
|
||||
this.pcmBufferPtr + this.bufferSize
|
||||
)
|
||||
);
|
||||
pcm.set(this.wasmModule.HEAPU8.subarray(this.pcmBufferPtr, this.pcmBufferPtr + this.bufferSize));
|
||||
|
||||
return pcm;
|
||||
}
|
||||
@@ -116,15 +100,7 @@ class TinyMidiPCM {
|
||||
renderMIDIMessage(midiMessagePtr) {
|
||||
const { _midi_render } = this.wasmModule;
|
||||
|
||||
return _midi_render(
|
||||
this.soundfontPtr,
|
||||
midiMessagePtr,
|
||||
this.channels,
|
||||
this.sampleRate,
|
||||
this.pcmBufferPtr,
|
||||
this.bufferSize,
|
||||
this.msecsPtr
|
||||
);
|
||||
return _midi_render(this.soundfontPtr, midiMessagePtr, this.channels, this.sampleRate, this.pcmBufferPtr, this.bufferSize, this.msecsPtr);
|
||||
}
|
||||
|
||||
render(midiBuffer) {
|
||||
@@ -136,8 +112,7 @@ class TinyMidiPCM {
|
||||
|
||||
window.clearTimeout(this.renderTimer);
|
||||
|
||||
const { setValue, getValue, _tsf_reset, _tsf_channel_set_bank_preset } =
|
||||
this.wasmModule;
|
||||
const { setValue, getValue, _tsf_reset, _tsf_channel_set_bank_preset } = this.wasmModule;
|
||||
|
||||
setValue(this.msecsPtr, 0, 'double');
|
||||
|
||||
|
||||
+1645
-1612
File diff suppressed because it is too large
Load Diff
+68
-68
@@ -1,73 +1,73 @@
|
||||
import '../3rdparty/tinymidipcm/tinymidipcm.mjs';
|
||||
import '#3rdparty/tinymidipcm/tinymidipcm.mjs';
|
||||
|
||||
import GameShell from './GameShell';
|
||||
import GameShell from '#/client/GameShell.js';
|
||||
import InputTracking from '#/client/InputTracking.js';
|
||||
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import FloType from '#/config/FloType.js';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
import LocType from '#/config/LocType.js';
|
||||
import ObjType from '#/config/ObjType.js';
|
||||
import NpcType from '#/config/NpcType.js';
|
||||
import IdkType from '#/config/IdkType.js';
|
||||
import SpotAnimType from '#/config/SpotAnimType.js';
|
||||
import VarpType from '#/config/VarpType.js';
|
||||
import Component from '#/config/Component.js';
|
||||
|
||||
import World3D from '../dash3d/World3D';
|
||||
import World from '../dash3d/World';
|
||||
import CollisionMap from '../dash3d/CollisionMap';
|
||||
import PlayerEntity from '../dash3d/entity/PlayerEntity';
|
||||
import NpcEntity from '../dash3d/entity/NpcEntity';
|
||||
import {Int32Array2d, TypedArray1d, TypedArray3d} from '../util/Arrays';
|
||||
import {canvas2d} from '../graphics/Canvas';
|
||||
import JString from '../datastruct/JString';
|
||||
import {downloadUrl, sleep} from '../util/JsUtil';
|
||||
import {playMidi, stopMidi, playWave, setMidiVolume, setWaveVolume} from '../util/AudioUtil';
|
||||
import FloType from '../config/FloType';
|
||||
import AnimBase from '../graphics/AnimBase';
|
||||
import AnimFrame from '../graphics/AnimFrame';
|
||||
import Tile from '../dash3d/type/Tile';
|
||||
import ClientWorkerStream from '../io/ClientWorkerStream';
|
||||
import CollisionMap from '#/dash3d/CollisionMap.js';
|
||||
import CollisionFlag from '#/dash3d/CollisionFlag.js';
|
||||
import DirectionFlag from '#/dash3d/DirectionFlag.js';
|
||||
import LocAngle from '#/dash3d/LocAngle.js';
|
||||
import LocLayer from '#/dash3d/LocLayer.js';
|
||||
import LocShape from '#/dash3d/LocShape.js';
|
||||
import World from '#/dash3d/World.js';
|
||||
import World3D from '#/dash3d/World3D.js';
|
||||
|
||||
import SeqType from '../config/SeqType';
|
||||
import LocType from '../config/LocType';
|
||||
import ObjType from '../config/ObjType';
|
||||
import NpcType from '../config/NpcType';
|
||||
import IdkType from '../config/IdkType';
|
||||
import SpotAnimType from '../config/SpotAnimType';
|
||||
import VarpType from '../config/VarpType';
|
||||
import Component from '../config/Component';
|
||||
import NpcEntity from '#/dash3d/entity/NpcEntity.js';
|
||||
import PlayerEntity from '#/dash3d/entity/PlayerEntity.js';
|
||||
|
||||
import PixMap from '../graphics/PixMap';
|
||||
import Draw2D from '../graphics/Draw2D';
|
||||
import Draw3D from '../graphics/Draw3D';
|
||||
import Pix8 from '../graphics/Pix8';
|
||||
import Pix24 from '../graphics/Pix24';
|
||||
import PixFont from '../graphics/PixFont';
|
||||
import Model from '../graphics/Model';
|
||||
import Colors from '../graphics/Colors';
|
||||
import LocSpawned from '#/dash3d/type/LocSpawned.js';
|
||||
import LocTemporary from '#/dash3d/type/LocTemporary.js';
|
||||
import Tile from '#/dash3d/type/Tile.js';
|
||||
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import ClientStream from '../io/ClientStream';
|
||||
import Protocol from '../io/Protocol';
|
||||
import Isaac from '../io/Isaac';
|
||||
import Database from '../io/Database';
|
||||
import ServerProt from '../io/ServerProt';
|
||||
import ClientProt from '../io/ClientProt';
|
||||
import LocEntity from '#/dash3d/entity/LocEntity.js';
|
||||
import ObjStackEntity from '#/dash3d/entity/ObjStackEntity.js';
|
||||
import PathingEntity from '#/dash3d/entity/PathingEntity.js';
|
||||
import ProjectileEntity from '#/dash3d/entity/ProjectileEntity.js';
|
||||
import SpotAnimEntity from '#/dash3d/entity/SpotAnimEntity.js';
|
||||
|
||||
import WordFilter from '../wordenc/WordFilter';
|
||||
import WordPack from '../wordenc/WordPack';
|
||||
import JString from '#/datastruct/JString.js';
|
||||
import LinkList from '#/datastruct/LinkList.js';
|
||||
|
||||
import Wave from '../sound/Wave';
|
||||
import InputTracking from '../client/InputTracking';
|
||||
import LocLayer from '../dash3d/LocLayer';
|
||||
import LocShape from '../dash3d/LocShape';
|
||||
import LocAngle from '../dash3d/LocAngle';
|
||||
import LocTemporary from '../dash3d/type/LocTemporary';
|
||||
import LocSpawned from '../dash3d/type/LocSpawned';
|
||||
import CollisionFlag from '../dash3d/CollisionFlag';
|
||||
import ObjStackEntity from '../dash3d/entity/ObjStackEntity';
|
||||
import LocEntity from '../dash3d/entity/LocEntity';
|
||||
import PathingEntity from '../dash3d/entity/PathingEntity';
|
||||
import ProjectileEntity from '../dash3d/entity/ProjectileEntity';
|
||||
import SpotAnimEntity from '../dash3d/entity/SpotAnimEntity';
|
||||
import { Int32Array2d, TypedArray1d, TypedArray3d, Int32Array3d, Uint8Array3d } from '#/util/Arrays.js';
|
||||
import { playMidi, stopMidi, playWave, setMidiVolume, setWaveVolume } from '#/util/AudioUtil.js';
|
||||
import { downloadUrl, sleep, arraycopy } from '#/util/JsUtil.js';
|
||||
|
||||
import {arraycopy} from '../util/JsUtil';
|
||||
import {Int32Array3d, Uint8Array3d} from '../util/Arrays';
|
||||
import DirectionFlag from '../dash3d/DirectionFlag';
|
||||
import BZip2 from '../io/BZip2.js';
|
||||
import AnimBase from '#/graphics/AnimBase.js';
|
||||
import AnimFrame from '#/graphics/AnimFrame.js';
|
||||
import { canvas2d } from '#/graphics/Canvas.js';
|
||||
import Colors from '#/graphics/Colors.js';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
import Model from '#/graphics/Model.js';
|
||||
import Pix8 from '#/graphics/Pix8.js';
|
||||
import Pix24 from '#/graphics/Pix24.js';
|
||||
import PixFont from '#/graphics/PixFont.js';
|
||||
import PixMap from '#/graphics/PixMap.js';
|
||||
|
||||
import BZip2 from '#/io/BZip2.js';
|
||||
import ClientStream from '#/io/ClientStream.js';
|
||||
import ClientProt from '#/io/ClientProt.js';
|
||||
import Database from '#/io/Database.js';
|
||||
import Isaac from '#/io/Isaac.js';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
import Protocol from '#/io/Protocol.js';
|
||||
import ServerProt from '#/io/ServerProt.js';
|
||||
|
||||
import WordFilter from '#/wordenc/WordFilter.js';
|
||||
import WordPack from '#/wordenc/WordPack.js';
|
||||
|
||||
import Wave from '#/sound/Wave.js';
|
||||
|
||||
export class Client extends GameShell {
|
||||
static readonly clientversion: number = 225;
|
||||
@@ -125,7 +125,7 @@ export class Client extends GameShell {
|
||||
protected db: Database | null = null;
|
||||
protected loopCycle: number = 0;
|
||||
protected archiveChecksums: number[] = [];
|
||||
protected stream: ClientStream | ClientWorkerStream | null = null;
|
||||
protected stream: ClientStream | null = null;
|
||||
protected in: Packet = Packet.alloc(1);
|
||||
protected out: Packet = Packet.alloc(1);
|
||||
protected loginout: Packet = Packet.alloc(1);
|
||||
@@ -1678,7 +1678,7 @@ export class Client extends GameShell {
|
||||
console.error(err);
|
||||
this.errorLoading = true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async update() {
|
||||
if (this.errorStarted || this.errorLoading || this.errorHost) {
|
||||
@@ -1690,7 +1690,7 @@ export class Client extends GameShell {
|
||||
} else {
|
||||
await this.updateTitleScreen();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async draw() {
|
||||
if (this.errorStarted || this.errorLoading || this.errorHost) {
|
||||
@@ -1703,11 +1703,11 @@ export class Client extends GameShell {
|
||||
await this.drawTitleScreen();
|
||||
}
|
||||
this.dragCycles = 0;
|
||||
};
|
||||
}
|
||||
|
||||
async refresh() {
|
||||
this.redrawTitleBackground = true;
|
||||
};
|
||||
}
|
||||
|
||||
showProgress = async (progress: number, str: string): Promise<void> => {
|
||||
console.log(`${progress}%: ${str}`);
|
||||
@@ -2188,7 +2188,7 @@ export class Client extends GameShell {
|
||||
this.loginMessage1 = 'Connecting to server...';
|
||||
await this.drawTitleScreen();
|
||||
}
|
||||
this.stream = new ClientStream(await ClientStream.openSocket({host: Client.serverAddress, port: 43594 + Client.portOffset}));
|
||||
this.stream = new ClientStream(await ClientStream.openSocket({ host: Client.serverAddress, port: 43594 + Client.portOffset }));
|
||||
await this.stream.readBytes(this.in.data, 0, 8);
|
||||
this.in.pos = 0;
|
||||
this.serverSeed = this.in.g8;
|
||||
@@ -5762,7 +5762,7 @@ export class Client extends GameShell {
|
||||
await this.logout();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private logout = async (): Promise<void> => {
|
||||
if (this.stream) {
|
||||
|
||||
+38
-41
@@ -1,10 +1,11 @@
|
||||
import PixMap from '../graphics/PixMap';
|
||||
import Draw3D from '../graphics/Draw3D';
|
||||
import { CanvasEnabledKeys, KeyCodes } from '#/client/KeyCodes.js';
|
||||
import InputTracking from '#/client/InputTracking.js';
|
||||
|
||||
import {sleep} from '../util/JsUtil';
|
||||
import {CanvasEnabledKeys, KeyCodes} from './KeyCodes';
|
||||
import InputTracking from './InputTracking';
|
||||
import {canvas, canvas2d} from '../graphics/Canvas';
|
||||
import { canvas, canvas2d } from '#/graphics/Canvas.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
import PixMap from '#/graphics/PixMap.js';
|
||||
|
||||
import { sleep } from '#/util/JsUtil.js';
|
||||
|
||||
export default abstract class GameShell {
|
||||
protected slowestMS: number = 0.0; // custom
|
||||
@@ -219,7 +220,7 @@ export default abstract class GameShell {
|
||||
if (this.state === -1) {
|
||||
this.shutdown();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected shutdown = (): void => {
|
||||
this.state = -2;
|
||||
@@ -249,17 +250,13 @@ export default abstract class GameShell {
|
||||
this.state = -1;
|
||||
};
|
||||
|
||||
protected async load() {
|
||||
}
|
||||
protected async load() {}
|
||||
|
||||
protected async update() {
|
||||
}
|
||||
protected async update() {}
|
||||
|
||||
protected async draw() {
|
||||
}
|
||||
protected async draw() {}
|
||||
|
||||
protected async refresh() {
|
||||
}
|
||||
protected async refresh() {}
|
||||
|
||||
protected async showProgress(progress: number, message: string): Promise<void> {
|
||||
const width: number = this.width;
|
||||
@@ -326,7 +323,7 @@ export default abstract class GameShell {
|
||||
|
||||
this.idleCycles = Date.now();
|
||||
|
||||
const keyCode: {code: number; ch: number} = KeyCodes[key];
|
||||
const keyCode: { code: number; ch: number } = KeyCodes[key];
|
||||
if (!keyCode || (e.code.length === 0 && !e.isTrusted)) {
|
||||
console.warn(`Unhandled key: ${key}`);
|
||||
return;
|
||||
@@ -404,7 +401,7 @@ export default abstract class GameShell {
|
||||
|
||||
this.idleCycles = Date.now();
|
||||
|
||||
const keyCode: {code: number; ch: number} = KeyCodes[key];
|
||||
const keyCode: { code: number; ch: number } = KeyCodes[key];
|
||||
if (!keyCode || (e.code.length === 0 && !e.isTrusted)) {
|
||||
console.warn(`Unhandled key: ${key}`);
|
||||
return;
|
||||
@@ -563,8 +560,8 @@ export default abstract class GameShell {
|
||||
|
||||
// CUSTOM: taken from later versions, releases all keys
|
||||
for (let i = 0; i < 128; i++) {
|
||||
this.actionKey[i] = 0;
|
||||
}
|
||||
this.actionKey[i] = 0;
|
||||
}
|
||||
|
||||
if (InputTracking.enabled) {
|
||||
InputTracking.focusLost();
|
||||
@@ -585,7 +582,7 @@ export default abstract class GameShell {
|
||||
const touch: Touch = e.changedTouches[0];
|
||||
const clientX: number = touch.clientX | 0;
|
||||
const clientY: number = touch.clientY | 0;
|
||||
this.onmousemove(new MouseEvent('mousemove', {clientX: clientX, clientY: clientY}));
|
||||
this.onmousemove(new MouseEvent('mousemove', { clientX: clientX, clientY: clientY }));
|
||||
|
||||
this.sx = this.nx = this.mx = touch.screenX | 0;
|
||||
this.sy = this.ny = this.my = touch.screenY | 0;
|
||||
@@ -603,15 +600,15 @@ export default abstract class GameShell {
|
||||
const touch: Touch = e.changedTouches[0];
|
||||
const clientX: number = touch.clientX | 0;
|
||||
const clientY: number = touch.clientY | 0;
|
||||
this.onmousemove(new MouseEvent('mousemove', {clientX: clientX, clientY: clientY}));
|
||||
this.onmousemove(new MouseEvent('mousemove', { clientX: clientX, clientY: clientY }));
|
||||
|
||||
this.nx = touch.screenX | 0;
|
||||
this.ny = touch.screenY | 0;
|
||||
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowLeft', code: 'ArrowLeft'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowUp', code: 'ArrowUp'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowRight', code: 'ArrowRight'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowDown', code: 'ArrowDown'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowLeft', code: 'ArrowLeft' }));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowUp', code: 'ArrowUp' }));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowRight', code: 'ArrowRight' }));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowDown', code: 'ArrowDown' }));
|
||||
|
||||
if (this.startedInViewport && !this.insideViewportArea()) {
|
||||
this.touching = false;
|
||||
@@ -672,28 +669,28 @@ export default abstract class GameShell {
|
||||
return;
|
||||
}
|
||||
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: data, code: data}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: data, code: data }));
|
||||
};
|
||||
}
|
||||
|
||||
input.onkeydown = (e: KeyboardEvent): void => {
|
||||
if (this.isAndroid) {
|
||||
if (e.key === 'Enter' || e.key === 'Backspace') {
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: e.key, code: e.key}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: e.key, code: e.key }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: e.key, code: e.key}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: e.key, code: e.key }));
|
||||
};
|
||||
|
||||
input.onkeyup = (e: KeyboardEvent): void => {
|
||||
if (this.isAndroid) {
|
||||
if (e.key === 'Enter' || e.key === 'Backspace') {
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: e.key, code: e.key}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: e.key, code: e.key }));
|
||||
}
|
||||
return;
|
||||
}
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: e.key, code: e.key}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: e.key, code: e.key }));
|
||||
};
|
||||
|
||||
input.onfocus = (e: FocusEvent): void => {
|
||||
@@ -713,7 +710,7 @@ export default abstract class GameShell {
|
||||
|
||||
if (longPress && !moved) {
|
||||
this.touching = true;
|
||||
this.onmousedown(new MouseEvent('mousedown', {buttons: 2}));
|
||||
this.onmousedown(new MouseEvent('mousedown', { buttons: 2 }));
|
||||
} else {
|
||||
this.mouseButton = 0;
|
||||
this.touching = false;
|
||||
@@ -728,7 +725,7 @@ export default abstract class GameShell {
|
||||
const touch: Touch = e.changedTouches[0];
|
||||
const clientX: number = touch.clientX | 0;
|
||||
const clientY: number = touch.clientY | 0;
|
||||
this.onmousemove(new MouseEvent('mousemove', {clientX: clientX, clientY: clientY}));
|
||||
this.onmousemove(new MouseEvent('mousemove', { clientX: clientX, clientY: clientY }));
|
||||
|
||||
this.nx = touch.screenX | 0;
|
||||
this.ny = touch.screenY | 0;
|
||||
@@ -748,7 +745,7 @@ export default abstract class GameShell {
|
||||
}
|
||||
} else if (this.startedInTabArea || this.getViewportInterfaceId() !== -1) {
|
||||
// Drag and drop
|
||||
this.onmousedown(new MouseEvent('mousedown', {buttons: 1}));
|
||||
this.onmousedown(new MouseEvent('mousedown', { buttons: 1 }));
|
||||
}
|
||||
|
||||
this.mx = this.nx;
|
||||
@@ -835,17 +832,17 @@ export default abstract class GameShell {
|
||||
|
||||
private rotate = (direction: number): void => {
|
||||
if (direction === 0) {
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowRight', code: 'ArrowRight'}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: 'ArrowLeft', code: 'ArrowLeft'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowRight', code: 'ArrowRight' }));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: 'ArrowLeft', code: 'ArrowLeft' }));
|
||||
} else if (direction === 1) {
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowDown', code: 'ArrowDown'}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: 'ArrowUp', code: 'ArrowUp'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowDown', code: 'ArrowDown' }));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: 'ArrowUp', code: 'ArrowUp' }));
|
||||
} else if (direction === 2) {
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowLeft', code: 'ArrowLeft'}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: 'ArrowRight', code: 'ArrowRight'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowLeft', code: 'ArrowLeft' }));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: 'ArrowRight', code: 'ArrowRight' }));
|
||||
} else if (direction === 3) {
|
||||
this.onkeyup(new KeyboardEvent('keyup', {key: 'ArrowUp', code: 'ArrowUp'}));
|
||||
this.onkeydown(new KeyboardEvent('keydown', {key: 'ArrowDown', code: 'ArrowDown'}));
|
||||
this.onkeyup(new KeyboardEvent('keyup', { key: 'ArrowUp', code: 'ArrowUp' }));
|
||||
this.onkeydown(new KeyboardEvent('keydown', { key: 'ArrowDown', code: 'ArrowDown' }));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Packet from '../io/Packet';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class InputTracking {
|
||||
static enabled: boolean = false;
|
||||
|
||||
+13
-9
@@ -1,12 +1,16 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import PixFont from '../graphics/PixFont';
|
||||
import Model from '../graphics/Model';
|
||||
import LruCache from '../datastruct/LruCache';
|
||||
import Pix24 from '../graphics/Pix24';
|
||||
import JString from '../datastruct/JString';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import Draw2D from '../graphics/Draw2D';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
import PixFont from '#/graphics/PixFont.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
import JString from '#/datastruct/JString.js';
|
||||
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Pix24 from '#/graphics/Pix24.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class Component {
|
||||
static instances: Component[] = [];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Packet from '../io/Packet';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export abstract class ConfigType {
|
||||
id: number;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class FloType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Model from '../graphics/Model';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class IdkType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
+13
-8
@@ -1,11 +1,16 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import LruCache from '../datastruct/LruCache';
|
||||
import Model from '../graphics/Model';
|
||||
import LocShape from '../dash3d/LocShape';
|
||||
import LocAngle from '../dash3d/LocAngle';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
|
||||
import LocShape from '#/dash3d/LocShape.js';
|
||||
import LocAngle from '#/dash3d/LocAngle.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class LocType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
import {ConfigType} from './ConfigType';
|
||||
|
||||
import Packet from '../io/Packet';
|
||||
|
||||
// server-sided chat (message) animations
|
||||
export default class MesAnimType extends ConfigType {
|
||||
static count: number = 0;
|
||||
static instances: MesAnimType[] = [];
|
||||
|
||||
static unpack = (dat: Packet): void => {
|
||||
this.count = dat.g2;
|
||||
for (let i: number = 0; i < this.count; i++) {
|
||||
this.instances[i] = new MesAnimType(i).decodeType(dat);
|
||||
}
|
||||
};
|
||||
|
||||
// ----
|
||||
|
||||
len: Int32Array = new Int32Array(4).fill(-1);
|
||||
|
||||
decode(code: number, dat: Packet): void {
|
||||
if (code >= 1 && code < 5) {
|
||||
this.len[code - 1] = dat.g2;
|
||||
} else if (code === 250) {
|
||||
this.debugname = dat.gjstr;
|
||||
} else {
|
||||
console.log('Error unrecognised mesanim config code: ', code);
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
-6
@@ -1,9 +1,13 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import LruCache from '../datastruct/LruCache';
|
||||
import Model from '../graphics/Model';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class NpcType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
+14
-10
@@ -1,13 +1,17 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import Pix24 from '../graphics/Pix24';
|
||||
import LruCache from '../datastruct/LruCache';
|
||||
import Model from '../graphics/Model';
|
||||
import Draw3D from '../graphics/Draw3D';
|
||||
import Draw2D from '../graphics/Draw2D';
|
||||
import Colors from '../graphics/Colors';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import Colors from '#/graphics/Colors.js';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
import Model from '#/graphics/Model.js';
|
||||
import Pix24 from '#/graphics/Pix24.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class ObjType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import AnimFrame from '../graphics/AnimFrame';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import AnimFrame from '#/graphics/AnimFrame.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class SeqType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import SeqType from './SeqType';
|
||||
import Model from '../graphics/Model';
|
||||
import LruCache from '../datastruct/LruCache';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class SpotAnimType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {ConfigType} from './ConfigType';
|
||||
import Packet from '../io/Packet';
|
||||
import { ConfigType } from '#/config/ConfigType.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class VarpType extends ConfigType {
|
||||
static count: number = 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import CollisionFlag from './CollisionFlag';
|
||||
import LocAngle from './LocAngle';
|
||||
import LocShape from './LocShape';
|
||||
import DirectionFlag from './DirectionFlag';
|
||||
import CollisionFlag from '#/dash3d/CollisionFlag.js';
|
||||
import DirectionFlag from '#/dash3d/DirectionFlag.js';
|
||||
import LocAngle from '#/dash3d/LocAngle.js';
|
||||
import LocShape from '#/dash3d/LocShape.js';
|
||||
|
||||
export default class CollisionMap {
|
||||
static readonly LEVELS: number = 4;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import LocLayer from './LocLayer';
|
||||
import LocLayer from '#/dash3d/LocLayer.js';
|
||||
|
||||
export default class LocShape {
|
||||
static readonly WALL_STRAIGHT: LocShape = new LocShape(0, LocLayer.WALL);
|
||||
|
||||
+23
-15
@@ -1,18 +1,26 @@
|
||||
import CollisionMap from './CollisionMap';
|
||||
import FloType from '../config/FloType';
|
||||
import Packet from '../io/Packet';
|
||||
import Draw3D from '../graphics/Draw3D';
|
||||
import World3D from './World3D';
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import LocType from '../config/LocType';
|
||||
import Model from '../graphics/Model';
|
||||
import LocEntity from './entity/LocEntity';
|
||||
import SeqType from '../config/SeqType';
|
||||
import LocShape from './LocShape';
|
||||
import LocAngle from './LocAngle';
|
||||
import Colors from '../graphics/Colors';
|
||||
import TileOverlayShape from './type/TileOverlayShape';
|
||||
import {Int32Array2d, Int32Array3d, Uint8Array3d} from '../util/Arrays';
|
||||
|
||||
import FloType from '#/config/FloType.js';
|
||||
import LocType from '#/config/LocType.js';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
|
||||
import LinkList from '#/datastruct/LinkList.js';
|
||||
|
||||
import CollisionMap from '#/dash3d/CollisionMap.js';
|
||||
import LocAngle from '#/dash3d/LocAngle.js';
|
||||
import LocShape from '#/dash3d/LocShape.js';
|
||||
import World3D from '#/dash3d/World3D.js';
|
||||
|
||||
import LocEntity from '#/dash3d/entity/LocEntity.js';
|
||||
|
||||
import TileOverlayShape from '#/dash3d/type/TileOverlayShape.js';
|
||||
|
||||
import Colors from '#/graphics/Colors.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { Int32Array2d, Int32Array3d, Uint8Array3d } from '#/util/Arrays.js';
|
||||
|
||||
// noinspection JSSuspiciousNameCombination,DuplicatedCode
|
||||
export default class World {
|
||||
|
||||
+23
-18
@@ -1,21 +1,26 @@
|
||||
import Draw3D from '../graphics/Draw3D';
|
||||
import Loc from './type/Loc';
|
||||
import Tile from './type/Tile';
|
||||
import Occluder from './type/Occluder';
|
||||
import CollisionMap from './CollisionMap';
|
||||
import Model, {VertexNormal} from '../graphics/Model';
|
||||
import GroundDecoration from './type/GroundDecoration';
|
||||
import Entity from './entity/Entity';
|
||||
import Wall from './type/Wall';
|
||||
import WallDecoration from './type/WallDecoration';
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import ObjStack from './type/ObjStack';
|
||||
import TileUnderlay from './type/TileUnderlay';
|
||||
import Draw2D from '../graphics/Draw2D';
|
||||
import TileOverlay from './type/TileOverlay';
|
||||
import TileOverlayShape from './type/TileOverlayShape';
|
||||
import LocAngle from './LocAngle';
|
||||
import {Int32Array3d, TypedArray1d, TypedArray2d, TypedArray3d, TypedArray4d} from '../util/Arrays';
|
||||
import CollisionMap from '#/dash3d/CollisionMap.js';
|
||||
import LocAngle from '#/dash3d/LocAngle.js';
|
||||
|
||||
import Entity from '#/dash3d/entity/Entity.js';
|
||||
|
||||
import GroundDecoration from '#/dash3d/type/GroundDecoration.js';
|
||||
import Loc from '#/dash3d/type/Loc.js';
|
||||
import ObjStack from '#/dash3d/type/ObjStack.js';
|
||||
import Occluder from '#/dash3d/type/Occluder.js';
|
||||
import Tile from '#/dash3d/type/Tile.js';
|
||||
import TileOverlay from '#/dash3d/type/TileOverlay.js';
|
||||
import TileOverlayShape from '#/dash3d/type/TileOverlayShape.js';
|
||||
import TileUnderlay from '#/dash3d/type/TileUnderlay.js';
|
||||
import Wall from '#/dash3d/type/Wall.js';
|
||||
import WallDecoration from '#/dash3d/type/WallDecoration.js';
|
||||
|
||||
import LinkList from '#/datastruct/LinkList.js';
|
||||
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
import Model, { VertexNormal } from '#/graphics/Model.js';
|
||||
|
||||
import { Int32Array3d, TypedArray1d, TypedArray2d, TypedArray3d, TypedArray4d } from '#/util/Arrays.js';
|
||||
|
||||
export default class World3D {
|
||||
private static visibilityMatrix: boolean[][][][] = new TypedArray4d(8, 32, 51, 51, false);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import Model from '../../graphics/Model';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default abstract class Entity extends Linkable {
|
||||
abstract draw(loopCycle: number): Model | null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import SeqType from '../../config/SeqType';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class LocEntity extends Linkable {
|
||||
// constructor
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import PathingEntity from './PathingEntity';
|
||||
import NpcType from '../../config/NpcType';
|
||||
import Model from '../../graphics/Model';
|
||||
import SpotAnimType from '../../config/SpotAnimType';
|
||||
import SeqType from '../../config/SeqType';
|
||||
import NpcType from '#/config/NpcType.js';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
import SpotAnimType from '#/config/SpotAnimType.js';
|
||||
|
||||
import PathingEntity from '#/dash3d/entity/PathingEntity.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class NpcEntity extends PathingEntity {
|
||||
static readonly ANIM: number = 0x2;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class ObjStackEntity extends Linkable {
|
||||
// constructor
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Entity from './Entity';
|
||||
import SeqType from '../../config/SeqType';
|
||||
import {TypedArray1d} from '../../util/Arrays';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
|
||||
import Entity from '#/dash3d/entity/Entity.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default abstract class PathingEntity extends Entity {
|
||||
x: number = 0;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import PathingEntity from './PathingEntity';
|
||||
import Model from '../../graphics/Model';
|
||||
import LruCache from '../../datastruct/LruCache';
|
||||
import SpotAnimType from '../../config/SpotAnimType';
|
||||
import SeqType from '../../config/SeqType';
|
||||
import IdkType from '../../config/IdkType';
|
||||
import ObjType from '../../config/ObjType';
|
||||
import Packet from '../../io/Packet';
|
||||
import JString from '../../datastruct/JString';
|
||||
import {TypedArray1d} from '../../util/Arrays';
|
||||
import Colors from '../../graphics/Colors';
|
||||
import IdkType from '#/config/IdkType.js';
|
||||
import ObjType from '#/config/ObjType.js';
|
||||
import SpotAnimType from '#/config/SpotAnimType.js';
|
||||
import SeqType from '#/config/SeqType.js';
|
||||
|
||||
import LruCache from '#/datastruct/LruCache.js';
|
||||
import JString from '#/datastruct/JString.js';
|
||||
|
||||
import PathingEntity from '#/dash3d/entity/PathingEntity.js';
|
||||
|
||||
import Colors from '#/graphics/Colors.js';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class PlayerEntity extends PathingEntity {
|
||||
static readonly APPEARANCE: number = 0x1;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import SpotAnimType from '../../config/SpotAnimType';
|
||||
import Entity from './Entity';
|
||||
import Model from '../../graphics/Model';
|
||||
import SpotAnimType from '#/config/SpotAnimType.js';
|
||||
|
||||
import Entity from '#/dash3d/entity/Entity.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class ProjectileEntity extends Entity {
|
||||
// constructor
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import Entity from './Entity';
|
||||
import SpotAnimType from '../../config/SpotAnimType';
|
||||
import Model from '../../graphics/Model';
|
||||
import SpotAnimType from '#/config/SpotAnimType.js';
|
||||
|
||||
import Entity from '#/dash3d/entity/Entity.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class SpotAnimEntity extends Entity {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Model from '../../graphics/Model';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class GroundDecoration {
|
||||
// constructor
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import Model from '../../graphics/Model';
|
||||
import Entity from '../entity/Entity';
|
||||
import Entity from '#/dash3d/entity/Entity.js';
|
||||
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class Loc {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class LocSpawned extends Linkable {
|
||||
readonly plane: number;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class LocTemporary extends Linkable {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Model from '../../graphics/Model';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class ObjStack {
|
||||
// constructor
|
||||
|
||||
+11
-9
@@ -1,12 +1,14 @@
|
||||
import Linkable from '../../datastruct/Linkable';
|
||||
import Loc from './Loc';
|
||||
import TileUnderlay from './TileUnderlay';
|
||||
import TileOverlay from './TileOverlay';
|
||||
import Wall from './Wall';
|
||||
import WallDecoration from './WallDecoration';
|
||||
import GroundDecoration from './GroundDecoration';
|
||||
import ObjStack from './ObjStack';
|
||||
import {TypedArray1d} from '../../util/Arrays';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
import GroundDecoration from '#/dash3d/type/GroundDecoration.js';
|
||||
import Loc from '#/dash3d/type/Loc.js';
|
||||
import ObjStack from '#/dash3d/type/ObjStack.js';
|
||||
import TileOverlay from '#/dash3d/type/TileOverlay.js';
|
||||
import TileUnderlay from '#/dash3d/type/TileUnderlay.js';
|
||||
import Wall from '#/dash3d/type/Wall.js';
|
||||
import WallDecoration from '#/dash3d/type/WallDecoration.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class Tile extends Linkable {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Model from '../../graphics/Model';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class Wall {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Model from '../../graphics/Model';
|
||||
import Model from '#/graphics/Model.js';
|
||||
|
||||
export default class WallDecoration {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from './Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class HashTable {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from './Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class Hashable extends Linkable {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Linkable from './Linkable';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
export default class LinkList {
|
||||
// constructor
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import Stack from './Stack';
|
||||
import HashTable from './HashTable';
|
||||
import Hashable from './Hashable';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
import HashTable from '#/datastruct/HashTable.js';
|
||||
import Stack from '#/datastruct/Stack.js';
|
||||
|
||||
export default class LruCache {
|
||||
// constructor
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Hashable from './Hashable';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
export default class Stack {
|
||||
readonly head: Hashable;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class AnimBase {
|
||||
static instances: AnimBase[] = [];
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import AnimBase from './AnimBase';
|
||||
import Packet from '../io/Packet';
|
||||
import AnimBase from '#/graphics/AnimBase.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class AnimFrame {
|
||||
static instances: AnimFrame[] = [];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
export const canvas: HTMLCanvasElement = document.getElementById('canvas') as HTMLCanvasElement;
|
||||
export const canvas2d: CanvasRenderingContext2D = canvas.getContext('2d', {willReadFrequently: true})!;
|
||||
export const canvas2d: CanvasRenderingContext2D = canvas.getContext('2d', { willReadFrequently: true })!;
|
||||
|
||||
export const jpegCanvas: HTMLCanvasElement = document.createElement('canvas');
|
||||
export const jpegImg: HTMLImageElement = document.createElement('img');
|
||||
export const jpeg2d: CanvasRenderingContext2D = jpegCanvas.getContext('2d', {willReadFrequently: true})!;
|
||||
export const jpeg2d: CanvasRenderingContext2D = jpegCanvas.getContext('2d', { willReadFrequently: true })!;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
export default class Draw2D extends Hashable {
|
||||
static pixels: Int32Array = new Int32Array();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import Draw2D from './Draw2D';
|
||||
import Pix8 from './Pix8';
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import {Int32Array2d, TypedArray1d} from '../util/Arrays';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Pix8 from '#/graphics/Pix8.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import { Int32Array2d, TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
// noinspection JSSuspiciousNameCombination,DuplicatedCode
|
||||
export default class Draw3D extends Draw2D {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {jpeg2d, jpegCanvas, jpegImg} from './Canvas';
|
||||
import { jpeg2d, jpegCanvas, jpegImg } from '#/graphics/Canvas.js';
|
||||
|
||||
export const decodeJpeg = async (data: Uint8Array): Promise<ImageData> => {
|
||||
if (data[0] !== 0xff) {
|
||||
@@ -7,7 +7,7 @@ export const decodeJpeg = async (data: Uint8Array): Promise<ImageData> => {
|
||||
}
|
||||
|
||||
URL.revokeObjectURL(jpegImg.src); // Remove previous decoded jpeg.
|
||||
jpegImg.src = URL.createObjectURL(new Blob([data], {type: 'image/jpeg'}));
|
||||
jpegImg.src = URL.createObjectURL(new Blob([data], { type: 'image/jpeg' }));
|
||||
|
||||
// wait for img to load
|
||||
await new Promise<void>((resolve): (() => void) => (jpegImg.onload = (): void => resolve()));
|
||||
|
||||
+16
-15
@@ -1,13 +1,14 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import AnimBase from '#/graphics/AnimBase.js';
|
||||
import AnimFrame from '#/graphics/AnimFrame.js';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import Draw3D from '#/graphics/Draw3D.js';
|
||||
|
||||
import Draw2D from './Draw2D';
|
||||
import Draw3D from './Draw3D';
|
||||
import AnimFrame from './AnimFrame';
|
||||
import AnimBase from './AnimBase';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
import {Int32Array2d, TypedArray1d} from '../util/Arrays';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
import { Int32Array2d, TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
class Metadata {
|
||||
vertexCount: number = 0;
|
||||
@@ -901,7 +902,7 @@ export default class Model extends Hashable {
|
||||
identical = vertexCount++;
|
||||
}
|
||||
|
||||
return {vertex: identical, vertexCount};
|
||||
return { vertex: identical, vertexCount };
|
||||
};
|
||||
|
||||
for (let i: number = 0; i < count; i++) {
|
||||
@@ -954,11 +955,11 @@ export default class Model extends Hashable {
|
||||
if (model.faceColor) {
|
||||
faceColor[faceCount] = model.faceColor[face];
|
||||
}
|
||||
const a: {vertex: number; vertexCount: number} = addVertex(model, model.faceVertexA[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const a: { vertex: number; vertexCount: number } = addVertex(model, model.faceVertexA[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = a.vertexCount;
|
||||
const b: {vertex: number; vertexCount: number} = addVertex(model, model.faceVertexB[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const b: { vertex: number; vertexCount: number } = addVertex(model, model.faceVertexB[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = b.vertexCount;
|
||||
const c: {vertex: number; vertexCount: number} = addVertex(model, model.faceVertexC[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const c: { vertex: number; vertexCount: number } = addVertex(model, model.faceVertexC[face], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = c.vertexCount;
|
||||
faceVertexA[faceCount] = a.vertex;
|
||||
faceVertexB[faceCount] = b.vertex;
|
||||
@@ -967,11 +968,11 @@ export default class Model extends Hashable {
|
||||
}
|
||||
|
||||
for (let f: number = 0; f < model.texturedFaceCount; f++) {
|
||||
const a: {vertex: number; vertexCount: number} = addVertex(model, model.texturedVertexA[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const a: { vertex: number; vertexCount: number } = addVertex(model, model.texturedVertexA[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = a.vertexCount;
|
||||
const b: {vertex: number; vertexCount: number} = addVertex(model, model.texturedVertexB[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const b: { vertex: number; vertexCount: number } = addVertex(model, model.texturedVertexB[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = b.vertexCount;
|
||||
const c: {vertex: number; vertexCount: number} = addVertex(model, model.texturedVertexC[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
const c: { vertex: number; vertexCount: number } = addVertex(model, model.texturedVertexC[f], vertexX, vertexY, vertexZ, vertexLabel, vertexCount);
|
||||
vertexCount = c.vertexCount;
|
||||
texturedVertexA[texturedFaceCount] = a.vertex;
|
||||
texturedVertexB[texturedFaceCount] = b.vertex;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import Draw2D from './Draw2D';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
import { decodeJpeg } from '#/graphics/Jpeg.js';
|
||||
import Pix8 from '#/graphics/Pix8.js';
|
||||
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
|
||||
import {decodeJpeg} from './Jpeg';
|
||||
import Pix8 from './Pix8';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class Pix24 extends Hashable {
|
||||
// constructor
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import Draw2D from './Draw2D';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
// identical to Pix24 except the image is indexed by a palette
|
||||
export default class Pix8 extends Hashable {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import Draw2D from './Draw2D';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
import JavaRandom from '../util/JavaRandom';
|
||||
import Colors from './Colors';
|
||||
import Colors from '#/graphics/Colors.js';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import JavaRandom from '#/util/JavaRandom.js';
|
||||
|
||||
export default class PixFont extends Hashable {
|
||||
static readonly CHARSET: string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!"£$%^&*()-_=+[{]};:\'@#~,<.>/?\\| ';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Draw2D from './Draw2D';
|
||||
import {canvas2d} from './Canvas';
|
||||
import { canvas2d } from '#/graphics/Canvas.js';
|
||||
import Draw2D from '#/graphics/Draw2D.js';
|
||||
|
||||
export default class PixMap {
|
||||
// constructor
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import BZ2Wasm from '../3rdparty/bzip2-wasm.js';
|
||||
import BZ2Wasm from '#/3rdparty/bzip2-wasm.js';
|
||||
|
||||
const BZip2 = new BZ2Wasm();
|
||||
await BZip2.init();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import Linkable from '../datastruct/Linkable';
|
||||
import {sleep} from '../util/JsUtil';
|
||||
import LinkList from '#/datastruct/LinkList.js';
|
||||
import Linkable from '#/datastruct/Linkable.js';
|
||||
|
||||
import { sleep } from '#/util/JsUtil.js';
|
||||
|
||||
export type Socket = {
|
||||
host: string;
|
||||
@@ -60,7 +61,7 @@ export default class ClientStream {
|
||||
}
|
||||
|
||||
async read(): Promise<number> {
|
||||
return this.closed ? 0 : this.wsin.fastByte() ?? (await this.wsin.slowByte());
|
||||
return this.closed ? 0 : (this.wsin.fastByte() ?? (await this.wsin.slowByte()));
|
||||
}
|
||||
|
||||
async readBytes(dst: Uint8Array, off: number, len: number): Promise<void> {
|
||||
|
||||
@@ -1,266 +0,0 @@
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import Linkable from '../datastruct/Linkable';
|
||||
import {sleep} from '../util/JsUtil';
|
||||
|
||||
export default class ClientWorkerStream {
|
||||
// constructor
|
||||
private readonly worker: Worker;
|
||||
public wwin: WorkerReader;
|
||||
private readonly wwout: WorkerWriter;
|
||||
|
||||
// runtime
|
||||
private closed: boolean = false;
|
||||
private ioerror: boolean = false;
|
||||
|
||||
constructor(worker: Worker, uniqueId: string) {
|
||||
this.worker = worker;
|
||||
this.worker.onerror = this.onerror;
|
||||
this.worker.onmessageerror = this.onmessageerror;
|
||||
this.wwin = new WorkerReader(5000);
|
||||
this.wwout = new WorkerWriter(this.worker, 5000, uniqueId);
|
||||
this.worker.postMessage({type: 'connection', id: uniqueId});
|
||||
}
|
||||
|
||||
get available(): number {
|
||||
return this.closed ? 0 : this.wwin.available;
|
||||
}
|
||||
|
||||
write(src: Uint8Array, len: number): void {
|
||||
this.wwout.write(src, len);
|
||||
}
|
||||
|
||||
async read(): Promise<number> {
|
||||
return this.closed ? 0 : this.wwin.fastByte() ?? (await this.wwin.slowByte());
|
||||
}
|
||||
|
||||
async readBytes(dst: Uint8Array, off: number, len: number): Promise<void> {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
while (len > 0) {
|
||||
const read: Uint8Array = this.wwin.fastBytes(dst, off, len) ?? (await this.wwin.slowBytes(dst, off, len));
|
||||
if (read.length <= 0) {
|
||||
throw new Error('EOF');
|
||||
}
|
||||
off += read.length;
|
||||
len -= read.length;
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.closed = true;
|
||||
this.wwin.close();
|
||||
this.wwout.close();
|
||||
console.log('connection close!');
|
||||
if (this.ioerror) {
|
||||
console.log('connection error!');
|
||||
}
|
||||
}
|
||||
|
||||
private onerror = (event: Event): void => {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.ioerror = true;
|
||||
this.close();
|
||||
};
|
||||
|
||||
private onmessageerror = (event: MessageEvent): void => {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
this.ioerror = true;
|
||||
this.close();
|
||||
};
|
||||
}
|
||||
|
||||
class WorkerWriter {
|
||||
// constructor
|
||||
private readonly worker: Worker;
|
||||
private readonly limit: number;
|
||||
private readonly uniqueId: string;
|
||||
|
||||
private closed: boolean = false;
|
||||
private ioerror: boolean = false;
|
||||
|
||||
constructor(socket: Worker, limit: number, uniqueId: string) {
|
||||
this.worker = socket;
|
||||
this.limit = limit;
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
|
||||
write(src: Uint8Array, len: number): void {
|
||||
if (this.closed) {
|
||||
return;
|
||||
}
|
||||
if (this.ioerror) {
|
||||
this.ioerror = false;
|
||||
throw new Error('Error in writer thread');
|
||||
}
|
||||
if (len > this.limit || src.length > this.limit) {
|
||||
throw new Error('buffer overflow');
|
||||
}
|
||||
try {
|
||||
this.worker.postMessage({type: 'data', data: src.subarray(0, len), id: this.uniqueId});
|
||||
} catch (e) {
|
||||
this.ioerror = true;
|
||||
}
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.closed = true;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkerEvent extends Linkable {
|
||||
private readonly bytes: Uint8Array;
|
||||
private position: number;
|
||||
|
||||
constructor(bytes: Uint8Array) {
|
||||
super();
|
||||
this.bytes = bytes;
|
||||
this.position = 0;
|
||||
}
|
||||
|
||||
get available(): number {
|
||||
return this.bytes.length - this.position;
|
||||
}
|
||||
|
||||
get read(): number {
|
||||
return this.bytes[this.position++];
|
||||
}
|
||||
|
||||
get len(): number {
|
||||
return this.bytes.length;
|
||||
}
|
||||
}
|
||||
|
||||
class WorkerReader {
|
||||
// constructor
|
||||
private readonly limit: number;
|
||||
|
||||
// runtime
|
||||
private queue: LinkList = new LinkList();
|
||||
private event: WorkerEvent | null = null;
|
||||
private callback: ((data: WorkerEvent | null) => void) | null = null;
|
||||
private total: number = 0;
|
||||
private closed: boolean = false;
|
||||
|
||||
constructor(limit: number) {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
get available(): number {
|
||||
return this.total;
|
||||
}
|
||||
|
||||
public onmessage = (e: MessageEvent): void => {
|
||||
const msg: {type: string; data: Uint8Array | Array<number>; id: string} = typeof e.data === 'string' ? JSON.parse(e.data) : e;
|
||||
if (msg.type !== 'data') {
|
||||
console.error('Unexpected message type: ', msg.type);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader is closed!');
|
||||
}
|
||||
const event: WorkerEvent = new WorkerEvent(new Uint8Array(msg.data));
|
||||
if (this.event) {
|
||||
this.queue.addTail(event);
|
||||
} else {
|
||||
this.event = event;
|
||||
}
|
||||
this.total += event.len;
|
||||
if (!this.callback) {
|
||||
return;
|
||||
}
|
||||
this.callback(this.event);
|
||||
this.callback = null;
|
||||
// check for the overflow after the callback
|
||||
if (this.total > this.limit) {
|
||||
throw new Error('buffer overflow');
|
||||
}
|
||||
};
|
||||
|
||||
private readFastByte(): number | null {
|
||||
if (this.event && this.event.available > 0) {
|
||||
return this.event.read;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private async readSlowByte(len: number): Promise<number> {
|
||||
this.event = this.queue.removeHead() as WorkerEvent | null;
|
||||
while (this.total < len) {
|
||||
await Promise.race([
|
||||
new Promise((resolve): ((value: PromiseLike<((data: WorkerEvent | null) => void) | null>) => void) => (this.callback = resolve)),
|
||||
sleep(2000).then((): void => {
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader closed while reading.');
|
||||
}
|
||||
})
|
||||
]);
|
||||
}
|
||||
return this.event ? this.event.read : this.readSlowByte(len);
|
||||
}
|
||||
|
||||
fastBytes(dst: Uint8Array, off: number, len: number): Uint8Array | null {
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader is closed!');
|
||||
}
|
||||
if (!(this.event && this.event.available >= len)) {
|
||||
return null;
|
||||
}
|
||||
while (len > 0) {
|
||||
const fast: number | null = this.readFastByte();
|
||||
if (fast === null) {
|
||||
throw new Error('EOF - tried to read a fast byte when there was not enough immediate bytes.');
|
||||
}
|
||||
dst[off++] = fast;
|
||||
this.total--;
|
||||
len--;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
async slowBytes(dst: Uint8Array, off: number, len: number): Promise<Uint8Array> {
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader is closed!');
|
||||
}
|
||||
while (len > 0) {
|
||||
dst[off++] = this.readFastByte() ?? (await this.readSlowByte(len));
|
||||
this.total--;
|
||||
len--;
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
fastByte(): number | null {
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader is closed!');
|
||||
}
|
||||
const fast: number | null = this.readFastByte();
|
||||
if (fast === null) {
|
||||
return null;
|
||||
}
|
||||
this.total--;
|
||||
return fast;
|
||||
}
|
||||
|
||||
async slowByte(): Promise<number> {
|
||||
if (this.closed) {
|
||||
throw new Error('WorkerReader is closed!');
|
||||
}
|
||||
const slow: number = await this.readSlowByte(1);
|
||||
this.total--;
|
||||
return slow;
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.closed = true;
|
||||
this.callback = null;
|
||||
this.total = 0;
|
||||
this.event = null;
|
||||
this.queue.clear();
|
||||
}
|
||||
}
|
||||
+4
-6
@@ -42,7 +42,7 @@ export default class Database {
|
||||
resolve(undefined);
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
async cachesave(name: string, src: Uint8Array) {
|
||||
return await new Promise<void>((resolve, reject): void => {
|
||||
@@ -58,13 +58,11 @@ export default class Database {
|
||||
reject();
|
||||
};
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
private onclose = (event: Event): void => {
|
||||
};
|
||||
private onclose = (event: Event): void => {};
|
||||
|
||||
private onerror = (event: Event): void => {
|
||||
};
|
||||
private onerror = (event: Event): void => {};
|
||||
|
||||
private genHash = (str: string): number => {
|
||||
const trimmed: string = str.trim();
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import BZip2 from './BZip2.ts';
|
||||
import Packet from './Packet';
|
||||
import BZip2 from '#/io/BZip2.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class Jagfile {
|
||||
static genHash = (name: string): number => {
|
||||
|
||||
+6
-4
@@ -1,7 +1,9 @@
|
||||
import {bigIntModPow, bigIntToBytes, bytesToBigInt} from '../util/JsUtil';
|
||||
import Isaac from './Isaac';
|
||||
import LinkList from '../datastruct/LinkList';
|
||||
import Hashable from '../datastruct/Hashable';
|
||||
import Hashable from '#/datastruct/Hashable.js';
|
||||
import LinkList from '#/datastruct/LinkList.js';
|
||||
|
||||
import Isaac from '#/io/Isaac.js';
|
||||
|
||||
import { bigIntModPow, bigIntToBytes, bytesToBigInt } from '#/util/JsUtil.js';
|
||||
|
||||
export default class Packet extends Hashable {
|
||||
private static readonly CRC32_POLYNOMIAL: number = 0xedb88320;
|
||||
|
||||
@@ -1,118 +0,0 @@
|
||||
export class Host {
|
||||
private peers: Map<string, RTCDataChannel> = new Map();
|
||||
private worker: Worker;
|
||||
public uniqueId: string = self.isSecureContext ? self.crypto.randomUUID() : '0';
|
||||
|
||||
constructor(worker: Worker) {
|
||||
this.worker = worker;
|
||||
}
|
||||
|
||||
async setupPeerConnection(): Promise<void> {
|
||||
const pc: RTCPeerConnection = new RTCPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]});
|
||||
const dc: RTCDataChannel = pc.createDataChannel('channel');
|
||||
const id: string = crypto.randomUUID();
|
||||
this.peers.set(id, dc);
|
||||
|
||||
await pc.setLocalDescription(await pc.createOffer());
|
||||
|
||||
pc.onicegatheringstatechange = async (): Promise<void> => {
|
||||
if (pc.iceGatheringState === 'complete') {
|
||||
if (self.isSecureContext) {
|
||||
await navigator.clipboard.writeText(JSON.stringify(pc.localDescription));
|
||||
} else {
|
||||
console.log(JSON.stringify(pc.localDescription));
|
||||
}
|
||||
|
||||
let answer: string | null;
|
||||
try {
|
||||
while ((answer = prompt('Offer copied to clipboard, paste answer here')) === null);
|
||||
pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(answer)));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dc.onopen = (): void => {
|
||||
dc.send(JSON.stringify({type: 'id', id: id}));
|
||||
console.log('Connected to peer!');
|
||||
};
|
||||
|
||||
dc.onerror = (e): void => {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
dc.onmessage = (e: MessageEvent): void => {
|
||||
const msg: {type: string; data: object; id: string} = JSON.parse(e.data);
|
||||
|
||||
if (msg.data) {
|
||||
msg.data = Object.values(msg.data);
|
||||
}
|
||||
|
||||
if (this.worker) {
|
||||
this.worker.postMessage(msg);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public postMessage(e: MessageEvent): void {
|
||||
const dc: RTCDataChannel | undefined = this.peers.get(e.data.id);
|
||||
const msg: {type: string; data: Uint8Array | object; id: string} = e.data;
|
||||
|
||||
if (msg.data) {
|
||||
msg.data = Array.from(e.data.data);
|
||||
}
|
||||
if (dc && dc.readyState === 'open') {
|
||||
dc.send(JSON.stringify(msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Peer {
|
||||
public pc: RTCPeerConnection;
|
||||
public dc: RTCDataChannel | undefined = undefined;
|
||||
public uniqueId: string | undefined;
|
||||
|
||||
constructor(worker: Worker) {
|
||||
this.pc = new RTCPeerConnection({iceServers: [{urls: 'stun:stun.l.google.com:19302'}]});
|
||||
|
||||
this.pc.ondatachannel = (e: RTCDataChannelEvent): void => {
|
||||
this.dc = e.channel;
|
||||
|
||||
this.dc.onopen = (): void => {
|
||||
console.log('Connected to host!');
|
||||
};
|
||||
|
||||
this.dc.onerror = (e): void => {
|
||||
console.error(e);
|
||||
};
|
||||
|
||||
this.dc.onmessage = (e: MessageEvent): void => {
|
||||
if (!this.uniqueId) {
|
||||
const msg: {type: string; data: Array<number>; id: string} = JSON.parse(e.data);
|
||||
if (msg.type === 'id') {
|
||||
this.uniqueId = msg.id;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (worker.onmessage) worker.onmessage(e);
|
||||
};
|
||||
};
|
||||
|
||||
this.pc.onicegatheringstatechange = async (): Promise<void> => {
|
||||
if (this.pc.iceGatheringState === 'complete') {
|
||||
if (self.isSecureContext) {
|
||||
await navigator.clipboard.writeText(JSON.stringify(this.pc.localDescription));
|
||||
} else {
|
||||
console.log(JSON.stringify(this.pc.localDescription));
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public async handleOffer(offer: string): Promise<void> {
|
||||
await this.pc.setRemoteDescription(new RTCSessionDescription(JSON.parse(offer)));
|
||||
await this.pc.setLocalDescription(await this.pc.createAnswer());
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import Packet from '../io/Packet';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class SoundEnvelope {
|
||||
start: number = 0;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import SoundEnvelope from './SoundEnvelope';
|
||||
import Packet from '../io/Packet';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import SoundEnvelope from '#/sound/SoundEnvelope.js';
|
||||
|
||||
export default class SoundTone {
|
||||
static buffer: Int32Array | null = null;
|
||||
|
||||
+6
-4
@@ -1,7 +1,9 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import SoundTone from './SoundTone';
|
||||
import Packet from '../io/Packet';
|
||||
import {TypedArray1d} from '../util/Arrays';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
import SoundTone from '#/sound/SoundTone.js';
|
||||
|
||||
import { TypedArray1d } from '#/util/Arrays.js';
|
||||
|
||||
export default class Wave {
|
||||
static readonly delays: Int32Array = new Int32Array(1000);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import './MidiUtil.js';
|
||||
import '#/util/MidiUtil.js';
|
||||
|
||||
let waveGain;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import TinyMidiPCM from '../3rdparty/tinymidipcm.js';
|
||||
import TinyMidiPCM from '#/3rdparty/tinymidipcm.js';
|
||||
|
||||
// Fix iOS Audio Context by Blake Kus https://gist.github.com/kus/3f01d60569eeadefe3a1
|
||||
// MIT license
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import Jagfile from '../io/Jagfile';
|
||||
import Packet from '../io/Packet';
|
||||
import Jagfile from '#/io/Jagfile.js';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class WordFilter {
|
||||
private static readonly PERIOD: Uint16Array = new Uint16Array(
|
||||
@@ -264,7 +264,7 @@ export default class WordFilter {
|
||||
const domainLength: number = domain.length;
|
||||
const charsLength: number = chars.length;
|
||||
for (let index: number = 0; index <= charsLength - domainLength; index++) {
|
||||
const {matched, currentIndex} = this.findMatchingDomain(index, domain, chars);
|
||||
const { matched, currentIndex } = this.findMatchingDomain(index, domain, chars);
|
||||
if (!matched) {
|
||||
continue;
|
||||
}
|
||||
@@ -312,7 +312,7 @@ export default class WordFilter {
|
||||
}
|
||||
}
|
||||
|
||||
return {matched: domainIndex >= domainLength, currentIndex};
|
||||
return { matched: domainIndex >= domainLength, currentIndex };
|
||||
};
|
||||
|
||||
private static filterBadCombinations = (combos: number[][] | null, chars: string[], bads: Uint16Array): void => {
|
||||
@@ -321,7 +321,7 @@ export default class WordFilter {
|
||||
}
|
||||
for (let startIndex: number = 0; startIndex <= chars.length - bads.length; startIndex++) {
|
||||
let currentIndex: number = startIndex;
|
||||
const {currentIndex: updatedCurrentIndex, badIndex, hasSymbol, hasNumber, hasDigit} = this.processBadCharacters(chars, bads, currentIndex);
|
||||
const { currentIndex: updatedCurrentIndex, badIndex, hasSymbol, hasNumber, hasDigit } = this.processBadCharacters(chars, bads, currentIndex);
|
||||
currentIndex = updatedCurrentIndex;
|
||||
let currentChar: string = chars[currentIndex];
|
||||
let nextChar: string = currentIndex + 1 < chars.length ? chars[currentIndex + 1] : '\u0000';
|
||||
@@ -466,7 +466,7 @@ export default class WordFilter {
|
||||
}
|
||||
}
|
||||
}
|
||||
return {currentIndex: index, badIndex, hasSymbol, hasNumber, hasDigit};
|
||||
return { currentIndex: index, badIndex, hasSymbol, hasNumber, hasDigit };
|
||||
};
|
||||
|
||||
private static getEmulatedBadCharLen = (nextChar: string, badChar: string, currentChar: string): number => {
|
||||
@@ -678,7 +678,7 @@ export default class WordFilter {
|
||||
return;
|
||||
}
|
||||
for (let index: number = 0; index <= chars.length - tld.length; index++) {
|
||||
const {currentIndex, tldIndex} = this.processTlds(chars, tld, index);
|
||||
const { currentIndex, tldIndex } = this.processTlds(chars, tld, index);
|
||||
if (tldIndex < tld.length) {
|
||||
continue;
|
||||
}
|
||||
@@ -793,7 +793,7 @@ export default class WordFilter {
|
||||
}
|
||||
}
|
||||
}
|
||||
return {currentIndex, tldIndex};
|
||||
return { currentIndex, tldIndex };
|
||||
};
|
||||
|
||||
private static isSymbol = (char: string): boolean => !this.isAlpha(char) && !this.isNumerical(char);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import Packet from '../io/Packet';
|
||||
import Packet from '#/io/Packet.js';
|
||||
|
||||
export default class WordPack {
|
||||
// prettier-ignore
|
||||
|
||||
+28
-22
@@ -1,27 +1,33 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext", "DOM"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
"baseUrl": "src",
|
||||
"paths": {
|
||||
"#3rdparty/*": ["3rdparty/*"],
|
||||
"#/*": ["*"]
|
||||
},
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user