diff --git a/Extension/ScratchHome.js b/Extension/ScratchHome.js index e6606eb..5d8c160 100644 --- a/Extension/ScratchHome.js +++ b/Extension/ScratchHome.js @@ -5,6 +5,7 @@ class ScratchHome { static y = 0; static agle = 0; static sprite = undefined; + static clickObjectlist = undefined; constructor(runtime) { this.runtime = runtime; @@ -14,6 +15,11 @@ class ScratchHome { if (ScratchHome.sprite){ this.objectlist = ScratchHome.sprite.lookupVariableById("CNn7j*SP0QT%rN4=j[xz"); this.lamplist = ScratchHome.sprite.lookupVariableById("GoN|030ruZ,{H+4$)C-$"); + var clickObjectlist = {}; + for (let o of this.objectlist.value){ + clickObjectlist[o] = false; + } + ScratchHome.clickObjectlist = clickObjectlist; } } @@ -136,6 +142,22 @@ class ScratchHome { }); } } + + if (this.objectlist && this.objectlist.value.length > 0){ + for (let o of this.objectlist.value){ + result.push({ + "opcode": "isObjectClicked", + blockType: BlockType.BOOLEAN, + "text": "[object] est clické ?", + "arguments": { + "object": { + "type": "string", + "defaultValue": o + } + } + }); + } + } result.push( { "opcode": 'getMessage', @@ -216,9 +238,12 @@ class ScratchHome { ScratchHome.sprite.setXY(ScratchHome.x,ScratchHome.y); ScratchHome.sprite.setDirection(ScratchHome.angle); } - } else{ + } else if (msgrec.startsWith("click")){ + var click = msgrec.split("/") + ScratchHome.clickObjectlist[click[1]] = true; + }else{ ScratchHome.message = event.data; - } + } }; this.socket.onclose = function(event) { @@ -244,6 +269,12 @@ class ScratchHome { this.send("switchOnOff/"+switchList+"/"+lamp); } + + isObjectClicked({object}){ + var result = ScratchHome.clickObjectlist[object]; + ScratchHome.clickObjectlist[object] = false; + return result; + } /** * Get the current message. * @return {string} - the current message. diff --git a/ScratchOffline/lib.min.js b/ScratchOffline/lib.min.js index d7ce1d8..8e72bea 100644 --- a/ScratchOffline/lib.min.js +++ b/ScratchOffline/lib.min.js @@ -288594,7 +288594,7 @@ module.exports = Scratch3PenBlocks; !*** ./node_modules/scratch-vm/src/extensions/scratch3_rjm/index.js ***! \**********************************************************************/ /*! no static exports found */ -/***/ (function(module, exports) { +/***/ (function(module, exports,__webpack_require__) { function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } @@ -288616,6 +288616,8 @@ module.exports = Scratch3PenBlocks; function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } + var BlockType = __webpack_require__(/*! ../../extension-support/block-type */ "./node_modules/scratch-vm/src/extension-support/block-type.js"); + // https://kimokipo.github.io/ScratchHome.js // https://sheeptester.github.io/scratch-gui/?url=https://kimokipo.github.io/ScratchHome.js var ScratchHome = /*#__PURE__*/function () { @@ -288628,6 +288630,11 @@ function ScratchHome(runtime) { if (ScratchHome.sprite){ this.objectlist = ScratchHome.sprite.lookupVariableById("CNn7j*SP0QT%rN4=j[xz"); this.lamplist = ScratchHome.sprite.lookupVariableById("GoN|030ruZ,{H+4$)C-$"); + var clickObjectlist = {}; + for (let o of this.objectlist.value){ + clickObjectlist[o] = false; + } + ScratchHome.clickObjectlist = clickObjectlist; } } @@ -288649,6 +288656,9 @@ _createClass(ScratchHome, [{ },{ key: "sprite", value : undefined +},{ + key: "clickObjectlist", + value : undefined } , { key: "getInfo", @@ -288793,6 +288803,21 @@ value: function getBlocks(){ }); } } + if (this.objectlist && this.objectlist.value.length > 0){ + for (let o of this.objectlist.value){ + result.push({ + "opcode": "isObjectClicked", + blockType: BlockType.BOOLEAN, + "text": "[object] est clické ?", + "arguments": { + "object": { + "type": "string", + "defaultValue": o + } + } + }); + } + } result.push( { "opcode": 'getMessage', @@ -288838,7 +288863,14 @@ result.push( this.connect(); this.send("switchOnOff/"+switchList+"/"+lamp); } -}, { +},{ + key: "isObjectClicked", + value: function isObjectClicked({object}){ + var result = ScratchHome.clickObjectlist[object]; + ScratchHome.clickObjectlist[object] = false; + return result; + } +} ,{ key: "getStatus", value: function getStatus() { this.connect(); @@ -288894,7 +288926,10 @@ result.push( ScratchHome.sprite.setXY(ScratchHome.x,ScratchHome.y); ScratchHome.sprite.setDirection(ScratchHome.angle); } - } else{ + } else if (msgrec.startsWith("click")){ + var click = msgrec.split("/") + ScratchHome.clickObjectlist[click[1]] = true; + }else{ ScratchHome.message = event.data; } };