Skip to content

Commit 63cdc3f

Browse files
committed
Add Comment component
1 parent 17166a1 commit 63cdc3f

5 files changed

Lines changed: 62 additions & 1 deletion

File tree

src/Container.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import defaults from "lodash-es/defaults";
22
import isString from "lodash-es/isString";
33
import Component, { IComponentConstructor, IContainer } from "./Component";
4+
import Inert from "./Inert";
45
import ComponentRegistry from "./ComponentRegistry";
56
import IMain from "./IMain";
67
import TextureSetManager from "./webgl/TextureSetManager";
@@ -49,6 +50,9 @@ 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+
console.warn(`Inert Component: ${opts.type}. Will not affect rendering.`);
55+
}
5256
components.push(component);
5357
}
5458
}

src/EffectList.ts

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

src/Main.ts

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

0 commit comments

Comments
 (0)