Skip to content

Commit 858f4dc

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

88 files changed

Lines changed: 186 additions & 66 deletions

Some content is hidden

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

.DS_Store

0 Bytes
Binary file not shown.

dragonruby-html5-loader.js

Lines changed: 81 additions & 57 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,6 +360,31 @@ 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');
@@ -498,8 +523,14 @@ var base64Encode = function(ui8array) {
498523
return out;
499524
}
500525

526+
function startGame()
527+
{
528+
Module["removeRunDependency"]("dragonruby_init");
529+
}
530+
531+
501532
var Module = {
502-
noInitialRun: true,
533+
noInitialRun: false,
503534
preInit: [],
504535
clickedToPlay: false,
505536
clickToPlayListener: function() {
@@ -510,32 +541,50 @@ var Module = {
510541
div.removeEventListener('click', Module.clickToPlayListener);
511542
document.body.removeChild(div);
512543
}
513-
if (window.parent.window.gtk.starting) {
514-
window.parent.window.gtk.starting();
515-
}
516-
Module["callMain"](); // go go go!
544+
// if (window.parent.window.gtk.starting) {
545+
// window.parent.window.gtk.starting();
546+
// }
547+
548+
startGame(); // go go go!
517549
},
518550
startClickToPlay: function() {
519551
var base64 = base64Encode(FS.readFile(GDragonRubyIcon, {}));
520552
var div = document.createElement('div');
553+
var leftPx = ((window.innerWidth - 640) / 2);
554+
var leftPerc = Math.floor((leftPx / window.innerWidth) * 100);
521555
div.id = 'clicktoplaydiv';
556+
div.style.width = '360px';
557+
div.style.height = '360px';
522558
div.style.backgroundColor = 'rgb(40, 44, 52)';
523-
559+
div.style.position = 'absolute';
560+
div.style.top = '50%';
561+
div.style.left = '50%';
562+
div.style.transform = 'translate(-50%, -50%)';
524563

525564
var img = new Image();
526565
img.onload = function() { // once we know its size, scale it, keeping aspect ratio.
527-
img.style.width = '128px';
528-
img.style.height = '101px';
566+
var pct = 30;
567+
var w = img.naturalWidth;
568+
var h = img.naturalHeight;
569+
if (!w || !h || (w == h)) {
570+
img.style.width = '' + pct + '%';
571+
img.style.height = '' + pct + '%';
572+
} else if (w > h) {
573+
img.style.width = '' + pct + '%';
574+
} else {
575+
img.style.height = '' + pct + '%';
576+
}
529577
img.style.display = 'block';
530578
}
531579

532580
img.style.display = 'none';
533-
img.style.width = '128px';
534-
img.style.height = '101px';
581+
img.style.width = 'auto';
582+
img.style.height = 'auto';
535583
img.style.margin = 0;
536584
img.style.position = 'absolute';
537-
img.style.top = '10px';
538-
img.style.left = '176px';
585+
img.style.top = '50%';
586+
img.style.left = '50%';
587+
img.style.transform = 'translate(-50%, -50%)';
539588
img.src = 'data:image/png;base64,' + base64;
540589
div.appendChild(img);
541590

@@ -553,7 +602,7 @@ var Module = {
553602
div.appendChild(p);
554603

555604
p = document.createElement('p');
556-
p.innerHTML = 'Click here to begin, or press Ctrl+S<br/>in the code editor to the left.';
605+
p.innerHTML = 'Click the run button, or press Ctrl+S<br/>in the code editor to the left.';
557606
p.style['font-family'] = "monospace";
558607
p.style.textAlign = 'center';
559608
p.style.backgroundColor = 'rgb(40, 44, 52)';
@@ -568,25 +617,10 @@ var Module = {
568617
window.gtk.play = Module.clickToPlayListener;
569618
},
570619
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-
});
620+
// this prevents the game from running. We'll remove the dependency when
621+
// we have downloaded everything and the user has clicked-through to play.
622+
Module["addRunDependency"]("dragonruby_init");
623+
prepareFilesystem(); // will get data, async.
590624
},
591625
postRun: [],
592626
print: (function() {
@@ -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.

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

gamedata/fonts/console-font.ttf

-9.98 KB
Binary file not shown.

gamedata/fonts/font.ttf

-9.98 KB
Binary file not shown.

gamedata/metadata/game_metadata.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ devid=dragonruby
22
devtitle=DragonRuby
33
gameid=dragonruby-sandbox
44
gametitle=DragonRuby Sandbox
5-
version=2.0
5+
version=3.0
66
icon=metadata/icon.png

gamedata/metadata/ios_metadata.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# ios_metadata.txt is used by the Pro version of DragonRuby Game Toolkit to create iOS apps.
2+
# Information about the Pro version can be found at: http://dragonruby.org/toolkit/game#purchase
3+
4+
# teamname needs to be set to your assigned team id which can be found at https://developer.apple.com/account/#/membership/L7H57V9CRD
5+
teamid=
6+
# appid needs to be set to your application identifier which can be found at https://developer.apple.com/account/resources/identifiers/list
7+
appid=
8+
# appname is the name you want to show up underneath the app icon on the device
9+
appname=

0 commit comments

Comments
 (0)