-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed.js.orig
655 lines (615 loc) · 24.8 KB
/
seed.js.orig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
/*
This seed file is only a placeholder. It should be expanded and altered
to fit the development of your application.
It uses the same file the server uses to establish
the database connection:
--- server/db/index.js
The name of the database used is set in your environment files:
--- server/env/*
This seed file has a safety check to see if you already have users
in the database. If you are developing multiple applications with the
fsg scaffolding, keep in mind that fsg always uses the same database
name in the environment files.
*/
var mongoose = require('mongoose');
var Promise = require('bluebird');
var chalk = require('chalk');
var connectToDb = require('./server/db');
var User = Promise.promisifyAll(mongoose.model('User'));
var Story = Promise.promisifyAll(mongoose.model('Story'));
var Page = Promise.promisifyAll(mongoose.model('Page'));
User.remove({}, function(err, removed) {
if (err) console.log(err);
});
Story.remove({}, function(err, removed) {
if (err) console.log(err);
});
Page.remove({}, function(err, removed) {
if (err) console.log(err);
});
var concepts = ['For Loop', 'While Loop', 'If-statements', 'Conditionals', 'Expressions', 'Movement']
var descr = "Awesome adventure in progress- check back soon!";
var lorem = "<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>"
var backgrounds= ['images/space.png', 'images/flower-field.png', 'images/underwater.png'];
var covers = ['images/book-covers/background-castle.png','images/book-covers/background-circus.png', 'images/book-covers/background-dinosaur.png', 'images/book-covers/background-safari.png'];
var seedStories = function(){
var titles = ['Happy Dance', 'Omri', 'Joe\'s Salt', 'Adventures of Mark'];
//var images = ['http://www.smashingmagazine.com/images/book-covers/book-covers-18.jpg', 'https://s-media-cache-ak0.pinimg.com/236x/31/b0/7f/31b07f4c094b63a20fba3d7a3143b69c.jpg', 'https://geekybooksnob.files.wordpress.com/2012/11/200px-life_of_pi_cover.png', 'http://www.adweek.com/galleycat/files/2012/08/8-bit-book-cover-The-Two-Towers.jpg']
var stories = titles.map(function(title, i){
return {
title: title,
description: descr,
difficulty: Math.floor(Math.random()*10),
concepts: [concepts[Math.floor(Math.random()*concepts.length)]],
cover: covers[i]
};
});
stories.push({
title: 'Mopsy and Moopsy',
description: "Mopsy and Moopsy are in trouble- can you help them?",
difficulty: 2,
concepts: ['For Loop', 'If-statements'],
cover: 'images/book-covers/background-mopsy.png'
});
stories.push({
title: 'Space Princess',
description: "Aria gets lost in space and has to rescue a friend",
difficulty: 3,
concepts: ['Conditionals', 'While loop', 'For loop'],
cover: 'images/book-covers/background-space.png'
});
return Story.createAsync(stories);
};
var seedPages = function(stories){
var pages = [];
stories.forEach(function(story){
if(story.title==='Mopsy and Moopsy'){
pages.push({
story: story._id,
text:'<p>{{user.character.name}} was sitting at home, enjoying a nice cup of tea, when their super ears perked up- someone was crying for help! It\'s Moopsy Monkey! </p><p class="promptText"> Can you help {{user.character.name}} find out what\'s wrong?</p>',
tools: ['ifStatement', 'ask', 'move', 'give'],
variables: [
{text: 'Moopsy_Monkey', varType: 'person'},
{text: 'Whats_wrong', varType: 'variable'}
],
concepts: ['If-statements'],
hint: 'Make sure you ask Moopsy what\'s wrong',
requirements: {win: {ask: {'Whats_wrong': {Moopsy_Monkey: false}}}},
gameboard: [
[
[],
[],
[{
type: 'Person',
name: 'Monkey2',
varName: 'Moopsy_Monkey'
}],
[]
],
[
[],
[{
type:'Obstacle',
name:'Tree1'
}],
[],
[]
],
[
[],
[],
[],
[{
type:'Obstacle',
name: 'Tree1'
}]
],
[
[{
type: 'Avatar',
name:'Giraffe3'
}],
[],
[],
[]
]
],
pageNumber: 0,
boardBackground: 'images/flower-field.png'
},{
story: story._id,
text:'<p>"It\'s my brother," said Moopsy. "He\'s crying and I don\'t know what to do!" </p><p>"Don\'t worry Moopsy, I\'ll go see if I can help"</p><p class="promptText">Can you see if Mopsy needs any help?</p>',
tools: ['ifStatement', 'ask', 'move', 'give'],
variables: [
{text: 'Mopsy_Monkey', varType: 'person'},
{text: 'Mopsy needs help', varType: 'condition'},
{text: 'How_can_I_help', varType:'variable'}
],
concepts: ['If-statements'],
hint: 'If Mopsy needs help, ask what you can do!',
requirements: {win: {ask: {'How_can_I_help':{Mopsy_Monkey: false}}}},
gameboard: [
[
[],
[],
[{
type: 'Avatar',
name: 'Giraffe3'
}],
[]
],
[
[],
[{
type:'Obstacle',
name:'Tree1'
}],
[],
[]
],
[
[],
[],
[],
[{
type:'Obstacle',
name: 'Tree1'
}]
],
[
[],
[],
[],
[{
type: 'Person',
name:'Monkey1',
varName:'Mopsy_Monkey'
}]
]
],
pageNumber: 1,
boardBackground: 'images/flower-field.png'
},{
story: story._id,
text:'<p>"It\'s terrible," sighed Mopsy. "I\'ve dropped my bananas all over the place. It\'ll take forever to pick them up again!"</p><p>"Not if I can help it!" exclaimed {{user.character.name}}</p><p class="promptText">Can you get all of Mopsy\'s bananas using only 4 tools?</p>',
tools: ['ifStatement', 'pickUp', 'move', 'forLoop'],
variables: [
{text: 'Banana', varType: 'variable'},
{text: 'Apple', varType:'variable'}
],
concepts: ['For Loop'],
hint: 'You can use a repeat to do an action more than once',
requirements: {win:{ pickUp: {
'Banana&1': {noOne: false},
'Banana&2':{noOne: false},
'Banana&3': {noOne: false}
}}},
gameboard: [
[
[{
type:'Collectible',
name:'Banana',
varName:'Banana&3'
}],
[],
[],
[]
],
[
[],
[{
type:'Collectible',
name:'Banana',
varName:'Banana&2'
}],
[{
type:'Obstacle',
name:'Tree1'
}],
[]
],
[
[],
[],
[{
type:'Collectible',
name:'Banana',
varName:'Banana&1'
}],
[{
type:'Obstacle',
name: 'Tree1'
}]
],
[
[],
[],
[],
[{
type: 'Avatar',
name: 'Giraffe3'
}]
]
],
pageNumber: 2,
boardBackground: 'images/jungle.png'
}
);
} else if(story.title==='Space Princess'){
pages.push({
story: story._id,
text:'<p>Hi, I’m Aria. I’m ten years old, my favorite color is yellow, and I have a pet kitten named Omri. Oh, and I’m a princess. Most of the time, it’s pretty sweet. Unfortunately, it doesn’t exempt me from having an annoying younger brother who always steals my toys. He’s so annoying, ugg. </p> <p> Today is my birthday and my Aunt says she has an exciting surprise for me. She is a physicist at NASA, so I’m sure it will be something amazing. She hid it in one of these boxes. </p><p class="promptText"> Can you go to each one, and pick it up if it is my present?</p>',
<<<<<<< HEAD
tools: ['move', 'pickUp', 'ask', 'If-Statement', 'For Loop', 'While Loop', 'moveRandom'],
=======
tools: ['move', 'pickUp', 'ask', 'ifStatement', 'forLoop'],
>>>>>>> add pg works. yay. possible error with not saving the avatar correnctly
variables: [
{text: 'present', varType: 'variable'},
{text: 'a present is inside', varType: 'condition', fnType: 'match', arg: 'present'}
],
concepts: ['If-statements'],
hint: 'Try using the if-statement',
requirements: {win: {pickUp: {present: {noOne: false}}}},
gameboard: [
[
[{
type: 'Avatar',
name:'WizzardGirl3'
}],
[],
[],
[],
[]
],
[
[],
[{
type: 'Collectible',
name: 'Chest1',
rand: 'loc'
}],
[],
[],
[]
],
[
[],
[],
[],
[{
type: 'Collectible',
name: 'Chest1',
rand: 'loc'
}],
[]
],
[
[],
[],
[],
[],
[]
],
[
[{
type: 'Obstacle',
name:'Tree1'
}],
[],
[{
type: 'Collectible',
name: 'Chest1',
varName: 'box',
match: 'present',
rand: 'loc'
}, {
type:'Collectible',
name: 'Empty',
varName: 'present'
}],
[],
[]
]
],
pageNumber: 0,
boardBackground: 'images/flower-field.png'
},{
story: story._id,
text:'<p>"Wow! My present is a spaceship! I was planning to explore our solar system, and was especially excited to see Saturn’s rings, but my brother kept coming inside and messing everything up. He must have done some serious damage, because when I took off, I couldn’t control my navigation, and now I seem to have landed on a strange planet." </p><p>"When I got out of my spaceship, I was greeted by a strange creature, who introduced itself as Zeke. Zeke is worried because he can’t find his best friend, Liz."</p><p class="promptText">Can you go to each of the aliens on the page and ask them if they have seen Liz? You’re running low on power, so you can only use three commands.</p>',
tools: ['move', 'pickUp', 'ask', 'tell', 'ifStatement', 'forLoop'],
variables: [
{text: 'Have you seen Liz?', varType: 'variable'},
{text: 'Alien', varType: 'person'},
{text: 'Liz', varType:'person'},
{text: 'They have seen Liz', varType: 'condition', fnType: 'returnTrue', arg: 'arg'}
],
concepts: ['For Loop'],
hint: 'Try repeating, and think about using the bump to your advantage',
requirements: { win: { ask: {
'Alien&1': {'Have_you_seen_Liz?': false},
'Alien&2': {'Have_you_seen_Liz?': false},
'Alien&3': {'Have_you_seen_Liz?': false},
'Alien&4': {'Have_you_seen_Liz?': false}
}}},
gameboard: [
[
[{
type: 'Avatar',
name:'WizardGirl3'
}],
[],
[],
[],
[]
],[
[],
[{
type:'Collectible',
name:'Alien1',
varName:'Alien&1'
}],
[],
[],
[]
],[
[],
[],
[{
type:'Collectible',
name:'Alien2',
varName:'Alien&2'
}],
[],
[]
],[
[],
[],
[],
[{
type:'Collectible',
name:'Alien3',
varName:'Alien&3'
}],
[]
],[
[],
[],
[],
[{
type:'Collectible',
name:'Alien2',
varName:'Alien&4'
}],
[]
]
],
pageNumber: 1,
boardBackground: 'images/mars.png'
},{
story: story._id,
text:'<p>"Oh no, you discovered that Liz was captured by an evil warlord. He’s keeping her locked in a cell somewhere in his fortress. Fortunately, Zeke is friends with one of the guards, who will free Liz if you can bring him the key."</p><p>"To free Liz, you will need to find the right key, and give it to a guard named Nimit. Carefull, though, if you give the key to the wrong guard, the evil warlord might find out you are here. And in order to keep quiet, you can only use three moves at level one of your spell.</p>',
tools: ['move', 'pickUp', 'give', 'ask', 'whileLoop'],
variables: [
{text: 'key', varType: 'variable'},
{text: 'Guard', varType:'person'},
{text: 'What is your name?', varType: 'variable'},
{text: 'you are holding the key', varType: 'conditional', fnType: 'holding', arg: 'key'},
{text: 'The guard\s name is not Nimit', varType: 'condition', fnType: 'match', arg: 'notNimit'}
],
concepts: ['While Loop', 'Conditionals', 'Expressions'],
hint: 'You can use a repeat to do an action more than once',
requirements: { win:{
pickUp: {'key':{noOne: false}},
give: {key:{'Guard&2': false}},
}, lose: {
give: {
'key': {'Guard&1': false, 'Guard&3': false}
}}},
gameboard: [
[
[{
type: 'Avatar',
name:'WizzardGirl3'
}],
[{
type:'Collectible',
name:'Banana',
varName:'key'
}],
[],
[],
[]
],[
[],
[],
[{
type:'Person',
name:'Alien1',
varName:'Guard&1',
match: 'notNimit'
}],
[{
type:'Person',
name:'Alien2',
varName:'Guard&2',
}],
[{
type:'Person',
name:'Alien1',
varName:'Guard&3',
match: 'notNimit'
}]
],[
[],
[],
[],
[],
[]
],[
[],
[],
[],
[],
[]
],[
[],
[],
[],
[],
[]
]
],
pageNumber: 2,
boardBackground: 'images/mars.png'
}
);
}else{
for (i=0; i<3; i++){
pages.push({
story: story._id,
text: lorem,
tools: ['move', 'pickUp', 'give', 'ask', 'tell', 'ifStatement', 'forLoop', 'whileLoop'],
variables: [{text: 'Omri', varType: 'person'}, {text: 'Zeke', varType: 'person'}, {text: 'Joe', varType: 'person'}, {text: 'Say hi', varType: 'variable'}, {text: 'Green Potion', varType: 'variable'}, {text: 'The potion is green', varType: 'condition'}],
concepts: [concepts[Math.floor(Math.random()*concepts.length)]],
hint: 'Try harder',
requirements: {win:{pickUp: {Green_Potion: {noOne: false}}}},
gameboard: [
[
[{
type: 'Avatar',
name: 'WizardBoy2'
}],
[],
[{
type: 'Obstacle',
name: 'Rock1'
}],
[]
],
[
[],
[{
type: 'Collectible',
name: 'Potion2',
varName: 'Green_Potion'
}],
[],
[]
],
[
[],
[],
[],
[],
],
[
[],
[{
type: 'Obstacle',
name: 'Tree2',
varName: 'tree'
}],
[],
[]
]
],
pageNumber: i,
boardBackground: backgrounds[i]
});
}
}
});
return Page.createAsync(pages);
};
var seedUsers = function (stories, pages) {
var users = [
{
email: '[email protected]',
password: 'password',
username: 'Giraffe',
gender: 'other'
},
{
email: '[email protected]',
password: 'potus',
username: 'Obama',
gender: 'male',
isAdmin: true
},
{
email: '[email protected]',
password: 'becks',
username: 'Beckylee',
gender: 'female',
isAdmin: true
},
{
email: '[email protected]',
password: 'austin',
username: 'Austin',
gender: 'male',
isAdmin: true
},
{
email: '[email protected]',
password: 'chandra',
username: 'Chandra',
gender: 'female',
isAdmin: true
},
{
email: '[email protected]',
password: 'emily',
username:'Emily',
gender:'female',
isAdmin: true
}
];
var makeAge = function(min, max){
return Math.floor(Math.random()*(max-min)) + min;
};
var number = 0;
var randomNumber = function(){
number = Math.floor(Math.random()*10);
return number;
};
users.forEach(function(user){
user.age = makeAge(5, 13);
user.mastery = [];
concepts.forEach(function(concept){
user.mastery.push({
topic: concept,
pointsEarned: randomNumber() * (Math.floor(Math.random()* 10)/10*50),
pointsPossible:number*50
});
user.completedStories = [stories[Math.floor(Math.random()*stories.length)]._id];
user.unfinishedPages = [pages[Math.floor(Math.random()*pages.length)]._id];
});
});
return User.createAsync(users);
};
connectToDb.then(function () {
// User.findAsync({}).then(function (users) {
// if (users.length === 0) {
// return seedUsers();
// } else {
// console.log(chalk.magenta('Seems to already be user data, exiting!'));
// process.kill(0);
// }
var tempUsers, tempStories, tempPages;
seedStories()
.then(function(stories){
tempStories = stories;
return seedPages(tempStories);
}).then(function(pages){
tempPages = pages;
return seedUsers(tempStories, tempPages);
}).then(function () {
console.log(chalk.green('Seed successful!'));
process.kill(0);
}).catch(function (err) {
console.error(err);
process.kill(1);
});
});