Skip to content

Commit

Permalink
add sensing blocks (an object in SH3D is clicked ?) to ScratchHome Ex…
Browse files Browse the repository at this point in the history
…tension
  • Loading branch information
kimokipo committed Jun 30, 2022
1 parent bedaa63 commit d9c4b72
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 5 deletions.
35 changes: 33 additions & 2 deletions Extension/ScratchHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class ScratchHome {
static y = 0;
static agle = 0;
static sprite = undefined;
static clickObjectlist = undefined;

constructor(runtime) {
this.runtime = runtime;
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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.
Expand Down
41 changes: 38 additions & 3 deletions ScratchOffline/lib.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }

Expand All @@ -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 () {
Expand All @@ -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;
}
}

Expand All @@ -288649,6 +288656,9 @@ _createClass(ScratchHome, [{
},{
key: "sprite",
value : undefined
},{
key: "clickObjectlist",
value : undefined
} ,
{
key: "getInfo",
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
};
Expand Down

0 comments on commit d9c4b72

Please sign in to comment.