Permalink
Browse files

Fixed NodeJS compatibility

Implemented missing 'utils' module, limited input handling to browsers only.
  • Loading branch information...
koenkivits committed Dec 27, 2015
1 parent 4ce9803 commit 1538f7f55ef979f0d80dc4abb62de999df7e0468
Showing with 23 additions and 3 deletions.
  1. +1 −1 index.js
  2. +1 −1 package.json
  3. +5 −1 system/input/index.js
  4. +16 −0 utils.js
View
@@ -5,7 +5,7 @@ var Cartridge = require("./system/cartridge");
var Controllers = require("./system/controllers");
var Output = require("./system/output");
var Memory = require("./system/memory");
var utils = require("utils");
var utils = require("./utils");
var Input = require("./system/input");
var config = require("./config.json");
View
@@ -16,7 +16,7 @@
"prepublish": "make"
},
"browser": {
"utils": "./browser/utils.js"
"./utils.js": "./browser/utils.js"
},
"author": "Koen Kivits <koen@kivits.com> (http://koen.kivits.com/)",
"license": "MIT",
View
@@ -7,7 +7,11 @@ function Input( system ) {
this.inputHandlers = new Array( 2 );
this.initConfig();
this.enable();
// only enable input in browsers
if ( typeof window !== "undefined" ) {
this.enable();
}
}
Input.prototype = {
View
@@ -0,0 +1,16 @@
var fs = require("fs");
/**
* Wrapper around fs.readFile to make it easily replaceble by Browserify and to
* handle converting to an ArrayBuffer in a single place.
*/
exports.readFile = function( filename, callback ) {
fs.readFile( filename, function( err, data ) {
if ( err ) {
throw err;
}
var buffer = new Uint8Array( data ).buffer;
callback( buffer );
});
};

0 comments on commit 1538f7f

Please sign in to comment.