Store all data for prog bars in game object too

This commit is contained in:
Eric Fredricksen
2010-07-12 11:26:29 -07:00
parent cfbfe714a1
commit 929014671d
3 changed files with 46 additions and 51 deletions
+5 -5
View File
@@ -76,7 +76,7 @@
<div class="label">Experience</div> <div class="label">Experience</div>
<div class="progress-container" id="ExpBar"> <div class="progress-container" id="ExpBar">
<div class="hint" template="$remaining XP needed for next level"></div> <div class="hint"></div>
<div class="bar"></div> <div class="bar"></div>
</div> </div>
@@ -130,7 +130,7 @@
<div class="label">Encumbrance</div> <div class="label">Encumbrance</div>
<div class="progress-container" id="EncumBar"> <div class="progress-container" id="EncumBar">
<div class="hint" template="$Position/$Max cubits"></div> <div class="hint"></div>
<div class="bar"></div> <div class="bar"></div>
</div> </div>
</div> </div>
@@ -147,7 +147,7 @@
</div> </div>
<div class="progress-container" id="PlotBar"> <div class="progress-container" id="PlotBar">
<div class="hint" template="$time remaining"></div> <div class="hint"></div>
<div class="bar" style="width: 50%"></div> <div class="bar" style="width: 50%"></div>
</div> </div>
@@ -160,7 +160,7 @@
</div> </div>
<div class="progress-container" id="QuestBar"> <div class="progress-container" id="QuestBar">
<div class="hint" template="$percent% complete"></div> <div class="hint"></div>
<div class="bar" style="width: 50%"></div> <div class="bar" style="width: 50%"></div>
</div> </div>
</div> </div>
@@ -170,7 +170,7 @@
<div id="Kill" class="label"></div> <div id="Kill" class="label"></div>
<div class="progress-container" id="TaskBar"> <div class="progress-container" id="TaskBar">
<div class="hint" template="$percent%"></div> <div class="hint"></div>
<div class="bar" style="width: 50%"></div> <div class="bar" style="width: 50%"></div>
</div> </div>
+38 -46
View File
@@ -369,10 +369,8 @@ function Put(list, key, value) {
PutUI(list, key, value); PutUI(list, key, value);
if (key === 'STR') { if (key === 'STR')
EncumBar.Max = 10 + value; EncumBar.reset(10 + value, EncumBar.Position());
EncumBar.reposition(EncumBar.Position);
}
if (list === Inventory) if (list === Inventory)
EncumBar.reposition(Sum(Inventory) - GetI(Inventory,'Gold')); EncumBar.reposition(Sum(Inventory) - GetI(Inventory,'Gold'));
@@ -388,46 +386,44 @@ function PutUI(list, key, value) {
} }
function ProgressBar(id) { function ProgressBar(id, tmpl) {
this.id = id; this.id = id;
this.bar = $("#"+ id + " > .bar"); this.bar = $("#"+ id + " > .bar");
this.hint = ''; this.tmpl = tmpl;
this.reset = function (newmax) { this.Max = function () { return game[this.id].max; };
this.Max = newmax; this.Position = function () { return game[this.id].position; };
this.reposition(0);
this.reset = function (newmax, newposition) {
game[this.id].max = newmax;
this.reposition(newposition || 0);
}; };
this.reposition = function (newpos) { this.reposition = function (newpos) {
this.Position = Min(newpos, this.Max); game[this.id].position = Min(newpos, this.Max());
this.bar.css("width", 100 * this.Position / this.Max + "%");
// Recompute hint // Recompute hint
var label = $("#" + this.id).find(".hint"); var label = $("#" + this.id).find(".hint");
this.percent = (100 * this.Position).div(this.Max); this.percent = (100 * this.Position()).div(this.Max());
this.remaining = Math.floor(this.Max - this.Position); this.remaining = Math.floor(this.Max() - this.Position());
this.time = RoughTime(this.Max - this.Position); this.time = RoughTime(this.Max() - this.Position());
this.hint = template(label.attr("template"), this); game[this.id].hint = template(this.tmpl, this);
label.text(this.hint);
// Update UI
this.bar.css("width", 100 * this.Position() / this.Max() + "%");
label.text(game[this.id].hint);
}; };
this.increment = function (inc) { this.increment = function (inc) {
this.reposition(this.Position + inc); this.reposition(this.Position() + inc);
}; };
this.done = function () { this.done = function () {
return this.Position >= this.Max; return this.Position() >= this.Max();
};
this.save = function (game) {
game[id] = {position: this.Position,
max: this.Max,
hint: this.hint};
}; };
this.load = function (game) { this.load = function (game) {
this.Max = game[id].max; this.reposition(this.Position());
this.reposition(game[id].position);
}; };
} }
@@ -845,7 +841,6 @@ function LevelUp() {
WinStat(); WinStat();
WinStat(); WinStat();
WinSpell(); WinSpell();
ExpBar.Position = 0;
ExpBar.reset(LevelUpTime(GetI(Traits,'Level'))); ExpBar.reset(LevelUpTime(GetI(Traits,'Level')));
Brag('level'); Brag('level');
} }
@@ -868,11 +863,12 @@ function Pos(needle, haystack) {
function Timer1Timer() { function Timer1Timer() {
if (TaskBar.done()) { if (TaskBar.done()) {
game.tasks += 1; game.tasks += 1;
game.elapsed += TaskBar.Max.div(1000); game.elapsed += TaskBar.Max().div(1000);
ClearAllSelections(); ClearAllSelections();
if (Kill.text() == 'Loading....') TaskBar.Max = 0; if (Kill.text() == 'Loading....')
TaskBar.reset(0); // Not sure if this is still the ticket
// gain XP / level up // gain XP / level up
var gain = Pos('kill|', game.task) == 1; var gain = Pos('kill|', game.task) == 1;
@@ -880,7 +876,7 @@ function Timer1Timer() {
if (ExpBar.done()) if (ExpBar.done())
LevelUp(); LevelUp();
else else
ExpBar.increment(TaskBar.Max / 1000); ExpBar.increment(TaskBar.Max() / 1000);
} }
// advance quest // advance quest
@@ -888,7 +884,7 @@ function Timer1Timer() {
if (QuestBar.done() || !Quests.length()) { if (QuestBar.done() || !Quests.length()) {
CompleteQuest(); CompleteQuest();
} else { } else {
QuestBar.increment(TaskBar.Max / 1000); QuestBar.increment(TaskBar.Max() / 1000);
} }
} }
@@ -897,7 +893,7 @@ function Timer1Timer() {
if (PlotBar.done()) if (PlotBar.done())
InterplotCinematic(); InterplotCinematic();
else else
PlotBar.increment(TaskBar.Max / 1000); PlotBar.increment(TaskBar.Max() / 1000);
} }
Dequeue(); Dequeue();
@@ -911,17 +907,14 @@ function Timer1Timer() {
} }
function FormCreate() { function FormCreate() {
ExpBar = new ProgressBar("ExpBar"); ExpBar = new ProgressBar("ExpBar", "$remaining XP needed for next level");
PlotBar = new ProgressBar("PlotBar"); EncumBar = new ProgressBar("EncumBar", "$Position/$Max cubits");
TaskBar = new ProgressBar("TaskBar"); PlotBar = new ProgressBar("PlotBar", "$time remaining");
QuestBar = new ProgressBar("QuestBar"); QuestBar = new ProgressBar("QuestBar", "$percent% complete");
EncumBar = new ProgressBar("EncumBar"); TaskBar = new ProgressBar("TaskBar", "$percent%");
AllBars = [ExpBar,PlotBar,TaskBar,QuestBar,EncumBar]; AllBars = [ExpBar,PlotBar,TaskBar,QuestBar,EncumBar];
// TODO: probably get rid of this line
$.each(AllBars, function (i,bar) { bar.reset(1); });
Traits = new ListBox("Traits", 2, true); Traits = new ListBox("Traits", 2, true);
Stats = new ListBox("Stats", 2, true); Stats = new ListBox("Stats", 2, true);
Spells = new ListBox("Spells", 2, false); Spells = new ListBox("Spells", 2, false);
@@ -991,7 +984,7 @@ function Cheats() {
} }
cheat("Task", function () { cheat("Task", function () {
TaskBar.reposition(TaskBar.Max); TaskBar.reposition(TaskBar.Max());
}); });
cheat("Level", function () { cheat("Level", function () {
@@ -999,13 +992,13 @@ function Cheats() {
}); });
cheat("Quest", function () { cheat("Quest", function () {
QuestBar.reposition(QuestBar.Max); QuestBar.reposition(QuestBar.Max());
TaskBar.reposition(TaskBar.Max); TaskBar.reposition(TaskBar.Max());
}); });
cheat("Plot", function () { cheat("Plot", function () {
PlotBar.reposition(PlotBar.Max); PlotBar.reposition(PlotBar.Max());
TaskBar.reposition(TaskBar.Max); TaskBar.reposition(TaskBar.Max());
}); });
@@ -1077,7 +1070,6 @@ function HotOrNot() {
function SaveGame() { function SaveGame() {
Log('Saving game: ' + GameSaveName()); Log('Saving game: ' + GameSaveName());
$.each(AllBars, function (i, e) { e.save(game); });
HotOrNot(); HotOrNot();
game.date = ''+new Date(); game.date = ''+new Date();
game.stamp = +new Date(); game.stamp = +new Date();
+3
View File
@@ -175,6 +175,9 @@ function sold() {
], ],
}; };
newguy.date = newguy.birthday;
newguy.stamp = newguy.birthstamp;
$.each(K.Equips, function (i,equip) { newguy.Equips[equip] = ''; }); $.each(K.Equips, function (i,equip) { newguy.Equips[equip] = ''; });
newguy.Equips.Weapon = newguy.bestequip; newguy.Equips.Weapon = newguy.bestequip;
newguy.Equips.Hauberk = "-3 Burlap"; newguy.Equips.Hauberk = "-3 Burlap";