Spaces:
Runtime error
Runtime error
File size: 2,683 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 |
const BlockType = require('../../extension-support/block-type');
const ArgumentType = require('../../extension-support/argument-type');
/**
* Class for blocks
* @constructor
*/
class JgBestExtensionBlocks {
constructor(runtime) {
/**
* The runtime instantiating this block package.
* @type {Runtime}
*/
this.runtime = runtime;
/**
* @type {HTMLVideoElement}
*/
this.videoElement = null;
this.runtime.on('PROJECT_STOP_ALL', () => {
if (!this.videoElement) return;
this.videoElement.remove();
this.videoElement = null;
});
this.runtime.on('RUNTIME_PAUSED', () => {
if (!this.videoElement) return;
this.videoElement.pause();
});
this.runtime.on('RUNTIME_UNPAUSED', () => {
if (!this.videoElement) return;
this.videoElement.play();
});
this.runtime.on('BEFORE_EXECUTE', () => {
this.setVolumeProperly();
});
}
setVolumeProperly() {
if (!this.videoElement) return;
try {
this.videoElement.volume = this.runtime.audioEngine.inputNode.gain.value * 0.5;
} catch {
// well that sucks
}
}
/**
* @returns {object} metadata for this extension and its blocks.
*/
getInfo() {
return {
id: 'jgBestExtension',
name: 'the great',
color1: '#ff0000',
color2: '#00ff00',
color3: '#0000ff',
blocks: [
{
opcode: 'ohioBlock',
text: 'absolutely delectable!',
blockType: BlockType.COMMAND,
disableMonitor: false
}
]
};
}
ohioBlock() {
if (this.videoElement) return;
const canvas = this.runtime.renderer.canvas;
if (!canvas) return;
if (!canvas.parentElement) return;
const video = document.createElement("video");
video.style = 'width: 100%; height: 100%; z-index: 10000; position: absolute; left: 0; top: 0;';
video.innerHTML = '<source src="https://penguinmod.com/bx-tv1.mp4" type="video/mp4">'
+ '<source src="https://penguinmod.com/vr/themes/selection.mp3" type="audio/mpeg">';
this.videoElement = video;
canvas.parentElement.appendChild(video);
this.setVolumeProperly();
video.play();
video.onended = () => {
video.remove();
this.videoElement = null;
};
}
}
module.exports = JgBestExtensionBlocks;
|