Skip to content

Commit e8ff90b

Browse files
committed
Added sidebar instance for better usability and tutorial integration.
This will fix #152 and allow an better integration of #132. In this PR a lot of additional design changes were introducted for easier maintaince and to provide an better user experience. Updated tutorial addon example to use the sidebar instance instead of the former message instance.
1 parent 16cd70c commit e8ff90b

File tree

33 files changed

+731
-608
lines changed

33 files changed

+731
-608
lines changed

src/addon/tutorial/tutorial.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,22 @@ cwc.addon.Tutorial.prototype.eventsModder = function(e) {
115115
let file = e.data.file;
116116
this.log_.info('Change Mode', mode, 'for file', file);
117117
if (mode == cwc.mode.Type.BASIC_BLOCKLY && file == 'tutorial-1.cwc') {
118-
this.log_.info('Adding message pane ...');
119-
let messageInstance = this.helper.getInstance('message');
120-
if (messageInstance) {
121-
messageInstance.show(true);
122-
messageInstance.renderContent(cwc.soy.addon.Tutorial.tutorial, {
123-
prefix: this.prefix,
124-
});
118+
this.log_.info('Adding sidebar content ...');
119+
let sidebarInstance = this.helper.getInstance('sidebar');
120+
if (sidebarInstance) {
121+
// Preparing Sidebar Icon ...
122+
let button = sidebarInstance.addCustomButton(
123+
'tutorial', 'library_books', 'Select a Tutorial ...', function() {
124+
this.helper.getInstance('sidebar').renderContent(
125+
'Tutorial', cwc.soy.addon.Tutorial.tutorial, {
126+
prefix: this.prefix,
127+
});
128+
}.bind(this));
129+
130+
// Showing tutorial
131+
button.click();
132+
133+
// Starting Tour ...
125134
let tour = new Shepherd.Tour({
126135
'defaults': {
127136
'classes': 'shepherd-theme-arrows',

src/file_format/file_format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ cwc.fileFormat.File.loadJSON = function(file, data) {
596596
file.setAuthor(decodeURIComponent(jsonData['author']));
597597
}
598598
if (jsonData['description']) {
599-
file.setModel(decodeURIComponent(jsonData['description']));
599+
file.setDescription(decodeURIComponent(jsonData['description']));
600600
}
601601
if (jsonData['model']) {
602602
file.setModel(decodeURIComponent(jsonData['model']));

src/file_handler/file_handler.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ cwc.fileHandler.File.prototype.getFileContent = function() {
188188
};
189189

190190

191+
/**
192+
* @return {!string}
193+
*/
194+
cwc.fileHandler.File.prototype.getFileDescription = function() {
195+
if (this.file_) {
196+
return this.file_.getDescription();
197+
}
198+
return '';
199+
};
200+
201+
191202
/**
192203
* @param {string} filename
193204
*/

src/mode/modder.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ cwc.mode.Modder.prototype.setMode = function(mode) {
124124
dialogInstance.close();
125125
}
126126

127+
// Remove custom sidebar button.
128+
let sidebarInstance = this.helper.getInstance('sidebar');
129+
if (sidebarInstance) {
130+
sidebarInstance.clear();
131+
}
132+
127133
this.log_.info('Initialize mode and decorate UI for', mode, '…');
128134
this.mode = mode;
129135
this.modder = modeConfig.getMod(this.helper);

src/protocol/robots/makeblock/mbot/api.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ goog.provide('cwc.protocol.makeblock.mbot.Api');
2424

2525
goog.require('cwc.protocol.bluetooth.classic.Events');
2626
goog.require('cwc.protocol.makeblock.mbot.Commands');
27-
goog.require('cwc.protocol.makeblock.mbot.IndexType');
27+
goog.require('cwc.protocol.makeblock.mbot.CallbackType');
2828
goog.require('cwc.protocol.makeblock.mbot.Monitoring');
2929
goog.require('cwc.protocol.makeblock.mbot.Port');
3030
goog.require('cwc.utils.ByteTools');
@@ -350,15 +350,15 @@ cwc.protocol.makeblock.mbot.Api.prototype.handleOnReceive_ = function(e) {
350350
let dataType = dataBuffer[3];
351351
let data = dataBuffer.slice(4, dataBuffer.length);
352352
switch (indexType) {
353-
case cwc.protocol.makeblock.mbot.IndexType.VERSION:
353+
case cwc.protocol.makeblock.mbot.CallbackType.VERSION:
354354
console.log('mBot Firmware', new TextDecoder('utf-8').decode(data));
355355
break;
356-
case cwc.protocol.makeblock.mbot.IndexType.ULTRASONIC:
357-
case cwc.protocol.makeblock.mbot.IndexType.LINEFOLLOWER:
358-
case cwc.protocol.makeblock.mbot.IndexType.LIGHTSENSOR:
356+
case cwc.protocol.makeblock.mbot.CallbackType.ULTRASONIC:
357+
case cwc.protocol.makeblock.mbot.CallbackType.LINEFOLLOWER:
358+
case cwc.protocol.makeblock.mbot.CallbackType.LIGHTSENSOR:
359359
this.handleSensorData_(indexType, data, 4);
360360
break;
361-
case cwc.protocol.makeblock.mbot.IndexType.INNER_BUTTON:
361+
case cwc.protocol.makeblock.mbot.CallbackType.INNER_BUTTON:
362362
this.handleSensorData_(indexType, data);
363363
break;
364364
default:
@@ -369,7 +369,7 @@ cwc.protocol.makeblock.mbot.Api.prototype.handleOnReceive_ = function(e) {
369369

370370
/**
371371
* Handles the different type of sensor data.
372-
* @param {!cwc.protocol.makeblock.mbot.IndexType} index_type
372+
* @param {!cwc.protocol.makeblock.mbot.CallbackType} index_type
373373
* @param {Array} data
374374
* @param {number=} opt_data_size
375375
* @private
@@ -388,24 +388,24 @@ cwc.protocol.makeblock.mbot.Api.prototype.handleSensorData_ = function(
388388
this.sensorDataCache_[index_type] = data;
389389

390390
switch (index_type) {
391-
case cwc.protocol.makeblock.mbot.IndexType.INNER_BUTTON:
391+
case cwc.protocol.makeblock.mbot.CallbackType.INNER_BUTTON:
392392
this.dispatchSensorEvent_(index_type,
393393
cwc.protocol.makeblock.mbot.Events.ButtonPressed, data[0]);
394394
break;
395-
case cwc.protocol.makeblock.mbot.IndexType.LIGHTSENSOR:
395+
case cwc.protocol.makeblock.mbot.CallbackType.LIGHTSENSOR:
396396
this.dispatchSensorEvent_(index_type,
397397
cwc.protocol.makeblock.mbot.Events.LightnessSensorValue,
398398
this.parseFloatBytes_(data));
399399
break;
400-
case cwc.protocol.makeblock.mbot.IndexType.LINEFOLLOWER:
400+
case cwc.protocol.makeblock.mbot.CallbackType.LINEFOLLOWER:
401401
this.dispatchSensorEvent_(index_type,
402402
cwc.protocol.makeblock.mbot.Events.LinefollowerSensorValue, {
403403
'left': data[3] >= 64,
404404
'right': data[2] >= 64,
405405
'raw': data,
406406
});
407407
break;
408-
case cwc.protocol.makeblock.mbot.IndexType.ULTRASONIC:
408+
case cwc.protocol.makeblock.mbot.CallbackType.ULTRASONIC:
409409
this.dispatchSensorEvent_(index_type,
410410
cwc.protocol.makeblock.mbot.Events.UltrasonicSensorValue,
411411
this.parseFloatBytes_(data));
@@ -416,7 +416,7 @@ cwc.protocol.makeblock.mbot.Api.prototype.handleSensorData_ = function(
416416

417417
/**
418418
* Dispatch event for sensor data change.
419-
* @param {!cwc.protocol.makeblock.mbot.IndexType} index
419+
* @param {!cwc.protocol.makeblock.mbot.CallbackType} index
420420
* @param {!Function} event
421421
* @param {Object|number} data
422422
* @private

src/protocol/robots/makeblock/mbot/buffer.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ goog.provide('cwc.protocol.makeblock.mbot.Buffer');
2121

2222
goog.require('cwc.protocol.makeblock.mbot.CommandType');
2323
goog.require('cwc.protocol.makeblock.mbot.Header');
24-
goog.require('cwc.protocol.makeblock.mbot.IndexType');
24+
goog.require('cwc.protocol.makeblock.mbot.CallbackType');
2525
goog.require('cwc.utils.ByteArray');
2626

2727

@@ -70,11 +70,11 @@ cwc.protocol.makeblock.mbot.Buffer.prototype.writePort = function(port) {
7070

7171

7272
/**
73-
* @param {!cwc.protocol.makeblock.mbot.IndexType} index
73+
* @param {!cwc.protocol.makeblock.mbot.CallbackType} index
7474
* @return {THIS}
7575
* @template THIS
7676
*/
77-
cwc.protocol.makeblock.mbot.Buffer.prototype.writeIndex = function(index) {
77+
cwc.protocol.makeblock.mbot.Buffer.prototype.writeCallback = function(index) {
7878
return this.writeUInt(index);
7979
};
8080

src/protocol/robots/makeblock/mbot/commands.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ goog.require('cwc.protocol.makeblock.mbot.Buffer');
2323
goog.require('cwc.protocol.makeblock.mbot.CommandType');
2424
goog.require('cwc.protocol.makeblock.mbot.Device');
2525
goog.require('cwc.protocol.makeblock.mbot.Header');
26-
goog.require('cwc.protocol.makeblock.mbot.IndexType');
26+
goog.require('cwc.protocol.makeblock.mbot.CallbackType');
2727
goog.require('cwc.protocol.makeblock.mbot.Port');
2828
goog.require('cwc.protocol.makeblock.mbot.Slot');
2929

@@ -51,7 +51,7 @@ cwc.protocol.makeblock.mbot.Commands = function() {
5151
cwc.protocol.makeblock.mbot.Commands.prototype.setRGBLED = function(red, green,
5252
blue, index = 0x00) {
5353
return new cwc.protocol.makeblock.mbot.Buffer()
54-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.NONE)
54+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.NONE)
5555
.writeType(cwc.protocol.makeblock.mbot.CommandType.RUN)
5656
.writeDevice(cwc.protocol.makeblock.mbot.Device.LEDLIGHT)
5757
.writePort(cwc.protocol.makeblock.mbot.Port.LED_LIGHT)
@@ -74,7 +74,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.setRGBLED = function(red, green,
7474
cwc.protocol.makeblock.mbot.Commands.prototype.playTone = function(frequency,
7575
duration) {
7676
return new cwc.protocol.makeblock.mbot.Buffer()
77-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.NONE)
77+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.NONE)
7878
.writeType(cwc.protocol.makeblock.mbot.CommandType.RUN)
7979
.writeDevice(cwc.protocol.makeblock.mbot.Device.BUZZER)
8080
.writeShort(frequency)
@@ -93,7 +93,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.playTone = function(frequency,
9393
cwc.protocol.makeblock.mbot.Commands.prototype.setMotorPower = function(power,
9494
port = cwc.protocol.makeblock.mbot.Port.RIGHT_MOTOR) {
9595
return new cwc.protocol.makeblock.mbot.Buffer()
96-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.NONE)
96+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.NONE)
9797
.writeType(cwc.protocol.makeblock.mbot.CommandType.RUN)
9898
.writeDevice(cwc.protocol.makeblock.mbot.Device.DCMOTOR)
9999
.writePort(port)
@@ -110,7 +110,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.setMotorPower = function(power,
110110
cwc.protocol.makeblock.mbot.Commands.prototype.readUltrasonicSensor = function(
111111
) {
112112
return new cwc.protocol.makeblock.mbot.Buffer()
113-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.ULTRASONIC)
113+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.ULTRASONIC)
114114
.writeType(cwc.protocol.makeblock.mbot.CommandType.GET)
115115
.writeDevice(cwc.protocol.makeblock.mbot.Device.ULTRASONIC)
116116
.writePort(cwc.protocol.makeblock.mbot.Port.ULTRASONIC)
@@ -125,7 +125,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.readUltrasonicSensor = function(
125125
*/
126126
cwc.protocol.makeblock.mbot.Commands.prototype.readLightSensor = function() {
127127
return new cwc.protocol.makeblock.mbot.Buffer()
128-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.LIGHTSENSOR)
128+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.LIGHTSENSOR)
129129
.writeType(cwc.protocol.makeblock.mbot.CommandType.GET)
130130
.writeDevice(cwc.protocol.makeblock.mbot.Device.LIGHTSENSOR)
131131
.writePort(cwc.protocol.makeblock.mbot.Port.LIGHTSENSOR)
@@ -141,7 +141,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.readLightSensor = function() {
141141
cwc.protocol.makeblock.mbot.Commands.prototype.readLineFollowerSensor =
142142
function() {
143143
return new cwc.protocol.makeblock.mbot.Buffer()
144-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.LINEFOLLOWER)
144+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.LINEFOLLOWER)
145145
.writeType(cwc.protocol.makeblock.mbot.CommandType.GET)
146146
.writeDevice(cwc.protocol.makeblock.mbot.Device.LINEFOLLOWER)
147147
.writePort(cwc.protocol.makeblock.mbot.Port.LINEFOLLOWER)
@@ -156,7 +156,7 @@ function() {
156156
*/
157157
cwc.protocol.makeblock.mbot.Commands.prototype.getVersion = function() {
158158
return new cwc.protocol.makeblock.mbot.Buffer()
159-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.VERSION)
159+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.VERSION)
160160
.writeType(cwc.protocol.makeblock.mbot.CommandType.GET)
161161
.writeDevice(cwc.protocol.makeblock.mbot.Device.VERSION)
162162
.readSigned();
@@ -170,7 +170,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.getVersion = function() {
170170
*/
171171
cwc.protocol.makeblock.mbot.Commands.prototype.reset = function() {
172172
return new cwc.protocol.makeblock.mbot.Buffer()
173-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.NONE)
173+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.NONE)
174174
.writeType(cwc.protocol.makeblock.mbot.CommandType.RESET)
175175
.readSigned();
176176
};
@@ -183,7 +183,7 @@ cwc.protocol.makeblock.mbot.Commands.prototype.reset = function() {
183183
*/
184184
cwc.protocol.makeblock.mbot.Commands.prototype.start = function() {
185185
return new cwc.protocol.makeblock.mbot.Buffer()
186-
.writeIndex(cwc.protocol.makeblock.mbot.IndexType.NONE)
186+
.writeCallback(cwc.protocol.makeblock.mbot.CallbackType.NONE)
187187
.writeType(cwc.protocol.makeblock.mbot.CommandType.START)
188188
.readSigned();
189189
};

src/protocol/robots/makeblock/mbot/constants.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ goog.provide('cwc.protocol.makeblock.mbot.CommandType');
2525
goog.provide('cwc.protocol.makeblock.mbot.DataType');
2626
goog.provide('cwc.protocol.makeblock.mbot.Device');
2727
goog.provide('cwc.protocol.makeblock.mbot.Header');
28-
goog.provide('cwc.protocol.makeblock.mbot.IndexType');
28+
goog.provide('cwc.protocol.makeblock.mbot.CallbackType');
2929
goog.provide('cwc.protocol.makeblock.mbot.Port');
3030
goog.provide('cwc.protocol.makeblock.mbot.Slot');
3131

@@ -94,7 +94,7 @@ cwc.protocol.makeblock.mbot.Header = [0xff, 0x55];
9494
* Enum of implemented callback types.
9595
* @enum {!number}
9696
*/
97-
cwc.protocol.makeblock.mbot.IndexType = {
97+
cwc.protocol.makeblock.mbot.CallbackType = {
9898
NONE: 0x00,
9999
ULTRASONIC: 0x10,
100100
LINEFOLLOWER: 0x11,

src/runner/runnerConnector.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ cwc.runner.Connector.prototype.addApiProfile = function(api) {
171171

172172
/**
173173
* @param {!string} name
174-
* @param {!function(Object, string)} func
174+
* @param {!function(Object, string)|cwc.runner.Connector} func
175175
* @param {?=} scope
176176
* @export
177177
*/
@@ -181,11 +181,7 @@ cwc.runner.Connector.prototype.addCommand = function(name, func, scope) {
181181
return;
182182
}
183183
this.log_.info('Adding command', name);
184-
if (scope) {
185-
this.commands[name] = func.bind(scope);
186-
} else {
187-
this.commands[name] = func;
188-
}
184+
this.commands[name] = scope ? func.bind(scope) : func;
189185
};
190186

191187

src/ui/builder.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ goog.require('cwc.ui.Navigation');
6060
goog.require('cwc.ui.Notification');
6161
goog.require('cwc.ui.SelectScreen');
6262
goog.require('cwc.ui.SettingScreen');
63+
goog.require('cwc.ui.Sidebar');
6364
goog.require('cwc.ui.connectScreen.Screens');
6465
goog.require('cwc.utils.Dialog');
6566
goog.require('cwc.utils.Events');
@@ -105,6 +106,7 @@ cwc.ui.BuilderHelpers = {
105106
'renderer': cwc.renderer.Renderer,
106107
'selectScreen': cwc.ui.SelectScreen,
107108
'settingScreen': cwc.ui.SettingScreen,
109+
'sidebar': cwc.ui.Sidebar,
108110
};
109111

110112

0 commit comments

Comments
 (0)