mirror of
https://bitbucket.org/grumdrig/pq-web.git
synced 2026-09-29 08:44:00 -06:00
Partway towards moving to a model where the game object contains state, not the UI
This commit is contained in:
@@ -350,10 +350,24 @@ function Dequeue() {
|
|||||||
|
|
||||||
|
|
||||||
function Put(list, key, value) {
|
function Put(list, key, value) {
|
||||||
var item = list.item(key);
|
if (!game[list.id])
|
||||||
item.children().last().text(value);
|
game[list.id] = list.fixedkeys ? {} : [];
|
||||||
item.addClass("selected");
|
|
||||||
item.each(function () {this.scrollIntoView();});
|
if (list.fixedkeys) {
|
||||||
|
game[list.id][key] = value;
|
||||||
|
} else {
|
||||||
|
var i = 0;
|
||||||
|
for (; i < game[list.id].length; ++i) {
|
||||||
|
if (game[list.id][i][0] === key) {
|
||||||
|
game[list.id][i][1] = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (i == game[list.id].length)
|
||||||
|
game[list.id].push([key,value]);
|
||||||
|
}
|
||||||
|
|
||||||
|
PutUI(list, key, value);
|
||||||
|
|
||||||
if (key === 'STR') {
|
if (key === 'STR') {
|
||||||
EncumBar.Max = 10 + value;
|
EncumBar.Max = 10 + value;
|
||||||
@@ -364,6 +378,15 @@ function Put(list, key, value) {
|
|||||||
EncumBar.reposition(Sum(Inventory) - GetI(Inventory,'Gold'));
|
EncumBar.reposition(Sum(Inventory) - GetI(Inventory,'Gold'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function PutUI(list, key, value) {
|
||||||
|
// Update UI
|
||||||
|
var item = list.item(key);
|
||||||
|
item.children().last().text(value);
|
||||||
|
item.addClass("selected");
|
||||||
|
item.each(function () {this.scrollIntoView();});
|
||||||
|
}
|
||||||
|
|
||||||
function LevelUpTime(level) { // seconds
|
function LevelUpTime(level) { // seconds
|
||||||
// 20 minutes per level
|
// 20 minutes per level
|
||||||
return 20 * level * 60;
|
return 20 * level * 60;
|
||||||
@@ -432,7 +455,7 @@ function ListBox(id, columns, fixedkeys) {
|
|||||||
this.columns = columns;
|
this.columns = columns;
|
||||||
this.fixedkeys = fixedkeys;
|
this.fixedkeys = fixedkeys;
|
||||||
|
|
||||||
this.Add = function (caption) {
|
this.AddUI = function (caption) {
|
||||||
var tr = $("<tr><td><input type=checkbox disabled> " +
|
var tr = $("<tr><td><input type=checkbox disabled> " +
|
||||||
caption + "</td></tr>");
|
caption + "</td></tr>");
|
||||||
tr.appendTo(this.box);
|
tr.appendTo(this.box);
|
||||||
@@ -481,6 +504,7 @@ function ListBox(id, columns, fixedkeys) {
|
|||||||
|
|
||||||
|
|
||||||
this.save = function (game) {
|
this.save = function (game) {
|
||||||
|
return;
|
||||||
var that = this;
|
var that = this;
|
||||||
var dict = game[this.id];
|
var dict = game[this.id];
|
||||||
if (this.fixedkeys) {
|
if (this.fixedkeys) {
|
||||||
@@ -514,7 +538,7 @@ function ListBox(id, columns, fixedkeys) {
|
|||||||
if (that.columns == 2)
|
if (that.columns == 2)
|
||||||
Put(that, row[0], row[1]);
|
Put(that, row[0], row[1]);
|
||||||
else
|
else
|
||||||
that.Add(row);
|
that.AddUI(row);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -576,7 +600,7 @@ function InitializeCharacter(sheet) {
|
|||||||
Q('plot|2|Loading');
|
Q('plot|2|Loading');
|
||||||
|
|
||||||
PlotBar.reset(26);
|
PlotBar.reset(26);
|
||||||
Plots.Add((game.bestplot = 'Prologue'));
|
Plots.AddUI((game.bestplot = 'Prologue'));
|
||||||
game.act = 0;
|
game.act = 0;
|
||||||
|
|
||||||
QuestBar.reset(1);
|
QuestBar.reset(1);
|
||||||
@@ -751,7 +775,12 @@ function CompleteQuest() {
|
|||||||
game.questmonster = ''; // We're trying to placate them, after all
|
game.questmonster = ''; // We're trying to placate them, after all
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Quests.Add((game.bestquest = caption));
|
if (!game.Quests) game.Quests = [];
|
||||||
|
while (game.Quests.length > 99) game.Quests.shift();
|
||||||
|
game.Quests.push(caption);
|
||||||
|
game.bestquest = caption;
|
||||||
|
Quests.AddUI(caption);
|
||||||
|
|
||||||
|
|
||||||
Log('Commencing quest: ' + caption);
|
Log('Commencing quest: ' + caption);
|
||||||
|
|
||||||
@@ -819,8 +848,7 @@ function CompleteAct() {
|
|||||||
PlotBar.reset(60 * 60 * (1 + 5 * game.act)); // 1 hr + 5/act
|
PlotBar.reset(60 * 60 * (1 + 5 * game.act)); // 1 hr + 5/act
|
||||||
while (Plots.length() > 99)
|
while (Plots.length() > 99)
|
||||||
Plots.remove(0);
|
Plots.remove(0);
|
||||||
Plots.Add((game.bestplot = 'Act ' + toRoman(game.act)));
|
Plots.AddUI((game.bestplot = 'Act ' + toRoman(game.act)));
|
||||||
|
|
||||||
|
|
||||||
if (game.act > 1) {
|
if (game.act > 1) {
|
||||||
WinItem();
|
WinItem();
|
||||||
@@ -877,6 +905,10 @@ function Min(a,b) {
|
|||||||
return a < b ? a : b;
|
return a < b ? a : b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Max(a,b) {
|
||||||
|
return a > b ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
function Sum(list) {
|
function Sum(list) {
|
||||||
var result = 0;
|
var result = 0;
|
||||||
list.rows().each(function (index) {
|
list.rows().each(function (index) {
|
||||||
@@ -983,6 +1015,13 @@ function FormCreate() {
|
|||||||
Plots = new ListBox("Plots", 1);
|
Plots = new ListBox("Plots", 1);
|
||||||
Quests = new ListBox("Quests", 1);
|
Quests = new ListBox("Quests", 1);
|
||||||
|
|
||||||
|
Plots.load = function (sheet) {
|
||||||
|
for (var i = Max(0, game.act-99); i <= game.act; ++i)
|
||||||
|
this.AddUI(i ? 'Act ' + toRoman(i) : "Prologue");
|
||||||
|
|
||||||
|
};
|
||||||
|
Plots.save = function () {};
|
||||||
|
|
||||||
AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests];
|
AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests];
|
||||||
|
|
||||||
Kill = $("#Kill");
|
Kill = $("#Kill");
|
||||||
|
|||||||
Reference in New Issue
Block a user