mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 16:54:04 -06:00
Kind of working - one shot characters using cookies
This commit is contained in:
@@ -146,10 +146,30 @@ function GenerateName() {
|
||||
return result.charAt(0).toUpperCase() + result.slice(1);
|
||||
}
|
||||
|
||||
var cookieStorage = {
|
||||
getItem: function(key) {
|
||||
try {
|
||||
var sheet = JSON.parse(unescape(document.cookie));
|
||||
var result = {};
|
||||
result[sheet.name] = sheet;
|
||||
return result;
|
||||
} catch (err) {
|
||||
// Probably a JSON parse error
|
||||
return {}
|
||||
}
|
||||
},
|
||||
|
||||
setItem: function (key, value) {
|
||||
document.cookie = escape(JSON.stringify(value[something]));
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
var storage = window.localStorage;
|
||||
|
||||
function loadRoster() {
|
||||
if (window.localStorage) {
|
||||
var r = window.localStorage.getItem("roster");
|
||||
if (storage) {
|
||||
var r = storage.getItem("roster");
|
||||
if (!r) return {};
|
||||
try {
|
||||
return JSON.parse(r);
|
||||
@@ -159,16 +179,29 @@ function loadRoster() {
|
||||
}
|
||||
}
|
||||
|
||||
function loadSheet(name) {
|
||||
if (storage) {
|
||||
return loadRoster()[name];
|
||||
} else try {
|
||||
return JSON.parse(unescape(document.cookie));
|
||||
} catch (err) {
|
||||
alert("Cookies must be enabled");
|
||||
window.location = "roster.html";
|
||||
}
|
||||
}
|
||||
|
||||
function storeRoster(roster) {
|
||||
if (window.localStorage)
|
||||
window.localStorage.setItem("roster", JSON.stringify(roster));
|
||||
if (storage)
|
||||
storage.setItem("roster", JSON.stringify(roster));
|
||||
}
|
||||
|
||||
function addToRoster(newguy) {
|
||||
if (window.localStorage) {
|
||||
if (storage) {
|
||||
var r = loadRoster();
|
||||
r[newguy.name] = newguy;
|
||||
storeRoster(r);
|
||||
} else {
|
||||
document.cookie = escape(JSON.stringify(newguy));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -976,7 +976,7 @@ function FormCreate() {
|
||||
function LoadCharacter() {
|
||||
var result = true;
|
||||
var name = window.location.href.split('#')[1];
|
||||
var sheet = loadRoster()[name];
|
||||
var sheet = loadSheet(name);
|
||||
|
||||
if (!sheet.Traits) {
|
||||
// New game
|
||||
|
||||
@@ -6,11 +6,11 @@ $(document).ready(function () {
|
||||
var roster = $("#roster");
|
||||
roster.empty();
|
||||
|
||||
games = loadRoster();
|
||||
if (!games) {
|
||||
if (!storage) {
|
||||
roster.html("<b>This browser does not support local storage. You may still play fast and loose: the game will last only as long as the page stays open in your browser.");
|
||||
return;
|
||||
}
|
||||
games = loadRoster() || {};
|
||||
$.each(games, function (key, c) {
|
||||
var name = c.Traits.Name;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user