Skip to content

Commit

Permalink
clean up testbed class
Browse files Browse the repository at this point in the history
  • Loading branch information
shakiba committed Nov 10, 2024
1 parent 56f0d71 commit 4cd1883
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 49 deletions.
53 changes: 4 additions & 49 deletions src/util/Testbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export abstract class Testbed {
/** World viewbox center horizontal offset. */
y: number = -10;

/** @hidden */
scaleY: number = -1;

/** World simulation step frequency */
Expand Down Expand Up @@ -78,44 +79,10 @@ export abstract class Testbed {
return;
};

private statusText = '';
private statusMap: Record<string, any> = {};

status(name: string, value: any): void;
status(value: object | string): void;
status(a: any, b?: any) {
if (typeof b !== 'undefined') {
const key = a;
const value = b;
if (typeof value !== 'function' && typeof value !== 'object') {
this.statusMap[key] = value;
}
} else if (a && typeof a === 'object') {
// tslint:disable-next-line:no-for-in
for (const key in a) {
const value = a[key];
if (typeof value !== 'function' && typeof value !== 'object') {
this.statusMap[key] = value;
}
}
} else if (typeof a === 'string') {
this.statusText = a;
}

var newline = '\n';
var text = this.statusText || '';
for (var key in this.statusMap) {
var value = this.statusMap[key];
if (typeof value === 'function') continue;
text += (text && newline) + key + ': ' + value;
}

this._status(text);
}
abstract status(name: string, value: any): void;
abstract status(value: object | string): void;

info(text: string): void {
this._info(text);
}
abstract info(text: string): void;

color(r: number, g: number, b: number): string {
r = r * 256 | 0;
Expand All @@ -133,18 +100,6 @@ export abstract class Testbed {

abstract start(world: World): void;

/** @internal */
abstract _pause(): void;

/** @internal */
abstract _resume(): void;

/** @internal */
abstract _status(string: string): void;

/** @internal */
abstract _info(text: string): void;

abstract findOne(query: string): (Body | Joint | Fixture | null);
abstract findAll(query: string): (Body | Joint | Fixture)[];
}
Expand Down
39 changes: 39 additions & 0 deletions testbed/StageTestbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,45 @@ class StageTestbed extends Testbed {
_resume() {
}

private statusText = '';
private statusMap: Record<string, any> = {};

status(name: string, value: any): void;
status(value: object | string): void;
status(a: any, b?: any) {
if (typeof b !== 'undefined') {
const key = a;
const value = b;
if (typeof value !== 'function' && typeof value !== 'object') {
this.statusMap[key] = value;
}
} else if (a && typeof a === 'object') {
// tslint:disable-next-line:no-for-in
for (const key in a) {
const value = a[key];
if (typeof value !== 'function' && typeof value !== 'object') {
this.statusMap[key] = value;
}
}
} else if (typeof a === 'string') {
this.statusText = a;
}

var newline = '\n';
var text = this.statusText || '';
for (var key in this.statusMap) {
var value = this.statusMap[key];
if (typeof value === 'function') continue;
text += (text && newline) + key + ': ' + value;
}

this._status(text);
}

info(text: string): void {
this._info(text);
}

/** @internal */
_status(string: string) {
}
Expand Down

0 comments on commit 4cd1883

Please sign in to comment.