Skip to content

Commit 33dbff1

Browse files
committed
Simplified tutorial integration from #153.
Move tutorial files to seperated folder and changed button layout.
1 parent 5c77074 commit 33dbff1

File tree

20 files changed

+707
-623
lines changed

20 files changed

+707
-623
lines changed

package-lock.json

Lines changed: 239 additions & 239 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/addon/message/message.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ cwc.addon.Message.prototype.prepare = function() {
6565
}
6666
};
6767

68+
6869
/**
6970
* @param {Event} e
7071
*/

src/file_format/file_format.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,26 @@ cwc.fileFormat.File.prototype.getTitle = function() {
394394
};
395395

396396

397+
/**
398+
* @return {Object}
399+
*/
400+
cwc.fileFormat.File.prototype.getTutorial = function() {
401+
return this.getMetadata('tutorial');
402+
};
403+
404+
405+
/**
406+
* @return {Array}
407+
*/
408+
cwc.fileFormat.File.prototype.getTutorialTour = function() {
409+
let tour = this.getMetadata('tour', 'tutorial');
410+
if (tour && Array.isArray(tour)) {
411+
return tour;
412+
}
413+
return null;
414+
};
415+
416+
397417
/**
398418
* @param {!string} version
399419
* @return {cwc.fileFormat.File}

src/file_handler/file_handler.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ cwc.fileHandler.File.prototype.getFileDescription = function() {
199199
};
200200

201201

202+
/**
203+
* @return {Array}
204+
*/
205+
cwc.fileHandler.File.prototype.getFileTutorialTour = function() {
206+
if (this.file_) {
207+
return this.file_.getTutorialTour();
208+
}
209+
return null;
210+
};
211+
212+
202213
/**
203214
* @param {string} filename
204215
*/

src/file_handler/file_loader.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,17 @@ cwc.fileHandler.FileLoader.prototype.loadCWCFile = function(file,
222222
}
223223
}
224224

225+
// Handle tutorial / tour data
226+
let tutorialInstance = this.helper.getInstance('tutorial');
227+
if (tutorialInstance) {
228+
tutorialInstance.setTour(file.getTutorialTour());
229+
}
230+
225231
// Handle sidebar icons
226232
let sidebarInstance = this.helper.getInstance('sidebar');
227233
if (sidebarInstance) {
228234
sidebarInstance.enableDescription(file.getDescription());
235+
sidebarInstance.enableTutorial(file.getTutorialTour());
229236
}
230237

231238
modeInstance.postMode();

src/mode/modder.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ goog.provide('cwc.mode.Modder');
2323
goog.require('cwc.utils.mime.Type');
2424
goog.require('cwc.mode.Config');
2525
goog.require('cwc.mode.Type');
26-
goog.require('cwc.Tutorial');
2726
goog.require('cwc.utils.Helper');
2827
goog.require('cwc.utils.Logger');
2928

@@ -60,9 +59,6 @@ cwc.mode.Modder = function(helper) {
6059

6160
/** @private {string} */
6261
this.templatePath_ = '../resources/templates/';
63-
64-
/** @private {cwc.Tutorial} */
65-
this.tutorial_ = null;
6662
};
6763

6864

@@ -134,12 +130,6 @@ cwc.mode.Modder.prototype.setMode = function(mode) {
134130
sidebarInstance.clear();
135131
}
136132

137-
// Remove tutorial
138-
if (this.tutorial_) {
139-
this.tutorial_.clear();
140-
this.tutorial_ = null;
141-
}
142-
143133
this.log_.info('Initialize mode and decorate UI for', mode, '…');
144134
this.mode = mode;
145135
this.modder = modeConfig.getMod(this.helper);
@@ -194,9 +184,11 @@ cwc.mode.Modder.prototype.postMode = function(mode = this.mode) {
194184
this.syncLibrary();
195185
}
196186

197-
// Enable tutorials
198-
this.tutorial_ = new cwc.Tutorial(this.helper);
199-
this.tutorial_.render();
187+
// Start tutorial for tutorial files .cwct automatically
188+
let tutorialInstance = this.helper.getInstance('tutorial');
189+
if (tutorialInstance && this.filename.toLowerCase().endsWith('.cwct')) {
190+
tutorialInstance.startTour();
191+
}
200192
}
201193

202194
// Event Handling

src/tutorial/tutorial.js

Lines changed: 0 additions & 183 deletions
This file was deleted.

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.Notification');
6060
goog.require('cwc.ui.SelectScreen');
6161
goog.require('cwc.ui.SettingScreen');
6262
goog.require('cwc.ui.Sidebar');
63+
goog.require('cwc.ui.Tutorial');
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
'selectScreen': cwc.ui.SelectScreen,
106107
'settingScreen': cwc.ui.SettingScreen,
107108
'sidebar': cwc.ui.Sidebar,
109+
'tutorial': cwc.ui.Tutorial,
108110
};
109111

110112

src/ui/select_screen/normal/basic/basic.soy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,20 @@
9595
{param title: 'Coding with Chrome Basics' /}
9696
{param text: 'An introduction to Coding with Chrome' /}
9797
{param opt_link_text: 'Learn Coding with Chrome' /}
98-
{param file: 'basic/blocks/cwc.cwct' /}
98+
{param tutorial: 'basic/blocks/cwc.cwct' /}
9999
{param opt_color_class: 'bg-light-blue' /}
100100
{param opt_icon: 'school' /}
101101
{/call}
102+
102103
{call cwc.soy.SelectScreenTemplate.fileCard data="all"}
103104
{param title: 'Blockly Basics' /}
104105
{param text: 'Learn drag-and-drop programming' /}
105106
{param opt_link_text: 'Learn Blockly' /}
106-
{param file: 'basic/blocks/blockly.cwct' /}
107+
{param tutorial: 'basic/blocks/blockly.cwct' /}
107108
{param opt_color_class: 'bg-light-blue' /}
108109
{param opt_icon: 'school' /}
109110
{/call}
111+
110112
</div>
111113
</div>
112114
{/if}

src/ui/select_screen/select_screen.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ cwc.ui.SelectScreen = function(helper) {
7070

7171
/** @private {!string} */
7272
this.resourcesPath_ = '../resources/examples/';
73+
74+
/** @private {!string} */
75+
this.tutorialPath_ = '../resources/tutorial/';
7376
};
7477

7578

@@ -298,6 +301,13 @@ cwc.ui.SelectScreen.prototype.handleFileClick_ = function(e) {
298301
.loadLocalFile(this.resourcesPath_ + filename);
299302
break;
300303
}
304+
case 'loadTutorial': {
305+
this.showDialog_('Loading tutorial file ' + filename,
306+
cwc.soy.SelectScreen.loading_);
307+
this.helper.getInstance('fileLoader')
308+
.loadLocalFile(this.tutorialPath_ + filename);
309+
break;
310+
}
301311
case 'loadMode': {
302312
this.showDialog_('Loading mode ' + filename,
303313
cwc.soy.SelectScreen.loading_);

0 commit comments

Comments
 (0)