| [.ShellClassInfo] | ||
| IconResource=C:\Program Files\nodejs\node.exe,0 | ||
| [ViewState] | ||
| Mode= | ||
| Vid= | ||
| FolderType=Generic |
+59
-43
@@ -1,64 +0,74 @@ | ||
| let packageJson = require('./package.json'); | ||
| let packageJson = require('./package.json') | ||
| exports.getVersion = function() { | ||
| return packageJson.name + '@' + packageJson.version; | ||
| return packageJson.name + '@' + packageJson.version | ||
| } | ||
| exports.getUrl = function( url, callback ) { | ||
| let xhr = new XMLHttpRequest(); | ||
| xhr.open( "GET", url, true ); | ||
| xhr.responseType = "json"; | ||
| let xhr = new XMLHttpRequest() | ||
| xhr.open( "GET", url, true ) | ||
| xhr.responseType = "json" | ||
| xhr.onload = function() { | ||
| let status = xhr.status; | ||
| let status = xhr.status | ||
| if (status === 200) { | ||
| callback( null, xhr.response ); | ||
| callback( null, xhr.response ) | ||
| } else { | ||
| callback( status, xhr.response ); | ||
| callback( status, xhr.response ) | ||
| } | ||
| }; | ||
| xhr.send(); | ||
| }; | ||
| } | ||
| xhr.send() | ||
| } | ||
| exports.keyListen = function( isEnable, up, down, left, right, space, ctrl) { | ||
| /* | ||
| * All arguments are callbacks, isEnable, up, down, left, right are mandatory | ||
| */ | ||
| exports.keyListen = function( isEnable, up, down, left, right, space, ctrl, esc, tab ) { | ||
| window.onkeydown = function( e ) { | ||
| if( !isEnable() ) { | ||
| return; | ||
| return | ||
| } | ||
| var key = e.which; | ||
| var keyLeft = 37; | ||
| var keyUp = 38; | ||
| var keyRight = 39; | ||
| var keyDown = 40; | ||
| var keySpace = 32; | ||
| var keyW = 87; | ||
| var keyA = 65; | ||
| var keyS = 83; | ||
| var keyD = 68; | ||
| let key = e.which | ||
| let keyLeft = 37 | ||
| let keyUp = 38 | ||
| let keyRight = 39 | ||
| let keyDown = 40 | ||
| let keySpace = 32 | ||
| let keyW = 87 | ||
| let keyA = 65 | ||
| let keyS = 83 | ||
| let keyD = 68 | ||
| let keyEsc = 27 | ||
| let keyTab = 9 | ||
| if( key === keyUp || key === keyW ) { | ||
| up(); | ||
| up() | ||
| } else if( key === keyLeft || key === keyA ) { | ||
| left() | ||
| } else if( key === keyDown || key === keyS ) { | ||
| down(); | ||
| } else if( key === keyLeft || key === keyA ) { | ||
| left(); | ||
| down() | ||
| } else if( key === keyRight || key === keyD ) { | ||
| right(); | ||
| } else if( key === keySpace ) { | ||
| space(); | ||
| } else if( e.ctrlKey ) { | ||
| ctrl(); | ||
| right() | ||
| } else if( space && key === keySpace ) { | ||
| space() | ||
| } else if( ctrl && e.ctrlKey ) { | ||
| ctrl() | ||
| } else if( esc && key === keyEsc ) { | ||
| esc() | ||
| } else if( tab && key === keyTab ) { | ||
| e.preventDefault() | ||
| tab() | ||
| } | ||
| } | ||
| }; | ||
| } | ||
| exports.randomizeArray = function( array ) { | ||
| var currentIndex = array.length, temporaryValue, randomIndex; | ||
| let currentIndex = array.length, temporaryValue, randomIndex | ||
| while ( 0 !== currentIndex ) { | ||
| randomIndex = Math.floor( Math.random() * currentIndex ); | ||
| currentIndex -= 1; | ||
| temporaryValue = array[currentIndex]; | ||
| array[currentIndex] = array[randomIndex]; | ||
| array[randomIndex] = temporaryValue; | ||
| randomIndex = Math.floor( Math.random() * currentIndex ) | ||
| currentIndex -= 1 | ||
| temporaryValue = array[currentIndex] | ||
| array[currentIndex] = array[randomIndex] | ||
| array[randomIndex] = temporaryValue | ||
| } | ||
| return array; | ||
| return array | ||
| } | ||
@@ -68,10 +78,16 @@ | ||
| if( str.length > len ) { | ||
| return; | ||
| return | ||
| } | ||
| if(fillerChar.length > 1 ) { | ||
| fillerChar=fillerChar.substring(0,1); | ||
| fillerChar=fillerChar.substring(0,1) | ||
| } | ||
| return fillerChar.repeat( len - str.length ) + str; | ||
| return fillerChar.repeat( len - str.length ) + str | ||
| } | ||
| exports.initCanvas = function() { | ||
| let canvasEl = document.createElement('canvas') | ||
| canvasEl.setAttribute('id', 'canvas') | ||
| document.body.appendChild( canvasEl ) | ||
| } |
+1
-1
| { | ||
| "name": "wetbox", | ||
| "version": "0.1.25", | ||
| "version": "0.2.25", | ||
| "description": "A collection of prototype tools", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
+16
-0
@@ -13,4 +13,20 @@  | ||
| Adds some keyboard listeners to the page for typical game commands. All input parameters are callback functions. | ||
| ``` | ||
| wet = require( wetbox ); | ||
| wet.keyListen( | ||
| () => { return true }, | ||
| () => { console.log( 'up' ) }, | ||
| () => { console.log( 'down' ) }, | ||
| () => { console.log( 'left' ) }, | ||
| () => { console.log( 'right' ) }, | ||
| () => { console.log( 'space' ) }, | ||
| () => { console.log( 'ctrl' ) } | ||
| ); | ||
| ``` | ||
| `randomizeArray( array )` | ||
| Returns array with random-ordered elements using the Fisher-Yates-Knuth shuffle. | ||
| `leftPad( str, len, fillerChar )` | ||
| Pads a string up to length len, with single-char: fillerChar |
50656
1.88%5
25%82
22.39%32
100%