mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 08:44:00 -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);
|
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() {
|
function loadRoster() {
|
||||||
if (window.localStorage) {
|
if (storage) {
|
||||||
var r = window.localStorage.getItem("roster");
|
var r = storage.getItem("roster");
|
||||||
if (!r) return {};
|
if (!r) return {};
|
||||||
try {
|
try {
|
||||||
return JSON.parse(r);
|
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) {
|
function storeRoster(roster) {
|
||||||
if (window.localStorage)
|
if (storage)
|
||||||
window.localStorage.setItem("roster", JSON.stringify(roster));
|
storage.setItem("roster", JSON.stringify(roster));
|
||||||
}
|
}
|
||||||
|
|
||||||
function addToRoster(newguy) {
|
function addToRoster(newguy) {
|
||||||
if (window.localStorage) {
|
if (storage) {
|
||||||
var r = loadRoster();
|
var r = loadRoster();
|
||||||
r[newguy.name] = newguy;
|
r[newguy.name] = newguy;
|
||||||
storeRoster(r);
|
storeRoster(r);
|
||||||
|
} else {
|
||||||
|
document.cookie = escape(JSON.stringify(newguy));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -976,7 +976,7 @@ function FormCreate() {
|
|||||||
function LoadCharacter() {
|
function LoadCharacter() {
|
||||||
var result = true;
|
var result = true;
|
||||||
var name = window.location.href.split('#')[1];
|
var name = window.location.href.split('#')[1];
|
||||||
var sheet = loadRoster()[name];
|
var sheet = loadSheet(name);
|
||||||
|
|
||||||
if (!sheet.Traits) {
|
if (!sheet.Traits) {
|
||||||
// New game
|
// New game
|
||||||
|
|||||||
@@ -6,11 +6,11 @@ $(document).ready(function () {
|
|||||||
var roster = $("#roster");
|
var roster = $("#roster");
|
||||||
roster.empty();
|
roster.empty();
|
||||||
|
|
||||||
games = loadRoster();
|
if (!storage) {
|
||||||
if (!games) {
|
|
||||||
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.");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
games = loadRoster() || {};
|
||||||
$.each(games, function (key, c) {
|
$.each(games, function (key, c) {
|
||||||
var name = c.Traits.Name;
|
var name = c.Traits.Name;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user