Skip to content

Commit df7dce0

Browse files
committed
Updated fiddle, with latest version of DRGTK Standard.
1 parent 1d0f0d4 commit df7dce0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+332
-496
lines changed

.DS_Store

0 Bytes
Binary file not shown.

dragonruby-html5-loader.js

Lines changed: 96 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var GDragonRubyGameId = 'dragonruby-sandbox';
22
var GDragonRubyGameTitle = 'DragonRuby Sandbox';
33
var GDragonRubyDevTitle = 'DragonRuby';
4-
var GDragonRubyGameVersion = '2.0';
4+
var GDragonRubyGameVersion = '3.0';
55
var GDragonRubyIcon = '/metadata/icon.png';
66

77
function syncDataFiles(dbname, baseurl)
@@ -360,27 +360,56 @@ function syncDataFiles(dbname, baseurl)
360360
return retval;
361361
}
362362

363+
var prepareFilesystem = function()
364+
{
365+
// Download the game data and set up the filesystem!
366+
// set up a persistent store for save games, etc.
367+
FS.mkdir('/persistent');
368+
FS.mount(IDBFS, {}, '/persistent');
369+
FS.syncfs(true, function(err) {
370+
if (err) {
371+
console.log("WARNING: Failed to populate persistent store. Save games likely lost?");
372+
} else {
373+
console.log("Read in from persistent store.");
374+
}
375+
376+
loadDataFiles(GDragonRubyGameId, 'gamedata/', function() {
377+
console.log("Game data is sync'd to MEMFS. Starting click-to-play()...");
378+
//Module.setStatus("Ready!");
379+
//setTimeout(function() { Module.setStatus(""); statusElement.style.display='none'; }, 1000);
380+
Module.setStatus("");
381+
statusElement.style.display='none';
382+
Module.startClickToPlay();
383+
});
384+
});
385+
}
386+
387+
363388
var statusElement = document.getElementById('status');
364389
var progressElement = document.getElementById('progress');
365390
var canvasElement = document.getElementById('canvas');
366391

367-
canvasElement.style.width = '480px';
368-
canvasElement.style.height = '270px';
392+
canvasElement.style.width = '100%';
393+
canvasElement.style.height = '100%';
394+
document.getElementById('borderdiv').style.border = '0px';
369395

370-
statusElement.style.display = 'none';
371-
progressElement.style.display = 'none';
372-
document.getElementById('progressdiv').style.display = 'none';
396+
//statusElement.style.display = 'none';
397+
//progressElement.style.display = 'none';
398+
//document.getElementById('progressdiv').style.display = 'none';
373399
document.getElementById('output').style.display = 'none';
374-
document.getElementById('game-input').style.display = "none"
375400

376-
if (!window.parent.window.gtk) {
377-
window.parent.window.gtk = {};
378-
}
401+
// if (!window.parent.window.gtk) {
402+
// window.parent.window.gtk = {};
403+
// }
379404

380405
window.parent.window.gtk.saveMain = function(text) {
381406
FS.writeFile('app/main.rb', text);
382407
window.gtk.play();
383408
}
409+
// window.parent.window.gtk.saveMain = function(text) {
410+
// FS.writeFile('app/main.rb', text);
411+
// window.gtk.play();
412+
// }
384413

385414

386415
var loadDataFiles = function(dbname, baseurl, onsuccess) {
@@ -498,8 +527,14 @@ var base64Encode = function(ui8array) {
498527
return out;
499528
}
500529

530+
function startGame()
531+
{
532+
Module["removeRunDependency"]("dragonruby_init");
533+
}
534+
535+
501536
var Module = {
502-
noInitialRun: true,
537+
noInitialRun: false,
503538
preInit: [],
504539
clickedToPlay: false,
505540
clickToPlayListener: function() {
@@ -510,32 +545,50 @@ var Module = {
510545
div.removeEventListener('click', Module.clickToPlayListener);
511546
document.body.removeChild(div);
512547
}
513-
if (window.parent.window.gtk.starting) {
514-
window.parent.window.gtk.starting();
515-
}
516-
Module["callMain"](); // go go go!
548+
// if (window.parent.window.gtk.starting) {
549+
// window.parent.window.gtk.starting();
550+
// }
551+
552+
startGame(); // go go go!
517553
},
518554
startClickToPlay: function() {
519555
var base64 = base64Encode(FS.readFile(GDragonRubyIcon, {}));
520556
var div = document.createElement('div');
557+
var leftPx = ((window.innerWidth - 640) / 2);
558+
var leftPerc = Math.floor((leftPx / window.innerWidth) * 100);
521559
div.id = 'clicktoplaydiv';
560+
div.style.width = '360px';
561+
div.style.height = '360px';
522562
div.style.backgroundColor = 'rgb(40, 44, 52)';
523-
563+
div.style.position = 'absolute';
564+
div.style.top = '50%';
565+
div.style.left = '50%';
566+
div.style.transform = 'translate(-50%, -50%)';
524567

525568
var img = new Image();
526569
img.onload = function() { // once we know its size, scale it, keeping aspect ratio.
527-
img.style.width = '128px';
528-
img.style.height = '101px';
570+
var pct = 30;
571+
var w = img.naturalWidth;
572+
var h = img.naturalHeight;
573+
if (!w || !h || (w == h)) {
574+
img.style.width = '' + pct + '%';
575+
img.style.height = '' + pct + '%';
576+
} else if (w > h) {
577+
img.style.width = '' + pct + '%';
578+
} else {
579+
img.style.height = '' + pct + '%';
580+
}
529581
img.style.display = 'block';
530582
}
531583

532584
img.style.display = 'none';
533-
img.style.width = '128px';
534-
img.style.height = '101px';
585+
img.style.width = 'auto';
586+
img.style.height = 'auto';
535587
img.style.margin = 0;
536588
img.style.position = 'absolute';
537-
img.style.top = '10px';
538-
img.style.left = '176px';
589+
img.style.top = '25%';
590+
img.style.left = '50%';
591+
img.style.transform = 'translate(-50%, -50%)';
539592
img.src = 'data:image/png;base64,' + base64;
540593
div.appendChild(img);
541594

@@ -553,40 +606,26 @@ var Module = {
553606
div.appendChild(p);
554607

555608
p = document.createElement('p');
556-
p.innerHTML = 'Click here to begin, or press Ctrl+S<br/>in the code editor to the left.';
609+
p.innerHTML = 'Click the run button, or press Ctrl+S<br/>in the code editor to the left.';
557610
p.style['font-family'] = "monospace";
611+
p.style['font-size'] = "14px";
558612
p.style.textAlign = 'center';
559613
p.style.backgroundColor = 'rgb(40, 44, 52)';
560614
p.style.color = '#FFFFFF';
561615
p.style.width = '100%';
562616
p.style.position = 'absolute';
563-
p.style.top = '70%';
617+
p.style.top = '60%';
564618
div.appendChild(p);
565619

566620
document.body.appendChild(div);
567621
div.addEventListener('click', Module.clickToPlayListener);
568622
window.gtk.play = Module.clickToPlayListener;
569623
},
570624
preRun: function() {
571-
// set up a persistent store for save games, etc.
572-
FS.mkdir('/persistent');
573-
FS.mount(IDBFS, {}, '/persistent');
574-
FS.syncfs(true, function(err) {
575-
if (err) {
576-
console.log("WARNING: Failed to populate persistent store. Save games likely lost?");
577-
} else {
578-
console.log("Read in from persistent store.");
579-
}
580-
581-
loadDataFiles(GDragonRubyGameId, 'gamedata/', function() {
582-
console.log("Game data is sync'd to MEMFS. Starting click-to-play()...");
583-
//Module.setStatus("Ready!");
584-
//setTimeout(function() { Module.setStatus(""); statusElement.style.display='none'; }, 1000);
585-
Module.setStatus("");
586-
statusElement.style.display='none';
587-
Module.startClickToPlay();
588-
});
589-
});
625+
// this prevents the game from running. We'll remove the dependency when
626+
// we have downloaded everything and the user has clicked-through to play.
627+
Module["addRunDependency"]("dragonruby_init");
628+
prepareFilesystem(); // will get data, async.
590629
},
591630
postRun: [],
592631
print: (function() {
@@ -624,11 +663,6 @@ var Module = {
624663
canvas.addEventListener("click", function() {
625664
document.getElementById('toplevel').click();
626665
document.getElementById('toplevel').focus();
627-
document.getElementById('game-input').style.display = "inline"
628-
document.getElementById('game-input').focus();
629-
document.getElementById('game-input').blur();
630-
document.getElementById('game-input').style.display = "none"
631-
window.scrollTo(0, 0);
632666
canvas.focus();
633667
});
634668

@@ -668,36 +702,26 @@ window.onerror = function(event) {
668702
};
669703
};
670704

705+
// sanity check this before downloading anything heavy.
671706
var hasWebAssembly = false;
672707
if (typeof WebAssembly==="object" && typeof WebAssembly.Memory==="function") {
673708
hasWebAssembly = true;
674709
}
675710
//console.log("Do we have WebAssembly? " + ((hasWebAssembly) ? "YES" : "NO"));
711+
if (!hasWebAssembly) {
712+
Module.setStatus("Your browser doesn't have WebAssembly support. Please upgrade.");
713+
} else {
714+
var buildtype = "wasm";
715+
var module = "dragonruby-" + buildtype + ".js";
716+
window.gtk = {};
717+
window.gtk.module = Module;
676718

677-
var buildtype = hasWebAssembly ? "wasm" : "asmjs";
678-
var module = "dragonruby-" + buildtype + ".js";
679-
window.gtk = {};
680-
window.gtk.module = Module;
681-
682-
//console.log("Our main module is: " + module);
719+
//console.log("Our main module is: " + module);
683720

684-
var script = document.createElement('script');
685-
script.src = module;
686-
if (hasWebAssembly) {
721+
var script = document.createElement('script');
722+
script.src = module;
687723
script.async = true;
688-
} else {
689-
script.async = false; // !!! FIXME: can this be async?
690-
(function() {
691-
var memoryInitializer = module + '.mem';
692-
if (typeof Module['locateFile'] === 'function') {
693-
memoryInitializer = Module['locateFile'](memoryInitializer);
694-
} else if (Module['memoryInitializerPrefixURL']) {
695-
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
696-
}
697-
var meminitXHR = Module['memoryInitializerRequest'] = new XMLHttpRequest();
698-
meminitXHR.open('GET', memoryInitializer, true);
699-
meminitXHR.responseType = 'arraybuffer';
700-
meminitXHR.send(null);
701-
})();
724+
document.body.appendChild(script);
702725
}
703-
document.body.appendChild(script);
726+
727+
// end of dragonruby-html5-loader.js ...

dragonruby-wasm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dragonruby-wasm.wasm

154 KB
Binary file not shown.

game.css

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,5 @@ body {
44
border: 0;
55
}
66
canvas {
7-
background-color: rgb(80, 80, 80);
8-
border: 0px none;
9-
}
10-
11-
#borderdiv {
12-
width: 1280px;
13-
height: 720px;
14-
margin-left: auto;
15-
margin-right: auto;
16-
display: block;
7+
background-color: rgb(40, 44, 52);
178
}

game.html

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,85 @@
22
<html lang="en-us">
33
<head>
44
<meta charset="utf-8">
5+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
6+
<link rel="icon" href="favicon.png" type="image/png" />
7+
<title>DragonRuby</title>
8+
<style>
9+
body {
10+
font-family: arial;
11+
margin: 0;
12+
padding: none;
13+
background: #000000;
14+
}
15+
16+
.emscripten { padding-right: 0; margin-left: auto; margin-right: auto; display: block; }
17+
div.emscripten { text-align: center; }
18+
div.emscripten_border { border: 1px solid black; }
19+
/* the canvas *must not* have any border or padding, or mouse coords will be wrong */
20+
canvas.emscripten { border: 0px none; background-color: black; }
21+
22+
#emscripten_logo {
23+
display: inline-block;
24+
margin: 0;
25+
}
26+
27+
@-webkit-keyframes rotation {
28+
from {-webkit-transform: rotate(0deg);}
29+
to {-webkit-transform: rotate(360deg);}
30+
}
31+
@-moz-keyframes rotation {
32+
from {-moz-transform: rotate(0deg);}
33+
to {-moz-transform: rotate(360deg);}
34+
}
35+
@-o-keyframes rotation {
36+
from {-o-transform: rotate(0deg);}
37+
to {-o-transform: rotate(360deg);}
38+
}
39+
@keyframes rotation {
40+
from {transform: rotate(0deg);}
41+
to {transform: rotate(360deg);}
42+
}
43+
44+
#status {
45+
display: inline-block;
46+
font-weight: bold;
47+
color: rgb(120, 120, 120);
48+
position: absolute;
49+
top: 50%;
50+
left: 50%;
51+
transform: translate(-50%, -50%);
52+
}
53+
54+
#progress {
55+
height: 20px;
56+
width: 30px;
57+
}
58+
59+
#output {
60+
width: 100%;
61+
height: 200px;
62+
margin: 0 auto;
63+
margin-top: 10px;
64+
border-left: 0px;
65+
border-right: 0px;
66+
padding-left: 0px;
67+
padding-right: 0px;
68+
display: none;
69+
background-color: black;
70+
color: white;
71+
font-family: 'Lucida Console', Monaco, monospace;
72+
outline: none;
73+
}
74+
</style>
575
<link rel="stylesheet" href="game.css" />
676
<title>DragonRuby Game Toolkit Tutorial</title>
777
</head>
878
<body id='toplevel'>
9-
<textarea style="display: none;" id="output" rows="1"></textarea>
1079
<div class="emscripten_border" id='borderdiv'>
11-
<input id="game-input" autocomplete="off" />
12-
<canvas class="game emscripten" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
80+
<canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" tabindex=-1></canvas>
1381
</div>
14-
<br/>
82+
<textarea style="display: none;" id="output" rows="8"></textarea>
83+
1584
<div class="emscripten" id="status"></div>
1685
<div class="emscripten" id='progressdiv'>
1786
<progress value="0" max="100" id="progress"></progress>

gamedata/.DS_Store

6 KB
Binary file not shown.

gamedata/app/main.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
def tick args
2-
args.outputs.background_color = [40, 44, 52]
2+
args.outputs.labels << [640, 500, 'Hello World!', 5, 1]
3+
args.outputs.labels << [640, 460, 'Go to docs/docs.html and read it!', 5, 1]
4+
args.outputs.labels << [640, 420, 'Join the Discord! http://discord.dragonruby.org', 5, 1]
5+
args.outputs.sprites << [576, 280, 128, 101, 'dragonruby.png']
36
end

0 commit comments

Comments
 (0)