content/hifi-content/davidback/development/shortbow/displayServerEntity.js
2022-02-13 22:49:05 +01:00

35 lines
No EOL
1.2 KiB
JavaScript

(function() {
Script.include('utils.js');
Display = function() {
};
Display.prototype = {
preload: function(entityID) {
this.entityID = entityID;
var props = Entities.getEntityProperties(this.entityID, ['userData', 'parentID']);
var data = utils.parseJSON(props.userData);
if (data !== undefined && data.displayType !== undefined) {
this.commChannel = data.displayType + "-" + props.parentID;
} else {
print("scoreboardEntity.js | ERROR: userData does not contain a game channel and/or team number");
}
Messages.subscribe(this.commChannel);
Messages.messageReceived.connect(this, this.onReceivedMessage);
},
unload: function() {
Messages.unsubscribe(this.commChannel);
Messages.messageReceived.disconnect(this, this.onReceivedMessage);
},
onReceivedMessage: function(channel, message, senderID) {
if (channel === this.commChannel) {
Entities.editEntity(this.entityID, {
text: message
});
}
},
};
return new Display();
});