Enable non-default event parameter names in imported and exported .aia files
@@ -239,6 +239,14 @@ Blockly.Blocks.component_event = {
container.setAttribute('vertical_parameters', "true"); // Only store an element for vertical
// The absence of this attribute means horizontal.
}
+
+ // Note that this.parameterNames only contains parameter names that have
+ // overridden the default event parameter names specified in the component
+ // DB
+ for (var i = 0; i < this.parameterNames.length; i++) {
+ container.setAttribute('param_name' + i, this.parameterNames[i]);
+ }
+
return container;
},
@@ -269,6 +277,20 @@ Blockly.Blocks.component_event = {
delete this.instanceName;
}
+ // this.parameterNames will be set to a list of names that will override the
+ // default names specified in the component DB. Note that some parameter
+ // names may be overridden while others may remain their defaults
+ this.parameterNames = [];
+ var numParams = this.getDefaultParameters_().length
+ for (var i = 0; i < numParams; i++) {
+ var paramName = xmlElement.getAttribute('param_name' + i);
+ // For now, we only allow explicit parameter names starting at the beginning
+ // of the parameter list. Some day we may allow an arbitrary subset of the
+ // event params to be explicitly specified.
+ if (!paramName) break;
+ this.parameterNames.push(paramName);
+ }
+
// Orient parameters horizontally by default
var horizParams = xmlElement.getAttribute('vertical_parameters') !== "true";
@@ -406,6 +428,16 @@ Blockly.Blocks.component_event = {
// Return a list of parameter names
getParameters: function () {
/** @type {EventDescriptor} */
+ var defaultParameters = this.getDefaultParameters_();
+ var explicitParameterNames = this.getExplicitParameterNames_();
+ var params = [];
+ for (var i = 0; i < defaultParameters.length; i++) {
+ var paramName = explicitParameterNames[i] || defaultParameters[i].name;
+ params.push({name: paramName, type: defaultParameters[i].type});
+ }
+ return params;
+ },
+ getDefaultParameters_: function () {
var eventType = this.getEventTypeObject();
if (this.isGeneric) {
return [
@@ -415,6 +447,9 @@ Blockly.Blocks.component_event = {
}
return eventType && eventType.parameters;
},
+ getExplicitParameterNames_: function () {
+ return this.parameterNames;
+ },
// Renames the block's instanceName and type (set in BlocklyBlock constructor), and revises its title
rename : function(oldname, newname) {
if (this.instanceName == oldname) {
@@ -572,6 +607,7 @@ Blockly.Blocks.component_event = {
if (varList.length != params.length) {
return false; // parameters have changed
}
+ if ("true" === componentType.external) {
for (var x = 0; x < varList.length; ++x) {
var found = false;
for (var i = 0, param; param = params[i]; ++i) {
@@ -584,6 +620,7 @@ Blockly.Blocks.component_event = {
return false; // parameter name changed
}
}
+ }
// No need to check event return type, events do not return.
return true; // passed all our tests! block is defined!
};
