-
Notifications
You must be signed in to change notification settings - Fork 100
/
jurassicSystems.js
548 lines (478 loc) · 16.2 KB
/
jurassicSystems.js
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
(function($, sm) {
const jpTerminal = (function() {
const env = {
accessAttempts: 0,
active: null,
commands: {},
maxIndex: 1,
musicOn: false,
sounds: {},
};
const api = {};
api.buildCommandLine = function(line) {
const commandName = line.trim().split(/ /)[0];
const command =
env.commands[commandName] &&
env.commands[commandName].command;
env.active.find('.command-history')
.append($('<div class="entered-command">')
.text('> ' + line));
if (command) {
command(env, line);
} else if (commandName) {
env.active.find('.command-history')
.append($('<div>').text(commandName + ': command not found'));
}
}
api.addCommand = function(details) {
if (
details.name &&
!env.commands.hasOwnProperty(details.name) &&
(details.command.constructor === Function)
) {
env.commands[details.name] = details;
}
}
api.setActive = function(active) {
env.active = $(active) || env.active;
}
api.getActive = function() {
return env.active;
}
api.nextIndex = function() {
return ++env.maxIndex;
}
api.init = function() {
// HTML5 audio element detection
if (Modernizr.audio.mp3 || Modernizr.audio.wav || Modernizr.audio.ogg) {
const beepHTML5 = $('<audio preload="auto"/>');
const lockDownHTML5 = $('<audio preload="auto"/>');
const dennisMusicHTML5 = $('<audio preload="auto"/>');
beepHTML5.append('<source src="/snd/beep.ogg">');
beepHTML5.append('<source src="/snd/beep.mp3">');
beepHTML5.append('<source src="/snd/beep.wav">');
lockDownHTML5.append('<source src="/snd/lockDown.ogg">');
lockDownHTML5.append('<source src="/snd/lockDown.mp3">');
lockDownHTML5.append('<source src="/snd/lockDown.wav">');
dennisMusicHTML5.append('<source src="/snd/dennisMusic.ogg">');
dennisMusicHTML5.append('<source src="/snd/dennisMusic.mp3">');
dennisMusicHTML5.append('<source src="/snd/dennisMusic.wav">');
env.sounds.beep = {
play: function() {
beepHTML5[0].load();
beepHTML5[0].play();
}
};
env.sounds.lockDown = {
play: function() {
lockDownHTML5[0].load();
lockDownHTML5[0].play();
}
};
env.sounds.dennisMusic = {
play: function() {
dennisMusicHTML5[0].load();
dennisMusicHTML5[0].play();
},
stop: function() {
dennisMusicHTML5[0].pause();
},
};
dennisMusicHTML5.bind('ended', function() {
env.sounds.dennisMusic.play();
});
} else {
sm.setup({
url: '/swf/soundManager/',
onready: function() {
env.sounds.beep = sm.createSound({
autoLoad: true,
id: 'beep',
url: '/snd/beep.mp3',
});
env.sounds.lockDown = sm.createSound({
autoLoad: true,
id: 'lockDown',
url: '/snd/lockDown.mp3',
});
env.sounds.dennisMusic = sm.createSound({
autoLoad: true,
id: 'dennisMusic',
onfinish: function() {
sm.play('dennisMusic');
},
url: '/snd/dennisMusic.mp3',
});
},
});
}
};
return api;
}());
jpTerminal.init();
jpTerminal.setActive('#main-terminal');
jpTerminal.addCommand({
name: 'music',
summary: 'turn background music on or off',
manPage: 'SYNOPSIS\n' +
'\tmusic [on|off]\n\n' +
'DESCRIPTION\n' +
'\tManage the state of the \'Dennis Steals the Embryo\' ' +
'music. Use the \'on\' state for\n\tincreased epicness.\n\n' +
'AUTHOR\n' +
'\tWritten by <a href="https://tully.io">Tully Robinson</a>.\n',
command: function(env, inputLine) {
const arg = inputLine.trim().split(/ +/)[1] || '';
const output = $('<span/>').text('music: must specify state [on|off]');
if (!arg || !arg.match(/^(?:on|off)$/i)) {
$('#main-input').append(output);
} else {
if (arg.toLowerCase() === 'on') {
if (!env.musicOn) {
env.sounds.dennisMusic.play();
}
env.musicOn = true;
} else if (arg.toLowerCase() === 'off') {
env.sounds.dennisMusic.stop();
env.musicOn = false;
}
}
},
});
jpTerminal.addCommand({
name: 'access',
summary: 'access a target environment on the Jurassic Systems grid',
manPage: 'SYNOPSIS\n' +
'\taccess [SYSTEM_NAME] [MAGIC_WORD]\n\n' +
'DESCRIPTION\n' +
'\tGain read and write access to a specified environment.\n\n' +
'AUTHOR\n' +
'\tWritten by Dennis Nedry.\n',
command: function(env, inputLine) {
const output = $('<span>').text('access: PERMISSION DENIED.');
const arg = inputLine.split(/ +/)[1] || '';
const magicWord =
inputLine.substring(inputLine.trim().lastIndexOf(' ')) || '';
if (arg === '') {
$('#main-input').append($('<span/>')
.text('access: must specify target system'));
return;
} else if (
inputLine.split(' ').length > 2 &&
magicWord.trim() === 'please'
) {
$('#main-input')
.append($('<img id="asciiNewman" src="/img/asciiNewman.jpg" />'));
$('#asciiNewman').load(function() {
const wrap = $('.inner-wrap', env.active);
wrap.scrollTop(wrap[0].scrollHeight);
});
return;
}
$('#main-input').append(output);
env.sounds.beep.play();
if (++env.accessAttempts >= 3) {
const andMessage = $('<span>').text('...and...');
let errorSpam;
$('.irix-window').unbind('keydown');
$('#main-prompt').addClass('hide');
setTimeout(function() {
$('#main-input').append(andMessage);
}, 200);
setTimeout(function() {
env.sounds.lockDown.play();
}, 1000);
setTimeout(function() {
$('#environment').animate(
{'left': '+=3000'},
2000,
function() {
setTimeout(function() {
const theKingVideo = document.getElementById('the-king-video');
errorSpam != null && clearInterval(errorSpam);
theKingVideo != null && theKingVideo.play();
$('#irix-desktop').hide();
$('#mac-hd-window').css('background-image', 'url(/img/macHDBlur.jpg)');
$('#the-king-window').show();
setTimeout(function() {
$('#home-key').css('z-index', '64000');
}, 10000);
}, 2000);
},
);
}, 4000);
setTimeout(function() {
errorSpam = setInterval(function() {
var errorMessage = $('<div>YOU DIDN\'T SAY THE MAGIC WORD!</div>');
$('#main-input').append(errorMessage);
$('#main-inner').scrollTop($('#main-inner')[0].scrollHeight);
}, 50);
}, 1000);
}
}
});
jpTerminal.addCommand({
name: 'system',
summary: 'check a system\'s current status',
manPage: 'SYNOPSIS\n' +
'\tsystem [SYSTEM_NAME]\n\n' +
'DESCRIPTION\n' +
'\tCheck the input system and return each sector\'s ' +
'current status.\n\n' +
'AUTHOR\n' +
'\tWritten by Dennis Nedry.\n',
command: function(env, inputLine) {
const arg = inputLine.split(/ +/)[1] || '';
let output = '<span>system: must specify target system</span>';
if (arg.length > 0) {
let system = arg.replace(/s$/, '');
system = system[0].toUpperCase() + system.slice(1);
system = $('<div/>').text(system).html();
output = '<div>' + system + ' containment enclosure....</div>' +
'<table id="system-output"><tbody>' +
'<tr><td>Security</td><td>[OK]</td></tr>' +
'<tr><td>Fence</td><td>[OK]</td></tr>' +
'<tr><td>Feeding Pavilion</td><td>[OK]</td></tr>' +
'</tbody></table>';
$('#main-prompt').addClass('hide');
$('#main-input').append($(output));
output = '<div>System Halt!</div>';
env.sounds.beep.play();
setTimeout(function() {
const wrap = $('.inner-wrap', env.active);
env.sounds.beep.play();
$('#main-input').append($(output));
wrap.scrollTop(wrap[0].scrollHeight);
$('#main-prompt').removeClass('hide');
}, 900);
} else {
$('#main-input').append($(output));
}
}
});
jpTerminal.addCommand({
name: 'ls',
summary: 'list files in the current directory',
manPage: 'SYNOPSIS\n' +
'\tls [FILE] ...\n\n' +
'DESCRIPTION\n' +
'\tList information about the FILEs ' +
'(the current directory by default).\n\n' +
'AUTHOR\n' +
'\tWritten by Richard Stallman and David MacKenzie.\n',
command: function(env, inputLine) {
$('#main-input').append($('<div>zebraGirl.jpg</div>'));
}
});
jpTerminal.addCommand({
name: 'display',
summary: 'display image files (hint: use ls to find a \'file\')',
manPage: 'SYNOPSIS\n' +
'\tdisplay file ...\n\n' +
'DESCRIPTION\n' +
'\tDisplay is a machine architecture independent image ' +
'processing and display\n\tprogram. It can ' +
'<strong>display</strong> an image on any workstation screen ' +
'running an X server.\n\n' +
'AUTHOR\n' +
'\tJohn Cristy, ImageMagick Studio.\n',
command: function(env, inputLine) {
const args = inputLine.trim().split(' ');
if (args.length < 2) {
$('#main-input')
.append($('<span>display: no file specified</span>'));
return;
}
if (inputLine.match(/zebraGirl\.jpg/)) {
setTimeout(function() {
$('#zebra-girl').css('z-index', ++env.maxIndex);
$('#zebra-girl').show();
blurAllWindows();
}, 300);
}
}
});
jpTerminal.addCommand({
name: 'keychecks',
summary: 'display system level command history',
manPage: 'SYNOPSIS\n' +
'\tkeychecks\n\n' +
'DESCRIPTION\n' +
'\tA system level command log used for accountability ' +
'purposes. keychecks must be\n\tactivated or deactivated ' +
'via the main board.\n',
command: function(env, inputLine) {
const output =
'13,42,121,32,88,77,19,13,44,52,77,90,13,99,13,100,13,109,55,103,144,' +
'13,99,87,60,13,44,12,09,13,43,63,13,46,57,89,103,122,13,44,52,88,931,' +
'13,21,13,57,98,100,102,103,13,112,13,146,13,13,13,77,67,88,23,13,13\n' +
'system\n' +
'nedry\n' +
'go to command level\n' +
'nedry\n' +
'040/#xy/67&\n' +
'mr goodbytes\n' +
'security\n' +
'keycheck off\n' +
'safety off\n' +
'sl off\n' +
'security\n' +
'whte_rbt.obj\n';
$('#main-input').append(output);
}
});
jpTerminal.addCommand({
name: 'man',
summary: 'display reference manual for a given command',
manPage: 'SYNOPSIS\n' +
'\tman title ...\n\n' +
'DESCRIPTION\n' +
'\tman locates and prints the titled entries from the on-line ' +
'reference manuals.\n',
command: function(env, inputLine) {
const arg = inputLine.trim().split(/ +/)[1] || '';
let output = 'What manual page do you want?';
if (env.commands.hasOwnProperty(arg)) {
output = env.commands[arg].manPage;
} else if (arg) {
output = 'No manual entry for ' + $('<div/>').text(arg).html();
}
$('#main-input').append(output);
}
});
jpTerminal.addCommand({
name: 'help',
summary: 'list available commands',
manPage: 'SYNOPSIS\n' +
'\thelp\n\n' +
'DESCRIPTION\n' +
'\tDisplay a command summary for Jurassic Systems.\n\n' +
'AUTHOR\n' +
'\tWritten by <a href="https://tully.io">Tully Robinson</a>.\n',
command: function(env, inputLine) {
for (var command in env.commands) {
env.active.find('.command-history')
.append($('<div>')
.text(
env.commands[command].name +
' - ' +
env.commands[command].summary)
);
}
}
});
// helpers
const flicker = function(altId, interval, duration) {
let visible = true;
const alt = $('#' + altId).show();
const flickering = setInterval(function() {
if (visible) {
alt.css('opacity', '1');
} else {
alt.css('opacity', '0');
}
visible = !visible;
}, interval);
setTimeout(function() {
clearInterval(flickering);
alt.css('opacity', '0');
alt.hide()
}, duration);
};
const blurAllWindows = function() {
$('.cursor', '.irix-window').removeClass('active-cursor');
$('.buffer').blur();
};
$(document).ready(function() {
// attempt to cache objects
$(['theKingBlur.jpg',
'theKingFocus.jpg',
'macHDBlur.jpg',
'asciiNewman.jpg',
'zebraGirlWindow.jpg',
]).each(function() {
new Image().src = '/img/' + this;
});
// remove boot screen
setTimeout(function() {
$('#irix-boot').remove();
$('#main-buffer').focus();
if (!location.pathname.match(/system/)) {
$('#main-buffer').blur();
$('#intro').show();
$('#intro').click(function() {
$(this).fadeOut(1000);
$('#intro-scene').attr('src', '');
});
}
}, 4500);
$('body').click(blurAllWindows);
(function() {
let diffX = 0;
let diffY = 0;
$('.window-bar').mousedown(function(e) {
var dragging = $(this).parent()
.css('z-index', jpTerminal.nextIndex())
.addClass('dragging');
diffY = e.pageY - dragging.offset().top;
diffX = e.pageX - dragging.offset().left;
});
$('body').mousemove(function(e) {
$('.dragging').offset({
top: e.pageY - diffY,
left: e.pageX - diffX
});
});
}());
$('body').mouseup(function(e) {
$('.dragging').removeClass('dragging');
});
$('.irix-window').click(function(e) {
e.stopPropagation();
blurAllWindows();
jpTerminal.setActive(this);
$('.buffer', this).focus();
$(this).css('z-index', jpTerminal.nextIndex());
$(this).find('.cursor').addClass('active-cursor');
});
$(window).keydown(function(e) {
if ([37, 38, 39, 40].indexOf(e.keyCode || e.which) > -1) {
e.preventDefault();
}
});
$('.irix-window').keydown(function(e) {
const key = e.keyCode || e.which;
const activeTerminal = jpTerminal.getActive();
if (!activeTerminal) {
return false;
}
// if enter
if (key === 13) {
const line = activeTerminal.find('.buffer').val();
activeTerminal.find('.buffer').val('');
if (activeTerminal.attr('id') === 'chess-terminal') {
$('#curr-chess-input').html('');
activeTerminal.find('.command-history')
.append($('<div class="entered-command">')
.text(line || ' '));
} else {
$('#curr-main-input').html('');
jpTerminal.buildCommandLine(line);
}
}
const wrap = activeTerminal.find('.inner-wrap');
wrap.scrollTop(wrap[0].scrollHeight);
});
$('#main-terminal .buffer').bind('input propertychange', function() {
$('#curr-main-input').text($(this).val());
});
$('#chess-terminal .buffer').bind('input propertychange', function() {
$('#curr-chess-input').text($(this).val());
});
$('#apple-desktop').click(function(e){
if ($(e.target).closest('.mac-window').attr('id') !== 'the-king-window') {
flicker('the-king-blur', 50, 450);
}
});
});
}(jQuery, soundManager));