Skip to content

Commit

Permalink
feat: better way call player callback
Browse files Browse the repository at this point in the history
  • Loading branch information
dockfries committed Aug 29, 2022
1 parent 17b12c3 commit 452c4d0
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/controllers/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class BasePlayer {
private lastFps = 0;

public constructor() {
// Each instance can be called to callbacks, so you can split the logic.
OnPlayerConnect((playerid: number): void => {
if (playerid === this.id) this.OnConnect();
});
Expand Down Expand Up @@ -78,12 +79,9 @@ OnPlayerConnect((playerid: number): void => {
const p = new BasePlayer();
p.id = playerid;
BasePlayer.players.push(p);
// p.OnConnect();
});

OnPlayerDisconnect((playerid: number): void => {
const p = BasePlayer.findPlayerIdx(playerid);
if (p === -1) return;
// BasePlayer.players[p].OnDisconnect();
BasePlayer.players.splice(p, 1);
const pIdx = BasePlayer.findPlayerIdx(playerid);
if (pIdx !== -1) BasePlayer.players.splice(pIdx, 1);
});

0 comments on commit 452c4d0

Please sign in to comment.