-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading from localstorage, and basic buttons available/displayed
- Loading branch information
1 parent
dbd1a66
commit 14712b0
Showing
5 changed files
with
108 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,4 @@ | ||
// var level; | ||
|
||
// document.getElementById('levelParseStart').addEventListener('click', function (e) { | ||
// level = JSON.parse( | ||
// document.getElementById('levelDropZone').value | ||
// ); | ||
// console.log(level); | ||
// }) | ||
|
||
var request = new XMLHttpRequest(); | ||
request.overrideMimeType('application/json'); | ||
request.open('get', '/js/templates/example_level.json', true) | ||
request.onreadystatechange = function () { | ||
if (request.readyState === 4 && request.status == "200") { | ||
var level = JSON.parse(request.responseText); | ||
Level = level; | ||
// console.log(level); | ||
render_level(level) | ||
init_game() | ||
} | ||
} | ||
request.send(); | ||
document.addEventListener('DOMContentLoaded', function (e) { | ||
initialize(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function load_settings() { | ||
return { | ||
"localstorage": true, | ||
} | ||
} | ||
|
||
function initialize() { | ||
var settings = load_settings(); | ||
var gameWasLoadedFromLocalStorage = false; | ||
|
||
if (settings.localstorage) { | ||
gameWasLoadedFromLocalStorage = load_game(); | ||
} | ||
|
||
if (!gameWasLoadedFromLocalStorage) { | ||
console.log('We failed at loading from Localstorage'); | ||
load_fallback_json(); | ||
} | ||
|
||
init_game(); | ||
} | ||
|
||
|
||
|
||
function load_fallback_json() { | ||
var request = new XMLHttpRequest(); | ||
request.overrideMimeType('application/json'); | ||
request.open('get', '/js/templates/example_level.json', false) | ||
request.send(); | ||
|
||
if (request.readyState === 4 && request.status == "200") { | ||
var level = JSON.parse(request.responseText); | ||
Level = level; | ||
render_level(level) | ||
} | ||
} | ||
|
||
// function load_fallback_json_async() { | ||
// var request = new XMLHttpRequest(); | ||
// request.overrideMimeType('application/json'); | ||
// request.open('get', '/js/templates/example_level.json', true) | ||
// request.onreadystatechange = function () { | ||
// if (request.readyState === 4 && request.status == "200") { | ||
// var level = JSON.parse(request.responseText); | ||
// Level = level; | ||
// render_level(level) | ||
// // init_game() | ||
// } | ||
// } | ||
// request.send(); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters