From 23fb0b4ba56e7feb3afce1c51852a264c8a6aaaf Mon Sep 17 00:00:00 2001 From: Eric Fredricksen Date: Thu, 1 Dec 2011 22:35:24 -0800 Subject: [PATCH] Update sim.js to work with current v8 and node --- .hgignore | 1 + charsheet.txt | 24 ++++++++++++++++++++++++ sim.js | 22 ++++++++++++++++++---- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 charsheet.txt diff --git a/.hgignore b/.hgignore index ea6d6f6..5be44c2 100644 --- a/.hgignore +++ b/.hgignore @@ -1,2 +1,3 @@ syntax: glob local.storage +v8 diff --git a/charsheet.txt b/charsheet.txt new file mode 100644 index 0000000..5430044 --- /dev/null +++ b/charsheet.txt @@ -0,0 +1,24 @@ +$Traits.Name the $Traits.Race [$hostname] +"$motto" + +Level $Traits.Level $Traits.Class (exp. $ExpBar.position/$ExpBar.max) + +Plot stage: $bestplot ($PlotBar.hint) +Quest: $bestquest ($QuestBar.hint) + +Stats: + STR $Stats.STR + CON $Stats.CON + DEX $Stats.DEX + INT $Stats.INT + WIS $Stats.WIS HP Max $Stats.HP_Max + CHA $Stats.CHA MP Max $Stats.MP_Max + +Equipment: +$Equips.___ +Spell Book: +$Spells.___ +Inventory ($EncumBar.hint): +$Inventory.___ +-- $date +-- Progress Quest 6.3.web - http://progressquest.com/ diff --git a/sim.js b/sim.js index da07e6e..ae325a0 100644 --- a/sim.js +++ b/sim.js @@ -1,4 +1,15 @@ -//!/usr/bin/env v8 +// This is an in-console simulation of Progress Quest. It's rather a +// hack job. +// +// Run it with node.js like so: +// $ node sim.js +// or using a modified v8 shell, like so: +// $ git clone git://github.com/grumdrig/v8 +// $ (cd v8; scons sample=shell) +// $ v8/shell sim.js +// +// It's not realtime - simulation runs at maximum speed and the +// virtual time elapsed is displayed at each level-up. var window = { location: {href: "#Woogle"}, @@ -67,7 +78,8 @@ if (typeof process !== "undefined") { var sys = require("sys"); var load = function (filename) { var content = fs.readFileSync(filename); - global.eval.call(global, String(content)); + require("vm").runInThisContext(content, filename); + //global.eval.call(global, String(content)); }; var print = function () { for (var i = 0, len = arguments.length; i < len; ++i) { @@ -80,6 +92,7 @@ if (typeof process !== "undefined") { global.window = window; global.document = document; + global.navigator = navigator; global.$ = $; print("node"); } else { @@ -96,7 +109,7 @@ var setInterval = global.setInterval = function (callback, interval) { timers.push({callback:callback, interval:interval}); return timers.length-1; }; -var setTimeout = setInterval; // TODO: distinguish! +var setTimeout = global.setTimeout = setInterval; // TODO: distinguish! load("config.js"); @@ -106,6 +119,7 @@ print(cs, "characters"); load("newguy.js"); NewGuyFormLoad(); +traits.Name = "Shienzid"; sold(); write("local.storage", JSON.stringify(window.localStorage.items)); @@ -139,7 +153,7 @@ for (var j = 1, t = 0; j < 1001; ++j) { var tmpl = read("charsheet.txt"); storage.loadSheet("Shienzid", function (sheet) { game = sheet; - print(template(tmpl, sheet)); + print(template(''+tmpl, sheet)); var l = 0; for (var i = 0; i < 1000000000; ++i) {