Skip to content

Commit

Permalink
Some work on fixing manipulator (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
krzys-h committed Mar 20, 2014
1 parent 5c9b2da commit 60b37c3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
24 changes: 8 additions & 16 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ io.sockets.on('connection', function (socket) {

if(!('avatars' in player)) {
player = undefined;
return callback('fail', { code: 3, message: 'Currputed accound - no avatar list.'});
return callback('fail', { code: 3, message: 'Corrupted account - no avatar list.'});
}
for(var k in player.avatars) {
socket.join(k);
Expand All @@ -312,7 +312,9 @@ io.sockets.on('connection', function (socket) {
var check_feature = function(object, feature) {
if(!object.features[feature]) {
throw { code: 8, message: 'Specified component doesn\'t have ' + feature + ' capabilities' };
return false;
}
return true;
};

var battery_check = function(battery, energy) {
Expand Down Expand Up @@ -481,25 +483,15 @@ io.sockets.on('connection', function (socket) {
return;
if(typeof target.manipulator_slot === 'undefined')
return fail(999, 'Manipulator empty - nothing to be attached.');
var hub = find_co_component(target, data.hub, 'hub');
if(typeof data.hub_slot !== 'number')
return fail(999, 'hub slot should be a number.');
var idx = Math.round(data.skeleton_slot);
if(idx < 0)
return fail(999, 'Specified skeleton doesn\'t have negative slots.');
if(idx >= skeleton.skeleton_slots.length)
return fail(999, 'Specified skeleton doesn\'t have that many slots.');
if(skeleton.skeleton_slots[idx])
return fail(999, 'Skeleton '+data.skeleton+' slot '+idx+' occupied by '+skeleton.skeleton_slots[idx].id+'.');
if(typeof data.hub === 'undefined')
return fail(999, 'You must define hub to attach to.');
var hub = common.get(data.hub);

var o = target.manipulator_slot;
skeleton.skeleton_slots[idx] = o;
o.parent = skeleton;
delete target.manipulator_slot.position;
delete target.manipulator_slot.velocity;
connect(hub, o);
delete target.manipulator_slot.grabbed_by;
delete target.manipulator_slot;
socket.emit('manipulator attached', { manipulator: { id: target.id }, skeleton: { id: skeleton.id }, slot: idx, object: { id: o.id } });
socket.emit('manipulator attached', { manipulator: { id: target.id }, hub: { id: hub.id }, object: { id: o.id } });
});

on('manipulator detach', function(target, data) {
Expand Down
4 changes: 4 additions & 0 deletions static/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@
String.prototype.capitalize = function() {
return this.charAt(0).toUpperCase() + this.slice(1);
}

var get_position = e.get_position = function(object) {
return vectors.create(object.position);
};

})(typeof exports === 'undefined' ? this['common'] = {} : exports);

Expand Down
8 changes: 2 additions & 6 deletions static/manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,15 @@ socket.on('manipulator released', function(data) {
delete objects[data.id].manipulator_slot;
});

var attach = function(hub, slot) {
var attach = function(hub) {
hub = common.get(hub);
socket.emit('manipulator attach', {target: manipulator.id, hub: hub.id, hub_slot: slot});
socket.emit('manipulator attach', {target: manipulator.id, hub: hub.id});
};

socket.on('manipulator attached', function(data) {
var s = common.get(data.hub.id);
var o = common.get(data.object.id);
var m = common.get(data.manipulator.id);
s.hub_slots[data.slot] = o;
o.parent = s;
delete o.position;
delete o.velocity;
delete o.grabbed_by;
delete m.manipulator_slot;
socket.emit('report', { target: o.id });
Expand Down

0 comments on commit 60b37c3

Please sign in to comment.