logic blocks
This commit is contained in:
parent
3a620286c2
commit
7a9674b4a7
6 changed files with 70 additions and 82 deletions
|
|
@ -1,29 +1,24 @@
|
|||
export default {
|
||||
type: 'io_logic_boolean',
|
||||
|
||||
toolbox: {
|
||||
category: 'Logic',
|
||||
},
|
||||
|
||||
visualization: {
|
||||
colour: 60,
|
||||
tooltip: "A true or false value."
|
||||
},
|
||||
name: "Boolean",
|
||||
colour: 60,
|
||||
description: "A true or false value.",
|
||||
|
||||
connections: {
|
||||
mode: "value",
|
||||
output: "boolean",
|
||||
},
|
||||
|
||||
lines: [
|
||||
["", {
|
||||
field: "BOOL",
|
||||
template: "%BOOL",
|
||||
|
||||
fields: {
|
||||
BOOL: {
|
||||
options: [
|
||||
['true', 'TRUE'],
|
||||
['false', 'FALSE'],
|
||||
],
|
||||
}]
|
||||
],
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
generators: {
|
||||
json: block => {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
export default {
|
||||
type: 'io_logic_negate',
|
||||
bytecodeKey: "negate",
|
||||
name: "Negate",
|
||||
colour: 60,
|
||||
description: "Swaps a truthy value to `false`, or a falsy value to `true`.",
|
||||
|
||||
toolbox: {
|
||||
category: 'Logic',
|
||||
template: "not %EXPRESSION",
|
||||
|
||||
inputs: {
|
||||
EXPRESSION: {
|
||||
description: "Block diagram that will be resolved, then have its truthiness flipped.",
|
||||
shadow: 'io_logic_boolean'
|
||||
}
|
||||
},
|
||||
|
||||
visualization: {
|
||||
colour: 60,
|
||||
tooltip: "Swaps a truthy value to false, or a falsy value to true."
|
||||
},
|
||||
|
||||
lines: [
|
||||
["not", { inputValue: 'EXPRESSION', shadow: 'io_logic_boolean' }]
|
||||
],
|
||||
|
||||
generators: {
|
||||
json: (block, generator) => {
|
||||
const
|
||||
|
|
|
|||
|
|
@ -1,41 +1,34 @@
|
|||
export default {
|
||||
type: 'io_logic_operation',
|
||||
bytecodeKey: "logic",
|
||||
name: "Logic Operation",
|
||||
inputsInline: true,
|
||||
colour: 60,
|
||||
description: "Perform the specifed boolean logic operation on two operands.",
|
||||
|
||||
toolbox: {
|
||||
category: 'Logic',
|
||||
template: `%A %OP %B`,
|
||||
|
||||
inputs: {
|
||||
A: {
|
||||
description: "A block diagram that will be resolved to a truthy/falsy value",
|
||||
shadow: 'io_logic_boolean'
|
||||
},
|
||||
|
||||
B: {
|
||||
description: "A block diagram that will be resolved to a truthy/falsy value",
|
||||
shadow: 'io_logic_boolean'
|
||||
}
|
||||
},
|
||||
|
||||
visualization: {
|
||||
inputsInline: true,
|
||||
colour: 60,
|
||||
tooltip: [
|
||||
"Perform the specifed boolean logic operation on two operands.",
|
||||
"-",
|
||||
"Inputs:",
|
||||
"---------------",
|
||||
"Operator - the type of operation to perform, \"and\" or \"or\"",
|
||||
"\"and\" - true if all inputs are true, false otherwise",
|
||||
"\"or\" - true if any input is true, false otherwise",
|
||||
"Boolean A - the first boolean",
|
||||
"Boolean B - the second boolean",
|
||||
"-",
|
||||
"Casting:",
|
||||
"---------------",
|
||||
"both inputs are coerced to true or false before the operation",
|
||||
].join('\n'),
|
||||
},
|
||||
|
||||
lines: [
|
||||
["", { inputValue: 'A', shadow: 'io_logic_boolean' }],
|
||||
["", {
|
||||
field: 'OP',
|
||||
fields: {
|
||||
OP: {
|
||||
description: "Select the logic operation to perform on the inputs:",
|
||||
options: [
|
||||
['and', 'AND'],
|
||||
['or', 'OR'],
|
||||
['and', 'AND', "Resolve `true` if both operands are true, otherwise `false`."],
|
||||
['or', 'OR', "Resolve `true` if either or both operands are true, otherwise `false`."],
|
||||
]
|
||||
}],
|
||||
["", { inputValue: 'B', shadow: 'io_logic_boolean' }],
|
||||
],
|
||||
}
|
||||
},
|
||||
|
||||
generators: {
|
||||
json: (block, generator) => {
|
||||
|
|
|
|||
|
|
@ -1,22 +1,29 @@
|
|||
export default {
|
||||
disabled: true,
|
||||
|
||||
type: 'io_logic_ternary',
|
||||
name: "Ternary",
|
||||
colour: 60,
|
||||
|
||||
toolbox: {
|
||||
category: 'Logic',
|
||||
template: `
|
||||
if %IF
|
||||
then %THEN
|
||||
else %ELSE
|
||||
`,
|
||||
|
||||
inputs: {
|
||||
IF: {
|
||||
shadow: 'io_logic_boolean'
|
||||
},
|
||||
|
||||
THEN: {
|
||||
shadow: 'io_logic_boolean'
|
||||
},
|
||||
|
||||
ELSE: {
|
||||
shadow: 'io_logic_boolean'
|
||||
}
|
||||
},
|
||||
|
||||
visualization: {
|
||||
colour: 60,
|
||||
},
|
||||
|
||||
lines: [
|
||||
["if", { inputValue: 'IF', shadow: 'io_logic_boolean' }],
|
||||
["then", { inputValue: 'THEN', shadow: 'io_logic_boolean' }],
|
||||
["else", { inputValue: 'ELSE', shadow: 'io_logic_boolean' }],
|
||||
],
|
||||
|
||||
generators: {
|
||||
json: (block, generator) => {
|
||||
const
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ const
|
|||
const lines = []
|
||||
|
||||
// title for this field
|
||||
lines.push(`### \`${capitalize(field.field)}\`:`)
|
||||
lines.push(`### \`${capitalize(field.field)}\``)
|
||||
|
||||
// add lines based on what properties are present
|
||||
Object.hasOwn(field, 'description') && lines.push(niceTemplate(field.description))
|
||||
|
|
|
|||
|
|
@ -2535,7 +2535,7 @@ exports[`Block Snapshots > Blockly JSON > io_logic_boolean 1`] = `
|
|||
"colour": 60,
|
||||
"tooltip": "A true or false value.",
|
||||
"output": "boolean",
|
||||
"message0": " %1 %2",
|
||||
"message0": "%1 %2",
|
||||
"args0": [
|
||||
{
|
||||
"name": "BOOL",
|
||||
|
|
@ -2622,7 +2622,7 @@ exports[`Block Snapshots > Blockly JSON > io_logic_negate 1`] = `
|
|||
"inputsInline": false,
|
||||
"type": "io_logic_negate",
|
||||
"colour": 60,
|
||||
"tooltip": "Swaps a truthy value to false, or a falsy value to true.",
|
||||
"tooltip": "Swaps a truthy value to \`false\`, or a falsy value to \`true\`.",
|
||||
"output": null,
|
||||
"message0": "not %1",
|
||||
"args0": [
|
||||
|
|
@ -2640,9 +2640,9 @@ exports[`Block Snapshots > Blockly JSON > io_logic_operation 1`] = `
|
|||
"inputsInline": true,
|
||||
"type": "io_logic_operation",
|
||||
"colour": 60,
|
||||
"tooltip": "Perform the specifed boolean logic operation on two operands.\\n-\\nInputs:\\n---------------\\nOperator - the type of operation to perform, \\"and\\" or \\"or\\"\\n\\"and\\" - true if all inputs are true, false otherwise\\n\\"or\\" - true if any input is true, false otherwise\\nBoolean A - the first boolean\\nBoolean B - the second boolean\\n-\\nCasting:\\n---------------\\nboth inputs are coerced to true or false before the operation",
|
||||
"tooltip": "Perform the specifed boolean logic operation on two operands.",
|
||||
"output": null,
|
||||
"message0": " %1",
|
||||
"message0": "%1",
|
||||
"args0": [
|
||||
{
|
||||
"type": "input_value",
|
||||
|
|
@ -2667,13 +2667,6 @@ exports[`Block Snapshots > Blockly JSON > io_logic_operation 1`] = `
|
|||
],
|
||||
"text": ""
|
||||
},
|
||||
{
|
||||
"type": "input_dummy",
|
||||
"align": "RIGHT"
|
||||
}
|
||||
],
|
||||
"message2": " %1",
|
||||
"args2": [
|
||||
{
|
||||
"type": "input_value",
|
||||
"name": "B",
|
||||
|
|
|
|||
Loading…
Reference in a new issue