Skip to content

Commit efaf503

Browse files
committed
Add Comment component
1 parent 17166a1 commit efaf503

5 files changed

Lines changed: 60 additions & 1 deletion

File tree

src/Container.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import isString from "lodash-es/isString";
33
import Component, { IComponentConstructor, IContainer } from "./Component";
44
import ComponentRegistry from "./ComponentRegistry";
55
import IMain from "./IMain";
6+
import Inert from "./Inert";
67
import TextureSetManager from "./webgl/TextureSetManager";
78

89
/**
@@ -49,6 +50,10 @@ export default abstract class Container extends Component implements IContainer
4950
continue;
5051
}
5152
const component = new componentClass(this.main, this, opts);
53+
if (component instanceof Inert) {
54+
// tslint:disable-next-line:no-console
55+
console.warn(`Inert Component: ${opts.type}. Will not affect rendering.`);
56+
}
5257
components.push(component);
5358
}
5459
}

src/EffectList.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Container from "./Container";
33
import CodeInstance from "./expr/CodeInstance";
44
import compileExpr from "./expr/compileExpr";
55
import IMain from "./IMain";
6+
import Inert from "./Inert";
67
import { BlendMode } from "./utils";
78
import TextureSetManager from "./webgl/TextureSetManager";
89

@@ -177,7 +178,7 @@ export default class EffectList extends Container {
177178
// render all the components
178179
// for (let i = 0; i < this.components.length; i++) {
179180
for (const component of this.components) {
180-
if (component.isEnabled()) {
181+
if (component.isEnabled() && !(component instanceof Inert)) {
181182
component.draw();
182183
}
183184
}

src/Inert.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import Component, { IContainer } from "./Component";
2+
import IMain from "./IMain";
3+
4+
/**
5+
* Base class for passive components.
6+
*
7+
* A base class for component types that don't affect rendering,
8+
* most notably Comment, but also unknown components in general.
9+
*/
10+
export default abstract class Inert extends Component {
11+
protected opts: any;
12+
13+
/*tslint:disable:no-empty*/
14+
public init() {}
15+
public draw() {
16+
throw new Error("Calling draw on inert component.");
17+
}
18+
}

src/Main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import ComponentRegistry from "./ComponentRegistry";
88
import EffectList from "./EffectList";
99
import IMain from "./IMain";
1010
import BufferSave from "./misc/BufferSave";
11+
import Comment from "./misc/Comment";
1112
import GlobalVar from "./misc/GlobalVar";
1213
import Model from "./Model";
1314
import ClearScreen from "./render/ClearScreen";
@@ -403,6 +404,8 @@ export default class Main extends Model implements IMain {
403404

404405
BufferSave,
405406
GlobalVar,
407+
408+
Comment,
406409
]);
407410
}
408411

src/misc/Comment.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { IContainer } from "../Component";
2+
import IMain from "../IMain";
3+
import Inert from "../Inert";
4+
5+
export interface ICommentOpts {
6+
text: string;
7+
}
8+
9+
/**
10+
* A component containing free text.
11+
*/
12+
export default class Comment extends Inert {
13+
public static componentName: string = "Comment";
14+
public static componentTag: string = "misc";
15+
protected static optUpdateHandlers = {
16+
text: "updateText",
17+
};
18+
protected static defaultOptions: ICommentOpts = {
19+
text: "",
20+
};
21+
22+
protected opts: ICommentOpts;
23+
private text: string;
24+
25+
constructor(main: IMain, parent: IContainer, opts: any) {
26+
super(main, parent, opts);
27+
}
28+
29+
public updateText() {
30+
this.text = this.opts.text;
31+
}
32+
}

0 commit comments

Comments
 (0)