Skip to content

Commit 968b7f3

Browse files
committed
Make FPS hide when in small player mode
1 parent 18b0db9 commit 968b7f3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

addons/fps/userscript.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export default async function ({ addon, global, cons, msg }) {
2+
23
await new Promise((resolve) => {
34
if (addon.tab.traps.vm.editingTarget) return resolve();
45
addon.tab.traps.vm.runtime.once("PROJECT_LOADED", resolve);
@@ -9,6 +10,21 @@ export default async function ({ addon, global, cons, msg }) {
910
let fpsCounterElement = document.createElement("span");
1011
fpsCounterElement.className = "fps-counter";
1112

13+
function updateVisibility() {
14+
if (addon.tab.redux && addon.tab.redux.state.scratchGui.stageSize.stageSize === "small") {
15+
fpsCounterElement.style.display = "none";
16+
} else {
17+
addon.tab.displayNoneWhileDisabled(fpsCounterElement, { display: "flex" });
18+
}
19+
}
20+
21+
updateVisibility();
22+
23+
addon.tab.redux.addEventListener("statechanged", ({ detail }) => {
24+
if (detail.action.type !== "scratch-gui/StageSize/SET_STAGE_SIZE") return;
25+
updateVisibility();
26+
});
27+
1228
const renderTimes = [];
1329
var fps = "?";
1430
var lastFps = 0;
@@ -23,7 +39,6 @@ export default async function ({ addon, global, cons, msg }) {
2339
if (firstTime === -1) firstTime = now;
2440
if (now - firstTime <= 2500) fps = "?";
2541
if (fps !== lastFps) fpsCounterElement.innerText = msg("fpsCounter", { fps: (lastFps = fps) });
26-
addon.tab.displayNoneWhileDisabled(fpsCounterElement, { display: "flex" });
2742
renderer.ogDraw();
2843
};
2944

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

0 commit comments

Comments
 (0)