Ejemplo n.º 1
0
        /// <summary>
        /// Reconfigure this block based on the mutator dialog's components.
        /// </summary>
        /// <param name="containerBlock">Root block in mutator.</param>
        public override void compose(Block containerBlock)
        {
            var clauseBlock = containerBlock.getInputTargetBlock("STACK");

            // Count text of inputs.
            cases_        = new JsArray <Tuple <string, string> >();
            defaultCount_ = 0;
            var        statementConnections       = new JsArray <Connection>();
            Connection defaultStatementConnection = null;

            while (clauseBlock != null)
            {
                switch (clauseBlock.type)
                {
                case SwitchCaseTextConstBlock.type_name: {
                    var value = clauseBlock.getFieldValue("CONST");
                    cases_.Push(new Tuple <string, string>(value, null));
                    statementConnections.Push(((SwitchCaseTextConstBlock)clauseBlock).statementConnection_);
                }
                break;

                case SwitchCaseTextRangeBlock.type_name: {
                    var range_min = clauseBlock.getFieldValue("RANGE_MIN");
                    var range_max = clauseBlock.getFieldValue("RANGE_MAX");
                    cases_.Push(new Tuple <string, string>(range_min, range_max));
                    statementConnections.Push(((SwitchCaseTextRangeBlock)clauseBlock).statementConnection_);
                }
                break;

                case SwitchCaseTextDefaultBlock.type_name: {
                    defaultCount_++;
                    defaultStatementConnection = ((SwitchCaseTextDefaultBlock)clauseBlock).statementConnection_;
                }
                break;

                default:
                    throw new Exception("Unknown block type.");
                }
                clauseBlock = (clauseBlock.nextConnection != null) ?
                              clauseBlock.nextConnection.targetBlock() : null;
            }
            updateShape_();
            // Reconnect any child blocks.
            for (var i = 0; i <= cases_.Length; i++)
            {
                Mutator.reconnect(statementConnections[i], this, "DO" + i);
            }
            Mutator.reconnect(defaultStatementConnection, this, "DEFAULT_DO");
        }