Added untested Save, Load, Erase functions for handling game data.

This commit is contained in:
Robbie Antenesse 2016-04-17 13:45:43 -06:00
parent f20065727f
commit 16e27ec04c
1 changed files with 51 additions and 0 deletions

View File

@ -1361,6 +1361,57 @@ Oversimplified.Copy = function (object, newID, newName) {
return resultingCopy; return resultingCopy;
} }
Oversimplified.Save = function (location, data) {
// Set and overwrite data at specified location in browser's Local Storage
if(typeof(Storage) !== "undefined") {
localStorage.setItem(location, data);
if (localStorage.getItem(location) == data) {
if (Oversimplified.DEBUG.showMessages) console.log("Successfully saved " + data + " to localStorage[\"" + location + "\"].");
return true;
} else {
if (Oversimplified.DEBUG.showMessages) console.log("Could not save " + data + " to localStorage[\"" + location + "\"].");
}
} else {
if (Oversimplified.DEBUG.showMessages) console.log("This browser does not support saving to localStorage.");
}
return false;
}
Oversimplified.Load = function (location) {
// Load data from specified location in browser's Local Storage
if(typeof(Storage) !== "undefined") {
if (localStorage.getItem(location)) {
if (Oversimplified.DEBUG.showMessages) console.log("Successfully saved " + data + " to localStorage[\"" + location + "\"].");
return localStorage.getItem(location);
} else {
if (Oversimplified.DEBUG.showMessages) console.log("No data saved in localStorage[\"" + location + "\"].");
}
} else {
if (Oversimplified.DEBUG.showMessages) console.log("This browser does not support loading from localStorage.");
}
return false;
}
Oversimplified.Erase = function (location) {
// Remove data at specified location in browser's Local Storage
if(typeof(Storage) !== "undefined") {
if (localStorage.getItem(location)) {
localStorage.removeItem(location);
if (!localStorage.getItem(location)) {
if (Oversimplified.DEBUG.showMessages) console.log("Successfully erased localStorage[\"" + location + "\"].");
return true;
} else {
if (Oversimplified.DEBUG.showMessages) console.log("Could not erase localStorage[\"" + location + "\"].");
}
} else {
if (Oversimplified.DEBUG.showMessages) console.log("There is no data to remove from localStorage[\"" + location + "\"].");
}
} else {
if (Oversimplified.DEBUG.showMessages) console.log("This browser does not support manipulating localStorage.");
}
return false;
}
// DEBUG object // DEBUG object
Oversimplified.DEBUG = { Oversimplified.DEBUG = {
// Show console.log messages. // Show console.log messages.