Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions blocks/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getMeshFromBlock,
clearSkyMesh,
setClearSkyToBlack,
handleSkyBlockDeletion,
} from "../ui/blockmesh.js";
import { registerFieldColour } from "@blockly/field-colour";
import { createThemeConfig } from "../main/themes.js";
Expand Down Expand Up @@ -102,8 +103,7 @@ export function handleBlockDelete(event) {
clearSkyMesh();
setClearSkyToBlack();
} else if (blockJson.type === "set_sky_color") {
clearSkyMesh();
setClearSkyToBlack();
handleSkyBlockDeletion(blockJson.id);
}

// Check inputs for child blocks
Expand Down Expand Up @@ -173,8 +173,7 @@ export function handleMeshLifecycleChange(block, changeEvent) {
clearSkyMesh();
setClearSkyToBlack();
} else if (block.type === "set_sky_color") {
clearSkyMesh();
setClearSkyToBlack();
handleSkyBlockDeletion(block.id);
}
}
return true;
Expand Down
27 changes: 27 additions & 0 deletions ui/blockmesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,33 @@ export function clearSkyMesh({ preserveClearColor = true } = {}) {
delete meshMap["sky"];
}

/**
* Called when a set_sky_color block is deleted or disabled.
* Only clears the sky if the given block was the active one; if another
* enabled sky block remains in the workspace it is reapplied automatically.
*/
export function handleSkyBlockDeletion(blockId) {
// If the removed block wasn't the one controlling the sky, leave it alone.
if (meshBlockIdMap["sky"] !== blockId) {
return;
}

clearSkyMesh();

const workspace = Blockly.getMainWorkspace();
const remainingSky = workspace
?.getAllBlocks(false)
.find((b) => b.type === "set_sky_color" && b.isEnabled());

if (remainingSky) {
meshMap["sky"] = remainingSky;
meshBlockIdMap["sky"] = remainingSky.id;
updateSkyFromBlock(null, remainingSky, null);
} else {
setClearSkyToBlack();
}
}

export function setClearSkyToBlack() {
console.log("*** Setting clear sky to black");
const fallbackColor =
Expand Down
Loading