Skip to content

Commit fd642f0

Browse files
authored
Merge pull request #132 from tiny-devs/dev
Tab info and client fixes
2 parents 6679a25 + 1edb67b commit fd642f0

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

client/public/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/entities/Player.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,28 +149,28 @@ export class Player {
149149
switch (direction) {
150150
case Direction.Up:
151151
if (!this.isOnBorder(collisionShape, +this.x, +this.y - 1)) {
152-
if (collisionShape[+this.y - 1][+this.x]) {
152+
if (collisionShape[+this.y - 1][+this.x] !== 0 && collisionShape[+this.y - 1][+this.x] !== -1) {
153153
valid = false
154154
}
155155
}
156156
break
157157
case Direction.Down:
158158
if (!this.isOnBorder(collisionShape, +this.x, +this.y + 1)) {
159-
if (collisionShape[+this.y + 1][+this.x]) {
159+
if (collisionShape[+this.y + 1][+this.x] !== 0 && collisionShape[+this.y + 1][+this.x] !== -1) {
160160
valid = false
161161
}
162162
}
163163
break
164164
case Direction.Left:
165165
if (!this.isOnBorder(collisionShape, +this.x - 1, +this.y)) {
166-
if (collisionShape[+this.y][+this.x - 1]) {
166+
if (collisionShape[+this.y][+this.x - 1] !== 0 && collisionShape[+this.y][+this.x - 1] !== -1) {
167167
valid = false
168168
}
169169
}
170170
break
171171
case Direction.Right:
172172
if (!this.isOnBorder(collisionShape, +this.x + 1, +this.y)) {
173-
if (collisionShape[+this.y][+this.x + 1]) {
173+
if (collisionShape[+this.y][+this.x + 1] !== 0 && collisionShape[+this.y][+this.x + 1] !== -1) {
174174
valid = false
175175
}
176176
}

client/src/startup/GameClient.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export class GameClient {
7070
private adminPassword: string = ''
7171
private afkTimeout: number = 0
7272
private afkInterval: number = 240000 // 4min
73+
private afkTabMinCountdown: number = 9
74+
private afkTabSecCountdown: number = 59
7375

7476
constructor(game: Game, clientConfigs: PlayerConfig, mainElements: Main) {
7577
document.onkeydown = this.checkKey.bind(this)
@@ -187,6 +189,8 @@ export class GameClient {
187189
this.mobileMovement()
188190
}
189191

192+
this.showStatusOnTab()
193+
190194
this.game = game
191195
this.ws = null
192196
this.loggedIn = false
@@ -286,6 +290,8 @@ export class GameClient {
286290
}
287291

288292
checkKey(e: Partial<KeyboardEvent>) {
293+
this.afkTabMinCountdown = 9
294+
this.afkTabSecCountdown = 59
289295
this.restartAfkTimer()
290296
if (this.canMove) {
291297
this.delayMove()
@@ -566,6 +572,34 @@ export class GameClient {
566572
}, this.afkInterval);
567573
}
568574

575+
showStatusOnTab() {
576+
setTimeout(async () => {
577+
this.afkCountdownTick()
578+
if (document.hidden) {
579+
const player = this.game.spritesLayer.getPlayerById(this.playerId)!
580+
document.title = `AFK: ${this.afkTabMinCountdown}:${this.afkTabSecCountdown} HP: ${player.hp}`;
581+
} else {
582+
document.title = 'TLO'
583+
}
584+
585+
this.showStatusOnTab()
586+
}, 900);
587+
}
588+
589+
afkCountdownTick() {
590+
if (this.afkTabMinCountdown > 0 && this.afkTabSecCountdown == 0) {
591+
this.afkTabMinCountdown -= 1
592+
}
593+
594+
if (this.afkTabSecCountdown == 0) {
595+
if (this.afkTabMinCountdown > 0) {
596+
this.afkTabSecCountdown = 59
597+
}
598+
} else {
599+
this.afkTabSecCountdown -= 1
600+
}
601+
}
602+
569603
pingPong() {
570604
this.ws!.send(`${Command.Ping}`)
571605

0 commit comments

Comments
 (0)