-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
71 lines (63 loc) · 2.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
const util = require('./util.js');
const ui = require('./ui.js');
const io = require('./io.js');
const ngu = require('./ngu.js');
const logic = require('./logic.js');
const loops = require('./loops.js');
const gui = require('./gui.js');
const nguJs = require('./ngujs.js');
async function main() {
// uninstalling previous version of NGU.js
if( window.nguJs ) {
console.log( `Found a previous version of NGU.js. Uninstalling it.` );
try {
await util.withTimeout( window.nguJs.destroy() );
} catch( e ) {
console.error(`There was an issue uninstalling the previous version of NGU.js:`, e );
}
}
// fetching the game canvas
const gameCanvas = document.getElementById( '#canvas' );
{
if( ! gameCanvas ) {
console.log( `%cCouldn't find the game canvas!`, `color:red; font-size:x-large;` );
console.log( `%cMake sure that the game has loaded, and that you're pasting this code into "gameiframe" (in the dropdown menu of this JavaScript console - by default it reads "top")`, `color:red;` );
return;
}
}
// instantiating NGU.js
window.nguJs = new nguJs.NguJs( gameCanvas );
// printing a how-to message
{
const comment = (str)=>console.log( `%c// ${str}`, `color:Green;` );
const code = (str)=>console.log( `%c${str}`, `font-family: monospace;` );
const space = ()=>console.log();
comment(`To start hacking with this:`);
code(`var {px, rect} = nguJsLib.util;
var {coords, colors} = nguJsLib.ngu;`);
space();
comment(`Draw a point or a rect for debugging:`);
code(`coords.inv.slot(5,2).debug();
coords.inv.slot(5,2).center.debug();
coords.inv.slot(5,2).toString();`);
space();
comment(`Run some small pieces of logic:`);
code(`nguJs.focus();
nguJs.logic.inv.applyAllBoostsToCube();`);
space();
comment(`Run game management routines:`);
code(`nguJs.loops.fixInv();`);
space();
comment(`To stop game management routines:`);
code(`nguJs.loopRunner.stop();`);
space();
comment(`To uninstall:`);
code(`nguJs.destroy();`);
}
}
window.nguJsLib = Object.assign( module.exports, {
main, util, ui, io, ngu, logic, loops, gui, nguJs,
});
if( module === require.main ) {
main();
}