Skip to content

Commit

Permalink
feat: chat command to change font era from java client (#9)
Browse files Browse the repository at this point in the history
* feat: chat command to change font era from java client

* formatting
  • Loading branch information
lesleyrs authored May 24, 2024
1 parent caf5a50 commit 9792597
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Create your account on the 2004scape website.

`::debug` Shows performance metrics (FPS, frame times and more).

`::chat` Changes between 3 different chat font eras.

`::fps` Set a targeted FPS (ex. `::fps 30`)

A developer can utilize the debug command for development purposes.
Expand Down
1 change: 1 addition & 0 deletions src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export abstract class Client extends GameShell {
static serverAddress: string = '';
static httpAddress: string = '';
static showDebug: boolean = false;
static chatEra: number = 2; // 0 - early beta, 1 - late beta, 2 - launch
static githubRepository: string = 'https://raw.githubusercontent.com/2004scape/Server/main';

// original keys:
Expand Down
20 changes: 17 additions & 3 deletions src/js/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2373,7 +2373,10 @@ class Game extends Client {
} else if (this.chatInterfaceId !== -1) {
this.drawInterface(ComType.instances[this.chatInterfaceId], 0, 0, 0);
} else if (this.stickyChatInterfaceId === -1) {
const font: PixFont | null = this.fontPlain12;
let font: PixFont | null = this.fontPlain12;
if (Client.chatEra === 0) {
font = this.fontQuill8;
}
let line: number = 0;
Draw2D.setBounds(0, 0, 463, 77);
for (let i: number = 0; i < 100; i++) {
Expand Down Expand Up @@ -2442,8 +2445,17 @@ class Game extends Client {
this.chatScrollHeight = 78;
}
this.drawScrollbar(463, 0, this.chatScrollHeight - this.chatScrollOffset - 77, this.chatScrollHeight, 77);
font?.drawString(4, 90, JString.formatName(this.username) + ':', Colors.BLACK);
font?.drawString(font.stringWidth(this.username + ': ') + 6, 90, this.chatTyped + '*', Colors.BLUE);
if (Client.chatEra == 0) {
// 186-194?
font?.drawString(3, 90, this.chatTyped + '*', Colors.BLACK);
} else if (Client.chatEra == 1) {
// <204
font?.drawString(3, 90, this.chatTyped + '*', Colors.BLUE);
} else {
// 204+
font?.drawString(4, 90, JString.formatName(this.username) + ':', Colors.BLACK);
font?.drawString(font.stringWidth(this.username + ': ') + 6, 90, this.chatTyped + '*', Colors.BLUE);
}
Draw2D.drawHorizontalLine(0, 77, Colors.BLACK, 479);
} else {
this.drawInterface(ComType.instances[this.stickyChatInterfaceId], 0, 0, 0);
Expand Down Expand Up @@ -4092,6 +4104,8 @@ class Game extends Client {
}
} else if (this.chatTyped === '::debug') {
Client.showDebug = !Client.showDebug;
} else if (this.chatTyped === '::chat') {
Client.chatEra = (Client.chatEra + 1) % 3;
} else if (this.chatTyped.startsWith('::fps ')) {
try {
this.setTargetedFramerate(parseInt(this.chatTyped.substring(6), 10));
Expand Down
11 changes: 5 additions & 6 deletions src/js/mapview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class MapView extends GameShell {
lastOffsetX: number = -1;
lastOffsetZ: number = -1;

shouldClearEmptyTiles: boolean = false
shouldClearEmptyTiles: boolean = false;

readonly keyNames: string[] = [
'General Store',
Expand Down Expand Up @@ -246,8 +246,7 @@ class MapView extends GameShell {

this.floormapColors = new TypedArray2d(this.sizeX, this.sizeZ, 0);
this.averageUnderlayColors();
if (this.shouldClearEmptyTiles)
this.clearEmptyTiles();
if (this.shouldClearEmptyTiles) this.clearEmptyTiles();

this.imageOverview = new Pix24(this.imageOverviewWidth, this.imageOverviewHeight);
this.imageOverview.bind();
Expand Down Expand Up @@ -615,10 +614,10 @@ class MapView extends GameShell {
}

clearEmptyTiles(): void {
for (let x: number = 0; x < this.sizeX; x++ ) {
for (let z: number = 0; z < this.sizeZ; z++ ) {
for (let x: number = 0; x < this.sizeX; x++) {
for (let z: number = 0; z < this.sizeZ; z++) {
if (this.underlayTiles[x][z] == 0 && this.overlayTiles[x][z] == 0) {
this.floormapColors[x][z] = 0
this.floormapColors[x][z] = 0;
}
}
}
Expand Down

0 comments on commit 9792597

Please sign in to comment.