Skip to content

Commit

Permalink
testing addition of loadLanguage at startup, removal of en.js script
Browse files Browse the repository at this point in the history
  • Loading branch information
evemartin committed Apr 26, 2024
1 parent 8be873d commit 8e0f9a2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 110 deletions.
220 changes: 111 additions & 109 deletions game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,133 +10,135 @@ ocargo.Game = function () {
}

ocargo.Game.prototype.setup = function () {
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
)
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
)
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
)

// 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 =
'<br><span class="popup__text--warning">' +
gettext("You are not logged in. Your progress won't be saved.") +
'</span>'
}
// 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 =
'<br><span class="popup__text--warning">' +
gettext("You are not logged in. Your progress won't be saved.") +
'</span>'
}
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 =
'<br>' +
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 =
'<br>' +
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"))
]
)
});
}

// Script used to save and check for episode upon loading of the webpage
Expand Down
1 change: 0 additions & 1 deletion game/templates/game/game.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@
<script defer type="text/javascript" src="{% static 'game/js/blockly/blocks_compressed.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/blockly/javascript_compressed.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/blockly/python_compressed.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/blockly/msg/js/en.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/mobile-detect.min.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/raphael.js' %}"></script>
<script defer type="text/javascript" src="{% static 'game/js/howler.js' %}"></script>
Expand Down

0 comments on commit 8e0f9a2

Please sign in to comment.