tidepool 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,7 +49,7 @@ class Box {
49
49
  }
50
50
  }
51
51
  }
52
- for (let content of this.contents) {
52
+ for (const content of this.contents) {
53
53
  content.draw(screen, this.x + 1, this.y + 1, this.width - 2);
54
54
  }
55
55
  }
package/dist/screen.d.ts CHANGED
@@ -7,14 +7,18 @@ export declare class TideScreen {
7
7
  components: TideObject[];
8
8
  fps: number | null;
9
9
  updateFunction: (() => void) | null;
10
- constructor(width: number, height: number);
10
+ backgroundColor: string;
11
+ constructor(width: number, height: number, backgroundColor?: string);
11
12
  clearScreen(): void;
12
13
  clearBuffer(): void;
13
14
  addComponent(component: TideObject): void;
14
- renderBuffer(): void;
15
- render(): void;
15
+ private getBackgroundColorCode;
16
+ private renderBuffer;
17
+ applyBackgroundColor(): void;
18
+ private render;
16
19
  setUpdateFunction(fn: () => void): void;
17
20
  setFPS(fps: number): void;
21
+ nextFrame(): void;
18
22
  renderCycle(): void;
19
23
  }
20
24
  //# sourceMappingURL=screen.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;gBAE/B,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAQzC,WAAW;IAIX,WAAW;IAIX,YAAY,CAAC,SAAS,EAAE,UAAU;IAIlC,YAAY;IAMZ,MAAM;IAMN,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,WAAW;CAkBd"}
1
+ {"version":3,"file":"screen.d.ts","sourceRoot":"","sources":["../src/screen.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBAAa,UAAU;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC;IACnB,UAAU,EAAE,UAAU,EAAE,CAAC;IACzB,GAAG,EAAE,MAAM,GAAG,IAAI,CAAQ;IAC1B,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAQ;IAC3C,eAAe,EAAE,MAAM,CAAC;gBAEZ,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe,GAAE,MAAsB;IASlF,WAAW;IAIX,WAAW;IAIX,YAAY,CAAC,SAAS,EAAE,UAAU;IAIlC,OAAO,CAAC,sBAAsB;IAgB9B,OAAO,CAAC,YAAY;IAMpB,oBAAoB;IAUpB,OAAO,CAAC,MAAM;IAOd,iBAAiB,CAAC,EAAE,EAAE,MAAM,IAAI;IAIhC,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,SAAS;IAQT,WAAW;CAkBd"}
package/dist/screen.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TideScreen = void 0;
4
4
  class TideScreen {
5
- constructor(width, height) {
5
+ constructor(width, height, backgroundColor = 'transparent') {
6
6
  this.fps = null;
7
7
  this.updateFunction = null;
8
8
  this.width = width;
@@ -10,6 +10,7 @@ class TideScreen {
10
10
  this.screen = Array.from({ length: height }, () => Array(width).fill(' '));
11
11
  this.buffer = Array.from({ length: height }, () => Array(width).fill(' '));
12
12
  this.components = [];
13
+ this.backgroundColor = backgroundColor;
13
14
  }
14
15
  clearScreen() {
15
16
  this.screen = Array.from({ length: this.height }, () => Array(this.width).fill(' '));
@@ -20,12 +21,36 @@ class TideScreen {
20
21
  addComponent(component) {
21
22
  this.components.push(component);
22
23
  }
24
+ getBackgroundColorCode(color) {
25
+ const colors = {
26
+ black: '\x1b[40m',
27
+ red: '\x1b[41m',
28
+ green: '\x1b[42m',
29
+ yellow: '\x1b[43m',
30
+ blue: '\x1b[44m',
31
+ magenta: '\x1b[45m',
32
+ cyan: '\x1b[46m',
33
+ white: '\x1b[47m',
34
+ transparent: '\x1b[49m',
35
+ };
36
+ return colors[color.toLowerCase()] || colors['black'];
37
+ }
23
38
  renderBuffer() {
24
39
  this.clearBuffer();
25
40
  this.components.sort((a, b) => b.zIndex - a.zIndex);
26
41
  this.components.forEach(component => component.draw(this.buffer));
27
42
  }
43
+ applyBackgroundColor() {
44
+ const bgColorCode = this.getBackgroundColorCode(this.backgroundColor);
45
+ const resetCode = '\x1b[0m';
46
+ for (let i = 0; i < this.height; i++) {
47
+ for (let j = 0; j < this.width; j++) {
48
+ this.buffer[i][j] = `${bgColorCode}${this.buffer[i][j] || ' '}${resetCode}`;
49
+ }
50
+ }
51
+ }
28
52
  render() {
53
+ this.applyBackgroundColor();
29
54
  console.clear();
30
55
  const output = this.buffer.map(row => row.join('')).join('\n');
31
56
  console.log(output);
@@ -36,6 +61,13 @@ class TideScreen {
36
61
  setFPS(fps) {
37
62
  this.fps = fps;
38
63
  }
64
+ nextFrame() {
65
+ if (this.updateFunction) {
66
+ this.updateFunction();
67
+ }
68
+ this.renderBuffer();
69
+ this.render();
70
+ }
39
71
  renderCycle() {
40
72
  if (this.fps === null) {
41
73
  throw new Error("FPS must be set before starting the render cycle.");
@@ -45,8 +77,8 @@ class TideScreen {
45
77
  if (this.updateFunction) {
46
78
  this.updateFunction();
47
79
  }
48
- this.renderBuffer(); // Prepare the buffer with updated content
49
- this.render(); // Output the buffer to the screen
80
+ this.renderBuffer();
81
+ this.render();
50
82
  setTimeout(loop, interval);
51
83
  };
52
84
  loop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tidepool",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "author": "stuncs69",
5
5
  "main": "dist/index.js",
6
6
  "devDependencies": {