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 ccbc93e
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/Container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import isString from "lodash-es/isString";
import Component, { IComponentConstructor, IContainer } from "./Component";
import ComponentRegistry from "./ComponentRegistry";
import IMain from "./IMain";
import Inert from "./Inert";
import TextureSetManager from "./webgl/TextureSetManager";

/**
Expand Down Expand Up @@ -49,6 +50,10 @@ export default abstract class Container extends Component implements IContainer
continue;
}
const component = new componentClass(this.main, this, opts);
if (component instanceof Inert) {
// tslint:disable-next-line:no-console
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
Expand Up @@ -3,6 +3,7 @@ import Container from "./Container";
import CodeInstance from "./expr/CodeInstance";
import compileExpr from "./expr/compileExpr";
import IMain from "./IMain";
import Inert from "./Inert";
import { BlendMode } from "./utils";
import TextureSetManager from "./webgl/TextureSetManager";

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
19 changes: 19 additions & 0 deletions src/Inert.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
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 @@ -8,6 +8,7 @@ import ComponentRegistry from "./ComponentRegistry";
import EffectList from "./EffectList";
import IMain from "./IMain";
import BufferSave from "./misc/BufferSave";
import Comment from "./misc/Comment";
import GlobalVar from "./misc/GlobalVar";
import Model from "./Model";
import ClearScreen from "./render/ClearScreen";
Expand Down Expand Up @@ -403,6 +404,8 @@ export default class Main extends Model implements IMain {

BufferSave,
GlobalVar,

Comment,
]);
}

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

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 ccbc93e

Please sign in to comment.