emit component linked events
parent
71be2f19af
commit
3b09906efe
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue