diff --git a/game/admin.py b/game/admin.py index 480487605..e12f0d45a 100644 --- a/game/admin.py +++ b/game/admin.py @@ -43,7 +43,7 @@ class AttemptAdmin(admin.ModelAdmin): class LevelDecorAdmin(admin.ModelAdmin): search_fields = ["level__name"] - list_display = ["id", "level", "x", "y", "decorName"] + list_display = ["id", "level", "x", "y", "decor_name"] admin.site.register(Level, LevelAdmin) diff --git a/game/end_to_end_tests/test_cow_crashes.py b/game/end_to_end_tests/test_cow_crashes.py index d89244a0c..8b8527f5d 100644 --- a/game/end_to_end_tests/test_cow_crashes.py +++ b/game/end_to_end_tests/test_cow_crashes.py @@ -47,7 +47,7 @@ def setUpClass(cls): TestCowCrashes.cow_level = Level( name="Cow crashing", anonymous=False, - blocklyEnabled=True, + blockly_enabled=True, character=van, cows='[{"minCows":"7","maxCows":"7","potentialCoordinates":[{"x":4,"y":4},{"x":2,"y":4},{"x":3,"y":7},{"x":4,"y":6},{"x":2,"y":6},{"x":3,"y":1},{"x":4,"y":2}],"type":"WHITE"}]', default=False, @@ -57,7 +57,7 @@ def setUpClass(cls): model_solution="[1]", origin='{"coordinate":[2,5],"direction":"E"}', path='[{"coordinate":[2,5],"connectedNodes":[1]},{"coordinate":[3,5],"connectedNodes":[0,4,2,5]},{"coordinate":[4,5],"connectedNodes":[1]},{"coordinate":[3,7],"connectedNodes":[4]},{"coordinate":[3,6],"connectedNodes":[8,3,6,1]},{"coordinate":[3,4],"connectedNodes":[10,1,11,16]},{"coordinate":[4,6],"connectedNodes":[4,7]},{"coordinate":[4,7],"connectedNodes":[6]},{"coordinate":[2,6],"connectedNodes":[9,4]},{"coordinate":[2,7],"connectedNodes":[8]},{"coordinate":[2,4],"connectedNodes":[13,5,12]},{"coordinate":[4,4],"connectedNodes":[5,14,15]},{"coordinate":[2,3],"connectedNodes":[10]},{"coordinate":[1,4],"connectedNodes":[10]},{"coordinate":[5,4],"connectedNodes":[11]},{"coordinate":[4,3],"connectedNodes":[11,19]},{"coordinate":[3,3],"connectedNodes":[5,17]},{"coordinate":[3,2],"connectedNodes":[18,16,19,20]},{"coordinate":[2,2],"connectedNodes":[17]},{"coordinate":[4,2],"connectedNodes":[17,15,23,22]},{"coordinate":[3,1],"connectedNodes":[21,17,22]},{"coordinate":[2,1],"connectedNodes":[20]},{"coordinate":[4,1],"connectedNodes":[20,19]},{"coordinate":[5,2],"connectedNodes":[19]}]', - pythonEnabled=False, + python_enabled=False, theme=grass, threads=1, traffic_lights="[]", diff --git a/game/end_to_end_tests/test_python_levels.py b/game/end_to_end_tests/test_python_levels.py index a0d5b298f..24cbea68a 100644 --- a/game/end_to_end_tests/test_python_levels.py +++ b/game/end_to_end_tests/test_python_levels.py @@ -45,7 +45,7 @@ def test_animal_sound_horn(self): animal_level = Level( name="Animal commands", anonymous=False, - blocklyEnabled=False, + blockly_enabled=False, character=van, cows='[{"minCows":1,"maxCows":1,"potentialCoordinates":[{"x":3,"y":4}],"type":"WHITE"}]', default=False, @@ -55,7 +55,7 @@ def test_animal_sound_horn(self): model_solution="", origin='{"coordinate":[2,4],"direction":"E"}', path='[{"coordinate":[2,4],"connectedNodes":[1]},{"coordinate":[3,4],"connectedNodes":[0,2]},{"coordinate":[4,4],"connectedNodes":[1]}]', - pythonEnabled=True, + python_enabled=True, theme=grass, threads=1, traffic_lights="[]", diff --git a/game/level_management.py b/game/level_management.py index ebf0fb924..1554c8e3a 100644 --- a/game/level_management.py +++ b/game/level_management.py @@ -52,13 +52,13 @@ def get_decor(level): """Helper method parsing decor into a dictionary format 'sendable' to javascript.""" decorData = [] for ld in LevelDecor.objects.filter(level=level): - decor = get_decor_element(name=ld.decorName, theme=level.theme) + decor = get_decor_element(name=ld.decor_name, theme=level.theme) decorData.append( { "x": int(ld.x), "y": int(ld.y), "z": int(decor.z_index), - "decorName": str(ld.decorName), + "decorName": str(ld.decor_name), "width": int(decor.width), "height": int(decor.height), "url": str(decor.url), @@ -81,7 +81,10 @@ def set_decor_inner(level, decor, LevelDecor): for data in decor: level_decors.append( LevelDecor( - level_id=level.id, x=data["x"], y=data["y"], decorName=data["decorName"] + level_id=level.id, + x=data["x"], + y=data["y"], + decor_name=data["decorName"], ) ) LevelDecor.objects.bulk_create(level_decors) @@ -160,9 +163,9 @@ def save_level(level, data): level.max_fuel = data["max_fuel"] level.traffic_lights = data["traffic_lights"] level.cows = data["cows"] - level.blocklyEnabled = data.get("blocklyEnabled", True) - level.pythonEnabled = data.get("pythonEnabled", False) - level.pythonViewEnabled = data.get("pythonViewEnabled", False) + level.blockly_enabled = data.get("blockly_enabled", True) + level.python_enabled = data.get("python_enabled", False) + level.python_view_enabled = data.get("python_view_enabled", False) level.theme = get_theme_by_pk(pk=data["theme"]) level.character = get_character_by_pk(pk=data["character"]) level.disable_algorithm_score = data.get("disable_algorithm_score", False) @@ -203,6 +206,6 @@ def email_new_custom_level( "STUDENT_NAME": student_name, "CLASS_NAME": class_name, "LEVEL_URL": level_url, - "MODERATE_URL": moderate_url - } + "MODERATE_URL": moderate_url, + }, ) diff --git a/game/migrations/0001_squashed_0025_levels_ordering_pt1.py b/game/migrations/0001_squashed_0025_levels_ordering_pt1.py index 78ff3ba8c..e6f3389f5 100644 --- a/game/migrations/0001_squashed_0025_levels_ordering_pt1.py +++ b/game/migrations/0001_squashed_0025_levels_ordering_pt1.py @@ -4,7 +4,7 @@ from django.db import models, migrations from django.conf import settings import json -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner # Functions from the following migrations need manual copying. @@ -2527,6 +2527,21 @@ def delete_old_limit_level(apps, schema_editor): old_limit_level.delete() +def set_decor_inner(level, decor, LevelDecor): + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) + + # Add episode 7 to 9 # Add levels 62, 51, 59, 57, 60, 61, 70 def add_episode_7_to_9(apps, schema_editor): diff --git a/game/migrations/0026_levels_pt2.py b/game/migrations/0026_levels_pt2.py index cf1486cbf..996639f84 100644 --- a/game/migrations/0026_levels_pt2.py +++ b/game/migrations/0026_levels_pt2.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner import json @@ -13,7 +13,18 @@ def change_levels(apps, schema_editor): Block = apps.get_model("game", "Block") def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) def set_blocks(level, blocks): set_blocks_inner(level, blocks, LevelBlock, Block) diff --git a/game/migrations/0032_cannot_turn_left_level.py b/game/migrations/0032_cannot_turn_left_level.py index 9db4c39e0..d28f023eb 100644 --- a/game/migrations/0032_cannot_turn_left_level.py +++ b/game/migrations/0032_cannot_turn_left_level.py @@ -1,5 +1,5 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner import json @@ -12,7 +12,18 @@ def new_level(apps, schema_editor): Block = apps.get_model("game", "Block") def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) def set_blocks(level, blocks): set_blocks_inner(level, blocks, LevelBlock, Block) diff --git a/game/migrations/0033_recursion_level.py b/game/migrations/0033_recursion_level.py index 2df8d9cb6..b2a693f60 100644 --- a/game/migrations/0033_recursion_level.py +++ b/game/migrations/0033_recursion_level.py @@ -1,5 +1,5 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner import json @@ -15,7 +15,18 @@ def new_level(apps, schema_editor): Block = apps.get_model("game", "Block") def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) def set_blocks(level, blocks): set_blocks_inner(level, blocks, LevelBlock, Block) diff --git a/game/migrations/0034_joes_level.py b/game/migrations/0034_joes_level.py index a5a00b5a3..215666770 100644 --- a/game/migrations/0034_joes_level.py +++ b/game/migrations/0034_joes_level.py @@ -1,5 +1,5 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner import json @@ -12,7 +12,18 @@ def new_level(apps, schema_editor): Block = apps.get_model("game", "Block") def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) def set_blocks(level, blocks): set_blocks_inner(level, blocks, LevelBlock, Block) diff --git a/game/migrations/0035_disable_route_score_level_70.py b/game/migrations/0035_disable_route_score_level_70.py index ed0695c2e..b3649041d 100644 --- a/game/migrations/0035_disable_route_score_level_70.py +++ b/game/migrations/0035_disable_route_score_level_70.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def disable_route_score(apps, schema_editor): diff --git a/game/migrations/0036_level_score_73.py b/game/migrations/0036_level_score_73.py index 0b331539e..f0928930f 100644 --- a/game/migrations/0036_level_score_73.py +++ b/game/migrations/0036_level_score_73.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def update_level(apps, schema_editor): diff --git a/game/migrations/0037_level_score_79.py b/game/migrations/0037_level_score_79.py index 63bc0edad..7a406972f 100644 --- a/game/migrations/0037_level_score_79.py +++ b/game/migrations/0037_level_score_79.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def update_level(apps, schema_editor): diff --git a/game/migrations/0038_level_score_40.py b/game/migrations/0038_level_score_40.py index 291165f57..1272e1d7a 100644 --- a/game/migrations/0038_level_score_40.py +++ b/game/migrations/0038_level_score_40.py @@ -1,5 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner import json diff --git a/game/migrations/0042_level_score_73.py b/game/migrations/0042_level_score_73.py index 3690a42d1..1d8b4b2e7 100644 --- a/game/migrations/0042_level_score_73.py +++ b/game/migrations/0042_level_score_73.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def update_level(apps, schema_editor): diff --git a/game/migrations/0048_add_cow_field_and_blocks.py b/game/migrations/0048_add_cow_field_and_blocks.py index f7d95d4c9..d7face095 100644 --- a/game/migrations/0048_add_cow_field_and_blocks.py +++ b/game/migrations/0048_add_cow_field_and_blocks.py @@ -1,9 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -import json from django.db import models, migrations -from game.level_management import set_blocks_inner, set_decor_inner def add_cows_block(apps, schema_editor): diff --git a/game/migrations/0049_level_score_34.py b/game/migrations/0049_level_score_34.py index da1bc0439..84e22b21f 100644 --- a/game/migrations/0049_level_score_34.py +++ b/game/migrations/0049_level_score_34.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def update_level(apps, schema_editor): diff --git a/game/migrations/0050_level_score_40.py b/game/migrations/0050_level_score_40.py index 02f49b2ff..abf5f7d6f 100644 --- a/game/migrations/0050_level_score_40.py +++ b/game/migrations/0050_level_score_40.py @@ -1,6 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner -import json def update_level(apps, schema_editor): diff --git a/game/migrations/0051_level_score_49.py b/game/migrations/0051_level_score_49.py index 8b16f2ab7..d927a5d06 100644 --- a/game/migrations/0051_level_score_49.py +++ b/game/migrations/0051_level_score_49.py @@ -1,5 +1,4 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner import json diff --git a/game/migrations/0086_loop_levels.py b/game/migrations/0086_loop_levels.py index 84f6d546f..f400fd17e 100644 --- a/game/migrations/0086_loop_levels.py +++ b/game/migrations/0086_loop_levels.py @@ -3,7 +3,7 @@ from django.apps.registry import Apps from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner def add_loop_levels(apps: Apps, *args): @@ -365,7 +365,18 @@ def add_loop_levels(apps: Apps, *args): ) def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) set_decor( level_110, diff --git a/game/migrations/0097_add_python_den_levels.py b/game/migrations/0097_add_python_den_levels.py index e9e6d0923..86fd893cb 100644 --- a/game/migrations/0097_add_python_den_levels.py +++ b/game/migrations/0097_add_python_den_levels.py @@ -2,7 +2,7 @@ from django.db import migrations -from game.level_management import set_decor_inner, set_blocks_inner +from game.level_management import set_blocks_inner def add_python_den_levels(apps, schema_editor): @@ -931,7 +931,18 @@ def add_python_den_decor(apps, schema_editor): LevelDecor = apps.get_model("game", "LevelDecor") def set_decor(level, decor): - set_decor_inner(level, decor, LevelDecor) + """Helper method creating LevelDecor objects given a list of decor in dictionary form.""" + LevelDecor.objects.filter(level=level).delete() + + level_decors = [] + for data in decor: + level_decors.append( + LevelDecor( + level_id=level.id, x=data["x"], y=data["y"], decorName=data[ + "decorName"] + ) + ) + LevelDecor.objects.bulk_create(level_decors) def bulk_copy_decor(old_level_name, new_level_name): old_level = Level.objects.get(name=old_level_name, default=True) diff --git a/game/migrations/0105_delete_invalid_attempts.py b/game/migrations/0105_delete_invalid_attempts.py new file mode 100644 index 000000000..5455e078c --- /dev/null +++ b/game/migrations/0105_delete_invalid_attempts.py @@ -0,0 +1,18 @@ +from django.apps.registry import Apps +from django.db import migrations + + +def delete_invalid_attempts(apps: Apps, *args): + Attempt = apps.get_model("game", "Attempt") + + Attempt.objects.filter(start_time__isnull=True).delete() + + +class Migration(migrations.Migration): + dependencies = [("game", "0104_remove_level_direct_drive")] + operations = [ + migrations.RunPython( + delete_invalid_attempts, + reverse_code=migrations.RunPython.noop, + ) + ] diff --git a/game/migrations/0106_fields_to_snake_case.py b/game/migrations/0106_fields_to_snake_case.py new file mode 100644 index 000000000..d66206e41 --- /dev/null +++ b/game/migrations/0106_fields_to_snake_case.py @@ -0,0 +1,48 @@ +# Generated by Django 3.2.25 on 2024-11-01 13:12 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('game', '0105_delete_invalid_attempts'), + ] + + operations = [ + migrations.RenameField( + model_name='episode', + old_name='r_blocklyEnabled', + new_name='r_blockly_enabled', + ), + migrations.RenameField( + model_name='episode', + old_name='r_pythonEnabled', + new_name='r_python_enabled', + ), + migrations.RenameField( + model_name='episode', + old_name='r_trafficLights', + new_name='r_traffic_lights', + ), + migrations.RenameField( + model_name='level', + old_name='blocklyEnabled', + new_name='blockly_enabled', + ), + migrations.RenameField( + model_name='level', + old_name='pythonEnabled', + new_name='python_enabled', + ), + migrations.RenameField( + model_name='level', + old_name='pythonViewEnabled', + new_name='python_view_enabled', + ), + migrations.RenameField( + model_name='leveldecor', + old_name='decorName', + new_name='decor_name', + ), + ] diff --git a/game/models.py b/game/models.py index 189a10cfc..04aa7eaf1 100644 --- a/game/models.py +++ b/game/models.py @@ -55,9 +55,9 @@ class Episode(models.Model): r_curviness = models.FloatField(default=0, null=True) r_num_tiles = models.IntegerField(default=5, null=True) r_blocks = models.ManyToManyField(Block, related_name="episodes") - r_blocklyEnabled = models.BooleanField(default=True) - r_pythonEnabled = models.BooleanField(default=False) - r_trafficLights = models.BooleanField(default=False) + r_blockly_enabled = models.BooleanField(default=True) + r_python_enabled = models.BooleanField(default=False) + r_traffic_lights = models.BooleanField(default=False) r_cows = models.BooleanField(default=False) lesson_plan_link = models.CharField( @@ -175,9 +175,9 @@ class Level(models.Model): disable_route_score = models.BooleanField(default=False) disable_algorithm_score = models.BooleanField(default=False) threads = models.IntegerField(blank=False, default=1) - blocklyEnabled = models.BooleanField(default=True) - pythonEnabled = models.BooleanField(default=True) - pythonViewEnabled = models.BooleanField(default=False) + blockly_enabled = models.BooleanField(default=True) + python_enabled = models.BooleanField(default=True) + python_view_enabled = models.BooleanField(default=False) theme_name = models.CharField( max_length=10, choices=theme_choices(), @@ -286,7 +286,7 @@ class LevelDecor(models.Model): x = models.IntegerField() y = models.IntegerField() level = models.ForeignKey(Level, on_delete=models.CASCADE) - decorName = models.CharField(max_length=100, default="tree1") + decor_name = models.CharField(max_length=100, default="tree1") class Workspace(models.Model): diff --git a/game/random_road.py b/game/random_road.py index 66ceba5b7..8adde0e5a 100644 --- a/game/random_road.py +++ b/game/random_road.py @@ -58,7 +58,7 @@ def create(episode=None): loopiness = episode.r_loopiness if episode else DEFAULT_LOOPINESS curviness = episode.r_curviness if episode else DEFAULT_CURVINESS blocks = episode.r_blocks.all() if episode else Block.objects.all() - traffic_lights = episode.r_trafficLights if episode else DEFAULT_TRAFFIC_LIGHTS + traffic_lights = episode.r_traffic_lights if episode else DEFAULT_TRAFFIC_LIGHTS cows = episode.r_cows if episode else DEFAULT_TRAFFIC_LIGHTS decor = DEFAULT_DECOR @@ -68,8 +68,8 @@ def create(episode=None): level_data["theme"] = 1 level_data["name"] = ("Random level for " + episode.name) if episode else "Default random level" level_data["character"] = 1 - level_data["blocklyEnabled"] = episode.r_blocklyEnabled if episode else True - level_data["pythonEnabled"] = episode.r_pythonEnabled if episode else False + level_data["blockly_enabled"] = episode.r_blockly_enabled if episode else True + level_data["python_enabled"] = episode.r_python_enabled if episode else False level_data["blocks"] = [{"type": block.type} for block in blocks] level = Level(default=False, anonymous=True) @@ -276,7 +276,7 @@ def generate_traffic_lights(path): random.shuffle(candidateNodes) nodesSelected = candidateNodes[:numberOfJunctions] - trafficLights = [] + traffic_lights = [] for node in nodesSelected: controlledNeighbours = [] @@ -291,7 +291,7 @@ def generate_traffic_lights(path): direction = get_direction(node, neighbour) - trafficLights.append( + traffic_lights.append( { "sourceCoordinate": {"x": neighbour["coordinate"].x, "y": neighbour["coordinate"].y}, "direction": direction, @@ -303,7 +303,7 @@ def generate_traffic_lights(path): ) counter += 1 - return trafficLights + return traffic_lights def generate_cows(path): @@ -346,7 +346,7 @@ def find_decor_by_coordinate(x, y, elem, decor): elem == "pond" and (coord["x"] // GRID_SIZE == x + 1 and coord["y"] // GRID_SIZE == y or x + 1 < WIDTH) ) - or (dec["decorName"] == "pond" and coord["x"] // GRID_SIZE + 1 == x and coord["y"] // GRID_SIZE == y) + or (dec["decor_name"] == "pond" and coord["x"] // GRID_SIZE + 1 == x and coord["y"] // GRID_SIZE == y) ): return True @@ -368,7 +368,7 @@ def append_decor(decor, x, y, dec, dx=0, dy=0): x = x * GRID_SIZE + int((GRID_SIZE - decor_object.width) * 0.5 * (1 - dx)) y = y * GRID_SIZE + int((GRID_SIZE - decor_object.height) * 0.5 * (1 - dy)) - decor.append({"coordinate": {"x": x, "y": y}, "decorName": dec, "height": decor_object.height}) + decor.append({"coordinate": {"x": x, "y": y}, "decor_name": dec, "height": decor_object.height}) def place_near_road(elem, decor, path): for i in range(1, len(path) - 1): @@ -389,7 +389,7 @@ def place_randomly(dec, decor): def place_bush(elem, decor, nodes): bush_exists = False for dec in decor: - if dec["decorName"] == elem: + if dec["decor_name"] == elem: bush_exists = True for (dx, dy) in DIRECTIONS: x = dec["coordinate"]["x"] // GRID_SIZE + dx diff --git a/game/serializers.py b/game/serializers.py index 7fa8830e0..0678f7fe4 100644 --- a/game/serializers.py +++ b/game/serializers.py @@ -26,8 +26,8 @@ class Meta(object): "name", "title", "default", - "blocklyEnabled", - "pythonEnabled", + "blockly_enabled", + "python_enabled", ) def get_title(self, obj): @@ -67,9 +67,9 @@ class Meta(object): "levelblock_set", "map", "mode", - "blocklyEnabled", - "pythonEnabled", - "pythonViewEnabled", + "blockly_enabled", + "python_enabled", + "python_view_enabled", ) def get_title(self, obj): @@ -101,7 +101,7 @@ def get_leveldecor_set(self, obj): class LevelModeSerializer(serializers.HyperlinkedModelSerializer): class Meta(object): model = Level - fields = ("blocklyEnabled", "pythonEnabled", "pythonViewEnabled") + fields = ("blockly_enabled", "python_enabled", "python_view_enabled") class LevelMapListSerializer(serializers.HyperlinkedModelSerializer): diff --git a/game/static/game/js/game.js b/game/static/game/js/game.js index aff0caacd..86b3a9c74 100644 --- a/game/static/game/js/game.js +++ b/game/static/game/js/game.js @@ -1152,7 +1152,7 @@ ocargo.Game.prototype._setupSaveTab = function () { python_contents: ocargo.pythonControl.getCode(), blockly_enabled: BLOCKLY_ENABLED, python_enabled: PYTHON_ENABLED, - pythonViewEnabled: PYTHON_VIEW_ENABLED + python_view_enabled: PYTHON_VIEW_ENABLED } this.saving.saveWorkspace( diff --git a/game/static/game/js/level_editor.js b/game/static/game/js/level_editor.js index 65a8bd64a..7ad26bcf2 100644 --- a/game/static/game/js/level_editor.js +++ b/game/static/game/js/level_editor.js @@ -2540,9 +2540,9 @@ ocargo.LevelEditor = function(levelId) { // Language data var language = $('#language_select').val(); - state.blocklyEnabled = language === 'blockly' || language === 'both' || language === 'blocklyWithPythonView'; - state.pythonViewEnabled = language === 'blocklyWithPythonView'; - state.pythonEnabled = language === 'python' || language === 'both'; + state.blockly_enabled = language === 'blockly' || language === 'both' || language === 'blocklyWithPythonView'; + state.python_view_enabled = language === 'blocklyWithPythonView'; + state.python_enabled = language === 'python' || language === 'both'; // Description and hint data if ($('#subtitle').val().length > 0) { @@ -2675,11 +2675,11 @@ ocargo.LevelEditor = function(levelId) { // Load in language data var languageSelect = $('#language_select'); - if (state.blocklyEnabled && state.pythonViewEnabled){ + if (state.blockly_enabled && state.python_view_enabled){ languageSelect.val('blocklyWithPythonView'); - } else if(state.blocklyEnabled && state.pythonEnabled) { + } else if(state.blockly_enabled && state.python_enabled) { languageSelect.val('both'); - } else if(state.pythonEnabled) { + } else if(state.python_enabled) { languageSelect.val('python'); } else { languageSelect.val('blockly'); @@ -2869,7 +2869,7 @@ ocargo.LevelEditor = function(levelId) { // you can copy and paste into a Django migration file var state = extractState(); - var boolFields = ["pythonEnabled", "blocklyEnabled", 'fuel_gauge']; + var boolFields = ["python_enabled", "blockly_enabled", 'fuel_gauge']; var stringFields = ['path', 'traffic_lights', 'cows', 'origin', 'destinations']; var otherFields = ['max_fuel']; diff --git a/game/templates/game/game.html b/game/templates/game/game.html index 300517f7e..bf8af5a3a 100644 --- a/game/templates/game/game.html +++ b/game/templates/game/game.html @@ -73,9 +73,9 @@ var MAX_FUEL = {{level.max_fuel}} var NEXT_EPISODE = {% if level.episode.next_episode == None %}null{% else %}"{{level.episode.next_episode.id}}"{% endif %} var WORKSPACE = {% if workspace == None %}null{% else %}"{{workspace}}"{% endif %} - var BLOCKLY_ENABLED = {{level.blocklyEnabled|booltojs}} - var PYTHON_ENABLED = {{level.pythonEnabled|booltojs}} - var PYTHON_VIEW_ENABLED = {{level.pythonViewEnabled|booltojs}} + var BLOCKLY_ENABLED = {{level.blockly_enabled|booltojs}} + var PYTHON_ENABLED = {{level.python_enabled|booltojs}} + var PYTHON_VIEW_ENABLED = {{level.python_view_enabled|booltojs}} var RETURN_URL = "{{return_url}}" var PYTHON_WORKSPACE = {% if python_workspace == None %}null{% else %}"{{python_workspace|linebreaksbr}}"{% endif %} @@ -151,7 +151,7 @@