Skip to content

Commit

Permalink
fix: Set Python scores to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Feb 22, 2024
1 parent 94bd745 commit d2f2a9c
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 9 deletions.
28 changes: 28 additions & 0 deletions game/migrations/0090_python_levels_no_algo_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.apps.registry import Apps
from django.db import migrations


def disable_algo_score_for_python_levels(apps: Apps, *args):
Level = apps.get_model("game", "Level")

Level.objects.filter(default=True, blocklyEnabled=False).update(
disable_algorithm_score=True
)


def enable_algo_score_for_python_levels(apps: Apps, *args):
Level = apps.get_model("game", "Level")

Level.objects.filter(default=True, blocklyEnabled=False).update(
disable_algorithm_score=False
)


class Migration(migrations.Migration):
dependencies = [("game", "0089_episodes_in_development")]
operations = [
migrations.RunPython(
disable_algo_score_for_python_levels,
reverse_code=enable_algo_score_for_python_levels,
)
]
30 changes: 30 additions & 0 deletions game/migrations/0091_set_python_scores_to_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.apps.registry import Apps
from django.db import migrations


def set_successful_python_attempts_to_10(apps: Apps, *args):
Attempt = apps.get_model("game", "Attempt")

Attempt.objects.filter(
level__default=True, level__blocklyEnabled=False,
level__disable_algorithm_score=True, score=20
).update(score=10)


def set_successful_python_attempts_to_20(apps: Apps, *args):
Attempt = apps.get_model("game", "Attempt")

Attempt.objects.filter(
level__default=True, level__blocklyEnabled=False,
level__disable_algorithm_score=True, score=10
).update(score=20)


class Migration(migrations.Migration):
dependencies = [("game", "0090_python_levels_no_algo_score")]
operations = [
migrations.RunPython(
set_successful_python_attempts_to_10,
reverse_code=set_successful_python_attempts_to_20,
)
]
20 changes: 11 additions & 9 deletions game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ ocargo.Game.prototype.setup = function () {
}
}


// Function being called when there is a change in game level.
ocargo.Game.prototype.onLevelChange = function() {
const currentLevelId = LEVEL_ID;
localStorage.setItem('currentEpisode', EPISODE);
const currentLevelId = LEVEL_ID;
localStorage.setItem('currentEpisode', EPISODE);
}

restoreCmsLogin()
Expand Down Expand Up @@ -123,7 +123,7 @@ ocargo.Game.prototype.onLevelChange = function() {
}

this.drawing.enablePanning()

const showMascot = BLOCKLY_ENABLED && !PYTHON_VIEW_ENABLED && LEVEL_NAME <= 80; // show mascot on Blockly-only levels that are not above 80

ocargo.Drawing.startPopup(
Expand All @@ -146,7 +146,7 @@ document.addEventListener("DOMContentLoaded", function() {
if (currentEpisode) {
localStorage.setItem('currentEpisode', currentEpisode);
}
});
});

ocargo.Game.prototype.clearWorkspaceNameInputInSaveTab = function () {
$('#workspaceNameInput').val('')
Expand Down Expand Up @@ -238,10 +238,12 @@ ocargo.Game.prototype.sendAttempt = function (score) {
return /^(GET|HEAD|OPTIONS|TRACE)$/.test(method)
}

// hack scores so that it works for demo and python TODO implement max scores and remove this!!
if (PYTHON_ENABLED) {
score *= 2
}
// TODO: Remove below - keeping it for now as a reminder that we need to
// implement some kind of algorithm score for Python levels.
// // hack scores so that it works for demo and python TODO implement max scores and remove this!!
// if (PYTHON_ENABLED) {
// score *= 2
// }

// Check that we should actually be sending an attempt - either if only blockly is enabled
// or if python is enabled and we're on the python tab (assumes they don't change tab quickly...)
Expand Down

0 comments on commit d2f2a9c

Please sign in to comment.