mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 08:44:00 -06:00
First pass at loading characters and a readable roster
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
Put(Traits, 'Race', ch.race);
|
||||||
|
Put(Traits, 'Class', ch['class']);
|
||||||
|
Put(Stats, 'STR', ch.STR);
|
||||||
|
Put(Stats, 'CON', ch.CON);
|
||||||
|
Put(Stats, 'DEX', ch.DEX);
|
||||||
|
Put(Stats, 'INT', ch.INT);
|
||||||
|
Put(Stats, 'WIS', ch.WIS);
|
||||||
|
Put(Stats, 'CHA', ch.CHA);
|
||||||
|
Put(Stats, 'HP Max', ch['HP Max']);
|
||||||
|
Put(Stats, 'MP Max', ch['MP Max']);
|
||||||
|
Put(Equips, 'Weapon', ch.equips.Weapon);
|
||||||
|
Put(Inventory,'Gold',0);
|
||||||
|
ClearAllSelections();
|
||||||
|
|
||||||
/* TODO: something like this
|
GoButtonClick();
|
||||||
with (NewGuyForm) {
|
|
||||||
Put(Traits,'Name',Name.Text);
|
|
||||||
Put(Traits,'Race',Race[Race.ItemIndex]);
|
|
||||||
Put(Traits,'Class',Klass[Klass.ItemIndex]);
|
|
||||||
Put(Traits,'Level',1);
|
|
||||||
Put(Stats,'STR',STR.Tag);
|
|
||||||
Put(Stats,'CON',CON.Tag);
|
|
||||||
Put(Stats,'DEX',DEX.Tag);
|
|
||||||
Put(Stats,'INT',INT.Tag);
|
|
||||||
Put(Stats,'WIS',WIS.Tag);
|
|
||||||
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);
|
|
||||||
ClearAllSelections();
|
|
||||||
GoButtonClick(NewGuyForm);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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
@@ -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>
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user