Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Orientation_Detection.js (from JosiahW2011) #264

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
73 changes: 73 additions & 0 deletions static/extensions/JosiahW2011/Orientation_Detection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**!
* @author JosiahW2011 https://github.com/JosiahW2011
* @version 1.0
* @copyright MIT License
* Removing this will not do well...
*/
(function(Scratch) {
'use strict';
class Extension {
getInfo() {
return {
id: "OrDe",
name: "Orientation Detection",
color1: "#FFD700",
color2: "#473c00",
blocks: [
{
/**! "isLandscape?" */
opcode: 'isLandscape',
text: 'isLandscape?',
blockType: Scratch.BlockType.BOOLEAN,
disableMonitor: false
},
{
/**! "isPortrait?" */
opcode: 'isPortrait',
text: 'isPortrait?',
blockType: Scratch.BlockType.BOOLEAN,
disableMonitor: false
},
{
/**! "currentOrientation?" */
opcode: 'currentOrientationType',
text: 'currentOrientation?',
blockType: Scratch.BlockType.REPORTER,
disableMonitor: false
}
],
};
}

/**! "Functions section" */
isLandscape() {
let isLandscape = false;
const handleOrientationChange = () => {
const orientation = screen.orientation.type;
isLandscape = orientation !== "portrait-primary" && orientation !== "portrait-secondary";
};

screen.orientation.addEventListener("change", handleOrientationChange);
handleOrientationChange();
return isLandscape;
}

isPortrait() {
let isPortrait = false;
const handleOrientationChange = () => {
const orientation = screen.orientation.type;
isPortrait = orientation !== "landscape-primary" && orientation !== "landscape-secondary";
};

screen.orientation.addEventListener("change", handleOrientationChange);
handleOrientationChange();
return isPortrait;
}

currentOrientationType() {
return screen.orientation.type;
}
}
/**! "End of class Extension" */
Scratch.extensions.register(new Extension());
})(Scratch);