From 76ce2551d4f8a88f91cf45764d9eb4b10ba99a44 Mon Sep 17 00:00:00 2001 From: Eve Martin Date: Fri, 26 Apr 2024 14:22:48 +0000 Subject: [PATCH] add back what I changed --- game/static/game/js/game.js | 223 ++++++++++++++++++------------------ 1 file changed, 111 insertions(+), 112 deletions(-) diff --git a/game/static/game/js/game.js b/game/static/game/js/game.js index e5956bda2..12315d0cf 100644 --- a/game/static/game/js/game.js +++ b/game/static/game/js/game.js @@ -12,138 +12,137 @@ ocargo.Game = function () { ocargo.Game.prototype.setup = function () { let _this = this; - if(new Date().getMonth() === 11) { - $("#paper").css('background-color', '#eef7ff') - } - - if (NIGHT_MODE_FEATURE_ENABLED) { - if (NIGHT_MODE) { - $('#paper').css('background-color', 'black') + loadLanguage("/static/game/js/blockly/msg/js/", navigator.language.toLowerCase(), function() { + if(new Date().getMonth() === 11) { + $("#paper").css('background-color', '#eef7ff') } - if (!ANONYMOUS) { - $('#nightmode_tab').show() + if (NIGHT_MODE_FEATURE_ENABLED) { + if (NIGHT_MODE) { + $('#paper').css('background-color', 'black') + } + + if (!ANONYMOUS) { + $('#nightmode_tab').show() + } } - } - // Function being called when there is a change in game level. - ocargo.Game.prototype.onLevelChange = function() { - const currentLevelId = LEVEL_ID; - localStorage.setItem('currentEpisode', EPISODE); - } + // Function being called when there is a change in game level. + ocargo.Game.prototype.onLevelChange = function() { + const currentLevelId = LEVEL_ID; + localStorage.setItem('currentEpisode', EPISODE); + } - restoreCmsLogin() - initCustomBlocks() - ocargo.solutionLoaded = false - ocargo.blocklyControl = new ocargo.BlocklyControl() - ocargo.pythonControl = new ocargo.PythonControl() - ocargo.blocklyCompiler = new ocargo.BlocklyCompiler() - ocargo.model = new ocargo.Model( - PATH, - ORIGIN, - DESTINATIONS, - TRAFFIC_LIGHTS, - COWS, - MAX_FUEL - ) + restoreCmsLogin() + initCustomBlocks() + ocargo.solutionLoaded = false + ocargo.blocklyControl = new ocargo.BlocklyControl() + ocargo.pythonControl = new ocargo.PythonControl() + ocargo.blocklyCompiler = new ocargo.BlocklyCompiler() + ocargo.model = new ocargo.Model( + PATH, + ORIGIN, + DESTINATIONS, + TRAFFIC_LIGHTS, + COWS, + MAX_FUEL + ) - _this.drawing = new ocargo.Drawing(ocargo.model.startingPosition()) - _this.drawing.preloadRoadTiles() - ocargo.animation = new ocargo.Animation(ocargo.model, DECOR, _this.drawing) - _this.saving = new ocargo.Saving() - _this.sharing = new ocargo.Sharing( - () => parseInt(LEVEL_ID), - () => true - ) + _this.drawing = new ocargo.Drawing(ocargo.model.startingPosition()) + _this.drawing.preloadRoadTiles() + ocargo.animation = new ocargo.Animation(ocargo.model, DECOR, _this.drawing) + _this.saving = new ocargo.Saving() + _this.sharing = new ocargo.Sharing( + () => parseInt(LEVEL_ID), + () => true + ) - // Setup the blockly workspace - ocargo.blocklyControl.reset() - ocargo.blocklyControl.loadPreviousAttempt() - ocargo.pythonControl.loadPreviousAttempt() + // Setup the blockly workspace + ocargo.blocklyControl.reset() + ocargo.blocklyControl.loadPreviousAttempt() + ocargo.pythonControl.loadPreviousAttempt() - // Setup the ui - _this._setupConsoleSliderListeners() - _this._setupPythonViewSliderListeners() - _this._setupConsoleLogViewSliderListeners() - _this._setupDirectDriveListeners() - _this._setupFuelGauge(ocargo.model.map.nodes, BLOCKS) - _this._setupTabs() + // Setup the ui + _this._setupConsoleSliderListeners() + _this._setupPythonViewSliderListeners() + _this._setupConsoleLogViewSliderListeners() + _this._setupDirectDriveListeners() + _this._setupFuelGauge(ocargo.model.map.nodes, BLOCKS) + _this._setupTabs() - _this.onStopControls() + _this.onStopControls() - // default controller - if (BLOCKLY_ENABLED) { - ocargo.controller = ocargo.blocklyControl - } else { - ocargo.controller = ocargo.pythonControl - } + // default controller + if (BLOCKLY_ENABLED) { + ocargo.controller = ocargo.blocklyControl + } else { + ocargo.controller = ocargo.pythonControl + } - // Setup blockly to python - Blockly.Python.init(Blockly.getMainWorkspace()) - window.addEventListener( - 'unload', - function (event) { - ocargo.pythonControl.teardown() - ocargo.blocklyControl.teardown() - }.bind(this) - ) + // Setup blockly to python + Blockly.Python.init(Blockly.getMainWorkspace()) + window.addEventListener( + 'unload', + function (event) { + ocargo.pythonControl.teardown() + ocargo.blocklyControl.teardown() + }.bind(this) + ) - var loggedOutWarning = '' - // Check if logged on - if (USER_STATUS == 'UNTRACKED') { - loggedOutWarning = - '
' + - gettext("You are not logged in. Your progress won't be saved.") + - '' - } - // Start the popup - var title = gettext('Try solving this one...') - if (LEVEL_ID) { - var titlePrefix = '' - if (NIGHT_MODE) { - titlePrefix = gettext('Night Level %(level_name)s') - } else if (DEFAULT_LEVEL) { - titlePrefix = gettext('Level %(level_name)s') + var loggedOutWarning = '' + // Check if logged on + if (USER_STATUS == 'UNTRACKED') { + loggedOutWarning = + '
' + + gettext("You are not logged in. Your progress won't be saved.") + + '' } - if (titlePrefix) { - title = interpolate(titlePrefix, { level_name: LEVEL_NAME }, true) - } else { - title = LEVEL_NAME + // Start the popup + var title = gettext('Try solving this one...') + if (LEVEL_ID) { + var titlePrefix = '' + if (NIGHT_MODE) { + titlePrefix = gettext('Night Level %(level_name)s') + } else if (DEFAULT_LEVEL) { + titlePrefix = gettext('Level %(level_name)s') + } + if (titlePrefix) { + title = interpolate(titlePrefix, { level_name: LEVEL_NAME }, true) + } else { + title = LEVEL_NAME + } } - } - var message - if (NIGHT_MODE) { - message = - '
' + - gettext( - 'In Night Mode you can only see a very short distance. ' + - "We've given you more blocks to help you find your way!" - ) - } else { - message = loggedOutWarning - } + var message + if (NIGHT_MODE) { + message = + '
' + + gettext( + 'In Night Mode you can only see a very short distance. ' + + "We've given you more blocks to help you find your way!" + ) + } else { + message = loggedOutWarning + } - _this.drawing.enablePanning() + _this.drawing.enablePanning() - const showMascot = BLOCKLY_ENABLED && !PYTHON_VIEW_ENABLED && LEVEL_NAME <= 80; // show mascot on Blockly-only levels that are not above 80 + const showMascot = BLOCKLY_ENABLED && !PYTHON_VIEW_ENABLED && LEVEL_NAME <= 80; // show mascot on Blockly-only levels that are not above 80 - ocargo.Drawing.startPopup( - title, - LESSON, - message, - showMascot, - [ - ocargo.button.dismissButtonHtml("prev_button", gettext("Previous level")), - ocargo.button.dismissButtonHtml('play_button', gettext('Play')), - ocargo.button.dismissButtonHtml("next_button", gettext("Next level")) - ] - ) + ocargo.Drawing.startPopup( + title, + LESSON, + message, + showMascot, + [ + ocargo.button.dismissButtonHtml("prev_button", gettext("Previous level")), + ocargo.button.dismissButtonHtml('play_button', gettext('Play')), + ocargo.button.dismissButtonHtml("next_button", gettext("Next level")) + ] + ) - loadLanguage("/static/game/js/blockly/msg/js/", navigator.language.toLowerCase(), function() { - reloadWorkspace(blockly.mainWorkspace); - }) + }); } // Script used to save and check for episode upon loading of the webpage