Skip to content

Commit

Permalink
feat: check cookie consent when muting game (#1157)
Browse files Browse the repository at this point in the history
* feat: check cookie consent when muting game

* reduced mute function complexity

* Merge branch 'master' into managed-cookies
  • Loading branch information
razvan-pro authored Apr 16, 2021
1 parent c041935 commit 85b5279
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions game/static/game/js/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ocargo.Game = function () {
this.tabs = null
this.failures = 0
this.currentlySelectedTab = null
this.isMuted = $.cookie('muted') === 'true'
}

ocargo.Game.prototype.setup = function () {
Expand Down Expand Up @@ -476,13 +477,13 @@ ocargo.Game.prototype.onSlowControls = function () {
}

ocargo.Game.prototype.mute = function (mute) {
this.isMuted = mute
setMutedCookie(mute)
if (mute) {
ocargo.sound.mute()
$.cookie('muted', 'true', { path: Urls.levels() })
this.tabs.mute.transitTo('muted')
} else {
ocargo.sound.unmute()
$.cookie('muted', 'false', { path: Urls.levels() })
this.tabs.mute.transitTo('unmuted')
}
}
Expand Down Expand Up @@ -1147,7 +1148,7 @@ ocargo.Game.prototype._setupHelpTab = function () {
ocargo.Game.prototype._setupMuteTab = function () {
this.tabs.mute.setOnChange(
function () {
this.mute($.cookie('muted') !== 'true')
this.mute(!this.isMuted)
this._selectPreviousTab()
}.bind(this)
)
Expand Down Expand Up @@ -1219,8 +1220,18 @@ function restoreCmsLogin () {
.css('display', 'inline')
}

function hasFunctionalCookiesConsent() {
return OnetrustActiveGroups && OnetrustActiveGroups.split(',').includes('C0003')
}

function setMutedCookie(mute) {
if (hasFunctionalCookiesConsent()) {
$.cookie('muted', mute.toString(), { path: Urls.levels() })
}
}

$(document).ready(function () {
ocargo.game = new ocargo.Game()
ocargo.game.setup()
ocargo.game.mute($.cookie('muted') === 'true')
ocargo.game.mute(ocargo.game.isMuted)
})

0 comments on commit 85b5279

Please sign in to comment.