Commit a14e79a2 authored by Roque's avatar Roque

erp5_standard_babylonjs: jslint

parent 11a5aab5
/*global window, rJS, domsugar, DroneGameManager*/
/*jslint nomen: true, indent: 2, maxlen: 80, white: true, evil: false */
(function (window, rJS, domsugar, DroneGameManager) {
"use strict";
......@@ -37,8 +40,7 @@
})
.declareJob('runGame', function runGame(options) {
var gadget = this,
game_manager = new DroneGameManager();
var game_manager = new DroneGameManager();
return game_manager.play(options);
});
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.22220.55651.16947</string> </value>
<value> <string>1004.22551.38156.49220</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1668521119.96</float>
<float>1668541051.5</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, RSVP, domsugar, console,
requestAnimationFrame, cancelAnimationFrame,
Worker, DroneGameManager*/
/*global window, rJS, RSVP, BABYLON, console*/
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
var runGame, updateGame;
......@@ -12,25 +10,30 @@ var runGame, updateGame;
console.log('runGame', canvas);
var finish_deferred = RSVP.defer();
var finish_deferred = RSVP.defer(), engine, scene, camera, light, sphere;
// Create the Babylon engine
var engine = new BABYLON.Engine(canvas, true);
engine = new BABYLON.Engine(canvas, true);
engine.enableOfflineSupport = false;
// Create the base scene
var scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color4(88/255,171/255,217/255,255/255);
scene = new BABYLON.Scene(engine);
scene.clearColor = new BABYLON.Color4(88 / 255, 171 / 255, 217 / 255, 1);
// Camera
var camera = new BABYLON.ArcRotateCamera("camera1", 400, 1.25, 10, new BABYLON.Vector3(0, 5, -10), scene);
camera = new BABYLON.ArcRotateCamera("camera1", 400, 1.25, 10,
new BABYLON.Vector3(0, 5, -10), scene);
camera.setTarget(BABYLON.Vector3.Zero());
camera.wheelPrecision = 10;
camera.maxz = 40000
camera.attachControl(canvas, true);
camera.maxz = 40000;
camera.attachControl(canvas, true);
// Light
const light = new BABYLON.HemisphericLight("light", new BABYLON.Vector3(0, 1, 0), scene);
light = new BABYLON.HemisphericLight("light",
new BABYLON.Vector3(0, 1, 0),
scene);
light.intensity = 0.7;
// Some objects (sphere and plane)
const sphere = BABYLON.MeshBuilder.CreateSphere("sphere", {diameter: 2, segments: 32}, scene);
sphere = BABYLON.MeshBuilder.CreateSphere("sphere",
{diameter: 2, segments: 32},
scene);
sphere.position.y = 1;
BABYLON.MeshBuilder.CreateGround("ground", {width: 6, height: 6}, scene);
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.637.31290.20070</string> </value>
<value> <string>1004.22559.55266.7577</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1667226282.49</float>
<float>1668541447.24</float>
<string>UTC</string>
</tuple>
</state>
......
/*global window, rJS, jIO, RSVP, domsugar, console,
requestAnimationFrame, cancelAnimationFrame,
Worker, importScripts,
DroneGameManager*/
/*global self, window, rJS, jIO, RSVP, console, importScripts, bindHandler,
handlers, prepareCanvas, postMessage, runGame, updateGame, handleEvent*/
/*jslint nomen: true, indent: 2, maxerr: 3, maxlen: 80 */
self.window = {
addEventListener: function (event, fn, opt) {
bindHandler('window', event, fn, opt);
},
setTimeout: self.setTimeout.bind(self),
PointerEvent: true
addEventListener: function (event, fn, opt) {
bindHandler('window', event, fn, opt);
},
setTimeout: self.setTimeout.bind(self),
PointerEvent: true
};
self.document = {
addEventListener: function (event, fn, opt) {
bindHandler('document', event, fn, opt);
},
// Uses to detect wheel event like at src/Inputs/scene.inputManager.ts:797
createElement: function () {
return {onwheel: true};
},
defaultView: self.window,
addEventListener: function (event, fn, opt) {
bindHandler('document', event, fn, opt);
},
// Uses to detect wheel event like at src/Inputs/scene.inputManager.ts:797
createElement: function () {
return {onwheel: true};
},
defaultView: self.window
};
importScripts('babylon.js', 'babylon.gui.js', 'rsvp.js');
function mainToWorker(evt) {
var i, offscreen_canvas;
switch (evt.data.type) {
case 'start':
console.log("[WEB WORKER] Ready to handle the folliwing events:", handlers.keys());
for (var i = 0; i < evt.data.logic_url_list.length; i += 1) {
importScripts(evt.data.logic_url_list[i]);
}
var offscreen_canvas = prepareCanvas(evt.data);
RSVP = window.RSVP;
return new RSVP.Queue()
.push(function () {
postMessage({'type': 'started'});
return runGame(offscreen_canvas, evt.data.game_parameters);
})
.push(function (result) {
return postMessage({'type': 'finished', 'result': result});
}, function(error) {
console.log("ERROR:", error);
return postMessage({'type': 'error', 'error': error});
});
break;
case 'update':
return new RSVP.Queue()
.push(function () {
return updateGame();
})
.push(function () {
return postMessage({'type': 'updated'});
});
break;
case 'event':
handleEvent(evt.data);
break;
default:
throw new Error('Unsupported message ' + JSON.stringify(evt.data));
case 'start':
console.log("[WEB WORKER] Ready to handle the folliwing events:",
handlers.keys());
for (i = 0; i < evt.data.logic_url_list.length; i += 1) {
importScripts(evt.data.logic_url_list[i]);
}
offscreen_canvas = prepareCanvas(evt.data);
RSVP = window.RSVP;
return new RSVP.Queue()
.push(function () {
postMessage({'type': 'started'});
return runGame(offscreen_canvas, evt.data.game_parameters);
})
.push(function (result) {
return postMessage({'type': 'finished', 'result': result});
}, function (error) {
console.log("ERROR:", error);
return postMessage({'type': 'error', 'error': error});
});
case 'update':
return new RSVP.Queue()
.push(function () {
return updateGame();
})
.push(function () {
return postMessage({'type': 'updated'});
});
case 'event':
handleEvent(evt.data);
break;
default:
throw new Error('Unsupported message ' + JSON.stringify(evt.data));
}
};
}
// Doesn't work without it
class HTMLElement {}
......@@ -70,83 +68,83 @@ self.handlers = new Map();
self.canvas = null;
// getBoundingInfo()
const rect = {
top: 0,
left: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
height: 0,
width: 0,
var rect = {
top: 0,
left: 0,
right: 0,
bottom: 0,
x: 0,
y: 0,
height: 0,
width: 0
};
function bindHandler(targetName, eventName, fn, opt) {
const handlerId = targetName + eventName;
handlers.set(handlerId, fn);
postMessage({
type: 'event',
targetName: targetName,
eventName: eventName,
opt: opt,
})
var handlerId = targetName + eventName;
handlers.set(handlerId, fn);
postMessage({
type: 'event',
targetName: targetName,
eventName: eventName,
opt: opt
});
}
function noop() {}
function handleEvent(event) {
const handlerId = event.targetName + event.eventName;
event.eventClone.preventDefault = noop;
event.eventClone.target = self.canvas;
if (!handlers.has(handlerId)) {
throw new Error('Unknown handlerId: ' + handlerId);
}
handlers.get(handlerId)(event.eventClone);
var handlerId = event.targetName + event.eventName;
event.eventClone.preventDefault = noop;
event.eventClone.target = self.canvas;
if (!handlers.has(handlerId)) {
throw new Error('Unknown handlerId: ' + handlerId);
}
handlers.get(handlerId)(event.eventClone);
}
function prepareCanvas(data) {
const canvas = data.canvas;
var canvas = data.canvas, style;
self.canvas = canvas;
canvas.clientWidth = data.width;
canvas.clientHeight = data.height;
canvas.width = data.width;
canvas.height = data.height;
rect.right = rect.width = data.width;
rect.bottom = rect.height = data.height;
canvas.setAttribute = function (name, value) {
postMessage({
type: 'canvasMethod',
method: 'setAttribute',
args: [name, value],
})
};
canvas.addEventListener = function (event, fn, opt) {
bindHandler('canvas', event, fn, opt);
};
canvas.clientWidth = data.width;
canvas.clientHeight = data.height;
canvas.width = data.width;
canvas.height = data.height;
rect.right = rect.width = data.width;
rect.bottom = rect.height = data.height;
canvas.setAttribute = function (name, value) {
postMessage({
type: 'canvasMethod',
method: 'setAttribute',
args: [name, value]
});
};
canvas.addEventListener = function (event, fn, opt) {
bindHandler('canvas', event, fn, opt);
};
canvas.getBoundingClientRect = function () {
return rect;
};
canvas.focus = function () {
postMessage({
type: 'canvasMethod',
method: 'focus',
args: [],
})
};
// noinspection JSUnusedGlobalSymbols
const style = {
set touchAction(value) {
postMessage({
type: 'canvasStyle',
name: 'touchAction',
value: value,
})
}
};
Object.defineProperty(canvas, 'style', {get() {return style}});
return canvas;
return rect;
};
canvas.focus = function () {
postMessage({
type: 'canvasMethod',
method: 'focus',
args: []
});
};
// noinspection JSUnusedGlobalSymbols
style = {
set touchAction (value) {
postMessage({
type: 'canvasStyle',
name: 'touchAction',
value: value
});
}
};
Object.defineProperty(canvas, 'style', {get () { return style }});
return canvas;
}
function noop() {}
(function (worker) {
worker.onmessage = mainToWorker;
worker.postMessage({
......
......@@ -244,7 +244,7 @@
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>1004.637.44055.35925</string> </value>
<value> <string>1004.22590.20102.60876</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -262,7 +262,7 @@
</tuple>
<state>
<tuple>
<float>1667226285.84</float>
<float>1668543292.95</float>
<string>UTC</string>
</tuple>
</state>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment