@@ -15,6 +15,8 @@ class Player extends EventEmitter {
1515 #mouseLock = false ;
1616 #mouseCanvasPos = new Vector ( 0 , 0 ) ;
1717 #mousePos = new Vector ( 0 , 0 ) ;
18+
19+ #username = _window . localStorage . name ;
1820 #gamemode = _window . localStorage . gamemode ;
1921 #level = 1 ;
2022 #tank = 'Tank' ;
@@ -74,6 +76,14 @@ class Player extends EventEmitter {
7476 } ,
7577 } ) ;
7678
79+ // username
80+ _window . input . trySpawn = new Proxy ( _window . input . trySpawn , {
81+ apply : ( target , thisArg , args ) => {
82+ this . #username = args [ 0 ] ;
83+ return Reflect . apply ( target , thisArg , args ) ;
84+ } ,
85+ } ) ;
86+
7787 // tank and level event listener
7888 CanvasKit . hookCtx ( 'fillText' , ( target , thisArg , args ) => {
7989 const text = args [ 0 ] ;
@@ -151,16 +161,12 @@ class Player extends EventEmitter {
151161 gamepad . connected = value ;
152162 }
153163
154- async spawn ( name : string , attempts : number = 0 ) : Promise < void > {
155- if ( ! this . #isDead) return ;
156-
157- if ( name !== undefined ) ( document . getElementById ( 'textInput' ) as HTMLInputElement ) . value = name ;
158-
159- await input . keyPress ( 13 ) ;
160-
161- await sleep ( 250 ) ;
164+ async spawn ( name : string = this . #username) : Promise < void > {
165+ if ( ! this . #isDead) {
166+ return ;
167+ }
162168
163- await this . spawn ( name , attempts + 1 ) ;
169+ _window . input . trySpawn ( name ) ;
164170 }
165171
166172 async upgrade_stat ( id : number , level : number ) : Promise < void > {
0 commit comments