Skip to content

Commit

Permalink
Merge branch 'main' into weblate-fix-script
Browse files Browse the repository at this point in the history
  • Loading branch information
Felienne committed Sep 27, 2023
2 parents 39dc9e5 + 7aee5ea commit 7d70838
Show file tree
Hide file tree
Showing 120 changed files with 2,819 additions and 755 deletions.
Binary file modified all_snippet_hashes.pkl
Binary file not shown.
47 changes: 24 additions & 23 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ def echo_session_vars_main():


@app.route('/parse', methods=['POST'])
@querylog.timed_as('parse_handler')
def parse():
body = request.json
if not body:
Expand All @@ -483,17 +484,13 @@ def parse():
return "body.level must be a string", 400
if 'adventure_name' in body and not isinstance(body['adventure_name'], str):
return "if present, body.adventure_name must be a string", 400
# TODO: Once we figure out whats wrong with the skip faulty code, we need to reinstantiate this
# if 'skip_faulty' not in body:
# return "body.skip_faulty must be a boolean", 400

error_check = False
if 'error_check' in body:
error_check = True

code = body['code']
level = int(body['level'])
skip_faulty = False # bool(body['skip_faulty'])

# Language should come principally from the request body,
# but we'll fall back to browser default if it's missing for whatever
Expand All @@ -514,7 +511,7 @@ def parse():
keyword_lang = current_keyword_language()["lang"]
with querylog.log_time('transpile'):
try:
transpile_result = transpile_add_stats(code, level, lang, skip_faulty)
transpile_result = transpile_add_stats(code, level, lang)
if username and not body.get('tutorial'):
DATABASE.increase_user_run_count(username)
ACHIEVEMENTS.increase_count("run")
Expand All @@ -534,18 +531,18 @@ def parse():

try:
response['Code'] = transpile_result.code
# source_map_result = transpile_result.source_map.get_result()

# for i, mapping in source_map_result.items():
# if mapping['error'] is not None:
# source_map_result[i]['error'] = translate_error(
# source_map_result[i]['error'].error_code,
# source_map_result[i]['error'].arguments,
# keyword_lang
# )

# response['source_map'] = source_map_result
response['source_map'] = transpile_result.source_map.get_result()
source_map_result = transpile_result.source_map.get_result()

for i, mapping in source_map_result.items():
if mapping['error'] is not None:
source_map_result[i]['error'] = translate_error(
source_map_result[i]['error'].error_code,
source_map_result[i]['error'].arguments,
keyword_lang
)

response['source_map'] = source_map_result

if transpile_result.has_pygame:
response['has_pygame'] = True

Expand All @@ -554,10 +551,12 @@ def parse():
except Exception:
pass

try:
response['has_sleep'] = 'sleep' in hedy.all_commands(code, level, lang)
except BaseException:
pass
with querylog.log_time('detect_sleep'):
try:
response['has_sleep'] = 'sleep' in hedy.all_commands(code, level, lang)
except BaseException:
pass

try:
if username and not body.get('tutorial') and ACHIEVEMENTS.verify_run_achievements(
username, code, level, response):
Expand Down Expand Up @@ -713,11 +712,11 @@ def remove_file(response):
return send_file("machine_files/" + filename + "." + extension, as_attachment=True)


def transpile_add_stats(code, level, lang_, skip_faulty):
def transpile_add_stats(code, level, lang_):
username = current_user()['username'] or None
number_of_lines = code.count('\n')
try:
result = hedy.transpile(code, level, lang_, skip_faulty)
result = hedy.transpile(code, level, lang_)
statistics.add(
username, lambda id_: DATABASE.add_program_stats(id_, level, number_of_lines, None))
return result
Expand Down Expand Up @@ -747,6 +746,7 @@ def translate_error(code, arguments, keyword_lang):
'allowed_types',
'invalid_type',
'invalid_type_2',
'offending_keyword',
'character_found',
'concept',
'tip',
Expand All @@ -763,6 +763,7 @@ def translate_error(code, arguments, keyword_lang):
'guessed_command',
'invalid_argument',
'invalid_argument_2',
'offending_keyword',
'variable',
'invalid_value',
'print',
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/ar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
rock_2:
default_save_name: rock_2
levels:
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/bg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1885,6 +1885,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
and_or_command:
name: "{and} & {or}"
description: introducing and or
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/bn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers।"
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
and_or_command:
name: "{and} & {or}"
description: introducing and or
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/ca.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,15 @@ adventures:
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
while_command:
name: "{while}"
description: while
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
elif_command:
default_save_name: elif
levels:
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/cy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
while_command:
name: "{while}"
description: while
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/da.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
and_or_command:
name: "{and} & {or}"
description: introducing and or
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2608,6 +2608,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
and_or_command:
name: "{and} & {or}"
description: introducing and or
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/el.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,15 @@ adventures:
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
6:
start_code: "{print} '5 times 5 is ' 5 * 5"
story_text: "## 1 + 1\nIn this level you learn something new: you can now also calculate.\n\nThe plus is easy, you write it like with math: `5 + 5` for example. The minus also works fine, it is `5 - 5`.\n\nThe times is a bit different, because there is no times symbol on your keyboard. Just search, there really isn't!\nThat is why we multiply with the asterisk above 8: `5 * 5`. Read that as \"5 times 5\" that helps you remember it best.\n"
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,15 @@ adventures:
{print} 'Two and a half plus two and a half is...'
{print} 2.5 + 2.5
```
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
and_or_command:
name: "{and} & {or}"
description: "introducing and or"
Expand Down
9 changes: 9 additions & 0 deletions content/adventures/eo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -867,6 +867,15 @@ adventures:
start_code: "{print} 'decimal numbers now need to use a dot'\n{print} 2.5 + 2.5"
story_text: "**Decimal numbers**\nSo far, Hedy did not allow for decimal numbers like 1.5, but now we do allow that. Note that computers use the `.` for decimal numbers."
example_code: "```\n{print} 'Two and a half plus two and a half is...'\n{print} 2.5 + 2.5\n```\n"
story_text_2: |-
**Maths with words**
In this level you can also do addition with words like this:
example_code_2: |
```
a = 'Hello '
b = 'world!'
{print} a + b
```
name: maths
description: Introducing maths
default_save_name: maths
Expand Down
Loading

0 comments on commit 7d70838

Please sign in to comment.