Malfunctioning load and save

This commit is contained in:
Eric Fredricksen
2010-07-03 22:33:37 -07:00
parent 789171f46d
commit 1f5b6fc4d5
3 changed files with 82 additions and 110 deletions
+68 -101
View File
@@ -24,7 +24,7 @@ function StartTimer() {
game.timerid = setInterval(Timer1Timer, 100); game.timerid = setInterval(Timer1Timer, 100);
} }
// BS location for this, but... // BS location for this, but...
// MainForm.Caption = 'ProgressQuest - ' + ChangeFileExt(ExtractFileName(MainForm.GameSaveName), ''); // MainForm.Caption = 'ProgressQuest - ' + ChangeFileExt(ExtractFileName(MainForm.GameSaveName()), '');
} }
function GetPasskey() { return game.passkey; } function GetPasskey() { return game.passkey; }
@@ -439,9 +439,11 @@ function alert(k) {
} }
function ListBox(id) { function ListBox(id, columns, fixedkeys) {
this.id = id; this.id = id;
this.box = $("#"+ id); this.box = $("#"+ id);
this.columns = columns;
this.fixedkeys = fixedkeys;
this.Add = function (caption) { this.Add = function (caption) {
var tr = $("<tr><td>" + caption + "</td></tr>"); var tr = $("<tr><td>" + caption + "</td></tr>");
@@ -490,16 +492,18 @@ function ListBox(id) {
}; };
this.save = function (game) { this.save = function (game) {
game[this.id] = {items: []}; var dict = {html: this.box.html()};
this.rows().each(function (index) { if (this.columns == 2) {
game[this.id].items.push($(this).html()); this.rows().each(function (index) {
}); dict[$(this).children().first().text()] =
$(this).children().last().text();
});
}
game[this.id] = dict;
}; };
this.load = function (game) { this.load = function (game) {
this.rows().remove(); this.box.html(game[this.id].html);
for (var i = 0; i < game[this.id].length; ++i)
this.box.appeand(game[this.id][i]);
}; };
this.label = function (n) { this.label = function (n) {
@@ -508,9 +512,10 @@ function ListBox(id) {
} }
var ExpBar, PlotBar, TaskBar, QuestBar; var ExpBar, PlotBar, TaskBar, QuestBar, EncumBar;
var Traits,Stats,Spells,Equips,Inventory,Plots,Quests; var Traits,Stats,Spells,Equips,Inventory,Plots,Quests;
var Kill; var Kill;
var AllBars, AllLists;
function GoButtonClick() { function GoButtonClick() {
@@ -786,7 +791,7 @@ function CompleteAct() {
function Log(line) { function Log(line) {
/* TODO /* TODO
if (FLogEvents) { if (FLogEvents) {
var logname = ChangeFileExt(GameSaveName, '.log'); var logname = ChangeFileExt(GameSaveName(), '.log');
DateTimeToString(stamp, '[yyyy-mm-dd hh:nn:ss]', Now); DateTimeToString(stamp, '[yyyy-mm-dd hh:nn:ss]', Now);
AssignFile(log, logname); AssignFile(log, logname);
if (FileExists(logname)) Append(log); else Rewrite(log); if (FileExists(logname)) Append(log); else Rewrite(log);
@@ -800,7 +805,7 @@ function Log(line) {
function ExportCharSheet() { function ExportCharSheet() {
/* TODO /* TODO
AssignFile(f, ChangeFileExt(GameSaveName, '.sheet')); AssignFile(f, ChangeFileExt(GameSaveName(), '.sheet'));
Rewrite(f); Rewrite(f);
Write(f, CharSheet()); Write(f, CharSheet());
Flush(f); Flush(f);
@@ -1003,25 +1008,25 @@ function FormCreate() {
QuestBar = new ProgressBar("QuestBar"); QuestBar = new ProgressBar("QuestBar");
EncumBar = new ProgressBar("EncumBar"); EncumBar = new ProgressBar("EncumBar");
Traits = new ListBox("Traits"); AllBars = [ExpBar,PlotBar,TaskBar,QuestBar,EncumBar];
Stats = new ListBox("Stats");
Spells = new ListBox("Spells"); $.each(AllBars, function (i,bar) { bar.reposition(0); });
Equips = new ListBox("Equips");
Inventory = new ListBox("Inventory"); Traits = new ListBox("Traits", 2, true);
Plots = new ListBox("Plots"); Stats = new ListBox("Stats", 2, true);
Quests = new ListBox("Quests"); Spells = new ListBox("Spells", 2, false);
Equips = new ListBox("Equips", 2, true);
Inventory = new ListBox("Inventory", 2, false);
Plots = new ListBox("Plots", 1);
Quests = new ListBox("Quests", 1);
AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests];
Kill = $("#Kill"); Kill = $("#Kill");
QuestBar.reposition(0);
PlotBar.reposition(0);
TaskBar.reposition(0);
ExpBar.reposition(0);
EncumBar.reposition(0);
$("#quit").click(function () { $("#quit").click(function () {
SaveGame();
window.location = "roster.html"; window.location = "roster.html";
// TODO: save
}); });
LoadCharacter(); LoadCharacter();
@@ -1031,37 +1036,31 @@ 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 games = loadRoster(); var sheet = loadRoster()[name];
var ch;
$.each(games, function (index,sheet) {
if (sheet.name === name) {
ch = sheet;
return true;
}
});
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();
GoButtonClick(); if (!sheet.Traits) {
// New game
game = sheet;
Put(Traits, 'Name', sheet.name);
Put(Traits, 'Level', 1);
Put(Traits, 'Race', sheet.race);
Put(Traits, 'Class', sheet['class']);
Put(Stats, 'STR', sheet.STR);
Put(Stats, 'CON', sheet.CON);
Put(Stats, 'DEX', sheet.DEX);
Put(Stats, 'INT', sheet.INT);
Put(Stats, 'WIS', sheet.WIS);
Put(Stats, 'CHA', sheet.CHA);
Put(Stats, 'HP Max', Random(8) + sheet.CON.div(6));
Put(Stats, 'MP Max', Random(8) + sheet.INT.div(6));
Put(Equips, 'Weapon', 'Sharp Stick');
Put(Inventory,'Gold',0);
SaveGame();
ClearAllSelections();
GoButtonClick();
} else {
LoadGame(sheet);
}
} }
@@ -1163,46 +1162,15 @@ $(function() {
function SaveGame() { function SaveGame() {
/* TODO
Log('Saving game: ' + GameSaveName()); Log('Saving game: ' + GameSaveName());
try { $.each(AllBars.concat(AllLists), function (i, e) { e.save(game); });
if (FMakeBackups) { addToRoster(game);
DeleteFile(ChangeFileExt(GameSaveName, '.bak'));
MoveFile(PChar(GameSaveName), PChar(ChangeFileExt(GameSaveName, '.bak')));
}
f = TFileStream.Create(GameSaveName, fmCreate);
} catch (EfCreateError) {
return false;
}
//ClearAllSelections;
var m = TMemoryStream.Create;
for (var i = 0; i < ComponentCount-1; ++i)
m.WriteComponent(Components[i]);
m.Seek(0, soFromBeginning);
ZCompressStream(m, f);
m.Free();
f.Free()
return true;;
*/
} }
function TMainForm_LoadGame(name) { function LoadGame(sheet) {
FSaveFileName = name; game = sheet;
var m = TMemoryStream.Create; $.each(AllBars.concat(AllLists), function (i, e) { e.load(game); });
var f = TFileStream.Create(name, fmOpenRead);
Traits.Clear();
Stats.Clear();
Equips.Clear();
m.Seek(0, soFromBeginning);
for (i = 0; i <= ComponentCount-1; ++i)
m.ReadComponent(Components[i]);
m.Free();
/*$IFDEF LOGGING*/
Log('Loaded game: ' + name); Log('Loaded game: ' + name);
/*$ENDIF*/
StartTimer(); StartTimer();
} }
@@ -1211,25 +1179,24 @@ function TMainForm_FormClose() {
Timer1.Enabled = false; Timer1.Enabled = false;
if (SaveGame()) { if (SaveGame()) {
if (FReportSave) if (FReportSave)
ShowMessage('Game saved as ' + GameSaveName); ShowMessage('Game saved as ' + GameSaveName());
} }
} }
FReportSave = true; FReportSave = true;
Action = caFree; Action = caFree;
} }
function TMainForm_GameSaveName()
{ function GameSaveName() {
if (!FSaveFileName) { if (!game.saveName) {
FSaveFileName = Get(Traits,'Name'); game.saveName = Get(Traits, 'Name');
if (GetHostName()) if (GetHostName())
FSaveFileName = FSaveFileName + ' [' + GetHostName + ']'; game.saveName += ' [' + GetHostName() + ']';
FSaveFileName = FSaveFileName + kFileExt;
FSaveFileName = ExpandFileName(PChar(FSaveFileName));
} }
return FSaveFileName; return game.saveName;
} }
function TMainForm_FormKeyDown() { function TMainForm_FormKeyDown() {
if ((FindWindow('TAppBuilder', nil) > 0) && (ssCtrl in Shift) && (ssShift in Shift) && (Key == ord('C'))) { if ((FindWindow('TAppBuilder', nil) > 0) && (ssCtrl in Shift) && (ssShift in Shift) && (Key == ord('C'))) {
/*$IFDEF CHEATS*/ /*$IFDEF CHEATS*/
+12 -7
View File
@@ -5,8 +5,11 @@
<script src="config.js"></script> <script src="config.js"></script>
<script src="roster.js"></script> <script src="roster.js"></script>
<style> <style>
div.brag { td.brag {
font: 9pt Verdana font: 9pt Verdana;
background-color: #ddddff;
padding: 5px;
display: inline;
} }
div.rc { div.rc {
@@ -32,9 +35,11 @@ Here it goes
<script id="bumble" type="text/html"> <script id="bumble" type="text/html">
<div class="brag"> <table><tr><td class="brag">
<a><b>$traits.Name</b></a> of $realm ($plots.act) <div>
</div> <a><b>$Traits.Name</b></a> of Localhost ($Plots.act)
<div class="rc">Level $traits.Level $traits.Race $traits.Class</div> </div>
<div class="bs">$equips.best / $spells.best / $stats.best</div> <div class="rc">Level $Traits.Level $Traits.Race $Traits.Class</div>
<div class="bs">$Equips.best / $Spells.best / $Stats.best</div>
</td></tr></table>
</script> </script>
+2 -2
View File
@@ -49,14 +49,14 @@ $(document).ready(function () {
$("#test").click(function () { $("#test").click(function () {
var n = GenerateName(); var n = GenerateName();
games[n] = {traits: {level: -10},name:n,race:GenerateName(),"class":GenerateName()}; games[n] = {Traits: {Level: -10,Name:n,Race:GenerateName(),Class:GenerateName()}};
storeRoster(games); storeRoster(games);
load(); load();
}); });
function brag(sheet) { function brag(sheet) {
var tmpl = $("#bumble").html(); var tmpl = $("#bumble").html();
var brag = tmpl.replace(/\$([a-z.]+)/g, function (str, p1) { var brag = tmpl.replace(/\$([A-Za-z.]+)/g, function (str, p1) {
var dict = sheet; var dict = sheet;
$.each(p1.split("."), function (i,v) { $.each(p1.split("."), function (i,v) {
if (!dict) return true; if (!dict) return true;