Skip to content

Commit

Permalink
Add NexusKitten/controlcontrols extension (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
NexusKitten authored Aug 22, 2023
1 parent c3cca77 commit d7c46eb
Show file tree
Hide file tree
Showing 2 changed files with 158 additions and 1 deletion.
156 changes: 156 additions & 0 deletions extensions/NexusKitten/controlcontrols.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
// Name: Control Controls
// ID: nkcontrols
// Description: Show and hide the project's controls.
// By: NamelessCat <https://scratch.mit.edu/users/NexusKitten/>

(function (Scratch) {
'use strict';

if (!Scratch.extensions.unsandboxed) {
throw new Error('Control Controls must run unsandboxed');
}

var fullScreen;
var greenFlag;
var pauseButton;
var stopButton;

const getButtons = () => {
fullScreen = undefined;
greenFlag = undefined;
pauseButton = undefined;
stopButton = undefined;

const rightButtons = document.querySelectorAll('[class*="stage-header_stage-button_"]');
fullScreen = rightButtons[rightButtons.length - 1];
if (!fullScreen) {
fullScreen = document.querySelector('.fullscreen-button') || document.querySelector('.standalone-fullscreen-button');
}

greenFlag = document.querySelector('[class*="green-flag_green-flag_"]') || document.querySelector('.green-flag-button');
pauseButton = document.querySelector('.pause-btn') || document.querySelector('.pause-button');
stopButton = document.querySelector('[class*="stop-all_stop-all_"]') || document.querySelector('.stop-all-button');
};

class controlcontrols {
getInfo() {
return {
id: 'nkcontrols',
name: 'Control Controls',
color1: '#ffab19',
color2: '#ec9c13',
color3: '#b87d17',
blocks: [
{
opcode: 'showOption',
blockType: Scratch.BlockType.COMMAND,
text: 'show [OPTION]',
arguments: {
OPTION: {
type: Scratch.ArgumentType.STRING,
menu: 'OPTION'
}
}
},
{
opcode: 'hideOption',
blockType: Scratch.BlockType.COMMAND,
text: 'hide [OPTION]',
arguments: {
OPTION: {
type: Scratch.ArgumentType.STRING,
menu: 'OPTION'
}
}
},
'---',
{
opcode: 'optionShown',
blockType: Scratch.BlockType.BOOLEAN,
text: '[OPTION] shown?',
arguments: {
OPTION: {
type: Scratch.ArgumentType.STRING,
menu: 'OPTION'
}
}
},
'---',
{
opcode: 'optionExists',
blockType: Scratch.BlockType.BOOLEAN,
text: '[OPTION] exists?',
arguments: {
OPTION: {
type: Scratch.ArgumentType.STRING,
menu: 'OPTION'
}
}
},
],
menus: {
OPTION: {
acceptReporters: true,
items: ['green flag', 'pause', 'stop', 'fullscreen']
}
}
};
}

showOption(args) {
getButtons();
if (args.OPTION === "green flag" && greenFlag) {
greenFlag.style.display = 'block';
} else if (args.OPTION === "pause" && pauseButton) {
pauseButton.style.display = 'block';
} else if (args.OPTION === "stop" && stopButton) {
stopButton.style.display = 'block';
} else if (args.OPTION === "fullscreen" && fullScreen) {
fullScreen.style.display = 'block';
}
}

hideOption(args) {
getButtons();
if (args.OPTION === "green flag" && greenFlag) {
greenFlag.style.display = 'none';
} else if (args.OPTION === "pause" && pauseButton) {
pauseButton.style.display = 'none';
} else if (args.OPTION === "stop" && stopButton) {
stopButton.style.display = 'none';
} else if (args.OPTION === "fullscreen" && fullScreen) {
fullScreen.style.display = 'none';
}
}

optionShown(args) {
getButtons();
if (args.OPTION === "green flag" && greenFlag) {
return greenFlag.style.display !== 'none';
} else if (args.OPTION === "pause" && pauseButton) {
return pauseButton.style.display !== 'none';
} else if (args.OPTION === "stop" && stopButton) {
return stopButton.style.display !== 'none';
} else if (args.OPTION === "fullscreen" && fullScreen) {
return fullScreen.style.display !== 'none';
}
return false;
}

optionExists(args) {
getButtons();
if (args.OPTION === "green flag" && greenFlag) {
return true;
} else if (args.OPTION === "pause" && pauseButton) {
return true;
} else if (args.OPTION === "stop" && stopButton) {
return true;
} else if (args.OPTION === "fullscreen" && fullScreen) {
return true;
}
return false;
}

}
Scratch.extensions.register(new controlcontrols());
})(Scratch);
3 changes: 2 additions & 1 deletion extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"navigator",
"battery",
"TheShovel/CustomStyles",
"NexusKitten/controlcontrols",
"mdwalters/notifications",
"XeroName/Deltatime",
"ar",
Expand Down Expand Up @@ -69,4 +70,4 @@
"gamejolt",
"obviousAlexC/newgroundsIO",
"Lily/McUtils"
]
]

0 comments on commit d7c46eb

Please sign in to comment.