Skip to content

Commit

Permalink
change redirect behavior for level-less episodes
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Aug 27, 2024
1 parent 03b86fa commit de0a435
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 3 deletions.
26 changes: 26 additions & 0 deletions game/migrations/0101_update_python_den_level_41.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.apps.registry import Apps
from django.db import migrations

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

level41 = Level.objects.get(default=True, name="1041")
level41.next_level = None
level41.save()

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

level41 = Level.objects.get(default=True, name="1041")
level41.next_level = Level.objects.get(default=True, name="1042")
level41.save()

class Migration(migrations.Migration):
dependencies = [("game", "0100_reorder_python_levels")]

operations = [
migrations.RunPython(
code=update_python_den_level_41,
reverse_code=revert_python_den_level_41
)
]
6 changes: 5 additions & 1 deletion game/static/game/js/animation.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ ocargo.Animation.prototype.performAnimation = function(animation) {
} else {
// If there exists next level, add animation button which redirects the user to that
if (NEXT_LEVEL_URL) {
buttons += ocargo.button.redirectButtonHtml('next_level_button', NEXT_LEVEL_URL, gettext('Next level'));
if (NEXT_LEVEL_URL == "/pythonden/") {
buttons += ocargo.button.episodeRedirectButtonHtml('next_level_button', NEXT_LEVEL_URL, gettext('Next episode'), NEXT_EPISODE)
} else {
buttons += ocargo.button.redirectButtonHtml('next_level_button', NEXT_LEVEL_URL, gettext('Next level'))
}
}
else if (PREV_LEVEL_URL) {
buttons += ocargo.button.redirectButtonHtml('prev_level_button', PREV_LEVEL_URL, gettext('Previous level'));
Expand Down
12 changes: 12 additions & 0 deletions game/static/game/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ ocargo.button.redirectButtonHtml = function(id, location, label){
return Handlebars.templates['button-redirect']({id: id, location: location, label: label});
};

// Returns the html code for a button which redirects to a given episode on the level selection page
ocargo.button.episodeRedirectButtonHtml = function(id, location, label, next_episode){
return `<button id="${id}" class="navigation_button long_button"
onclick="function onClick() {
window.location.href='${location}';
localStorage.setItem('currentEpisode', '${next_episode}');
};
onClick()">
<span>${label}</span>
</button>`
}

// Returns the html code for a button which shows the try again message and closes the popup
ocargo.button.tryAgainButtonHtml = function(){
return ocargo.button.dismissButtonHtml('try_again_button', gettext('Try again'));
Expand Down
4 changes: 3 additions & 1 deletion game/static/game/js/drawing.js
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,9 @@ ocargo.Drawing.startPopup = function (
// adding links to buttons
currentButton.append(icons[i])
let currentLink = links[i] === "" ? "" : `window.location.replace('${links[i]}')`
currentButton.attr("onclick", currentLink)
if (currentID !== "next_button") {
currentButton.attr("onclick", currentLink);
}
}

// Close the video on the play button
Expand Down
6 changes: 5 additions & 1 deletion game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ ocargo.Game.prototype.setup = function () {
const showMascot = BLOCKLY_ENABLED && !PYTHON_VIEW_ENABLED && LEVEL_NAME <= 80; // show mascot on Blockly-only levels that are not above 80

const subtitle = SUBTITLE == "None" ? "" : "<b>" + SUBTITLE + "</b> <br> <br> ";
const next_button_html = NEXT_LEVEL_URL == "/pythonden/"
? ocargo.button.episodeRedirectButtonHtml("next_button", NEXT_LEVEL_URL, gettext('Next episode'), NEXT_EPISODE)
: ocargo.button.dismissButtonHtml("next_button", gettext('Next level'))
ocargo.Drawing.startPopup(
title,
subtitle + LESSON,
Expand All @@ -153,7 +156,7 @@ ocargo.Game.prototype.setup = function () {
[
ocargo.button.dismissButtonHtml("prev_button", gettext("Previous level")),
ocargo.button.dismissButtonHtml('play_button', gettext('Play')),
ocargo.button.dismissButtonHtml("next_button", gettext("Next level"))
next_button_html
]
)
}
Expand All @@ -162,6 +165,7 @@ ocargo.Game.prototype.setup = function () {
document.addEventListener("DOMContentLoaded", function() {
const dataElement = document.getElementById('data');
const currentEpisode = dataElement ? dataElement.getAttribute('data-episode') : null;
console.log(currentEpisode);
if (currentEpisode) {
localStorage.setItem('currentEpisode', currentEpisode);
}
Expand Down
3 changes: 3 additions & 0 deletions game/views/level.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def _next_level_url(level, user, night_mode, from_python_den):
the teacher has locked certain levels, then loop until we find the next
unlocked level (or we run out of levels).
"""

if not level.next_level:
if level.episode.pk == 13:
return reverse("python_levels")
return ""

next_level = level.next_level
Expand Down

0 comments on commit de0a435

Please sign in to comment.