repo: janusweb action: commit revision: path_from: revision_from: 60da62dc04854f52adc38949110531db2f0e455d: path_to: revision_to:
commit 60da62dc04854f52adc38949110531db2f0e455d Author: James BaicoianuDate: Fri Jun 24 04:45:17 2016 -0700 More scripting functionality (vector functions, room events, etc) diff --git a/scripts/janusweb.js b/scripts/janusweb.js
--- a/scripts/janusweb.js
+++ b/scripts/janusweb.js
@@ -71,7 +71,6 @@ elation.require(['janusweb.config', 'engine.things.generic','janusweb.remoteplay
if (this.engine.systems.admin) {
elation.events.add(this.engine.systems.admin, 'admin_edit_change', elation.bind(this, this.handleRoomEditSelf));
}
-
}
this.initScripting = function() {
window.janus = new elation.proxy(this, {
@@ -118,11 +117,12 @@ elation.require(['janusweb.config', 'engine.things.generic','janusweb.remoteplay
});
var player = this.engine.client.player;
+ player.properties.player_id = this.userId; // FIXME - player spawns without an id, so we fix it up here
window.player = new elation.proxy(player, {
pos: ['property', 'properties.position'],
//eye_pos: ['property', 'eyes.properties.position'],
head_pos: ['property', 'head.properties.position'],
- //cursor_pos: ['property', 'properties.cursor_position'],
+ cursor_pos: ['property', 'vectors.cursor_pos'],
//cursor_xdir: ['property', 'properties.cursor_xdir'],
//cursor_ydir: ['property', 'properties.cursor_ydir'],
//cursor_zdir: ['property', 'properties.cursor_zdir'],
@@ -145,7 +145,18 @@ elation.require(['janusweb.config', 'engine.things.generic','janusweb.remoteplay
hand1_ydir: ['property', 'vectors.hand1_ydir'],
hand1_zdir: ['property', 'vectors.hand1_zdir'],
});
-
+ window.Vector = function(x, y, z) {
+ return new THREE.Vector3(x, y, z);
+ }
+ window.distance = function(v1, v2) {
+ return v1.distanceTo(v2);
+ }
+ window.print = function() {
+ console.log.apply(console, arguments);
+ }
+ window.debug = function() {
+ console.log.apply(console, arguments);
+ }
}
this.createChildren = function() {
var hashargs = elation.url();
@@ -264,14 +275,14 @@ elation.require(['janusweb.config', 'engine.things.generic','janusweb.remoteplay
playSound: ['function', 'playSound'],
getObjectById: ['function', 'getObjectById'],
- onLoad: ['callback', 'room_load'],
+ onLoad: ['callback', 'janus_room_scriptload'],
update: ['callback', 'engine_frame', 'engine'],
onCollision: ['callback', 'physics_collide'],
- onClick: ['callback', 'click'],
- onMouseDown: ['callback', 'mousedown'],
- onMouseUp: ['callback', 'mouseup'],
- onKeyDown: ['callback', 'keydown'],
- onKeyUp: ['callback', 'keyup']
+ onClick: ['callback', 'click', 'engine.client.container'],
+ onMouseDown: ['callback', 'mousedown', 'engine.client.container'],
+ onMouseUp: ['callback', 'mouseup', 'engine.client.container'],
+ onKeyDown: ['callback', 'janus_room_keydown'],
+ onKeyUp: ['callback', 'janus_room_keyup']
});
} else {
this.load(url, true);
diff --git a/scripts/room.js b/scripts/room.js
--- a/scripts/room.js
+++ b/scripts/room.js
@@ -37,6 +37,8 @@ elation.require([
this.load();
this.roomsrc = '';
//this.showDebug();
+ elation.events.add(this.engine.client.container, 'keydown', elation.bind(this, this.onKeyDown));
+ elation.events.add(this.engine.client.container, 'keyup', elation.bind(this, this.onKeyUp));
}
this.createChildren = function() {
this.spawn('light_ambient', this.id + '_ambient', {
@@ -285,7 +287,6 @@ elation.require([
}
this.parseFireBox = function(fireboxsrc) {
- fireboxsrc = fireboxsrc.replace('scale="1.4 1.4 1" url="http://usagii.net/other/placeholder/jancredits/index.html"', 'url="http://usagii.net/other/placeholder/jancredits/index.html"');
var xml = elation.utils.parseXML(fireboxsrc, false, true);
var rooms = this.getAsArray(elation.utils.arrayget(xml, 'fireboxroom._children.room', {}));
var room = {_children: {}};
@@ -433,14 +434,28 @@ setTimeout(elation.bind(this, function() {
}
}));
var soundmap = {};
- if (assets.sound) assets.sound.forEach(function(n) { soundmap[n.id] = n; });
+ if (assets.sound) assets.sound.forEach(elation.bind(this, function(n) {
+ soundmap[n.id] = n;
+ var soundurl = (n.src.match(/^https?:/) || n.src[0] == '/' ? n.src : this.baseurl + n.src);
+
+ var proxyurl = this.properties.janus.properties.corsproxy;
+ soundurl = proxyurl + soundurl;
+ var sound = this.spawn('janussound', n.id + '_' + Math.round(Math.random() * 10000), {
+ 'room': this,
+ 'js_id': n.js_id,
+ 'position': n.pos,
+ 'src': soundurl,
+ 'distance': parseFloat(n.dist),
+ //'volume': n.scale[0],
+ 'autoplay': false,
+ 'loop': n.loop,
+ });
+ this.sounds[n.id] = sound;
+ }));
if (sounds) sounds.forEach(elation.bind(this, function(n) {
var soundargs = soundmap[n.id];
if (soundargs) {
- var soundurl = (soundargs.src.match(/^https?:/) || soundargs.src[0] == '/' ? soundargs.src : this.baseurl + soundargs.src);
-
- var proxyurl = this.properties.janus.properties.corsproxy;
- soundurl = proxyurl + soundurl;
+/*
var sound = this.spawn('janussound', n.id + '_' + Math.round(Math.random() * 10000), {
'room': this,
'js_id': n.js_id,
@@ -451,9 +466,13 @@ setTimeout(elation.bind(this, function() {
'autoplay': true,
'loop': n.loop,
});
+*/
+ var sound = this.sounds[n.id];
+ sound.properties.autoplay = true;
if (n.js_id) {
this.jsobjects[n.js_id] = sound.getProxyObject();
}
+ this.sounds[n.id] = sound;
} else {
console.log("Couldn't find sound: " + n.id);
}
@@ -518,12 +537,13 @@ setTimeout(elation.bind(this, function() {
}
if (assets.scripts) {
- assets.scripts.forEach(function(s) {
+ assets.scripts.forEach(elation.bind(this, function(s) {
var script = elation.engine.assets.find('script', s.src);
- elation.events.add(script, 'asset_load', function() {
+ elation.events.add(script, 'asset_load', elation.bind(this, function() {
document.head.appendChild(script);
- });
- });
+ script.onload = elation.bind(this, this.doScriptOnload);
+ }));
+ }));
}
//if (!this.active) {
@@ -793,8 +813,20 @@ setTimeout(elation.bind(this, function() {
'video': 'janusvideo',
};
var realtype = typemap[type.toLowerCase()] || type;
+ var nargs = {
+ 'room': this,
+ 'janus': this.properties.janus,
+ 'js_id': args.js_id,
+ 'position': args.pos || '0 0 0',
+ 'orientation': args.orientation || '0 0 0 1',
+ 'scale': args.scale || '1 1 1',
+ 'image_id': args.id,
+ 'color': args.col,
+ 'lighting': args.lighting
+ };
if (elation.engine.things[realtype]) {
- var object = this.spawn(realtype, args.js_id, args);
+console.log('spawn it', realtype, args, nargs);
+ var object = this.spawn(realtype, args.js_id, nargs);
if (args.js_id) {
this.jsobjects[args.js_id] = object.getProxyObject();
}
@@ -805,5 +837,19 @@ setTimeout(elation.bind(this, function() {
this.addCookie = function(name, value) {
this.cookies[name] = value;
}
+ this.doScriptOnload = function() {
+ elation.events.fire({type: 'janus_room_scriptload', element: this});
+ }
+ this.playSound = function(name) {
+ if (this.sounds[name]) {
+ this.sounds[name].play();
+ }
+ }
+ this.onKeyDown = function(ev) {
+ elation.events.fire({type: 'janus_room_keydown', element: this, extras: { keyCode: ev.key.toUpperCase() }});
+ }
+ this.onKeyUp = function(ev) {
+ elation.events.fire({type: 'janus_room_keyup', element: this, extras: { keyCode: ev.key.toUpperCase() }});
+ }
}, elation.engine.things.generic);
});
-----END OF PAGE-----