mirror of
https://github.com/skishore/makemeahanzi.git
synced 2025-11-02 21:41:28 +08:00
Clean up stage API slightly
This commit is contained in:
@ -9,6 +9,7 @@ const changeGlyph = (method, argument) => {
|
||||
Meteor.call(method, argument, function(err, data) {
|
||||
Session.set('editor.glyph', data);
|
||||
stage = new stages.strokes(data);
|
||||
stage.refresh();
|
||||
});
|
||||
}
|
||||
|
||||
@ -32,6 +33,7 @@ Template.editor.events({
|
||||
'click svg .selectable': function(event) {
|
||||
// We avoid the arrow function here so that this is bound to the template.
|
||||
stage.handleEvent(event, this);
|
||||
stage.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@ -2,6 +2,10 @@ if (this.stages !== undefined) throw new Error('Redifining stages global!');
|
||||
this.stages = {};
|
||||
|
||||
stages.AbstractStage = class AbstractStage {
|
||||
// Initialize this stage's internal state. The glyph may already include
|
||||
// output from this stage. If the internal state can be initialized in such
|
||||
// a way to achieve that output, it should be; doing so allows users to make
|
||||
// some edits, switch to another glyph, and later resume where they left off.
|
||||
constructor(glyph) {
|
||||
// Session variables the interface by which the stage interacts with UI:
|
||||
// - type - String type of this stage.
|
||||
@ -20,16 +24,17 @@ stages.AbstractStage = class AbstractStage {
|
||||
Session.set('stage.points', undefined);
|
||||
Session.set('stage.instructions', undefined);
|
||||
Session.set('stage.status', undefined);
|
||||
this.colors = ['#0074D9', '#2ECC40', '#FFDC00', '#FF4136', '#7FDBFF',
|
||||
'#001F3F', '#39CCCC', '#3D9970', '#01FF70', '#FF851B'];
|
||||
this.glyph = glyph;
|
||||
}
|
||||
getColors() {
|
||||
return ['#0074D9', '#2ECC40', '#FFDC00', '#FF4136', '#7FDBFF',
|
||||
'#001F3F', '#39CCCC', '#3D9970', '#01FF70', '#FF851B'];
|
||||
}
|
||||
// Update the stage's internal state and the editor.glyph Session variable
|
||||
// based on the event.
|
||||
handleEvent(event, template) {
|
||||
assert(false, 'handleEvent was not implemented!');
|
||||
}
|
||||
refresh(glyph) {
|
||||
// Refresh the stage UI based on the current state of this stage.
|
||||
refresh() {
|
||||
assert(false, 'refresh was not implemented!');
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,19 +36,16 @@ stages.strokes = class StrokesStage extends stages.AbstractStage {
|
||||
this.strokes.map((stroke) => include[stroke] = false);
|
||||
glyph.stages.strokes.map((stroke) => include[stroke] = true);
|
||||
}
|
||||
this.refresh();
|
||||
}
|
||||
handleEvent(event, template) {
|
||||
assert(this.include.hasOwnProperty(template.d));
|
||||
this.include[template.d] = !this.include[template.d];
|
||||
this.refresh();
|
||||
}
|
||||
refresh(glyph) {
|
||||
this.glyph = glyph || this.glyph;
|
||||
this.glyph.stages.strokes = this.strokes.filter((x) => this.include[x]);
|
||||
Session.set('editor.glyph', this.glyph);
|
||||
}
|
||||
refresh() {
|
||||
Session.set('stage.paths',
|
||||
getStrokePaths(this.strokes, this.include, super.getColors()));
|
||||
getStrokePaths(this.strokes, this.include, this.colors));
|
||||
const data = cjklib.getCharacterData(this.glyph.character);
|
||||
const actual = this.glyph.stages.strokes.length;
|
||||
const expected = this.glyph.metadata.strokes || data.strokes;
|
||||
|
||||
Reference in New Issue
Block a user