Spaces:
Build error
Build error
File size: 7,985 Bytes
30c32c8 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 |
const BlockType = require('../../extension-support/block-type');
const ArgumentType = require('../../extension-support/argument-type');
const Cast = require('../../util/cast');
const Icon = require('./icon.svg');
class JgPackagerApplicationsBlocks {
constructor(runtime) {
/**
* The runtime instantiating this block package.
*/
this.runtime = runtime;
}
/**
* metadata for this extension and its blocks.
* @returns {object}
*/
getInfo() {
return {
id: "jgPackagerApplications",
name: "Packager Applications",
color1: "#66b8ff",
color2: "#5092cc",
blockIconURI: Icon,
blocks: [
{
opcode: "isPackaged",
blockType: BlockType.BOOLEAN,
text: "is packaged?"
},
{
opcode: "moveWindow",
blockType: BlockType.COMMAND,
text: "move window to x: [X] y: [Y]",
arguments: {
X: {
type: ArgumentType.NUMBER,
defaultValue: 0
},
Y: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
},
{
opcode: "setX",
blockType: BlockType.COMMAND,
text: "set window x to [X]",
arguments: {
X: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
},
{
opcode: "changeX",
blockType: BlockType.COMMAND,
text: "change window x by [X]",
arguments: {
X: {
type: ArgumentType.NUMBER,
defaultValue: 10
}
}
},
{
opcode: "setY",
blockType: BlockType.COMMAND,
text: "set window y to [Y]",
arguments: {
Y: {
type: ArgumentType.NUMBER,
defaultValue: 0
}
}
},
{
opcode: "changeY",
blockType: BlockType.COMMAND,
text: "change window y by [Y]",
arguments: {
Y: {
type: ArgumentType.NUMBER,
defaultValue: 10
}
}
},
{
opcode: "windowX",
blockType: BlockType.REPORTER,
text: "window x"
},
{
opcode: "windowY",
blockType: BlockType.REPORTER,
text: "window y"
},
"---",
{
opcode: "resizeWindow",
blockType: BlockType.COMMAND,
text: "set window size to width: [WIDTH] height: [HEIGHT]",
arguments: {
WIDTH: {
type: ArgumentType.NUMBER,
defaultValue: 640
},
HEIGHT: {
type: ArgumentType.NUMBER,
defaultValue: 360
}
}
},
{
opcode: "windowWidth",
blockType: BlockType.REPORTER,
text: "window width"
},
{
opcode: "windowHeight",
blockType: BlockType.REPORTER,
text: "window height"
},
"---",
{
opcode: "enableFullscreen",
blockType: BlockType.COMMAND,
text: "enable fullscreen"
},
{
opcode: "exitFullscreen",
blockType: BlockType.COMMAND,
text: "exit fullscreen"
},
{
opcode: "isFullscreen",
blockType: BlockType.BOOLEAN,
text: "in fullscreen?"
},
{
opcode: "screenWidth",
blockType: BlockType.REPORTER,
text: "screen width"
},
{
opcode: "screenHeight",
blockType: BlockType.REPORTER,
text: "screen height"
},
"---",
{
opcode: "setWindowName",
blockType: BlockType.COMMAND,
text: "set window name to [NAME]",
arguments: {
NAME: {
type: ArgumentType.STRING,
defaultValue: "My Cool Game"
}
}
},
{
opcode: "getWindowName",
blockType: BlockType.REPORTER,
text: "window name"
},
{
opcode: "isFocused",
blockType: BlockType.BOOLEAN,
text: "is user using this window?"
},
{
opcode: "closeWindow",
blockType: BlockType.COMMAND,
isTerminal: true,
text: "close window"
},
]
};
}
// blocks
isPackaged() {
return this.runtime.isPackaged;
}
moveWindow(args) {
const x = Cast.toNumber(args.X);
const y = Cast.toNumber(args.Y);
window.moveTo(x, y);
}
setX(args) {
const x = Cast.toNumber(args.X);
const y = window.screenY;
window.moveTo(x, y);
}
changeX(args) {
const x = Cast.toNumber(args.X);
window.moveBy(x, 0);
}
setY(args) {
const x = window.screenX;
const y = Cast.toNumber(args.Y);
window.moveTo(x, y);
}
changeY(args) {
const y = Cast.toNumber(args.Y);
window.moveBy(0, y);
}
windowX() {
return window.screenLeft;
}
windowY() {
return window.screenTop;
}
resizeWindow(args) {
const width = Cast.toNumber(args.WIDTH);
const height = Cast.toNumber(args.HEIGHT);
window.resizeTo(width, height);
}
windowWidth() {
return window.outerWidth;
}
windowHeight() {
return window.outerHeight;
}
screenWidth() {
return screen.width;
}
screenHeight() {
return screen.height;
}
enableFullscreen() {
document.documentElement.requestFullscreen();
}
exitFullscreen() {
document.exitFullscreen();
}
isFullscreen() {
if (document.fullscreenElement) {
return true;
}
return false;
}
setWindowName(args) {
const name = Cast.toString(args.NAME);
document.title = name;
}
getWindowName() {
return document.title;
}
isFocused() {
return document.hasFocus();
}
closeWindow() {
window.close();
}
}
module.exports = JgPackagerApplicationsBlocks; |