Skip to content

Commit

Permalink
Move level decor helper method to migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Nov 1, 2024
1 parent ed8cef3 commit 215a97d
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 29 deletions.
17 changes: 16 additions & 1 deletion game/migrations/0001_squashed_0025_levels_ordering_pt1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0026_levels_pt2.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0032_cannot_turn_left_level.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0033_recursion_level.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0034_joes_level.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0035_disable_route_score_level_70.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0036_level_score_73.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0037_level_score_79.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 0 additions & 1 deletion game/migrations/0038_level_score_40.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import migrations
from game.level_management import set_decor_inner, set_blocks_inner
import json


Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0042_level_score_73.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0048_add_cow_field_and_blocks.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0049_level_score_34.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
2 changes: 0 additions & 2 deletions game/migrations/0050_level_score_40.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down
1 change: 0 additions & 1 deletion game/migrations/0051_level_score_49.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.db import migrations
from game.level_management import set_decor_inner, set_blocks_inner
import json


Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0086_loop_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand Down
15 changes: 13 additions & 2 deletions game/migrations/0097_add_python_den_levels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 215a97d

Please sign in to comment.