First pass at loading characters and a readable roster

This commit is contained in:
Eric Fredricksen
2010-07-02 21:07:49 -07:00
parent ca2f9b30c3
commit 1c6a681880
5 changed files with 92 additions and 80 deletions
+7 -3
View File
@@ -124,11 +124,15 @@ function loadRoster() {
if (!window.localStorage) { if (!window.localStorage) {
return; return;
} else { } else {
var roster = window.localStorage.getItem("roster"); var r = window.localStorage.getItem("roster");
roster = roster ? JSON.parse(roster) : []; try {
r = JSON.parse(r);
} catch (err) {
r = [];
}
//if (!$.isArray(roster)) //if (!$.isArray(roster))
// roster = []; // roster = [];
return roster; return r;
} }
} }
+32 -39
View File
@@ -555,7 +555,6 @@ function StrToIntDef(s, def) {
$(document).ready(FormCreate); $(document).ready(FormCreate);
$(document).ready(GoButtonClick);
function WinSpell() { function WinSpell() {
@@ -1019,51 +1018,45 @@ function FormCreate() {
TaskBar.reposition(0); TaskBar.reposition(0);
ExpBar.reposition(0); ExpBar.reposition(0);
EncumBar.reposition(0); EncumBar.reposition(0);
LoadCharacter();
} }
function TMainForm_RollCharacter() { function LoadCharacter() {
var reuslt = true; var result = true;
for (;;) { var name = window.location.href.split('#')[1];
if (! NewGuyForm.Go()) var games = loadRoster();
return false; var ch;
Put(Traits, 'Name', NewGuyForm.Name.Text); $.each(games, function (index,sheet) {
if (FileExists(GameSaveName()) && if (sheet.name === name) {
(mrNo = MessageDlg('The saved game "' + GameSaveName() + '" already exists. Do you want to overwrite it?', mtWarning, [mbYes,mbNo], 0))) { ch = sheet;
// go around again return true;
0;
} else {
f = FileCreate(GameSaveName());
if (f == -1) {
ShowMessage("The thought police don't like the name '" + GameSaveName() + "'. Choose a name without \\ / : * ? \" < > || | in it.");
} else {
FileClose(f);
break;
} }
});
if (!ch.level) {
ch.level = 1;
ch['HP Max'] = Random(8) + ch.CON.div(6);
ch['MP Max'] = Random(8) + ch.INT.div(6);
ch.equips = {'Weapon': 'Sharp Stick'};
} }
} Put(Traits, 'Name', ch.name);
Put(Traits, 'Level', ch.level);
/* TODO: something like this Put(Traits, 'Race', ch.race);
with (NewGuyForm) { Put(Traits, 'Class', ch['class']);
Put(Traits,'Name',Name.Text); Put(Stats, 'STR', ch.STR);
Put(Traits,'Race',Race[Race.ItemIndex]); Put(Stats, 'CON', ch.CON);
Put(Traits,'Class',Klass[Klass.ItemIndex]); Put(Stats, 'DEX', ch.DEX);
Put(Traits,'Level',1); Put(Stats, 'INT', ch.INT);
Put(Stats,'STR',STR.Tag); Put(Stats, 'WIS', ch.WIS);
Put(Stats,'CON',CON.Tag); Put(Stats, 'CHA', ch.CHA);
Put(Stats,'DEX',DEX.Tag); Put(Stats, 'HP Max', ch['HP Max']);
Put(Stats,'INT',INT.Tag); Put(Stats, 'MP Max', ch['MP Max']);
Put(Stats,'WIS',WIS.Tag); Put(Equips, 'Weapon', ch.equips.Weapon);
Put(Stats,'CHA',CHA.Tag);
Put(Stats,'HP Max',Random(8) + CON.Tag.div(6));
Put(Stats,'MP Max',Random(8) + INT.Tag.div(6));
Put(Equips,'Weapon','Sharp Stick');
Put(Inventory,'Gold',0); Put(Inventory,'Gold',0);
ClearAllSelections(); ClearAllSelections();
GoButtonClick(NewGuyForm);
} GoButtonClick();
*/
return true;
} }
+2 -1
View File
@@ -144,7 +144,8 @@ function sold() {
$.each('STR,CON,DEX,INT,WIS,CHA'.split(','), function (index,value) { $.each('STR,CON,DEX,INT,WIS,CHA'.split(','), function (index,value) {
newguy[value] = stats[value]; newguy[value] = stats[value];
}); });
addToRoster(JSON.stringify(newguy)); alert(JSON.stringify(newguy));
addToRoster(newguy);
} }
function GenClick() { function GenClick() {
+10 -36
View File
@@ -1,43 +1,17 @@
<html>
<head>
<title>Progress Quest X/web - Roster</title>
<script src="jquery.js"></script> <script src="jquery.js"></script>
<script src="config.js"></script> <script src="config.js"></script>
<script src="roster.js"></script>
</head>
<body>
<dl id=roster> <dl id=roster>
Here it goes Here it goes
</dl> </dl>
<script> <button id=test>Test</button>
$(document).ready(function () { <button id=clear>Clear</button>
var roster = $("#roster"); </body>
roster.text("Loading..."); </html>
var games = loadRoster()
if (!games) {
roster.text("No local storage");
return;
}
$.each(games, function (index, element) {
var p = $("<dt/>");
p.appendTo(roster);
p.text(element.name);
p = $("<dd/>");
p.appendTo(roster);
p.text(JSON.stringify(element));
});
var b = $("<button>Test</button>");
b.appendTo(roster);
b.click(function () {
games.push({testy: "betsy"});
storeRoster(games);
});
var b = $("<button>Clear</button>");
b.appendTo(roster);
b.click(function () {
games = [];
storeRoster();
});
});
</script>
+40
View File
@@ -0,0 +1,40 @@
$(document).ready(function () {
var games;
function load() {
var roster = $("#roster");
roster.empty();
roster.text("Loading...");
games = loadRoster()
if (!games) {
roster.text("Err...no local storage");
return;
}
$.each(games, function (index, c) {
var p = $("<dt/>");
p.appendTo(roster);
p.text(c.name);
var a = $("<a/>", {href: "main.html#" + c.name})
a.text(c.name);
a.appendTo(p);
p = $("<dd/>");
p.appendTo(roster);
p.text("Level " + (c.level || 1) + " " + c.race + " " + c['class']);
});
}
load();
$("#test").click(function () {
games.push({testy:"cul", "name":"betsy"});
storeRoster(games);
load();
});
$("#clear").click(function () {
storeRoster([]);
load();
});
});