Skip to content

Commit

Permalink
Overhaul the ordering system
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacodiva committed Aug 28, 2023
1 parent 03a31e3 commit 7766382
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 70 deletions.
4 changes: 2 additions & 2 deletions addons/middle-click-popup/BlockRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ function _renderBlock(block, container, parentCategory, isVertical) {
} else if (blockPart instanceof BlockInputEnum) {
if (blockPart.isRound) {
component = createBackedTextedComponent(
blockInput?.string ?? blockPart.values[0].string,
blockInput.string,
blockContainer,
BlockShapes.TextInput,
categoryClass,
Expand All @@ -282,7 +282,7 @@ function _renderBlock(block, container, parentCategory, isVertical) {
);
} else {
component = createBackedTextedComponent(
blockInput?.string ?? blockPart.values[0].string,
blockInput.string,
blockContainer,
BlockShapes.SquareInput,
categoryClass,
Expand Down
17 changes: 9 additions & 8 deletions addons/middle-click-popup/BlockTypeInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export class BlockInputEnum extends BlockInput {
}
}
this.isRound = isRound;
this.defaultValue = this.values[0];
}

/**
Expand Down Expand Up @@ -260,6 +261,10 @@ export class BlockInstance {
this.typeInfo = typeInfo;
/** @type {Array} */
this.inputs = inputs;

for (let i = 0; i < this.typeInfo.inputs.length; i++) {
if (this.inputs[i] == null) this.inputs[i] = this.typeInfo.inputs[i].defaultValue;
}
}

/**
Expand All @@ -275,9 +280,8 @@ export class BlockInstance {

const block = this.typeInfo.Blockly.Xml.domToBlock(this.typeInfo.domForm, this.typeInfo.workspace);
for (let i = 0; i < this.typeInfo.inputs.length; i++) {
const input = this.typeInfo.inputs[i];
const inputValue = this.inputs[i] ?? input.defaultValue;
if (inputValue != null) input.setValue(block, inputValue);
const inputValue = this.inputs[i];
if (inputValue != null) this.typeInfo.inputs[i].setValue(block, inputValue);
}

return block;
Expand Down Expand Up @@ -508,17 +512,14 @@ export class BlockTypeInfo {

const ofInputs = [];

const inputTarget = new BlockInputEnum(
ofInputs[baseVarInputIdx] = new BlockInputEnum(options, baseVarInput.inputIdx, baseVarInput.fieldIdx, false);
ofInputs[baseTargetInputIdx] = new BlockInputEnum(
[[targetInput.string, targetInput.value]],
baseTargetInput.inputIdx,
baseTargetInput.fieldIdx,
isStage
);

ofInputs[baseVarInputIdx] = new BlockInputEnum(options, baseVarInput.inputIdx, baseVarInput.fieldIdx, false);
ofInputs[baseTargetInputIdx] = inputTarget;
inputTarget.defaultValue = inputTarget.values[0];

const ofParts = [...parts];
ofParts[baseVarPartIdx] = ofInputs[baseVarInputIdx];
ofParts[baseTargetPartIdx] = ofInputs[baseTargetInputIdx];
Expand Down
Loading

0 comments on commit 7766382

Please sign in to comment.