emit component linked events

beta.r3js.org
-=yb4f310 2017-09-01 09:10:12 +02:00
parent 71be2f19af
commit 3b09906efe
2 changed files with 28 additions and 0 deletions

View File

@ -68,6 +68,7 @@ GameLib.Event.DELETE_COMPONENT_ERROR = 0x32;
GameLib.Event.COMPONENT_DELETED = 0x33;
GameLib.Event.COMPONENT_TYPES_UPDATED = 0x34;
GameLib.Event.SHAPE_INSTANCE_CREATED = 0x35;
GameLib.Event.COMPONENT_LINKED = 0x36;
/**
* Returns string name of event ID
@ -131,6 +132,7 @@ GameLib.Event.GetEventName = function(number) {
case 0x33 : return 'component_deleted';
case 0x34 : return 'component_types_updated';
case 0x35 : return 'shape_instance_created';
case 0x36 : return 'component_linked';
break;
}

View File

@ -120,18 +120,44 @@ GameLib.System.Linking.prototype.link = function(component, data) {
for (var property in component.linkedObjects) {
if (component.linkedObjects.hasOwnProperty(property)) {
if (component.linkedObjects[property] instanceof Array) {
var linked = [];
component[property] = component[property].map(function (entry) {
if (entry === data.component.id) {
linked.push({
parent : component,
property : property,
child : data.component
});
return data.component;
} else {
return entry;
}
});
linked.map(function(link) {
GameLib.Event.Emit(
GameLib.Event.COMPONENT_LINKED,
link
);
})
} else {
if (component[property] &&
component[property] === data.component.id) {
component[property] = data.component;
GameLib.Event.Emit(
GameLib.Event.COMPONENT_LINKED,
{
parent : component,
property : property,
child : data.component
}
);
}
}
}