Skip to content

Commit

Permalink
Make FPS hide when in small player mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Tacodiva committed Jul 7, 2024
1 parent 18b0db9 commit 968b7f3
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion addons/fps/userscript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default async function ({ addon, global, cons, msg }) {

await new Promise((resolve) => {
if (addon.tab.traps.vm.editingTarget) return resolve();
addon.tab.traps.vm.runtime.once("PROJECT_LOADED", resolve);
Expand All @@ -9,6 +10,21 @@ export default async function ({ addon, global, cons, msg }) {
let fpsCounterElement = document.createElement("span");
fpsCounterElement.className = "fps-counter";

function updateVisibility() {
if (addon.tab.redux && addon.tab.redux.state.scratchGui.stageSize.stageSize === "small") {
fpsCounterElement.style.display = "none";
} else {
addon.tab.displayNoneWhileDisabled(fpsCounterElement, { display: "flex" });
}
}

updateVisibility();

addon.tab.redux.addEventListener("statechanged", ({ detail }) => {
if (detail.action.type !== "scratch-gui/StageSize/SET_STAGE_SIZE") return;
updateVisibility();
});

const renderTimes = [];
var fps = "?";
var lastFps = 0;
Expand All @@ -23,7 +39,6 @@ export default async function ({ addon, global, cons, msg }) {
if (firstTime === -1) firstTime = now;
if (now - firstTime <= 2500) fps = "?";
if (fps !== lastFps) fpsCounterElement.innerText = msg("fpsCounter", { fps: (lastFps = fps) });
addon.tab.displayNoneWhileDisabled(fpsCounterElement, { display: "flex" });
renderer.ogDraw();
};

Expand All @@ -32,6 +47,7 @@ export default async function ({ addon, global, cons, msg }) {
markAsSeen: true,
reduxEvents: ["scratch-gui/mode/SET_PLAYER", "fontsLoaded/SET_FONTS_LOADED", "scratch-gui/locales/SELECT_LOCALE"],
});
console.log("Hai :D");
addon.tab.appendToSharedSpace({ space: "afterStopButton", element: fpsCounterElement, order: 3 });
}
}

0 comments on commit 968b7f3

Please sign in to comment.