Skip to content

Commit

Permalink
refactor: drop usage of dummy arguments for multi-inheritance (#54)
Browse files Browse the repository at this point in the history
  • Loading branch information
timkurvers committed Apr 10, 2024
1 parent 3cf2e4d commit 3ffcfdc
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/ui/components/abstract/ScriptObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class ScriptObject extends FrameScriptObject {

_name: string | null;

constructor(_dummy: unknown) {
super(_dummy);
constructor(..._args: unknown[]) {
super(..._args);

this._name = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/abstract/ScriptRegion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class ScriptRegion extends multipleClasses(ScriptObject, LayoutFrame) {

_parent: Frame | null;

constructor(_dummy: unknown) {
super(_dummy);
constructor(..._args: unknown[]) {
super(_args);

this._parent = null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/simple/Frame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Frame extends ScriptRegion {
strataLink: LinkedListLink<this>;

constructor(parent: Frame | null) {
super(null);
super();

this.id = 0;
this.flags = 0;
Expand Down Expand Up @@ -189,7 +189,7 @@ class Frame extends ScriptRegion {
}
}

// TODO: Seems to be necessary with split getter/setters + inheritance
// Note: Seems to be necessary with split getter/setters + inheritance
get parent() {
return this._parent;
}
Expand Down
8 changes: 5 additions & 3 deletions src/ui/components/simple/Region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { LinkedListLink } from '../../../utils';

import Frame from './Frame';

abstract class Region extends ScriptRegion {
class Region extends ScriptRegion {
drawLayerType: DrawLayerType | null;
shown: boolean;
visible: boolean;
Expand All @@ -17,7 +17,7 @@ abstract class Region extends ScriptRegion {
regionLink: LinkedListLink<this>;

constructor(frame: Frame, drawLayerType: DrawLayerType, show: boolean) {
super(null);
super();

this.drawLayerType = null;
this.shown = false;
Expand All @@ -34,7 +34,9 @@ abstract class Region extends ScriptRegion {
}
}

abstract draw(_batch: RenderBatch): void;
draw(_batch: RenderBatch) {
throw new Error(`${this.constructor.name} must implement 'draw'`);
}

onRegionChanged() {
// TODO: Implementation
Expand Down
2 changes: 1 addition & 1 deletion src/ui/scripting/FrameScriptObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class FrameScriptObject {
luaRef: lua_Ref | null;
scripts: ScriptRegistry;

constructor(_dummy: unknown) {
constructor(..._args: unknown[]) {
this.luaRef = null;

this.scripts = new ScriptRegistry();
Expand Down
4 changes: 2 additions & 2 deletions src/utils/inheritance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ const multipleClasses = <
}

const cls = class extends base {
constructor(..._args: any[]) {
constructor(...args: any[]) {
// Create an instance of the base class
super();
super(...args);

// Construct temporary throw-away instance of other class and assign own properties
// Warning: using `this` as a reference in other class' constructor will not work correctly
Expand Down

0 comments on commit 3ffcfdc

Please sign in to comment.