-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Comment component #42
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
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; | ||
|
||
/*tslint:disable:no-empty*/ | ||
public init() {} | ||
public draw() { | ||
throw new Error("Calling draw on inert component."); | ||
} | ||
} |
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't really need this update handler or the The update handlers are a way for the component to react to changes in opts and update internal state, re-compile shaders etc. |
||
this.text = this.opts.text; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry If I wasn't clear about this in my previous comment. We'll never have an
Inert
component in the preset so this if block will never run. What we really want to do here is to implicitly createInert
component whencomponentClass
cannot be found in the registry. So we can just replace thecontinue;
in the previous if block with something likecomponentClass = Inert;
.