Skip to content

Commit

Permalink
Add option to disable RD in online mode & challenges
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit d24d550
Author: tmalahie <[email protected]>
Date:   Mon Apr 1 23:29:01 2024 +0200

    v226

commit 9b3f226
Author: tmalahie <[email protected]>
Date:   Mon Apr 1 16:10:44 2024 +0200

    Add option to prevent reverse drift in challenges

commit 9deb8f2
Author: tmalahie <[email protected]>
Date:   Sun Mar 24 17:00:59 2024 +0100

    Make RD disable an option

commit e1ed118
Author: tmalahie <[email protected]>
Date:   Sun Mar 24 17:05:19 2024 +0100

    v225

commit f22b21c
Author: tmalahie <[email protected]>
Date:   Sat Mar 16 00:06:00 2024 +0100

    Clean code

commit 057d8f5
Author: tmalahie <[email protected]>
Date:   Sat Mar 16 00:05:54 2024 +0100

    Prevent users from reverse drifting
  • Loading branch information
tmalahie committed Apr 1, 2024
1 parent 5e3e7c7 commit b366c86
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 47 deletions.
8 changes: 0 additions & 8 deletions php/api/changeParam.php

This file was deleted.

32 changes: 0 additions & 32 deletions php/includes/getCourseOptions.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,9 @@
<?php
$defaultScreenScale = '(screen.width<800)?((screen.width<480)?4:6):((screen.width<1500)?8:10)';
$settingKeys = array('iQuality'=>'5', 'iScreenScale'=>null, 'bMusic'=>'0', 'iSfx'=>'0');
$isCookieSet = false;
foreach ($settingKeys as $settingKey=>$settingDef) {
if (isset($_COOKIE[$settingKey])) {
$isCookieSet = true;
break;
}
}
if ($isCookieSet) {
?>
{
quality: <?php echo (isset($_COOKIE['iQuality']) ? $_COOKIE['iQuality']:5); ?>,
music: <?php echo (isset($_COOKIE['bMusic']) ? $_COOKIE['bMusic']:0); ?>,
sfx: <?php echo (isset($_COOKIE['iSfx']) ? $_COOKIE['iSfx']:(isset($_COOKIE['bMusic']) ? $_COOKIE['bMusic']:0)); ?>,
screenscale: <?php echo (isset($_COOKIE['iScreenScale']) ? $_COOKIE['iScreenScale']:$defaultScreenScale); ?>
};
<?php
foreach ($settingKeys as $settingKey=>$settingDef) {
if (isset($_COOKIE[$settingKey]) && ($_COOKIE[$settingKey] !== $settingDef))
echo 'localStorage.setItem("'. $settingKey .'", "'. $_COOKIE[$settingKey] .'");';
}
?>
setTimeout(function() {
xhr("changeParam.php", "clear=1", function(reponse) {
return (reponse == 1);
});
}, 1000);
<?php
}
else {
?>
{
quality: localStorage.getItem("iQuality") ? +localStorage.getItem("iQuality") : 5,
music: localStorage.getItem("bMusic") ? +localStorage.getItem("bMusic"):0,
sfx: localStorage.getItem("iSfx") ? +localStorage.getItem("iSfx"):0,
screenscale: localStorage.getItem("iScreenScale") ? +localStorage.getItem("iScreenScale"):<?php echo $defaultScreenScale; ?>
}
<?php
}
2 changes: 1 addition & 1 deletion php/includes/mk/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
if ($_SERVER['HTTP_HOST'] !== 'mkpc.malahieude.net')
echo '<script type="text/javascript" src="scripts/mk.js"></script>';
else
echo '<script type="text/javascript" src="scripts/mk.v224.js"></script>';
echo '<script type="text/javascript" src="scripts/mk.v226.js"></script>';
?>
4 changes: 4 additions & 0 deletions php/includes/onlineRulesUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
'default' => 0,
'accepted' => array(1,1)
),
'noRd' => array(
'default' => 0,
'accepted' => array(1,1)
),
'doubleItems' => array(
'default' => 1,
'accepted' => array(1,1)
Expand Down
5 changes: 5 additions & 0 deletions php/includes/utils-challenges.php
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,11 @@
'group' => 'no_action',
'course' => array('vs', 'battle', 'cup', 'mcup', 'bcup', 'mbcup')
),
'no_rd' => array(
'description' => $language ? 'without reverse drifting':'sans faire de RD',
'group' => 'no_action',
'course' => array('vs', 'battle', 'cup', 'mcup', 'bcup', 'mbcup')
),
'without_turning' => array(
'description_mockup' => $language ? 'without turning...':'sans tourner...',
'description_lambda' => function($language,&$scope) {
Expand Down
84 changes: 78 additions & 6 deletions scripts/mk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4135,7 +4135,13 @@ function startGame() {
break;
case "down":
currentPressedKeys[gameAction] = true;
oPlayers[0].speedinc = -0.2;
if (isRdDisabled() && oPlayers[0].driftinc)
oPlayers[0].speedinc = 0;
else {
oPlayers[0].speedinc = -0.2;
if (oPlayers[0].driftinc)
clLocalVars.revDrifted = true;
}
break;
case "jump":
if (pause) break;
Expand Down Expand Up @@ -4210,7 +4216,7 @@ function startGame() {
break;
case "down_p2":
if (!oPlayers[1]) return;
oPlayers[1].speedinc -= 0.2;
oPlayers[1].speedinc = -0.2;
break;
case "jump_p2":
if (pause) break;
Expand Down Expand Up @@ -10782,6 +10788,9 @@ function resetDriftSprite(oKart) {
function isJumpEnabled() {
return !(isOnline && shareLink.options && shareLink.options.noJump);
}
function isRdDisabled() {
return (isOnline && shareLink.options && shareLink.options.noRd);
}
function isLocalScore() {
if (isOnline)
return (shareLink.options && shareLink.options.localScore);
Expand Down Expand Up @@ -12210,6 +12219,11 @@ var challengeRules = {
return !clLocalVars.drifted;
}
},
"no_rd": {
"success": function(scope) {
return !clLocalVars.revDrifted;
}
},
"avoid_items": {
"success": function(scope) {
return !clLocalVars.itemsGot;
Expand Down Expand Up @@ -12826,6 +12840,7 @@ function isSameDistrib(d1,d2) {
function reinitLocalVars() {
clLocalVars = {
drifted: false,
revDrifted: false,
stunted: false,
itemsGot: false,
itemsUsed: false,
Expand Down Expand Up @@ -19070,6 +19085,7 @@ function privateGameOptions(gameOptions, onProceed) {
var timeTrial = this.elements["option-timeTrial"].checked ? 1:0;
var noBumps = this.elements["option-noBumps"].checked ? 1:0;
var noJump = this.elements["option-noJump"].checked ? 1:0;
var noRd = this.elements["option-noRd"].checked ? 1:0;
var doubleItems = this.elements["option-doubleItems"].checked ? 0:1;
if (!team) {
manualTeams = 0;
Expand Down Expand Up @@ -19106,6 +19122,7 @@ function privateGameOptions(gameOptions, onProceed) {
timeTrial: timeTrial,
noBumps: noBumps,
noJump: noJump,
noRd: noRd,
doubleItems: doubleItems
});
oScr.innerHTML = "";
Expand Down Expand Up @@ -20377,8 +20394,6 @@ function privateGameOptions(gameOptions, onProceed) {
oTr.appendChild(oTd);
oTable.appendChild(oTr);

oScroll.appendChild(oTable);

var oTr = document.createElement("tr");
oTr.id = "option-noBumps-ctn";
if (!isOnline)
Expand Down Expand Up @@ -20415,8 +20430,6 @@ function privateGameOptions(gameOptions, onProceed) {
oTr.appendChild(oTd);
oTable.appendChild(oTr);

oScroll.appendChild(oTable);

var oTr = document.createElement("tr");
oTr.id = "option-noJump-ctn";
if (!isOnline)
Expand Down Expand Up @@ -20453,6 +20466,42 @@ function privateGameOptions(gameOptions, onProceed) {
oTr.appendChild(oTd);
oTable.appendChild(oTr);

var oTr = document.createElement("tr");
oTr.id = "option-noRd-ctn";
if (!isOnline)
oTr.style.display = "none";
var oTd = document.createElement("td");
oTd.style.textAlign = "center";
oTd.style.width = (iScreenScale*8) +"px";
var oCheckbox = document.createElement("input");
oCheckbox.style.transform = oCheckbox.style.WebkitTransform = oCheckbox.style.MozTransform = "scale("+ Math.round(iScreenScale/3) +")";
oCheckbox.id = "option-noRd";
oCheckbox.name = "option-noRd";
oCheckbox.type = "checkbox";
if (gameOptions && gameOptions.noRd)
oCheckbox.checked = true;
oTd.appendChild(oCheckbox);
oTr.appendChild(oTd);

var oTd = document.createElement("td");
var oLabel = document.createElement("label");
oLabel.style.cursor = "pointer";
oLabel.setAttribute("for", "option-noRd");
var oH1 = document.createElement("h1");
oH1.style.fontSize = (3*iScreenScale) +"px";
oH1.style.marginBottom = "0px";
oH1.innerHTML = toLanguage("Disable Reverse Drift", "Désactiver le Reverse Drift");
oLabel.appendChild(oH1);
var oDiv = document.createElement("div");
oDiv.style.fontSize = (2*iScreenScale) +"px";
oDiv.style.color = "white";
oDiv.innerHTML = toLanguage("If checked, the famous MKPC drifting technique is blocked", "Si coché, la fameuse technique de dérapage de MKPC est bloquée");
oLabel.appendChild(oDiv);
oTd.appendChild(oLabel);
oTd.style.padding = Math.round(iScreenScale*1.5) +"px 0";
oTr.appendChild(oTd);
oTable.appendChild(oTr);

oScroll.appendChild(oTable);

oForm.appendChild(oScroll);
Expand Down Expand Up @@ -21998,6 +22047,7 @@ function selectPlayerScreen(IdJ,newP,nbSels,additionalOptions) {
shareLink.options.timeTrial = options.timeTrial;
shareLink.options.noBumps = options.noBumps;
shareLink.options.noJump = options.noJump;
shareLink.options.noRd = options.noRd;
shareLink.options.doubleItems = options.doubleItems;
selectedTeams = options.team;
selectPlayerScreen(0);
Expand Down Expand Up @@ -23708,6 +23758,7 @@ var defaultGameOptions = {
timeTrial: false,
noBumps: false,
noJump: false,
noRd: false,
doubleItems: true
};
function isCustomOptions(linkOptions) {
Expand Down Expand Up @@ -24214,6 +24265,27 @@ function acceptRulesScreen() {
oTable.appendChild(oTr);
}

if (shareLink.options.noRd) {
var oTr = document.createElement("tr");
var oTd = document.createElement("td");
var oLabel = document.createElement("label");
oTd.appendChild(oLabel);

var oH1 = document.createElement("h1");
oH1.style.fontSize = (3*iScreenScale) +"px";
oH1.innerHTML = toLanguage("No Reverse Drift", "Pas de Reverse Drift");
oH1.style.marginBottom = "0px";
oLabel.appendChild(oH1);
var oDiv = document.createElement("div");
oDiv.style.fontSize = (2*iScreenScale) +"px";
oDiv.style.color = "white";
oDiv.innerHTML = toLanguage("The famous MKPC drifting technique is blocked", "La fameuse technique de dérapage de MKPC est bloquée");
oLabel.appendChild(oDiv);
oTd.appendChild(oLabel);
oTr.appendChild(oTd);
oTable.appendChild(oTr);
}

oScroll.appendChild(oTable);

oForm.appendChild(oScroll);
Expand Down
1 change: 1 addition & 0 deletions scripts/mk.v225.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions scripts/mk.v226.js

Large diffs are not rendered by default.

0 comments on commit b366c86

Please sign in to comment.