Skip to content

Commit a241ddf

Browse files
committed
Address errors from closure compiler
TODO: FIX GU / ETC
1 parent 206c879 commit a241ddf

13 files changed

+112
-81
lines changed

nin/backend/dasbootgen.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
const webpack = require('webpack');
1+
const ClosureCompiler = require('google-closure-compiler-js').webpack;
22
const p = require('path');
3+
const webpack = require('webpack');
34

45

56
async function dasbootGen(projectPath) {
@@ -11,7 +12,18 @@ async function dasbootGen(projectPath) {
1112
output: {
1213
path: p.join(projectPath, 'gen'),
1314
filename: 'dasBoot.js',
14-
}
15+
},
16+
plugins: [
17+
new ClosureCompiler({
18+
options: {
19+
languageIn: 'ECMASCRIPT6',
20+
languageOut: 'ECMASCRIPT5',
21+
compilationLevel: 'SIMPLE',
22+
warningLevel: 'VERBOSE',
23+
externs: ['GU', 'FILES', 'PROJECT', 'SHADERS'],
24+
},
25+
})
26+
]
1527
}).run((err) => {
1628
err ? reject() : resolve();
1729
});

nin/dasBoot/BEATBEAN.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ var framesPerBEAT;
22
window.BEAN = 0;
33
window.BEAT = false;
44

5-
initBeatBean = function() {
5+
const initBeatBean = function() {
66
window.BEAN = 0;
77
window.BEAT = false;
88

9-
var BEATsPerMinute = PROJECT.music.bpm * PROJECT.music.subdivision;
9+
var BEATsPerMinute = window.PROJECT.music.bpm * window.PROJECT.music.subdivision;
1010
var BEATsPerSecond = BEATsPerMinute / 60;
1111
var framesPerSecond = 60;
1212
framesPerBEAT = framesPerSecond / BEATsPerSecond;
@@ -20,7 +20,7 @@ initBeatBean = function() {
2020
};
2121
};
2222

23-
updateBeatBean = function(frame) {
23+
const updateBeatBean = function(frame) {
2424
window.BEAT = false;
2525
if ((((frame + 1.5) / framesPerBEAT) | 0) >
2626
((frame + 0.5) / framesPerBEAT) | 0) {

nin/dasBoot/CameraController.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const PathController = require('./PathController');
2+
13
function CameraController(rawPath) {
24
this.camera = new THREE.PerspectiveCamera(45, 16/9, 1, 50000);
35
this.rotVector = new THREE.Vector3(0, 0, 1);

nin/dasBoot/Loader.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const THREE = require('./lib/00_three');
2+
13
function Loader() {
24
this.eventNames = {
35
VIDEO: 'canplaythrough',
@@ -78,8 +80,8 @@ Loader.prototype.start = function(onprogress, oncomplete) {
7880
'webm': 'data:video/webm;base64,',
7981
'svg': 'data:image/svg+xml;base64,',
8082
}[item.filepath.slice(-3)];
81-
console.log(that.id, item.filepath, prefix + (FILES[item.filepath] && FILES[item.filepath].slice(0, 10)));
82-
item.element.src = prefix + FILES[item.filepath];
83+
console.log(that.id, item.filepath, prefix + (window.FILES[item.filepath] && window.FILES[item.filepath].slice(0, 10)));
84+
item.element.src = prefix + window.FILES[item.filepath];
8385
} else {
8486
item.element.crossOrigin = 'Anonymous';
8587
item.element.src = Loader.rootPath + item.filepath + '?_=' + Math.random();
@@ -88,8 +90,8 @@ Loader.prototype.start = function(onprogress, oncomplete) {
8890

8991
this.itemsToAjax.forEach(function(item) {
9092
if(window.FILES) {
91-
console.log(that.id, item.filepath, FILES[item.filepath] && atob(FILES[item.filepath]).slice(0, 10));
92-
var bytes = atob(FILES[item.filepath]);
93+
console.log(that.id, item.filepath, window.FILES[item.filepath] && atob(window.FILES[item.filepath]).slice(0, 10));
94+
var bytes = atob(window.FILES[item.filepath]);
9395
if(item.options.responseType == 'arraybuffer') {
9496
var buffer = new ArrayBuffer(bytes.length);
9597
var bufferView = new Uint8Array(buffer);

nin/dasBoot/NodeManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class NodeManager {
88
nodeInfo.options = nodeInfo.options || {};
99

1010
const nodeConstructor = nodeInfo.type.slice(0, 4) === 'NIN.' ?
11-
NIN[nodeInfo.type.slice(4)]
11+
window['NIN'][nodeInfo.type.slice(4)]
1212
: window[nodeInfo.type];
1313

1414
if (nodeConstructor === undefined) {

nin/dasBoot/PathController.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
const {lerp, smoothstep, easeIn, easeOut} = require('./interpolations');
2+
const THREE = require('./lib/00_three');
3+
14
function PathController(raw_path, path_type) {
25
this.path_type = path_type || '3D';
36

nin/dasBoot/RootNode.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
class RootNode extends NIN.Node {
1+
const Node = require('./node');
2+
const TextureInput = require('./TextureInput');
3+
4+
class RootNode extends Node {
25
constructor(id, options) {
36
super(id, {
4-
inputs: {screen: new NIN.TextureInput()}
7+
inputs: {screen: new TextureInput()}
58
});
69

710
this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);

nin/dasBoot/ShaderNode.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
class ShaderNode extends NIN.Node {
1+
const Node = require('./node');
2+
3+
class ShaderNode extends Node {
24
constructor(id, options) {
35
super(id, {
46
inputs: options.inputs,
@@ -16,7 +18,7 @@ class ShaderNode extends NIN.Node {
1618
});
1719

1820
const shader = typeof options.shader === 'string'
19-
? SHADERS[options.shader] : options.shader;
21+
? window.SHADERS[options.shader] : options.shader;
2022

2123
this.quad = new THREE.Mesh(
2224
new THREE.PlaneBufferGeometry(2, 2),
@@ -31,7 +33,7 @@ class ShaderNode extends NIN.Node {
3133
}
3234

3335
resize() {
34-
this.renderTarget.setSize(16 * GU, 9 * GU);
36+
this.renderTarget.setSize(16 * window.GU, 9 * window.GU);
3537
}
3638

3739
render(renderer) {

nin/dasBoot/THREENode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
class THREENode extends NIN.Node {
1+
const CameraController = require('./CameraController');
2+
const Loader = require('./Loader');
3+
const Node = require('./node');
4+
5+
class THREENode extends Node {
26
constructor(id, options) {
37
super(id, {
48
inputs: options.inputs,
@@ -30,7 +34,7 @@ class THREENode extends NIN.Node {
3034
}
3135

3236
resize() {
33-
this.renderTarget.setSize(16 * GU, 9 * GU);
37+
this.renderTarget.setSize(16 * window.GU, 9 * window.GU);
3438
}
3539

3640
render(renderer) {

nin/dasBoot/TextureNode.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
class TextureNode extends NIN.Node {
1+
const Loader = require('./Loader');
2+
const Node = require('./node');
3+
const TextureOutput = require('./TextureOutput');
4+
5+
class TextureNode extends Node {
26
constructor(id, options) {
37
super(id, {
48
inputs: {},
59
outputs: {
6-
A: new NIN.TextureOutput()
10+
A: new TextureOutput()
711
}
812
});
913
var that = this;

nin/dasBoot/bootstrap.js

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
window.THREE = require('./lib/00_three');
1+
const THREE = window['THREE'] = require('./lib/00_three');
22
require('./lib/01_EffectComposer');
33
require('./lib/BloomPass');
44
require('./lib/ClearPass');
@@ -25,34 +25,31 @@ NIN.THREENode = require('./THREENode');
2525
NIN.ShaderNode = require('./ShaderNode');
2626

2727
const {initBeatBean, updateBeatBean} = require('./BEATBEAN');
28-
window.initBeatBean = initBeatBean;
29-
window.updateBeatBean = updateBeatBean;
28+
window['initBeatBean'] = initBeatBean;
29+
window['updateBeatBean'] = updateBeatBean;
3030

3131
const {lerp, clamp, smoothstep, easeIn, easeOut} = require('./interpolations');
32-
window.lerp = lerp;
33-
window.clamp = clamp;
34-
window.smoothstep = smoothstep;
35-
window.easeIn = easeIn;
36-
window.easeOut = easeOut;
37-
38-
const {requestAnimFrame, makeFullscreen, audioContext} = require('./shims.js');
39-
window.requestAnimFrame = requestAnimFrame;
40-
window.makeFullscreen = makeFullscreen;
41-
window.audioContext = audioContext;
42-
43-
window.Random = require('./Random');
44-
window.PathController = require('./PathController');
45-
window.CameraController = require('./CameraController');
46-
window.Loader = require('./Loader');
47-
window.createLoop = require('./loop');
48-
window.loadMusic = require('./music');
49-
window.NodeManager = require('./NodeManager');
32+
window['lerp'] = lerp;
33+
window['clamp'] = clamp;
34+
window['smoothstep'] = smoothstep;
35+
window['easeIn'] = easeIn;
36+
window['easeOut'] = easeOut;
37+
38+
const {requestAnimFrame, makeFullscreen} = require('./shims.js');
39+
window['requestAnimFrame'] = requestAnimFrame;
40+
window['makeFullscreen'] = makeFullscreen;
41+
42+
window['Random'] = require('./Random');
43+
window['PathController'] = require('./PathController');
44+
const Loader = window['Loader'] = require('./Loader');
45+
const loadMusic = require('./music');
46+
const NodeManager = window['NodeManager'] = require('./NodeManager');
5047

5148
window['bootstrap'] = function(options) {
5249
options = options || {};
5350

5451
var demo = {};
55-
window.demo = demo;
52+
window['demo'] = demo;
5653

5754
var container = document.body;
5855

@@ -110,15 +107,15 @@ window['bootstrap'] = function(options) {
110107
width = width || rect.width;
111108
height = height || rect.height;
112109
if (width / height > 16 / 9) {
113-
GU = (height / 9);
110+
window.GU = (height / 9);
114111
} else {
115-
GU = (width / 16);
112+
window.GU = (width / 16);
116113
}
117-
demo.renderer.setSize(16 * GU, 9 * GU);
114+
demo.renderer.setSize(16 * window.GU, 9 * window.GU);
118115
demo.renderer.domElement.style.zIndex = 10;
119116
demo.renderer.domElement.style.position = 'absolute';
120-
demo.renderer.domElement.style.margin = ((rect.height - 9 * GU) / 2) +
121-
'px 0 0 ' + ((rect.width - 16 * GU) / 2) + 'px';
117+
demo.renderer.domElement.style.margin = ((rect.height - 9 * window.GU) / 2) +
118+
'px 0 0 ' + ((rect.width - 16 * window.GU) / 2) + 'px';
122119
demo.nm.resize();
123120
demo.update(currentFrame);
124121
demo.render(demo.renderer, 0);
@@ -131,6 +128,39 @@ window['bootstrap'] = function(options) {
131128

132129
demo.music = loadMusic();
133130

131+
function createLoop(options) {
132+
var frameLength = 1000 / (options.frameRateInHz || 60);
133+
var render = options.render;
134+
var update = options.update;
135+
var renderer = options.renderer;
136+
var music = options.music;
137+
138+
function Looper() {
139+
this.time = 0;
140+
this.oldTime = 0;
141+
this.deltaTime = 0;
142+
this.currentFrame = 0;
143+
this.frameLength = frameLength;
144+
145+
var that = this;
146+
this.loop = function() {
147+
that.time = music.getCurrentTime() * 1000;
148+
that.deltaTime += that.time - that.oldTime;
149+
that.oldTime = that.time;
150+
while (that.deltaTime >= frameLength) {
151+
that.deltaTime -= frameLength;
152+
demo.music._calculateFFT();
153+
updateBeatBean(that.currentFrame);
154+
update(that.currentFrame++);
155+
}
156+
render(renderer, that.deltaTime / frameLength);
157+
requestAnimFrame(that.loop);
158+
};
159+
}
160+
161+
return new Looper();
162+
}
163+
134164
demo.looper = createLoop({
135165
render: demo.render,
136166
update: demo.update,

nin/dasBoot/loop.js

Lines changed: 0 additions & 34 deletions
This file was deleted.

nin/dasBoot/music.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
const Loader = require('./Loader');
2+
const {audioContext} = require('./shims');
3+
14
function loadMusic() {
25
var webAudioContext = new audioContext();
36
var _bufferSource;
47
var _buffer;
58
var _loaded = false;
6-
Loader.loadAjax(PROJECT.music.path, {responseType: 'arraybuffer'}, function(data, registerAsLoaded) {
9+
Loader.loadAjax(window.PROJECT.music.path, {responseType: 'arraybuffer'}, function(data, registerAsLoaded) {
710
webAudioContext.decodeAudioData(data, function(buffer) {
811
_buffer = buffer;
912
_loaded = true;

0 commit comments

Comments
 (0)