Skip to content

Commit c2a0cb9

Browse files
committed
Added random operator, fixed untranslated string
1 parent 31f5101 commit c2a0cb9

11 files changed

+27
-89
lines changed

assets/0fb9be3e8397c983338cb71dc84d0b25.svg

Lines changed: 0 additions & 42 deletions
This file was deleted.
-560 Bytes
Binary file not shown.
-36.5 KB
Binary file not shown.

assets/9a4fb3ed82f74f5df24ade1a2aa48920.svg

Lines changed: 1 addition & 0 deletions
Loading

assets/bcf454acf82e4504149f7ffe07081dbc.svg

Lines changed: 0 additions & 42 deletions
This file was deleted.

assets/project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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":[{"assetId":"cd21514d0531fdffb22204e0ec5ed84a","name":"decor1","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","dataFormat":"svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[{"assetId":"83a9787d4cb6f3b7632b4ddfebf74367","name":"pop","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":{"M1uM[!,UT6wfx4:OY@~m":{"opcode":"event_whenkeypressed","next":"+Zcm|7/E]Fs%/ISKyJq;","parent":null,"inputs":{},"fields":{"KEY_OPTION":["up arrow",null]},"shadow":false,"topLevel":true,"x":163,"y":266},"+Zcm|7/E]Fs%/ISKyJq;":{"opcode":"motion_changeyby","next":null,"parent":"M1uM[!,UT6wfx4:OY@~m","inputs":{"DY":[1,[4,"10"]]},"fields":{},"shadow":false,"topLevel":false},"`H#)2HYe8*O@.,nX0Zgb":{"opcode":"event_whenkeypressed","next":"!{Z#3+!mYowB5;7=p*B-","parent":null,"inputs":{},"fields":{"KEY_OPTION":["down arrow",null]},"shadow":false,"topLevel":true,"x":716,"y":282},"!{Z#3+!mYowB5;7=p*B-":{"opcode":"motion_changeyby","next":null,"parent":"`H#)2HYe8*O@.,nX0Zgb","inputs":{"DY":[1,[4,"-10"]]},"fields":{},"shadow":false,"topLevel":false},"pp-1v@;w%nvO@zD18L6D":{"opcode":"event_whenkeypressed","next":"yc=8$6XJ`eneTtK4CJ]{","parent":null,"inputs":{},"fields":{"KEY_OPTION":["right arrow",null]},"shadow":false,"topLevel":true,"x":144,"y":459},"yc=8$6XJ`eneTtK4CJ]{":{"opcode":"motion_changexby","next":null,"parent":"pp-1v@;w%nvO@zD18L6D","inputs":{"DX":[1,[4,"10"]]},"fields":{},"shadow":false,"topLevel":false},"68oMcI}Fk+=..Qf!OtOv":{"opcode":"event_whenkeypressed","next":"rZEAf_-uDOaS,Ej|$uv{","parent":null,"inputs":{},"fields":{"KEY_OPTION":["left arrow",null]},"shadow":false,"topLevel":true,"x":646,"y":460},"rZEAf_-uDOaS,Ej|$uv{":{"opcode":"motion_changexby","next":null,"parent":"68oMcI}Fk+=..Qf!OtOv","inputs":{"DX":[1,[4,"-10"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"bcf454acf82e4504149f7ffe07081dbc","name":"costum1","bitmapResolution":1,"md5ext":"bcf454acf82e4504149f7ffe07081dbc.svg","dataFormat":"svg","rotationCenterX":48,"rotationCenterY":50},{"assetId":"0fb9be3e8397c983338cb71dc84d0b25","name":"costum2","bitmapResolution":1,"md5ext":"0fb9be3e8397c983338cb71dc84d0b25.svg","dataFormat":"svg","rotationCenterX":46,"rotationCenterY":53}],"sounds":[{"assetId":"83c36d806dc92327b9e7049a565c6bff","name":"Miau","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":"0.2.0-prerelease.20211103090905","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36"}}
1+
{"targets":[{"isStage":true,"name":"Stage","variables":{},"lists":{},"broadcasts":{},"blocks":{},"comments":{},"currentCostume":0,"costumes":[{"assetId":"cd21514d0531fdffb22204e0ec5ed84a","name":"backdrop1","md5ext":"cd21514d0531fdffb22204e0ec5ed84a.svg","dataFormat":"svg","rotationCenterX":240,"rotationCenterY":180}],"sounds":[],"volume":100,"layerOrder":0,"tempo":60,"videoTransparency":50,"videoState":"on","textToSpeechLanguage":"ro"},{"isStage":false,"name":"Cosmicat","variables":{},"lists":{},"broadcasts":{},"blocks":{"E;=y4~YoyP#A+s:jS0xd":{"opcode":"event_whenflagclicked","next":"*`q9Brc}_w8S^^Qi}rB3","parent":null,"inputs":{},"fields":{},"shadow":false,"topLevel":true,"x":120,"y":312},"*`q9Brc}_w8S^^Qi}rB3":{"opcode":"motion_gotoxy","next":"G!%/o$v|,%8mjWc{:#C,","parent":"E;=y4~YoyP#A+s:jS0xd","inputs":{"X":[1,[4,"0"]],"Y":[1,[4,"0"]]},"fields":{},"shadow":false,"topLevel":false},"G!%/o$v|,%8mjWc{:#C,":{"opcode":"control_wait","next":"jctW5vM^0j?OBU[c_QIX","parent":"*`q9Brc}_w8S^^Qi}rB3","inputs":{"DURATION":[1,[5,"1"]]},"fields":{},"shadow":false,"topLevel":false},"^PPAV3[UEMRuP%`Fky,@":{"opcode":"operator_random","next":null,"parent":"jctW5vM^0j?OBU[c_QIX","inputs":{"FROM":[1,[4,"-240"]],"TO":[1,[4,"240"]]},"fields":{},"shadow":false,"topLevel":false},"jctW5vM^0j?OBU[c_QIX":{"opcode":"motion_setx","next":null,"parent":"G!%/o$v|,%8mjWc{:#C,","inputs":{"X":[3,"^PPAV3[UEMRuP%`Fky,@",[4,"10"]]},"fields":{},"shadow":false,"topLevel":false}},"comments":{},"currentCostume":0,"costumes":[{"assetId":"9a4fb3ed82f74f5df24ade1a2aa48920","name":"Cosmicat","bitmapResolution":1,"md5ext":"9a4fb3ed82f74f5df24ade1a2aa48920.svg","dataFormat":"svg","rotationCenterX":47.2514000162754,"rotationCenterY":57.860045289335886}],"sounds":[],"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":"0.2.0-prerelease.20220302060126","agent":"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36"}}

block.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
"""
88

99
import random
10+
import i18n
11+
import config
12+
import math
13+
14+
i18n.set("locale", config.language)
15+
i18n.set("filename_format", "{locale}.{format}")
16+
i18n.load_path.append("./lang/")
17+
_ = i18n.t
18+
19+
1020

1121
class Block:
1222
def __init__(self):
@@ -44,7 +54,16 @@ def evaluateBlockValue(self):
4454
try:
4555
self.value = float(self.getInputValue("num1")) / float(self.getInputValue("num2"))
4656
except ZeroDivisionError:
47-
raise ZeroDivisionError("Project was trying to divide by 0")
57+
raise ZeroDivisionError(_("zero-division-error"))
58+
return self.value
59+
elif self.opcode == "operator_random": # () * ()
60+
decimals1 = len(str(math.modf(float(self.getInputValue("from"))))) - 2
61+
decimals2 = len(str(math.modf(float(self.getInputValue("to"))))) - 2
62+
if decimals1 > decimals2:
63+
decimals = decimals1
64+
else:
65+
decimals = decimals2
66+
self.value = random.randint(int(self.getInputValue("from")) * 10 ** decimals, int(self.getInputValue("to")) * 10 ** decimals) / 10 ** decimals
4867
return self.value
4968

5069
# Returns block input value

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
# Project file name
3131
# If the "manual" mode is chosen, set the Scratch project file to load.
32-
projectFileName: str = "projects/arrows.sb3"
32+
projectFileName: str = "projects/Math5.sb3"
3333

3434
# Extract on project run
3535
# Set whether to extract the project assets on run.

lang/en.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ en:
4545
project-error: "PROJECT ERROR:"
4646
unknown-opcode: "Unknown opcode:"
4747
new-sprite-position: "New position (%{x}, %{y}) set for sprite %{name}"
48-
stage: "Stage"
48+
stage: "Stage"
49+
zero-division-error: "Project was trying to divide by 0"

lang/ro.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,5 @@ ro:
4545
project-error: "EROARE PROIECT:"
4646
unknown-opcode: "Tip de bloc necunoscut:"
4747
new-sprite-position: "Poziție nouă (%{x}, %{y}) setată pentru personajul %{name}"
48-
stage: "Scena"
48+
stage: "Scena"
49+
zero-division-error: "Proiectul a încercat să împartă la 0"

0 commit comments

Comments
 (0)