Skip to content

Commit 0ea7756

Browse files
committed
old spellTest cleanup and move old levels into tests.
1 parent fe73a51 commit 0ea7756

File tree

6 files changed

+240
-71
lines changed

6 files changed

+240
-71
lines changed

lib/app/model/test/002.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
define([
2+
'app/model/test'
3+
], function (TestModel) {
4+
return TestModel.extend({
5+
defaults: {
6+
SpeakerModel: null,
7+
SpellScriptModel: null,
8+
TesterModel: null
9+
},
10+
initialize: function () {
11+
_.bindAll(this);
12+
},
13+
execute: function () {
14+
var data = this.toJSON();
15+
16+
this.get('SpeakerModel').say('What if you want to use that string again later on?!')
17+
this.get('SpeakerModel').say('You can use a \'variable\'. For example, to set \'hatColor\' to \'blue\' you would use the following: var hatColor = "blue";')
18+
this.get('SpeakerModel').say({
19+
text: 'Try it out. Set the variable \'moniker\' to "Merlin" in the spell caster below:',
20+
sticky: true
21+
});
22+
23+
this.get('SpellScriptModel').on('cast', this.onCast);
24+
},
25+
onCast: function (Model) {
26+
var code = Model.get('code');
27+
try {
28+
this.get('TesterModel').assertEquals(typeof moniker, 'string');
29+
this.get('TesterModel').assertEquals('Merlin', moniker);
30+
31+
this.get('SpeakerModel').say({
32+
text: 'Good work! On to the next quest!',
33+
force: true
34+
})
35+
36+
// Stop listening for spells
37+
this.get('SpellScriptModel').off('cast', this.onCast);
38+
// Let everyone know we're done
39+
this.trigger('done');
40+
this.trigger('done:success'); // We could have a done:failure in the future
41+
} catch (exception) {
42+
this.get('SpeakerModel').say({
43+
text: 'That doesn\'t seem right! Set the variable \'moniker\' to "Merlin" in the spell caster below:',
44+
sticky: true,
45+
force: true
46+
});
47+
}
48+
}
49+
});
50+
});

lib/app/model/test/003.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
define([
2+
'app/model/test'
3+
], function (TestModel) {
4+
return TestModel.extend({
5+
defaults: {
6+
SpeakerModel: null,
7+
SpellScriptModel: null,
8+
TesterModel: null
9+
},
10+
initialize: function () {
11+
_.bindAll(this);
12+
},
13+
execute: function () {
14+
var data = this.toJSON();
15+
16+
this.get('SpeakerModel').say('Continuing on the topic of strings, this universe provides you with all sorts of ways to manipulate them.');
17+
this.get('SpeakerModel').say('For example, you\'ve asked a peddler how much gold a fistfull of dates would cost. He replies');
18+
this.get('SpeakerModel').say('"THOSE DATES WILL COST 190 GOLD!"');
19+
this.get('SpeakerModel').say('Well, there\'s no reason to shout. With a function called \'toLowerCase()\' we can calm him down.');
20+
this.get('SpeakerModel').say('This function can be called by \'chaining\' it onto the variable itself: variableName.toLowerCase();');
21+
this.get('SpeakerModel').say('Note: The function will \'return\' a new, calmer, string, but it isn\'t saving it into the given var.');
22+
this.get('SpeakerModel').say({
23+
text: 'Given the variable below, try it in the spell caster:',
24+
sticky: true
25+
});
26+
27+
//var rudeReply = "THOSE DATES WILL COST 190 GOLD!";
28+
29+
this.get('SpellScriptModel').on('cast', this.onCast);
30+
},
31+
onCast: function (Model) {
32+
var code = Model.get('code');
33+
try {
34+
var res = eval(code);
35+
36+
this.get('TesterModel').assertEquals(typeof res, 'string');
37+
this.get('TesterModel').assertEquals('those dates will cost 190 gold!', res);
38+
39+
this.get('SpeakerModel').say({
40+
text: 'Good work! On to the next quest!',
41+
force: true
42+
})
43+
44+
// Stop listening for spells
45+
this.get('SpellScriptModel').off('cast', this.onCast);
46+
// Let everyone know we're done
47+
this.trigger('done');
48+
this.trigger('done:success'); // We could have a done:failure in the future
49+
} catch (exception) {
50+
this.get('SpeakerModel').say({
51+
text: 'That doesn\'t seem right! Given the variable below, try it in the spell caster:',
52+
sticky: true,
53+
force: true
54+
});
55+
}
56+
}
57+
});
58+
});

lib/app/model/test/004.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
define([
2+
'app/model/test'
3+
], function (TestModel) {
4+
return TestModel.extend({
5+
defaults: {
6+
SpeakerModel: null,
7+
SpellScriptModel: null,
8+
TesterModel: null
9+
},
10+
initialize: function () {
11+
_.bindAll(this);
12+
},
13+
execute: function () {
14+
var data = this.toJSON();
15+
16+
this.get('SpeakerModel').say('It seems we\'ve mostly calmed him down, but what\'s with the exclaimation!?');
17+
this.get('SpeakerModel').say('In the same way we used \'toLowerCase()\', let\'s use \'replace(searchvalue, newvalue)\' to swap out the \'!\' with a \'.\'.');
18+
this.get('SpeakerModel').say('Also, let\'s save the returned string into a new var named \'calmReply\'.');
19+
this.get('SpeakerModel').say('');
20+
this.get('SpeakerModel').say('');
21+
this.get('SpeakerModel').say('');
22+
this.get('SpeakerModel').say('');
23+
this.get('SpeakerModel').say({
24+
text: 'You know the drill, to the spell caster:',
25+
sticky: true
26+
});
27+
28+
//var lessRudeReply = "those dates will cost 190 gold!";
29+
30+
this.get('SpellScriptModel').on('cast', this.onCast);
31+
},
32+
onCast: function (Model) {
33+
var code = Model.get('code');
34+
try {
35+
this.get('TesterModel').assertEquals(typeof calmReply, 'string');
36+
this.get('TesterModel').assertEquals('those dates will cost 190 gold.', calmReply);
37+
38+
this.get('SpeakerModel').say({
39+
text: 'Good work! On to the next quest!',
40+
force: true
41+
})
42+
43+
// Stop listening for spells
44+
this.get('SpellScriptModel').off('cast', this.onCast);
45+
// Let everyone know we're done
46+
this.trigger('done');
47+
this.trigger('done:success'); // We could have a done:failure in the future
48+
} catch (exception) {
49+
this.get('SpeakerModel').say({
50+
text: 'That doesn\'t seem right! Set the variable \'calmReply\' to an exclaimation less version of the variable below:',
51+
sticky: true,
52+
force: true
53+
});
54+
}
55+
}
56+
});
57+
});

lib/app/model/test/005.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
define([
2+
'app/model/test'
3+
], function (TestModel) {
4+
return TestModel.extend({
5+
defaults: {
6+
SpeakerModel: null,
7+
SpellScriptModel: null,
8+
TesterModel: null
9+
},
10+
initialize: function () {
11+
_.bindAll(this);
12+
},
13+
execute: function () {
14+
var data = this.toJSON();
15+
16+
this.get('SpeakerModel').say('These function things are pretty cool, eh? Imagine if we could make our own?!');
17+
this.get('SpeakerModel').say('Guess what...? We can. Let\'s stick with the date salesman...');
18+
this.get('SpeakerModel').say('You have a lot of stuff to buy, and you\'re tired of haggling. Let\'s write a function to help, but first, the basics:');
19+
this.get('SpeakerModel').say('function functionName(parameterName)
20+
{
21+
// magic here
22+
return result;
23+
}');
24+
this.get('SpeakerModel').say('The \'result\' above can be many things (number, string, etc.), but here we\'re assuming it\'s a variable that was set during the magic.');
25+
this.get('SpeakerModel').say({
26+
text: 'Complete the function below that takes the cost of any goods, and subtracts 5 from it.',
27+
sticky: true
28+
});
29+
30+
/*
31+
function haggle(askingPrice)
32+
{
33+
var newPrice = ???;
34+
return newPrice; // we could also return 8, 'hello', but that wouldn't help.
35+
}
36+
*/
37+
38+
this.get('SpellScriptModel').on('cast', this.onCast);
39+
},
40+
onCast: function (Model) {
41+
var code = Model.get('code');
42+
try {
43+
44+
var checkImplemented = code.indexOf('???');
45+
46+
if (checkImplemented !== -1)
47+
{
48+
throw {type:"SpellTest", "This spell was not implemented."}
49+
}
50+
51+
this.get('TesterModel').assertEquals(typeof haggle, 'function');
52+
53+
var res = haggle(150);
54+
this.get('TesterModel').assertEquals(res, 145);
55+
56+
this.get('SpeakerModel').say({
57+
text: 'Good work! On to the next quest!',
58+
force: true
59+
})
60+
61+
// Stop listening for spells
62+
this.get('SpellScriptModel').off('cast', this.onCast);
63+
// Let everyone know we're done
64+
this.trigger('done');
65+
this.trigger('done:success'); // We could have a done:failure in the future
66+
} catch (exception) {
67+
this.get('SpeakerModel').say({
68+
text: 'That doesn\'t seem right! Set the variable \'moniker\' to "Merlin" in the spell caster below:',
69+
sticky: true,
70+
force: true
71+
});
72+
}
73+
}
74+
});
75+
});

lib/app/spells/spellTests.js

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

lib/app/view/page/home.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ define([
33
'app/view/page',
44
'text!template/page/home.mustache',
55
'crafty',
6-
'app/spells/spellTests',
76
'app/model/spell/script',
87
'app/collection/spell/scripts',
98
'app/view/widget/spell/script/editor',
@@ -15,7 +14,6 @@ define([
1514
PageView,
1615
Template,
1716
Crafty,
18-
spellTests,
1917
SpellScriptModel,
2018
SpellScriptsCollection,
2119
SpellScriptEditorView,
@@ -24,10 +22,6 @@ define([
2422
App
2523
) {
2624
return PageView.extend({
27-
events : {
28-
"click button[name=cast-spell]": "castSpell"
29-
},
30-
3125
// Specify the templatePath and let the PageView do the rest
3226
'template.mustache': Template,
3327
/**
@@ -69,22 +63,6 @@ define([
6963
return {
7064
'pageTitle': 'Home'
7165
};
72-
},
73-
castSpell: function() {
74-
// var currentQuest = this.currentScene.currentQuest;
75-
// if (currentQuest != null)
76-
// {
77-
// var res = spellTests.hocusPocus(currentQuest, this.gameEditor);
78-
//
79-
// if (res === true)
80-
// {
81-
// this.gameEditor.getSession().setValue("");
82-
// }
83-
// }
84-
// else
85-
// {
86-
87-
// }
8866
}
8967
});
9068
});

0 commit comments

Comments
 (0)