diff --git a/main.js b/main.js index ba33af6..b33c31d 100644 --- a/main.js +++ b/main.js @@ -496,14 +496,16 @@ function ListBox(id, columns, fixedkeys) { this.remove0 = function (n) { if (game[this.id]) game[this.id].shift(); - this.box.find("tr").first().remove(); + if (this.box) + this.box.find("tr").first().remove(); }; this.remove1 = function (n) { var t = game[this.id].shift(); game[this.id].shift(); game[this.id].unshift(t); - this.box.find("tr").eq(1).remove(); + if (this.box) + this.box.find("tr").eq(1).remove(); }; @@ -543,7 +545,7 @@ function StrToIntDef(s, def) { } -if (!navigator.v8) +if (document) $(document).ready(FormCreate); @@ -940,7 +942,7 @@ function FormCreate() { AllLists = [Traits,Stats,Spells,Equips,Inventory,Plots,Quests]; - if (!navigator.v8) { + if (document) { Kill = $("#Kill"); $("#quit").click(quit); @@ -986,7 +988,7 @@ function LoadCharacter() { LoadGame(sheet); - if (!navigator.v8) + if (document) $("#title").text("Progress Quest - " + GameSaveName()); if (window.location.href.indexOf("?quit#") > 0) diff --git a/newguy.js b/newguy.js index 669995e..1c1628f 100644 --- a/newguy.js +++ b/newguy.js @@ -3,7 +3,7 @@ function Roll(stat) { stats[stat] = 3 + Random(6) + Random(6) + Random(6); - if (!navigator.v8) + if (document) $("#"+stat).text(stats[stat]); return stats[stat]; } @@ -44,7 +44,7 @@ function RollEm() { (total < (3 * 18)) ? 'silver' : 'white'; - if (!navigator.v8) { + if (document) { var Total = $("#Total"); Total.text(total); Total.css("background-color", color); @@ -70,7 +70,7 @@ function fill(e, a, n) { var v = a[i].split("|")[0]; var check = (def == i) ? " checked " : " "; if (def == i) traits[n] = v; - if (!navigator.v8) { + if (document) { $("
").appendTo(e); } @@ -85,7 +85,7 @@ function NewGuyFormLoad() { fill("#races", K.Races, "Race"); fill("#classes", K.Klasses, "Class"); - if (!navigator.v8) { + if (document) { $("#Reroll").click(RerollClick); $("#Unroll").click(UnrollClick); $("#RandomName").click(GenClick); @@ -105,7 +105,7 @@ function NewGuyFormLoad() { } -if (!navigator.v8) +if (document) $(document).ready(NewGuyFormLoad); /* Multiplayer: @@ -191,7 +191,7 @@ function sold() { ] }; - if (!navigator.v8) { + if (document) { newguy.Traits.Name = $("#Name").val(); newguy.Traits.Race = $("input:radio[name=Race]:checked").val(); newguy.Traits.Class = $("input:radio[name=Class]:checked").val(); @@ -219,7 +219,7 @@ function cancel() { function GenClick() { traits.Name = GenerateName(); - if (!navigator.v8) + if (document) $("#Name").attr("value", traits.Name); } diff --git a/sim.js b/sim.js index 4dd09ed..aa84f04 100644 --- a/sim.js +++ b/sim.js @@ -1,68 +1,39 @@ //!/usr/bin/env v8 -function noop() {} -function nada() { return {}; } - -var document = { - addEventListener: noop, - createElement: function () { - var result = { - style: {}, - getElementsByTagName: nada, - appendChild: noop, - }; - result.lastChild = result; - return result; - }, - documentElement: { - insertBefore: noop, - removeChild: noop, - }, - getElementById: nada, - createComment: noop, - createDocumentFragment: nada, -}; - var window = { location: {href: "#Woogle"}, + localStorage: { - items: {}, + items: null, getItem: function(key) { + if (!this.items) { + try { + this.items = JSON.parse(read("local.storage")); + } catch (e) { + print(e); + this.items = {}; + } + } return this.items[key]; }, setItem: function (key, value) { this.items[key] = value; + write("local.storage", JSON.stringify(this.items)); }, removeItem: function (key) { delete this.items[key]; + write("local.storage", JSON.stringify(this.items)); } }, - document: document, - addEventListener: noop, }; + var location = window.location; -var v8 = true; - -var $ = function () { - return null; - return { - click: noop, - keypress: noop, - ready: noop, - unload: noop, - bind: noop, - text: noop, - appendTo: noop, - attr: noop, - focus: noop, - select: noop, - }; -}; +var $ = function () { return null; }; $.isFunction = function (obj) { return toString.call(obj) === "[object Function]"; }, @@ -87,21 +58,10 @@ $.each = function (object, callback) { return object; } +var document = null; -var navigator = { - v8: true, - userAgent: "V8 Shell" -}; var alert = function (m) { print("ALERT: " + m); }; -var randseed = function () {}; -try { - window.localStorage.items = JSON.parse(read("local.storage")); -} catch (e) { - print(e); - window.localStorage.items = {}; -} - var now = 0; var timers = [{}]; function setInterval(callback, interval) { @@ -109,10 +69,13 @@ function setInterval(callback, interval) { return timers.length-1; } -//load("jquery.js"); -//var $ = window.$; load("config.js"); +var cs = 0; +for (var c in loadRoster()) + cs++; +print(cs, "characters"); + load("newguy.js"); NewGuyFormLoad(); sold(); @@ -129,11 +92,11 @@ timeGetTime = function () { return now; } -for (var i = 0; i < 1000; ++i) { +for (var i = 0; i < 100000; ++i) { //assert(timers.id == 1);// TODO: this is for simplicity now += timers[1].interval; timers[1].callback(); } SaveGame(); -print(guy, game.elapsed, game.tasks, game.task);//JSON.stringify(loadSheet(guy))); \ No newline at end of file +print(guy, game.elapsed, game.tasks, game.Traits.Level, game.task);//JSON.stringify(loadSheet(guy)));