diff --git a/assets/project.json b/assets/project.json index 829597d..3f8329b 100644 --- a/assets/project.json +++ b/assets/project.json @@ -1 +1 @@ -{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["variabila mea",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"decor1","dataFormat":"svg","assetId":"cd21514d0531fdffb22204e0ec5ed84a","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"name":"pop","assetId":"83a9787d4cb6f3b7632b4ddfebf74367","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Personaj1","variables":{},"lists":{},"broadcasts":{},"blocks":{"i0sF-x|[yQ-#%j@rU%f,":{"opcode":"event_whenflagclicked","next":")u+B7H(M9g25%Em.w=5;","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":360,"y":168},")u+B7H(M9g25%Em.w=5;":{"opcode":"control_forever","next":null,"parent":"i0sF-x|[yQ-#%j@rU%f,","inputs":{"SUBSTACK":[2,"/B0dn4qYH?K,.K9rc;A`"]},"fields":{},"shadow":false,"topLevel":false},"/B0dn4qYH?K,.K9rc;A`":{"opcode":"control_if","next":"|LMd9D?RO[2$-2d9tSaH","parent":")u+B7H(M9g25%Em.w=5;","inputs":{"CONDITION":[2,"#Uk8A~y8%JVMqn}NHx[`"],"SUBSTACK":[2,"oh,d/q]c)nT*MAUu,[S@"]},"fields":{},"shadow":false,"topLevel":false},"#Uk8A~y8%JVMqn}NHx[`":{"opcode":"sensing_keypressed","next":null,"parent":"/B0dn4qYH?K,.K9rc;A`","inputs":{"KEY_OPTION":[1,"DNHO5a8nfKM+34^x:43}"]},"fields":{},"shadow":false,"topLevel":false},"DNHO5a8nfKM+34^x:43}":{"opcode":"sensing_keyoptions","next":null,"parent":"#Uk8A~y8%JVMqn}NHx[`","inputs":{},"fields":{"KEY_OPTION":["space",null]},"shadow":true,"topLevel":false},"oh,d/q]c)nT*MAUu,[S@":{"opcode":"looks_switchcostumeto","next":null,"parent":"/B0dn4qYH?K,.K9rc;A`","inputs":{"COSTUME":[1,"R^t{wX)}j(l,vXrOTX(g"]},"fields":{},"shadow":false,"topLevel":false},"R^t{wX)}j(l,vXrOTX(g":{"opcode":"looks_costume","next":null,"parent":"oh,d/q]c)nT*MAUu,[S@","inputs":{},"fields":{"COSTUME":["costum2",null]},"shadow":true,"topLevel":false},"|LMd9D?RO[2$-2d9tSaH":{"opcode":"control_if","next":null,"parent":"/B0dn4qYH?K,.K9rc;A`","inputs":{"CONDITION":[2,"46_hm$E}C?N}KA=/3@`u"],"SUBSTACK":[2,"[+(oxNIM5(qM,kq~)/=K"]},"fields":{},"shadow":false,"topLevel":false},"w!`lxu[+VTbb!a@:2IFM":{"opcode":"sensing_keypressed","next":null,"parent":"46_hm$E}C?N}KA=/3@`u","inputs":{"KEY_OPTION":[1,"@`Y@ky)Etn+{XJ-{4Vsb"]},"fields":{},"shadow":false,"topLevel":false},"@`Y@ky)Etn+{XJ-{4Vsb":{"opcode":"sensing_keyoptions","next":null,"parent":"w!`lxu[+VTbb!a@:2IFM","inputs":{},"fields":{"KEY_OPTION":["space",null]},"shadow":true,"topLevel":false},"[+(oxNIM5(qM,kq~)/=K":{"opcode":"looks_switchcostumeto","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"COSTUME":[1,"laZz,h-Z/Z?46wV,!;C*"]},"fields":{},"shadow":false,"topLevel":false},"laZz,h-Z/Z?46wV,!;C*":{"opcode":"looks_costume","next":null,"parent":"[+(oxNIM5(qM,kq~)/=K","inputs":{},"fields":{"COSTUME":["costum1",null]},"shadow":true,"topLevel":false},"46_hm$E}C?N}KA=/3@`u":{"opcode":"operator_not","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"OPERAND":[2,"w!`lxu[+VTbb!a@:2IFM"]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"name":"costum1","bitmapResolution":1,"dataFormat":"svg","assetId":"5b8a85774c8c983b993b7d1549b46082","md5ext":"5b8a85774c8c983b993b7d1549b46082.svg","rotationCenterX":47.678985050489445,"rotationCenterY":49.499230353205405},{"name":"costum2","bitmapResolution":1,"dataFormat":"svg","assetId":"1bf03016126b8879eb6228066a9a28a2","md5ext":"1bf03016126b8879eb6228066a9a28a2.svg","rotationCenterX":47.67898252524472,"rotationCenterY":49.49923017660271}],"sounds":[{"name":"Miau","assetId":"83c36d806dc92327b9e7049a565c6bff","dataFormat":"wav","format":"","rate":44100,"sampleCount":37376,"md5ext":"83c36d806dc92327b9e7049a565c6bff.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.2.52","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}} \ No newline at end of file +{"targets":[{"isStage":true,"name":"Stage","variables":{"`jEk@4|i[#Fk?(8x)AV.-my variable":["variabila mea",0]},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"name":"decor1","dataFormat":"svg","assetId":"cd21514d0531fdffb22204e0ec5ed84a","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"name":"pop","assetId":"83a9787d4cb6f3b7632b4ddfebf74367","dataFormat":"wav","format":"","rate":44100,"sampleCount":1032,"md5ext":"83a9787d4cb6f3b7632b4ddfebf74367.wav"}],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Personaj1","variables":{},"lists":{},"broadcasts":{},"blocks":{"i0sF-x|[yQ-#%j@rU%f,":{"opcode":"event_whenflagclicked","next":")u+B7H(M9g25%Em.w=5;","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":360,"y":168},")u+B7H(M9g25%Em.w=5;":{"opcode":"control_forever","next":null,"parent":"i0sF-x|[yQ-#%j@rU%f,","inputs":{"SUBSTACK":[2,"|LMd9D?RO[2$-2d9tSaH"]},"fields":{},"shadow":false,"topLevel":false},"|LMd9D?RO[2$-2d9tSaH":{"opcode":"control_if_else","next":"a,Odr3Ov}z^5Jf(!Hu`y","parent":")u+B7H(M9g25%Em.w=5;","inputs":{"CONDITION":[2,"w!`lxu[+VTbb!a@:2IFM"],"SUBSTACK":[2,"[+(oxNIM5(qM,kq~)/=K"],"SUBSTACK2":[2,"8|07x?GC!6r+k@Gn?Ipk"]},"fields":{},"shadow":false,"topLevel":false},"w!`lxu[+VTbb!a@:2IFM":{"opcode":"sensing_keypressed","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"KEY_OPTION":[1,"@`Y@ky)Etn+{XJ-{4Vsb"]},"fields":{},"shadow":false,"topLevel":false},"@`Y@ky)Etn+{XJ-{4Vsb":{"opcode":"sensing_keyoptions","next":null,"parent":"w!`lxu[+VTbb!a@:2IFM","inputs":{},"fields":{"KEY_OPTION":["space",null]},"shadow":true,"topLevel":false},"[+(oxNIM5(qM,kq~)/=K":{"opcode":"looks_switchcostumeto","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"COSTUME":[1,"laZz,h-Z/Z?46wV,!;C*"]},"fields":{},"shadow":false,"topLevel":false},"laZz,h-Z/Z?46wV,!;C*":{"opcode":"looks_costume","next":null,"parent":"[+(oxNIM5(qM,kq~)/=K","inputs":{},"fields":{"COSTUME":["costum2",null]},"shadow":true,"topLevel":false},"8|07x?GC!6r+k@Gn?Ipk":{"opcode":"looks_switchcostumeto","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"COSTUME":[1,"AVNA2_i-lp8Nh=W*Fvdj"]},"fields":{},"shadow":false,"topLevel":false},"AVNA2_i-lp8Nh=W*Fvdj":{"opcode":"looks_costume","next":null,"parent":"8|07x?GC!6r+k@Gn?Ipk","inputs":{},"fields":{"COSTUME":["costum1",null]},"shadow":true,"topLevel":false},"a,Odr3Ov}z^5Jf(!Hu`y":{"opcode":"control_wait","next":null,"parent":"|LMd9D?RO[2$-2d9tSaH","inputs":{"DURATION":[1,[5,"1"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"name":"costum1","bitmapResolution":1,"dataFormat":"svg","assetId":"5b8a85774c8c983b993b7d1549b46082","md5ext":"5b8a85774c8c983b993b7d1549b46082.svg","rotationCenterX":47.678985050489445,"rotationCenterY":49.499230353205405},{"name":"costum2","bitmapResolution":1,"dataFormat":"svg","assetId":"1bf03016126b8879eb6228066a9a28a2","md5ext":"1bf03016126b8879eb6228066a9a28a2.svg","rotationCenterX":47.67898252524472,"rotationCenterY":49.49923017660271}],"sounds":[{"name":"Miau","assetId":"83c36d806dc92327b9e7049a565c6bff","dataFormat":"wav","format":"","rate":44100,"sampleCount":37376,"md5ext":"83c36d806dc92327b9e7049a565c6bff.wav"}],"volume":100,"layerOrder":1,"visible":true,"x":0,"y":0,"size":100,"direction":90,"draggable":false,"rotationStyle":"all around"}],"monitors":[],"extensions":[],"meta":{"semver":"3.0.0","vm":"1.2.52","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"}} \ No newline at end of file diff --git a/block.py b/block.py index 73ff6a4..b94365f 100644 --- a/block.py +++ b/block.py @@ -37,6 +37,7 @@ def __init__(self): self.timeDelay = 0 # wait time from the wait block self.target = None # parent self.substack = set() # blocks inside + self.substack2 = set() # only for if then else self.script = set() # blocks below self.screenRefresh = False # do a screen refresh self.inEventLoop = False diff --git a/config.py b/config.py index 50dc3d0..b9577af 100644 --- a/config.py +++ b/config.py @@ -24,7 +24,7 @@ # Project file name # If in test mode, set the Scratch project file to load. -projectFileName: str = "projects/ChangeColour.sb3" +projectFileName: str = "projects/ChangeColourWithElse.sb3" # Download cache size # Number of recent downloaded projects stored. 0 means infinity. diff --git a/main.py b/main.py index 70673c4..95b3914 100644 --- a/main.py +++ b/main.py @@ -19,7 +19,7 @@ along with this program. If not, see . """ -__version__ = "v0.2.0" +__version__ = "v0.4.0" __author__ = "Secret-chest" import tkinter.simpledialog diff --git a/projects/ChangeColourWithElse.sb3 b/projects/ChangeColourWithElse.sb3 new file mode 100644 index 0000000..e502930 Binary files /dev/null and b/projects/ChangeColourWithElse.sb3 differ diff --git a/scratch.py b/scratch.py index 5d47c4d..980934c 100644 --- a/scratch.py +++ b/scratch.py @@ -387,11 +387,52 @@ def execute(block, s, events=eventContainer.EventContainer()): block.blockRan = True return nextBlock block.blockRan = True - # TODO why does it hang??? else: block.blockRan = True return s.target.blocks[block.next] + elif opcode == "control_if_else": # if <> then {...} + if block.target.blocks[inputs["CONDITION"][1]].evaluateBlockValue(events): + # If there are blocks, get them + if inputs["SUBSTACK"][1]: + # No blocks will be flagged as ran inside a forever loop + for b in block.substack: + s.target.blocks[b].blockRan = False + nextBlock = s.target.blocks[inputs["SUBSTACK"][1]] + nb = s.target.blocks[inputs["SUBSTACK"][1]] + block.substack.add(nb.blockID) + while nb.next and nb.next not in block.substack: + nb.blockRan = False + nb.waiting = False + nb.timeDelay = 0 + nb.executionTime = 0 + nb = s.target.blocks[nb.next] + block.substack.add(nb.blockID) + nb.next = block.next + block.blockRan = True + return nextBlock + block.blockRan = True + else: + # If there are blocks, get them + if inputs["SUBSTACK2"][1]: + # No blocks will be flagged as ran inside a forever loop + for b in block.substack2: + s.target.blocks[b].blockRan = False + nextBlock = s.target.blocks[inputs["SUBSTACK2"][1]] + nb = s.target.blocks[inputs["SUBSTACK2"][1]] + block.substack2.add(nb.blockID) + while nb.next and nb.next not in block.substack2: + nb.blockRan = False + nb.waiting = False + nb.timeDelay = 0 + nb.executionTime = 0 + nb = s.target.blocks[nb.next] + block.substack2.add(nb.blockID) + nb.next = block.next + block.blockRan = True + return nextBlock + block.blockRan = True + elif opcode == "looks_switchcostumeto": # switch costume to [... v] nextBlock = block.getBlockInputValue("costume") return s.target.blocks[nextBlock]