|
| 1 | +// https://github.com/scratchfoundation/scratch-blocks/blob/f210e042988b91bcdc2abeca7a2d85e178edadb2/blocks_vertical/procedures.js#L205 |
| 2 | +export function modifiedCreateAllInputs(connectionMap) { |
| 3 | + // Split the proc into components, by %n, %b, %s and %l (ignoring escaped). |
| 4 | + var procComponents = this.procCode_.split(/(?=[^\\]%[nbsl])/); |
| 5 | + procComponents = procComponents.map(function (c) { |
| 6 | + return c.trim(); // Strip whitespace. |
| 7 | + }); |
| 8 | + |
| 9 | + // Create arguments and labels as appropriate. |
| 10 | + var argumentCount = 0; |
| 11 | + for (var i = 0, component; (component = procComponents[i]); i++) { |
| 12 | + var labelText; |
| 13 | + // Don't treat %l as an argument |
| 14 | + if (component.substring(0, 1) == "%" && component.substring(1, 2) !== "l") { |
| 15 | + var argumentType = component.substring(1, 2); |
| 16 | + if (!(argumentType == "n" || argumentType == "b" || argumentType == "s")) { |
| 17 | + throw new Error("Found an custom procedure with an invalid type: " + argumentType); |
| 18 | + } |
| 19 | + labelText = component.substring(2).trim(); |
| 20 | + |
| 21 | + var id = this.argumentIds_[argumentCount]; |
| 22 | + |
| 23 | + var input = this.appendValueInput(id); |
| 24 | + if (argumentType == "b") { |
| 25 | + input.setCheck("Boolean"); |
| 26 | + } |
| 27 | + this.populateArgument_(argumentType, argumentCount, connectionMap, id, input); |
| 28 | + argumentCount++; |
| 29 | + } else { |
| 30 | + labelText = component == "%l" ? " " : component.replace("%l", "").trim(); |
| 31 | + } |
| 32 | + this.addProcedureLabel_(labelText.replace(/\\%/, "%")); |
| 33 | + } |
| 34 | + |
| 35 | + // remove all traces of %l at the earliest possible time |
| 36 | + this.procCode_ = this.procCode_.replace(/%l /g, ""); |
| 37 | +} |
| 38 | + |
| 39 | +//https://github.com/scratchfoundation/scratch-blocks/blob/f210e042988b91bcdc2abeca7a2d85e178edadb2/blocks_vertical/procedures.js#L565 |
| 40 | +export function modifiedUpdateDeclarationProcCode(prefixLabels = false) { |
| 41 | + this.procCode_ = ""; |
| 42 | + this.displayNames_ = []; |
| 43 | + this.argumentIds_ = []; |
| 44 | + for (var i = 0; i < this.inputList.length; i++) { |
| 45 | + if (i != 0) { |
| 46 | + this.procCode_ += " "; |
| 47 | + } |
| 48 | + var input = this.inputList[i]; |
| 49 | + if (input.type == 5) { |
| 50 | + // replaced Blocky.DUMMY_VALUE with 5 |
| 51 | + this.procCode_ += (prefixLabels ? "%l " : "") + input.fieldRow[0].getValue(); // modified to prepend %l delimiter, which prevents label merging |
| 52 | + } else if (input.type == 1) { |
| 53 | + // replaced Blocky.INPUT_VALUE with 1 |
| 54 | + // Inspect the argument editor. |
| 55 | + var target = input.connection.targetBlock(); |
| 56 | + this.displayNames_.push(target.getFieldValue("TEXT")); |
| 57 | + this.argumentIds_.push(input.name); |
| 58 | + if (target.type == "argument_editor_boolean") { |
| 59 | + this.procCode_ += "%b"; |
| 60 | + } else { |
| 61 | + this.procCode_ += "%s"; |
| 62 | + } |
| 63 | + } else { |
| 64 | + throw new Error("Unexpected input type on a procedure mutator root: " + input.type); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
0 commit comments