Allow v8 to simulate the game outside the browser. A little hacky

still but functional.
This commit is contained in:
Eric Fredricksen
2010-07-14 22:00:26 -07:00
parent 3bd9e90edc
commit 7e9648e192
3 changed files with 179 additions and 95 deletions
+74 -25
View File
@@ -6,11 +6,13 @@ function nada() { return {}; }
var document = {
addEventListener: noop,
createElement: function () {
return {
var result = {
style: {},
getElementsByTagName: nada,
appendChild: noop,
};
result.lastChild = result;
return result;
},
documentElement: {
insertBefore: noop,
@@ -24,20 +26,18 @@ var document = {
var window = {
location: {href: "#Woogle"},
localStorage: {
items: {},
getItem: function(key) {
return JSON.stringify({Woogle: {
Traits: {
Name: "Woogle"
}
}});
return this.items[key];
},
setItem: function (key, value) {
this.items[key] = value;
},
removeItem: function (key) {
delete this.items[key];
}
},
document: document,
@@ -46,8 +46,10 @@ var window = {
var location = window.location;
/*
var v8 = true;
var $ = function () {
return null;
return {
click: noop,
keypress: noop,
@@ -61,30 +63,77 @@ var $ = function () {
select: noop,
};
};
$.each = function (collection, callback) {
isArray: function( obj ) {
return toString.call(obj) === "[object Array]";
},
$.isFunction = function (obj) {
return toString.call(obj) === "[object Function]";
},
$.isArray = function (obj) {
return toString.call(obj) === "[object Array]";
}
$.each = function (object, callback) {
var name, i = 0,
length = object.length,
isObj = length === undefined || $.isFunction(object);
if (isObj) {
for (name in object) {
if (callback.call(object[name], name, object[name]) === false)
break;
}
} else {
for (var value = object[0];
i < length && callback.call(value, i, value) !== false;
value = object[++i]) { }
}
return object;
}
var navigator = {
v8: true,
userAgent: "V8 Shell"
};
*/
var navigator = { userAgent: "V8 Shell" };
var alert = function (m) { print("ALERT: " + m); };
function loadSheet(name) {
return { name: "bob" };
}
var storage = {
removeItem: function () {}
};
var randseed = function () {};
try {
window.localStorage.items = JSON.parse(read("local.storage"));
} catch (e) {
print(e);
window.localStorage.items = {};
}
load("jquery.js");
var $ = window.$;
var now = 0;
var timers = [{}];
function setInterval(callback, interval) {
timers.push({callback:callback, interval:interval});
return timers.length-1;
}
//load("jquery.js");
//var $ = window.$;
load("config.js");
load("newguy.js");
//NewGuyFormLoad();
NewGuyFormLoad();
sold();
write("local.storage", JSON.stringify(window.localStorage.items));
var guy = window.location.href.split("#")[1];
load("main.js");
//FormCreate();
FormCreate();
timeGetTime = function () {
return now;
}
for (var i = 0; i < 1000; ++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)));