Skip to content

Commit

Permalink
Updated DEMO
Browse files Browse the repository at this point in the history
  • Loading branch information
RichoM committed Aug 1, 2022
1 parent 9248be9 commit 6b3a541
Show file tree
Hide file tree
Showing 6 changed files with 255 additions and 177 deletions.
99 changes: 49 additions & 50 deletions docs/demo/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -880,36 +880,6 @@ let UziBlock = (function () {
},

// Control
boolean: {
text: "%boolean",
type: types.BOOLEAN,
inputs: {
"boolean": {
name: "value",
types: null,
builder: (block, input, name) => block.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[blocklyTranslate("true"), "true"],
[blocklyTranslate("false"), "false"]]), name),
}
},
connections: { up: false, down: false, left: true },
color: colors.CONTROL,
supportsBreakpoints: false,
},
boolean_cast: {
text: "bool ( %1 )",
type: types.BOOLEAN,
inputs: {
"1": {
name: "value",
types: allTypes(types.NUMBER),
builder: (block, input, name) => block.appendValueInput(name),
}
},
connections: { up: false, down: false, left: true },
color: colors.CONTROL,
supportsBreakpoints: false,
},
conditional_simple: {
text: "if %1 { \n %2 }",
type: null,
Expand Down Expand Up @@ -1106,6 +1076,52 @@ let UziBlock = (function () {
color: colors.CONTROL,
supportsBreakpoints: true,
},

// Math
boolean: {
text: "%boolean",
type: types.BOOLEAN,
inputs: {
"boolean": {
name: "value",
types: null,
builder: (block, input, name) => block.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[blocklyTranslate("true"), "true"],
[blocklyTranslate("false"), "false"]]), name),
}
},
connections: { up: false, down: false, left: true },
color: colors.MATH,
supportsBreakpoints: false,
},
boolean_cast: {
text: "bool ( %1 )",
type: types.BOOLEAN,
inputs: {
"1": {
name: "value",
types: allTypes(types.NUMBER),
builder: (block, input, name) => block.appendValueInput(name),
}
},
connections: { up: false, down: false, left: true },
color: colors.MATH,
supportsBreakpoints: false,
},
logical_not: {
text: "! %1",
type: types.BOOLEAN,
inputs: {
"1": {
name: "value",
types: [types.BOOLEAN],
builder: (block, input, name) => block.appendValueInput(name),
},
},
connections: { up: false, down: false, left: true },
color: colors.MATH,
supportsBreakpoints: true,
},
logical_compare: {
text: "( %left %logical_compare_op %right )",
type: types.BOOLEAN,
Expand Down Expand Up @@ -1133,7 +1149,7 @@ let UziBlock = (function () {
},
},
connections: { up: false, down: false, left: true },
color: colors.CONTROL,
color: colors.MATH,
supportsBreakpoints: true,
},
logical_operation: {
Expand All @@ -1159,25 +1175,9 @@ let UziBlock = (function () {
},
},
connections: { up: false, down: false, left: true },
color: colors.CONTROL,
supportsBreakpoints: true,
},
logical_not: {
text: "! %1",
type: types.BOOLEAN,
inputs: {
"1": {
name: "value",
types: [types.BOOLEAN],
builder: (block, input, name) => block.appendValueInput(name),
},
},
connections: { up: false, down: false, left: true },
color: colors.CONTROL,
color: colors.MATH,
supportsBreakpoints: true,
},

// Math
number: {
text: "%number",
type: types.NUMBER,
Expand Down Expand Up @@ -1219,8 +1219,7 @@ let UziBlock = (function () {
"numProp": {
name: "property",
types: null,
builder: (block, input, name) => block.appendDummyInput()
.appendField(new Blockly.FieldDropdown([[blocklyTranslate("isEven"),"even"],
builder: (block, input, name) => input.appendField(new Blockly.FieldDropdown([[blocklyTranslate("isEven"),"even"],
[blocklyTranslate("isOdd"),"odd"],
[blocklyTranslate("isPrime"),"prime"],
[blocklyTranslate("isWhole"),"whole"],
Expand Down
63 changes: 51 additions & 12 deletions docs/demo/ide.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,8 @@ let IDE = (function () {
function initializeInspectorPanel() {
$("#pin-choose-button").on("click", openInspectorPinDialog);
$("#global-choose-button").on("click", openInspectorGlobalDialog);
Uzi.on("update", updateInspectorPanel);
let editing = new Set();
Uzi.on("update", () => updateInspectorPanel(editing));
}

function initializeBlocklyMotorsModal() {
Expand Down Expand Up @@ -515,6 +516,13 @@ let IDE = (function () {
if (outputHistory.length == 100) { outputHistory.shift(); }
outputHistory.push(entry);

// Special case for the clear message
if (entry.type == "clear") {
$("#output-console").html("");
outputHistory = [];
return;
}

// Translate and format the message
let type = entry.type || "info";
let args = entry.args || [];
Expand Down Expand Up @@ -1167,20 +1175,20 @@ let IDE = (function () {
setSelectedPort(selectedPort);
}

function updateInspectorPanel() {
updatePinsPanel();
updateGlobalsPanel();
function updateInspectorPanel(editing) {
updatePinsPanel(editing);
updateGlobalsPanel(editing);
updateTasksPanel();
updateMemoryPanel();
updatePseudoVarsPanel();
}

function updatePinsPanel() {
updateValuesPanel(Uzi.state.pins, $("#pins-table tbody"), $("#no-pins-label"), "pin");
function updatePinsPanel(editing) {
updateValuesPanel(Uzi.state.pins, $("#pins-table tbody"), $("#no-pins-label"), "pin", editing, Uzi.setPinValues);
}

function updateGlobalsPanel() {
updateValuesPanel(Uzi.state.globals, $("#globals-table tbody"), $("#no-globals-label"), "global");
function updateGlobalsPanel(editing) {
updateValuesPanel(Uzi.state.globals, $("#globals-table tbody"), $("#no-globals-label"), "global", editing, Uzi.setGlobalValues);
}

function updatePseudoVarsPanel() {
Expand All @@ -1193,7 +1201,7 @@ let IDE = (function () {
}
}

function updateValuesPanel(values, $container, $emptyLabel, itemPrefix) {
function updateValuesPanel(values, $container, $emptyLabel, itemPrefix, editing, updateFn) {
if (!Uzi.state.connection.isConnected) {
// NOTE(Richo): If we're not connected we simply clear the panel
values = { available: [], elements: [] };
Expand Down Expand Up @@ -1232,13 +1240,42 @@ let IDE = (function () {
.attr("id", getEyeId(val))
.on("click", () => Plotter.toggle(val.name))))
.append($("<td>")
.text(val.name))
.append($("<td>")
.text(val.name));
let $value = $("<td>")
.addClass("text-right")
.addClass("pr-4")
.addClass("text-muted")
.attr("id", getElementId(val))
.text("?"));
.text("?");
if (editing != null) {
$value.attr("contenteditable", "true")
$value.on("focus", () => editing.add(val.name));
$value.on("blur", () => editing.delete(val.name));
$value.on("keydown", function (evt) {
/*
NOTE(Richo): If the user presses either Enter (13) or Tab (9) we update the value
*/
if (13 == evt.keyCode || 9 == evt.keyCode) {
let new_value = parseFloat(this.innerText);
if (isFinite(new_value) && updateFn) {
try {
updateFn([val.name], [new_value]);
} catch(err) {
console.error(err);
}
}
}
/*
NOTE(Richo): Additionally, if the user presses Enter (13) we prevent the
default event behavior and blur the input to simulate a "submit" event
*/
if (13 == evt.keyCode) {
evt.preventDefault();
$value.blur();
}
});
}
$row.append($value);
$container.append($row);
}
});
Expand All @@ -1259,6 +1296,8 @@ let IDE = (function () {
$eye.css("color", Plotter.colorFor(val.name) || "white");

if (reporting.has(val.name)) {
if (editing && editing.has(val.name)) return; // Ignore this element if we're editing its value

let $item = getElement(val);
if ($item.get(0) == undefined) { initializePanel(); }

Expand Down
Loading

0 comments on commit 6b3a541

Please sign in to comment.