Skip to content

Commit

Permalink
feat: normalize colors
Browse files Browse the repository at this point in the history
  • Loading branch information
ultraviolet-jordan committed Jan 28, 2024
1 parent 569a9f4 commit 623007d
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 169 deletions.
219 changes: 108 additions & 111 deletions src/js/client.ts

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/js/jagex2/config/ObjType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import LruCache from '../datastruct/LruCache';
import Model from '../graphics/Model';
import Draw3D from '../graphics/Draw3D';
import Draw2D from '../graphics/Draw2D';
import Colors from '../graphics/Colors';

export default class ObjType extends ConfigType {
static count: number = 0;
Expand Down Expand Up @@ -123,7 +124,7 @@ export default class ObjType extends ConfigType {

Draw3D.jagged = false;
Draw2D.bind(icon.pixels, 32, 32);
Draw2D.fillRect(0, 0, 32, 32, 0);
Draw2D.fillRect(0, 0, 32, 32, Colors.BLACK);
Draw3D.init2D();

const iModel: Model = obj.getInterfaceModel(1);
Expand Down
29 changes: 29 additions & 0 deletions src/js/jagex2/graphics/Colors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
export default class Colors {
static readonly RED: number = 0xff0000; // 16711680
static readonly GREEN: number = 0xff00; // 65280
static readonly BLUE: number = 0xff; // 255
static readonly YELLOW: number = 0xffff00; // 16776960
static readonly CYAN: number = 0xffff; // 65535
static readonly MAGENTA: number = 0xff00ff; // 16711935
static readonly WHITE: number = 0xffffff; // 16777215
static readonly BLACK: number = 0x0; // 0
static readonly LIGHTRED: number = 0xff9040; // 16748608
static readonly DARKRED: number = 0x800000; // 8388608
static readonly DARKBLUE: number = 0x80; // 128
static readonly ORANGE1: number = 0xffb000; // 16756736
static readonly ORANGE2: number = 0xff7000; // 16740352
static readonly ORANGE3: number = 0xff3000; // 16723968
static readonly GREEN1: number = 0xc0ff00; // 12648192
static readonly GREEN2: number = 0x80ff00; // 8453888
static readonly GREEN3: number = 0x40ff00; // 4259584

// other
static readonly PROGRESS_RED: number = 0x8c1111; // 9179409
static readonly OPTIONS_MENU: number = 0x5d5447; // 6116423
static readonly SCROLLBAR_TRACK: number = 0x23201b; // 2301979
static readonly SCROLLBAR_GRIP_FOREGROUND: number = 0x4d4233; // 5063219
static readonly SCROLLBAR_GRIP_HIGHLIGHT: number = 0x766654; // 7759444
static readonly SCROLLBAR_GRIP_LOWLIGHT: number = 0x332d25; // 3353893
static readonly TRADE_MESSAGE: number = 0x800080; // 8388736
static readonly DUEL_MESSAGE: number = 0xcbb789; // 13350793
}
80 changes: 40 additions & 40 deletions src/js/jagex2/graphics/PixFont.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Jagfile from '../io/Jagfile';
import Packet from '../io/Packet';
import Hashable from '../datastruct/Hashable';
import JavaRandom from '../util/JavaRandom';
import Colors from './Colors';

export default class PixFont extends Hashable {
static CHARSET: number[] = [];
Expand Down Expand Up @@ -140,7 +141,7 @@ export default class PixFont extends Hashable {

if (c !== 94) {
if (shadowed) {
this.copyCharacter(x + this.clipX[c] + 1, y + this.clipY[c] + 1, this.charWidth[c], this.charHeight[c], this.pixels[c], 0);
this.copyCharacter(x + this.clipX[c] + 1, y + this.clipY[c] + 1, this.charWidth[c], this.charHeight[c], this.pixels[c], Colors.BLACK);
}
this.copyCharacter(x + this.clipX[c], y + this.clipY[c], this.charWidth[c], this.charHeight[c], this.pixels[c], color);
}
Expand Down Expand Up @@ -210,7 +211,7 @@ export default class PixFont extends Hashable {
const c: number = PixFont.CHARSET[str.charCodeAt(i)];
if (c !== 94) {
if (shadowed) {
this.drawCharAlpha(x + this.clipX[c] + 1, offY + this.clipY[c] + 1, this.charWidth[c], this.charHeight[c], 0, 192, this.pixels[c]);
this.drawCharAlpha(x + this.clipX[c] + 1, offY + this.clipY[c] + 1, this.charWidth[c], this.charHeight[c], Colors.BLACK, 192, this.pixels[c]);
}

this.drawCharAlpha(x + this.clipX[c], offY + this.clipY[c], this.charWidth[c], this.charHeight[c], color, rand, this.pixels[c]);
Expand All @@ -229,7 +230,7 @@ export default class PixFont extends Hashable {
y = Math.trunc(y);

if (shadowed) {
this.draw(x - this.stringWidth(str) + 1, y + 1, str, 0);
this.draw(x - this.stringWidth(str) + 1, y + 1, str, Colors.BLACK);
}
this.draw(x - this.stringWidth(str), y, str, color);
};
Expand Down Expand Up @@ -457,43 +458,42 @@ export default class PixFont extends Hashable {
};

evaluateTag = (tag: string): number => {
switch (tag) {
case 'red':
return 0xff0000;
case 'gre':
return 0xff00;
case 'blu':
return 0xff;
case 'yel':
return 0xffff00;
case 'cya':
return 0xffff;
case 'mag':
return 0xff00ff;
case 'whi':
return 0xffffff;
case 'bla':
return 0;
case 'lre':
return 0xff9040;
case 'dre':
return 0x800000;
case 'dbl':
return 0x80;
case 'or1':
return 0xffb000;
case 'or2':
return 0xff7000;
case 'or3':
return 0xff3000;
case 'gr1':
return 0xc0ff00;
case 'gr2':
return 0x80ff00;
case 'gr3':
return 0x40ff00;
default:
return 0;
if (tag === 'red') {
return Colors.RED;
} else if (tag === 'gre') {
return Colors.GREEN;
} else if (tag === 'blu') {
return Colors.BLUE;
} else if (tag === 'yel') {
return Colors.YELLOW;
} else if (tag === 'cya') {
return Colors.CYAN;
} else if (tag === 'mag') {
return Colors.MAGENTA;
} else if (tag === 'whi') {
return Colors.WHITE;
} else if (tag === 'bla') {
return Colors.BLACK;
} else if (tag === 'lre') {
return Colors.LIGHTRED;
} else if (tag === 'dre') {
return Colors.DARKRED;
} else if (tag === 'dbl') {
return Colors.DARKBLUE;
} else if (tag === 'or1') {
return Colors.ORANGE1;
} else if (tag === 'or2') {
return Colors.ORANGE2;
} else if (tag === 'or3') {
return Colors.ORANGE3;
} else if (tag === 'gr1') {
return Colors.GREEN1;
} else if (tag === 'gr2') {
return Colors.GREEN2;
} else if (tag === 'gr3') {
return Colors.GREEN3;
} else {
return Colors.BLACK;
}
};

Expand Down
29 changes: 15 additions & 14 deletions src/js/playground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import Packet from './jagex2/io/Packet';
import Wave from './jagex2/sound/Wave';
import Database from './jagex2/io/Database';
import Bzip from './vendor/bzip';
import Colors from './jagex2/graphics/Colors';

class Playground extends GameShell {
static HOST = 'https://w2.225.2004scape.org';
Expand Down Expand Up @@ -152,7 +153,7 @@ class Playground extends GameShell {
// let y = this.b12.fontHeight;
// for (let i = 0; i < FloType.count; i++) {
// let flo = FloType.get(i);
// this.b12.draw(x, y, `${i}: ${flo.name}`, 0xFFFF00);
// this.b12.draw(x, y, `${i}: ${flo.name}`, Colors.YELLOW);

// let textSize = this.b12.getTextWidth(`${i}: ${flo.name}`);

Expand All @@ -176,32 +177,32 @@ class Playground extends GameShell {

// debug
if (this.fontBold12) {
this.fontBold12.drawRight(this.width, this.fontBold12.fontHeight, `FPS: ${this.fps}`, 0xffff00);
this.fontBold12.drawRight(this.width, this.height, `${this.model.pitch},${this.model.yaw},${this.model.roll},${this.camera.pitch},${this.camera.x},${this.camera.z},${this.camera.y}`, 0xffff00);
this.fontBold12.drawRight(this.width, this.fontBold12.fontHeight, `FPS: ${this.fps}`, Colors.YELLOW);
this.fontBold12.drawRight(this.width, this.height, `${this.model.pitch},${this.model.yaw},${this.model.roll},${this.camera.pitch},${this.camera.x},${this.camera.z},${this.camera.y}`, Colors.YELLOW);

// controls
let leftY: number = this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, `Model: ${this.model.id}`, 0xffff00);
this.fontBold12.draw(0, leftY, `Model: ${this.model.id}`, Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'Controls:', 0xffff00);
this.fontBold12.draw(0, leftY, 'Controls:', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'r - reset camera and model rotation + movement speed', 0xffff00);
this.fontBold12.draw(0, leftY, 'r - reset camera and model rotation + movement speed', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, '1 and 2 - change model', 0xffff00);
this.fontBold12.draw(0, leftY, '1 and 2 - change model', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, '[ and ] - adjust movement speed', 0xffff00);
this.fontBold12.draw(0, leftY, '[ and ] - adjust movement speed', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'left and right - adjust model yaw', 0xffff00);
this.fontBold12.draw(0, leftY, 'left and right - adjust model yaw', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'up and down - adjust model pitch', 0xffff00);
this.fontBold12.draw(0, leftY, 'up and down - adjust model pitch', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, '. and / - adjust model roll', 0xffff00);
this.fontBold12.draw(0, leftY, '. and / - adjust model roll', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'w and s - move camera along z axis', 0xffff00);
this.fontBold12.draw(0, leftY, 'w and s - move camera along z axis', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'a and d - move camera along x axis', 0xffff00);
this.fontBold12.draw(0, leftY, 'a and d - move camera along x axis', Colors.YELLOW);
leftY += this.fontBold12.fontHeight;
this.fontBold12.draw(0, leftY, 'q and e - move camera along y axis', 0xffff00);
this.fontBold12.draw(0, leftY, 'q and e - move camera along y axis', Colors.YELLOW);
}

this.drawArea?.draw(0, 0);
Expand Down
7 changes: 4 additions & 3 deletions src/js/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import Wave from './jagex2/sound/Wave';
import Database from './jagex2/io/Database';
import {canvas2d} from './jagex2/graphics/Canvas';
import Bzip from './vendor/bzip';
import Colors from './jagex2/graphics/Colors';

class Viewer extends GameShell {
static HOST: string = 'https://w2.225.2004scape.org';
Expand Down Expand Up @@ -178,7 +179,7 @@ class Viewer extends GameShell {
}

Draw2D.clear();
Draw2D.fillRect(0, 0, this.width, this.height, 0x000000);
Draw2D.fillRect(0, 0, this.width, this.height, Colors.BLACK);

if (this.model.built === null) {
this.model.built = Model.model(this.model.id);
Expand All @@ -188,8 +189,8 @@ class Viewer extends GameShell {
this.model.built.drawSimple(this.model.pitch, this.model.yaw, this.model.roll, this.camera.pitch, this.camera.x, this.camera.y, this.camera.z);

// debug
this.fontBold12?.drawRight(this.width - 1, this.fontBold12.fontHeight, `FPS: ${this.fps}`, 0xffff00);
this.fontBold12?.draw(1, this.fontBold12.fontHeight, `ID: ${this.model.id}`, 0xffff00);
this.fontBold12?.drawRight(this.width - 1, this.fontBold12.fontHeight, `FPS: ${this.fps}`, Colors.YELLOW);
this.fontBold12?.draw(1, this.fontBold12.fontHeight, `ID: ${this.model.id}`, Colors.YELLOW);

this.drawArea?.draw(0, 0);
};
Expand Down

0 comments on commit 623007d

Please sign in to comment.