Skip to content

Commit

Permalink
Add Comment component
Browse files Browse the repository at this point in the history
  • Loading branch information
grandchild committed Jun 27, 2018
1 parent 17166a1 commit 63cdc3f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Container.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import defaults from "lodash-es/defaults";
import isString from "lodash-es/isString";
import Component, { IComponentConstructor, IContainer } from "./Component";
import Inert from "./Inert";
import ComponentRegistry from "./ComponentRegistry";
import IMain from "./IMain";
import TextureSetManager from "./webgl/TextureSetManager";
Expand Down Expand Up @@ -49,6 +50,9 @@ export default abstract class Container extends Component implements IContainer
continue;
}
const component = new componentClass(this.main, this, opts);
if (component instanceof Inert) {
console.warn(`Inert Component: ${opts.type}. Will not affect rendering.`);
}
components.push(component);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/EffectList.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Component from "./Component";
import Inert from "./Inert";
import Container from "./Container";
import CodeInstance from "./expr/CodeInstance";
import compileExpr from "./expr/compileExpr";
Expand Down Expand Up @@ -177,7 +178,7 @@ export default class EffectList extends Container {
// render all the components
// for (let i = 0; i < this.components.length; i++) {
for (const component of this.components) {
if (component.isEnabled()) {
if (component.isEnabled() && !(component instanceof Inert)) {
component.draw();
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/Inert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Component, { IContainer } from "./Component";
import IMain from "./IMain";


/**
* Base class for passive components.
*
* A base class for component types that don't affect rendering,
* most notably Comment, but also unknown components in general.
*/
export default abstract class Inert extends Component {
protected opts: any;

public init() {
throw new Error("Calling init on inert component.");
}
public draw() {
throw new Error("Calling draw on inert component.");
}
}
3 changes: 3 additions & 0 deletions src/Main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Invert from "./trans/Invert";
import Mirror from "./trans/Mirror";
import Mosaic from "./trans/Mosaic";
import UniqueTone from "./trans/UniqueTone";
import Comment from "./misc/Comment";
import {checkRequiredOptions} from "./utils";
import Buffer from "./webgl/Buffer";
import CopyProgram from "./webgl/CopyProgram";
Expand Down Expand Up @@ -403,6 +404,8 @@ export default class Main extends Model implements IMain {

BufferSave,
GlobalVar,

Comment,
]);
}

Expand Down
33 changes: 33 additions & 0 deletions src/misc/Comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Inert from "../Inert";
import { IContainer } from "../Component";
import IMain from "../IMain";


export interface ICommentOpts {
text: string;
}

/**
* A component containing free text.
*/
export default class Comment extends Inert {
public static componentName: string = "Comment";
public static componentTag: string = "misc";
protected static optUpdateHandlers = {
text: "updateText",
};
protected static defaultOptions: ICommentOpts = {
text: "",
};

protected opts: ICommentOpts;
private text: string;

constructor(main: IMain, parent: IContainer, opts: any) {
super(main, parent, opts);
}

public updateText() {
this.text = this.opts.text;
}
}

0 comments on commit 63cdc3f

Please sign in to comment.