Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/apis/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Player extends EventEmitter {
#mouseLock = false;
#mouseCanvasPos = new Vector(0, 0);
#mousePos = new Vector(0, 0);

#username = _window.localStorage.name;
#gamemode = _window.localStorage.gamemode;
#level = 1;
#tank = 'Tank';
Expand Down Expand Up @@ -74,6 +76,14 @@ class Player extends EventEmitter {
},
});

// username
_window.input.trySpawn = new Proxy(_window.input.trySpawn, {
apply: (target, thisArg, args) => {
this.#username = args[0];
return Reflect.apply(target, thisArg, args);
},
});

// tank and level event listener
CanvasKit.hookCtx('fillText', (target, thisArg, args) => {
const text = args[0];
Expand Down Expand Up @@ -151,16 +161,12 @@ class Player extends EventEmitter {
gamepad.connected = value;
}

async spawn(name: string, attempts: number = 0): Promise<void> {
if (!this.#isDead) return;

if (name !== undefined) (document.getElementById('textInput') as HTMLInputElement).value = name;

await input.keyPress(13);

await sleep(250);
async spawn(name: string = this.#username): Promise<void> {
if (!this.#isDead) {
return;
}

await this.spawn(name, attempts + 1);
_window.input.trySpawn(name);
}

async upgrade_stat(id: number, level: number): Promise<void> {
Expand Down
13 changes: 5 additions & 8 deletions src/core/globals.d.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
interface Input {
mouse: (x: number, y: number) => void;
blur: () => void;
execute: (v: string) => void;
get_convar: (key: string) => null | string;
keyDown: (key: string | number) => void;
keyUp: (key: string | number) => void;
blur: () => void;
wheel: Function;
prevent_right_click: (value: boolean) => void;
flushInputHooks: Function;
mouse: (x: number, y: number) => void;
set_convar: (key: string, value: string) => boolean;
get_convar: (key: string) => null | string;
execute: (v: string) => void;
print_convar_help: () => void;
should_prevent_unload: () => boolean;
trySpawn: (username: string) => void;
}

declare var input: Input;
Expand Down