wow thats a lot of changes

This commit is contained in:
2026-01-20 16:50:04 -06:00
parent b0f26c4c6c
commit 9c9c6b99b3
12 changed files with 1679 additions and 112 deletions

View File

@@ -24,11 +24,20 @@ import {
} from "../functions/extensionManager.js";
import { Thread } from "../functions/threads.js";
import { runCodeWithFunctions } from "../functions/runCode.js";
import {
createMonitor,
removeMonitor,
updateAllMonitors,
getAllMonitors,
clearAllMonitors,
loadMonitors,
getMonitor
} from "../functions/monitors.js";
import config from "../config";
BlocklyJS.javascriptGenerator.addReservedWords(
"whenFlagClicked,moveSteps,getAngle,getMousePosition,sayMessage,waitOneFrame,wait,switchCostume,setSize,setAngle,projectTime,isKeyPressed,isMouseButtonPressed,getCostumeSize,getSpriteScale,_startTween,startTween,soundProperties,setSoundProperty,playSound,stopSound,stopAllSounds,isMouseTouchingSprite,setPenStatus,setPenColor,setPenColorHex,setPenSize,clearPen,Thread,fastExecution,BUBBLE_TEXTSTYLE,sprite,renderer,stage,costumeMap,soundMap,stopped,code,penGraphics,runningScripts,findOrFilterItem,registerEvent,triggerCustomEvent,hideSprite,showSprite,MyFunctions"
"whenFlagClicked,moveSteps,getAngle,getMousePosition,sayMessage,waitOneFrame,wait,switchCostume,setSize,setAngle,projectTime,isKeyPressed,isMouseButtonPressed,getCostumeSize,getSpriteScale,_startTween,startTween,soundProperties,setSoundProperty,playSound,stopSound,stopAllSounds,isMouseTouchingSprite,setPenStatus,setPenColor,setPenColorHex,setPenSize,clearPen,Thread,fastExecution,BUBBLE_TEXTSTYLE,sprite,renderer,stage,costumeMap,soundMap,stopped,code,penGraphics,runningScripts,findOrFilterItem,registerEvent,triggerCustomEvent,hideSprite,showSprite,MyFunctions,displayTextAsSprite,clearTextSprite,setTextProperty,isTouchingMouse,isTouchingEdge,isTouchingSprite,isMouseDown,isTouchingColor,distanceToMouse,distanceToSprite,askAndWait,getAnswer,getUsername,getLoudness,getCurrent,getDaysSince2000,showVariableMonitor,hideVariableMonitor,gotoVariableMonitor,moveVariableMonitor,setSpriteEffect,changeSpriteEffect,clearSpriteEffects"
);
import.meta.glob("../blocks/**/*.js", { eager: true });
@@ -40,6 +49,9 @@ let currentRoom = null;
let amHost = false;
let invitesEnabled = true;
let connectedUsers = [];
let mouseX = 0;
let mouseY = 0;
let mouseCoordsFrozen = false;
const wrapper = document.getElementById("stage-wrapper");
const stageContainer = document.getElementById("stage");
@@ -94,8 +106,10 @@ function createPenGraphics() {
}
createPenGraphics();
export let projectVariables = {};
export let sprites = [];
window.projectVariables = {};
export const projectVariables = window.projectVariables;
window.sprites = [];
export const sprites = window.sprites;
export let activeSprite = null;
window.projectSounds = [];
window.projectCostumes = ["default"];
@@ -186,6 +200,13 @@ workspace.registerToolboxCategoryCallback("GLOBAL_VARIABLES", function (_) {
varField.setAttribute("name", "VAR");
varField.textContent = name;
get.appendChild(varField);
// ADD THIS: Add checkbox for showing monitor
const checkbox = Blockly.utils.xml.createElement("field");
checkbox.setAttribute("name", "CHECKBOX");
checkbox.textContent = "FALSE";
get.appendChild(checkbox);
xmlList.push(get);
}
@@ -427,15 +448,19 @@ function renderSpriteInfo() {
const infoEl = document.getElementById("sprite-info");
if (!activeSprite) {
infoEl.innerHTML = "<p>Select a sprite to see its info.</p>";
infoEl.innerHTML = `
<p>Select a sprite to see its info.</p>
<p>Mouse: ${mouseX}, ${mouseY} ${mouseCoordsFrozen ? '🔒' : ''}</p>
`;
} else {
const sprite = activeSprite.pixiSprite;
infoEl.innerHTML = `
<p>${Math.round(sprite.x)}, ${Math.round(-sprite.y)}</p>
<p>${Math.round(sprite.angle)}º</p>
<p>size: ${Math.round(((sprite.scale.x + sprite.scale.y) / 2) * 100)}</p>
<p><i class="fa-solid fa-${sprite.visible ? "eye" : "eye-slash"}"></i></p>
<p>${Math.round(sprite.x)}, ${Math.round(-sprite.y)}</p>
<p>${Math.round(sprite.angle)}º</p>
<p>size: ${Math.round(((sprite.scale.x + sprite.scale.y) / 2) * 100)}</p>
<p><i class="fa-solid fa-${sprite.visible ? "eye" : "eye-slash"}"></i></p>
<p>Mouse: ${mouseX}, ${mouseY} ${mouseCoordsFrozen ? '🔒' : ''}</p>
`;
}
}
@@ -1024,7 +1049,20 @@ function stopAllScripts() {
clearTimeout(spriteData.sayTimeout);
spriteData.sayTimeout = null;
}
if (spriteData.textSprite) {
const sprite = spriteData.pixiSprite;
sprite.removeChild(spriteData.textSprite);
spriteData.textSprite.destroy();
spriteData.textSprite = null;
// Restore original texture
if (spriteData.originalTexture) {
sprite.texture = spriteData.originalTexture;
sprite.anchor.set(spriteData.originalAnchor.x, spriteData.originalAnchor.y);
}
}
}
updateAllMonitors();
}
async function runCode() {
@@ -1103,6 +1141,11 @@ async function runCode() {
}
}
// Add ticker for updating monitors
app.ticker.add(() => {
updateAllMonitors();
});
app.view.addEventListener("click", () => {
for (const entry of eventRegistry.stageClick) {
entry.cb();
@@ -1211,6 +1254,7 @@ export async function getProject() {
backdrops: backdropsData,
currentBackdrop: currentBackdrop,
projectName: projectName,
monitors: getAllMonitors().map(m => m.toJSON()),
};
}
@@ -1223,6 +1267,7 @@ async function saveProject() {
backdrops: [], // ADD THIS
currentBackdrop: currentBackdrop, // ADD THIS
projectName: projectName,
monitors: getAllMonitors().map(m => m.toJSON()),
};
const toUint8Array = base64 =>
Uint8Array.from(atob(base64), c => c.charCodeAt(0));
@@ -1516,14 +1561,20 @@ async function handleProjectData(data) {
for (const child of app.stage.removeChildren()) {
if (child.destroy) child.destroy({ children: true });
}
sprites = [];
sprites.length = 0;
window.sprites = sprites;
if (!Array.isArray(data.sprites)) {
window.alert("No valid sprites found in file.");
return;
}
if (data.variables) projectVariables = data.variables;
if (data.variables) {
for (const key in projectVariables) {
delete projectVariables[key];
}
Object.assign(projectVariables, data.variables);
}
// Reset arrays
window.projectCostumes = ["default"];
@@ -1677,6 +1728,27 @@ async function handleProjectData(data) {
// IMPORTANT: Update toolbox AFTER everything is loaded
workspace.updateToolbox(document.getElementById('toolbox'));
if (Array.isArray(data.monitors)) {
clearAllMonitors();
const valueGetters = {
variable: {},
timer: {
'timer': () => projectTime()
},
answer: {
'answer': () => window.lastAnswer || ''
}
};
// Add getters for all variables
Object.keys(projectVariables).forEach(varName => {
valueGetters.variable[varName] = () => projectVariables[varName];
});
loadMonitors(app, data.monitors, valueGetters);
}
// Force refresh all blocks with dropdowns to show correct values
setTimeout(() => {
@@ -1876,6 +1948,29 @@ window.addEventListener("resize", () => {
resizeCanvas();
});
// Track mouse position relative to stage
app.view.addEventListener("mousemove", (e) => {
if (mouseCoordsFrozen) return;
const rect = app.view.getBoundingClientRect();
const mouseScreenX = e.clientX - rect.left;
const mouseScreenY = e.clientY - rect.top;
// Convert to stage coordinates
mouseX = Math.round((mouseScreenX - app.stage.x) / app.stage.scale.x);
mouseY = -Math.round((mouseScreenY - app.stage.y) / app.stage.scale.y);
renderSpriteInfo();
});
// Toggle freeze on spacebar
window.addEventListener("keydown", (e) => {
if (e.key === "h" && !e.repeat) {
mouseCoordsFrozen = !mouseCoordsFrozen;
renderSpriteInfo();
}
});
function isXmlEmpty(input = "") {
input = input.trim();
return (
@@ -2741,3 +2836,16 @@ workspace.addChangeListener(event => {
workspace.updateAllFunctionCalls = () => {
updateAllFunctionCalls(workspace);
};
setInterval(() => {
window.projectVariables = projectVariables;
window.sprites = sprites;
}, 100);
window.app = app;
window.projectVariables = projectVariables;
window.sprites = sprites;
window.createMonitor = createMonitor;
window.removeMonitor = removeMonitor;
window.getAllMonitors = getAllMonitors;
window.getMonitor = getMonitor;