/// <summary> /// Return the uneditable container block that everything else attaches to in /// given workspace. /// </summary> /// <param name="workspace"> Where the root block lives.</param> /// <returns>Root block.</returns> public static Blockly.Block getRootBlock(Blockly.Workspace workspace) { var blocks = workspace.getTopBlocks(false); for (var i = 0; i < blocks.Length; i++) { var block = blocks[i]; if (block.type == "factory_base") { return(block); } } return(null); }
public FieldImage(Blockly.Workspace workspace) : base(workspace, type_name) { }
public FieldVariable(Blockly.Workspace workspace) : base(workspace, type_name) { }
public FieldColour(Blockly.Workspace workspace) : base(workspace, type_name) { }
public TypeString(Blockly.Workspace workspace) : base(workspace, type_name) { }
public TypeNull(Blockly.Workspace workspace) : base(workspace, type_name) { }
/// <summary> /// Create JS code required to create a top, bottom, or value connection. /// </summary> /// <param name="functionName"> JavaScript function name.</param> /// <param name="typeName"> Name of type input.</param> /// <param name="workspace"></param> Where the root block lives. /// <returns>Line of JavaScript code to create connection.</returns> private static string connectionLineJs_(string functionName, string typeName, Blockly.Workspace workspace) { var type = FactoryUtils.getOptTypesFrom( FactoryUtils.getRootBlock(workspace), typeName); if (!String.IsNullOrEmpty(type)) { type = ", " + type; } else { type = ""; } return(" this." + functionName + "(true" + type + ");"); }
public FieldStatic(Blockly.Workspace workspace) : base(workspace, type_name) { }
public FactoryBase(Blockly.Workspace workspace) : base(workspace, type_name) { }
public InputStatement(Blockly.Workspace workspace) : base(workspace, type_name) { }
public InputDummy(Blockly.Workspace workspace) : base(workspace, type_name) { }
public InputValue(Blockly.Workspace workspace) : base(workspace, type_name) { }
public ColourHue(Blockly.Workspace workspace) : base(workspace, type_name) { }
public TypeOther(Blockly.Workspace workspace) : base(workspace, type_name) { }
public TypeGroupContainer(Blockly.Workspace workspace) : base(workspace, type_name) { }
public FieldNumber(Blockly.Workspace workspace) : base(workspace, type_name) { }
public TypeGroupItem(Blockly.Workspace workspace) : base(workspace, type_name) { }
public FieldDropdownContainer(Blockly.Workspace workspace) : base(workspace, type_name) { }
/// <summary> /// Update the language code as JavaScript. /// </summary> /// <param name="blockType"> Name of block.</param> /// <param name="rootBlock"> Factory_base block.</param> /// <param name="workspace"></param> Where the root block lives. /// <returns>Generated language code.</returns> private static string formatJavaScript_(string blockType, Blockly.Block rootBlock, Blockly.Workspace workspace) { var code = new JsArray <string>(); code.Push("Blockly.Core.Blocks[\"" + blockType + "\"] = {"); code.Push(" init: () => {"); // Generate inputs. var TYPES = new Dictionary <string, string>() { { "input_value", "appendValueInput" }, { "input_statement", "appendStatementInput" }, { "input_dummy", "appendDummyInput" } }; var contentsBlock = rootBlock.getInputTargetBlock("INPUTS"); while (contentsBlock != null) { if (!contentsBlock.disabled && !contentsBlock.getInheritedDisabled()) { var name = ""; // Dummy inputs don't have names. Other inputs do. if (contentsBlock.type != "input_dummy") { name = FactoryUtils.escapeString(contentsBlock.getFieldValue("INPUTNAME")); } code.Push(" this." + TYPES[contentsBlock.type] + "(" + name + ")"); var check = FactoryUtils.getOptTypesFrom(contentsBlock, "TYPE"); if (!String.IsNullOrEmpty(check)) { code.Push(" .setCheck(" + check + ")"); } var align = contentsBlock.getFieldValue("ALIGN"); if (align != "LEFT") { code.Push(" .setAlign(Blockly.ALIGN_" + align + ")"); } var fields = FactoryUtils.getFieldsJs_( contentsBlock.getInputTargetBlock("FIELDS")); for (var i = 0; i < fields.Length; i++) { code.Push(" .appendField(" + fields[i] + ")"); } // Add semicolon to last line to finish the statement. code[code.Length - 1] += ";"; } contentsBlock = contentsBlock.nextConnection == null ? null : contentsBlock.nextConnection.targetBlock(); } // Generate inline/external switch. if (rootBlock.getFieldValue("INLINE") == "EXT") { code.Push(" this.setInputsInline(false);"); } else if (rootBlock.getFieldValue("INLINE") == "INT") { code.Push(" this.setInputsInline(true);"); } // Generate output, or next/previous connections. switch (rootBlock.getFieldValue("CONNECTIONS")) { case "LEFT": code.Push(FactoryUtils.connectionLineJs_("setOutput", "OUTPUTTYPE", workspace)); break; case "BOTH": code.Push( FactoryUtils.connectionLineJs_("setPreviousStatement", "TOPTYPE", workspace)); code.Push( FactoryUtils.connectionLineJs_("setNextStatement", "BOTTOMTYPE", workspace)); break; case "TOP": code.Push( FactoryUtils.connectionLineJs_("setPreviousStatement", "TOPTYPE", workspace)); break; case "BOTTOM": code.Push( FactoryUtils.connectionLineJs_("setNextStatement", "BOTTOMTYPE", workspace)); break; } // Generate colour. var colourBlock = rootBlock.getInputTargetBlock("COLOUR"); if (colourBlock != null && !colourBlock.disabled) { var hue = Script.ParseFloat(colourBlock.getFieldValue("HUE")); if (!Double.IsNaN(hue)) { code.Push(" this.setColour(" + hue + ");"); } } code.Push(" this.setTooltip(\"\");"); code.Push(" this.setHelpUrl(\"http://www.example.com/\");"); code.Push(" }"); code.Push("};"); return(code.Join("\n")); }
public FieldDropdownOption(Blockly.Workspace workspace) : base(workspace, type_name) { }
/// <summary> /// Get block definition code for the current block. /// </summary> /// <param name="blockType"></param> Type of block. /// <param name="rootBlock"> RootBlock from main workspace in which /// user uses Block Factory Blocks to create a custom block.</param> /// <param name="format">"JSON" or "JavaScript".</param> /// <param name="workspace"> Where the root block lives.</param> /// <returns>Block definition.</returns> public static string getBlockDefinition(string blockType, Blockly.Block rootBlock, string format, Blockly.Workspace workspace) { string code = null; blockType = blockType.Replace(new Regex(@"\W", RegexOptions.Multiline), "_").Replace(new Regex(@"^(\d)"), "_\\1"); switch (format) { case "JSON": code = FactoryUtils.formatJson_(blockType, rootBlock); break; case "JavaScript": code = FactoryUtils.formatJavaScript_(blockType, rootBlock, workspace); break; } return(code); }
public FieldCheckbox(Blockly.Workspace workspace) : base(workspace, type_name) { }
/// <summary> /// Get Blockly Block by rendering pre-defined block in workspace. /// </summary> /// <param name="blockType"> Type of block that has already been defined.</param> /// <param name="workspace">Workspace on which to render</param> /// the block. /// <returns>The Blockly.Block of desired type.</returns> public static Blockly.Block getDefinedBlock(string blockType, Blockly.Workspace workspace) { workspace.clear(); return(workspace.newBlock(blockType)); }
public TypeBoolean(Blockly.Workspace workspace) : base(workspace, type_name) { }