From 3bd9e90edcf003e30652deb082a743a6daaf532b Mon Sep 17 00:00:00 2001 From: Eric Fredricksen Date: Wed, 14 Jul 2010 16:48:17 -0700 Subject: [PATCH] Server side simulator using v8 (loads *.js so far) --- main.js | 3 +- newguy.js | 9 +++--- sim.js | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 6 deletions(-) create mode 100644 sim.js diff --git a/main.js b/main.js index be43ce0..6c718dc 100644 --- a/main.js +++ b/main.js @@ -1083,7 +1083,7 @@ function LoadGame(sheet) { $.each([Plots,Quests], function () { this.rows().find("input:checkbox").not(':last').attr("checked", "true"); }); - Log('Loaded game: ' + name); + Log('Loaded game: ' + game.Traits.Name); if (!game.elapsed) Brag('start'); StartTimer(); @@ -1099,7 +1099,6 @@ $(window).unload(function (event) { SaveGame(); }); - function GameSaveName() { if (!game.saveName) { game.saveName = Get(Traits, 'Name'); diff --git a/newguy.js b/newguy.js index a480112..92f9a26 100644 --- a/newguy.js +++ b/newguy.js @@ -67,7 +67,7 @@ function fill(e, a, n) { } } -$(document).ready(function () { +function NewGuyFormLoad() { fill("#races", K.Races, "Race"); fill("#classes", K.Klasses, "Class"); @@ -83,8 +83,8 @@ $(document).ready(function () { if (!$("#Name").text()) { GenClick(); - $("#Name")[0].focus(); - $("#Name")[0].select(); + $("#Name").focus(); + $("#Name").select(); } seed = new Alea(); @@ -92,9 +92,10 @@ $(document).ready(function () { if (window.location.href.indexOf("?sold") > 0) sold(); // TODO: cheesy -}); +} +$(document).ready(NewGuyFormLoad); /* Multiplayer: function TNewGuyForm_ParseSoldResponse(body) { diff --git a/sim.js b/sim.js new file mode 100644 index 0000000..670421f --- /dev/null +++ b/sim.js @@ -0,0 +1,90 @@ +//!/usr/bin/env v8 + +function noop() {} +function nada() { return {}; } + +var document = { + addEventListener: noop, + createElement: function () { + return { + style: {}, + getElementsByTagName: nada, + appendChild: noop, + }; + }, + documentElement: { + insertBefore: noop, + removeChild: noop, + }, + getElementById: nada, + createComment: noop, + createDocumentFragment: nada, +}; + +var window = { + location: {href: "#Woogle"}, + localStorage: { + getItem: function(key) { + return JSON.stringify({Woogle: { + Traits: { + Name: "Woogle" + } + }}); + }, + + setItem: function (key, value) { + + }, + + removeItem: function (key) { + + } + }, + document: document, + addEventListener: noop, +}; + +var location = window.location; + +/* +var $ = function () { + return { + click: noop, + keypress: noop, + ready: noop, + unload: noop, + bind: noop, + text: noop, + appendTo: noop, + attr: noop, + focus: noop, + select: noop, + }; +}; +$.each = function (collection, callback) { + isArray: function( obj ) { + return toString.call(obj) === "[object Array]"; + }, +}; +*/ +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 () {}; + +load("jquery.js"); +var $ = window.$; +load("config.js"); + +load("newguy.js"); +//NewGuyFormLoad(); + +load("main.js"); +//FormCreate(); +