Skip to content

Commit

Permalink
Complete mode - allow to override track components for each lap (#50)
Browse files Browse the repository at this point in the history
* Fix grlp.js

* Add option to select bullet bill route (wip)

* Implement bullet bill route IG

* Small fixes in arena editor

* wip

* Start implementing lap override flow in editor

* Fix aipoints + handle lap override persistance

* Fix other special cases

* Prepare map override data IG

* Start implementing override mechanics IG

* Small fixes (again)

* Keep implementing lap overrides IG (still wip)

* Fix TODOs (wip)

* Keep fixing TODOs (still wip)

* Fix shortcuts not reset properly

* Implement map img override (wip)

* Keep implementing image override flow

* Finish implementing image override

* Implement bg layer overrides

* Fix local multiplayer issues

* Fix online spectator mode

* Add help

* Don't apply override for sections

* Revert "Don't apply override for sections"

This reverts commit d0afb16.

* Small fixes

* Fix battle mode & multicups

* Many fixes with challenges

* Start allowing to override middle of lap

* Start implementing middle lap override IG

* Small fixes

* Start implementing new imgData logic (wip)

* Various fixes

* Keep fixing stuff

* Fix issue with ai autododge

* Fix issue with decor assets

* Minor UX/UI improvements in the editor

* Other minor fixes

* Fix TT replay

* Fix issue with off road

* Fix frame skip on lap change

* ux fix

* Clarify when override is disabled

* Fix duplicateCircuit sometimes not working

* Clear cache

* Fix wording

* Make cheat code for checkpoints more convenient

* Cache clear (again)
  • Loading branch information
tmalahie authored Aug 11, 2024
1 parent 6f34ea1 commit 2dc8cbb
Show file tree
Hide file tree
Showing 22 changed files with 3,222 additions and 1,358 deletions.
Binary file added images/editor/help-draw/help-lapoverrides.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions php/api/saveCourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
include('../includes/getId.php');
require_once('../includes/collabUtils.php');
$requireOwner = !hasCollabGrants('arenes', $data->id, $data->collab, 'edit');
if ($getCircuit = mysql_fetch_array(mysql_query('SELECT publication_date FROM arenes WHERE id="'.mysql_real_escape_string($id).'"'. ($requireOwner ? (' AND identifiant='.$identifiants[0].' AND identifiant2='.$identifiants[1].' AND identifiant3='.$identifiants[2].' AND identifiant4='.$identifiants[3]) : ''))))
if ($getCircuit = mysql_fetch_array(mysql_query('SELECT publication_date FROM arenes WHERE id="'.mysql_real_escape_string($id).'"'. ($requireOwner ? (' AND identifiant='.$identifiants[0].' AND identifiant2='.$identifiants[1].' AND identifiant3='.$identifiants[2].' AND identifiant4='.$identifiants[3]) : '')))) {
mysql_query('INSERT INTO arenes_data VALUES("'.mysql_real_escape_string($id).'","'.mysql_real_escape_string(gzcompress(json_encode($payload))).'") ON DUPLICATE KEY UPDATE data=VALUES(data)');
require_once('../includes/cache_creations.php');
@unlink(cachePath("coursepreview$id.png"));
}
echo 1;
mysql_close();
require_once('../includes/cache_creations.php');
@unlink(cachePath("coursepreview$id.png"));
}
?>
42 changes: 37 additions & 5 deletions php/api/saveMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,49 @@
header('Content-Type: text/plain');
$data = json_decode(file_get_contents('php://input'));
if (is_object($data) && isset($data->id) && isset($data->payload)) {
$id = $data->id;
$id = intval($data->id);
$payload = $data->payload;
include('../includes/initdb.php');
include('../includes/getId.php');
require_once('../includes/collabUtils.php');
$requireOwner = !hasCollabGrants('circuits', $data->id, $data->collab, 'edit');
if ($getCircuit = mysql_fetch_array(mysql_query('SELECT publication_date FROM circuits WHERE id="'.mysql_real_escape_string($id).'"'. ($requireOwner ? (' AND identifiant='.$identifiants[0].' AND identifiant2='.$identifiants[1].' AND identifiant3='.$identifiants[2].' AND identifiant4='.$identifiants[3]):''))))
mysql_query('INSERT INTO circuits_data VALUES("'.mysql_real_escape_string($id).'","'.mysql_real_escape_string(gzcompress(json_encode($payload))).'") ON DUPLICATE KEY UPDATE data=VALUES(data)');
if ($circuit = mysql_fetch_array(mysql_query('SELECT img_data FROM circuits WHERE id="'.$id.'"'. ($requireOwner ? (' AND identifiant='.$identifiants[0].' AND identifiant2='.$identifiants[1].' AND identifiant3='.$identifiants[2].' AND identifiant4='.$identifiants[3]):'')))) {
mysql_query('INSERT INTO circuits_data VALUES("'.$id.'","'.mysql_real_escape_string(gzcompress(json_encode($payload))).'") ON DUPLICATE KEY UPDATE data=VALUES(data)');
$circuitImg = json_decode($circuit['img_data']);
if (isset($data->imgOverrides) && isset($circuitImg->lapOverrides)) {
$lapOverrides = $circuitImg->lapOverrides;
$newLapOverrides = new stdClass();
$newImgs = array();
foreach ($data->imgOverrides as $lapId => $imgOverride) {
$newLapOverride = null;
foreach ($lapOverrides as $lapOverride) {
if ($lapOverride->url === $imgOverride->url && $lapOverride->local === $imgOverride->local) {
$newLapOverride = $lapOverride;
break;
}
}
if (!$newLapOverride && isset($lapOverrides->$lapId))
$newLapOverride = $lapOverrides->$lapId;
if ($newLapOverride) {
$newLapOverrides->$lapId = $newLapOverride;
if ($newLapOverride->local)
$newImgs[$newLapOverride->url] = true;
}
}
foreach ($lapOverrides as $lapOverride) {
if ($lapOverride->local && !isset($newImgs[$lapOverride->url])) {
require_once('../includes/circuitImgUtils.php');
$path = CIRCUIT_BASE_PATH.$lapOverride->url;
@unlink($path);
}
}
$circuitImg->lapOverrides = $newLapOverrides;
mysql_query('UPDATE circuits SET img_data="'.mysql_real_escape_string(json_encode($circuitImg)).'" WHERE id="'.$id.'"');
}
require_once('../includes/cache_creations.php');
@unlink(cachePath("racepreview$id.png"));
}
echo 1;
mysql_close();
require_once('../includes/cache_creations.php');
@unlink(cachePath("racepreview$id.png"));
}
?>
13 changes: 13 additions & 0 deletions php/includes/circuitImgUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ function getCircuitImgData(&$path,&$url,$local) {
function getCircuitImgDataRaw(&$path,&$url,$local) {
return mysql_real_escape_string(json_encode(getCircuitImgData($path,$url,$local)));
}
function getBaseCircuitImgDataRaw(&$baseCircuitImg,&$circuitImg, $lap) {
if ($lap) {
if (!isset($baseCircuitImg->lapOverrides))
$baseCircuitImg->lapOverrides = new stdClass();
$baseCircuitImg->lapOverrides->$lap = $circuitImg;
return mysql_real_escape_string(json_encode($baseCircuitImg));
}
else {
if (isset($baseCircuitImg->lapOverrides))
$circuitImg->lapOverrides = $baseCircuitImg->lapOverrides;
return mysql_real_escape_string(json_encode($circuitImg));
}
}
function getCircuitLocalFile($circuitImg) {
if ($circuitImg->local)
return array('path' => CIRCUIT_BASE_PATH.$circuitImg->url);
Expand Down
3 changes: 1 addition & 2 deletions php/includes/circuitUiUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ function printDecorTypeSelector() {
</div>
<div id="decor-bus-trajects">
<a href="javascript:manageBusDecor()"><?php echo $language ? 'Back':'Retour'; ?></a>&nbsp;
<select name="decor-bus-traject" id="decor-bus-traject" onchange="trajectChange(this.value,'bus')">
</select>
<select name="decor-bus-traject" id="decor-bus-traject" onchange="trajectChange(this.value,'bus')"></select>
</div>
</div>
</div>
Expand Down
13 changes: 11 additions & 2 deletions php/includes/file-quotas.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,20 @@ function file_total_size($item=null) {
$ownerIds[$i] = $identifiant;
}
$poids = 0;
$circuits = mysql_query('SELECT ID,img_data FROM `circuits` WHERE identifiant='.$ownerIds[0].' AND identifiant2='.$ownerIds[1].' AND identifiant3='.$ownerIds[2].' AND identifiant4='.$ownerIds[3] . (isset($item['circuit']) ? ' AND ID != '.$item['circuit'] : ''));
$circuits = mysql_query('SELECT ID,img_data FROM `circuits` WHERE identifiant='.$ownerIds[0].' AND identifiant2='.$ownerIds[1].' AND identifiant3='.$ownerIds[2].' AND identifiant4='.$ownerIds[3]);
$excludedCircuitId = isset($item['circuit']) ? $item['circuit'] : null;
$excludedLap = isset($item['lap']) ? $item['lap'] : 0;
while ($circuit = mysql_fetch_array($circuits)) {
$excludeCircuit = $excludedCircuitId == $circuit['ID'];
$circuitImg = json_decode($circuit['img_data']);
if ($circuitImg->local)
if ($circuitImg->local && (!$excludeCircuit || $excludedLap))
$poids += @filesize(CIRCUIT_BASE_PATH.$circuitImg->url);
if (isset($circuitImg->lapOverrides)) {
foreach ($circuitImg->lapOverrides as $lap=>$lapImg) {
if ($lapImg->local && (!$excludeCircuit || ($lap != $excludedLap)))
$poids += @filesize(CIRCUIT_BASE_PATH.$lapImg->url);
}
}
}
$arenes = mysql_query('SELECT ID,img_data FROM `arenes` WHERE identifiant='.$ownerIds[0].' AND identifiant2='.$ownerIds[1].' AND identifiant3='.$ownerIds[2].' AND identifiant4='.$ownerIds[3] . (isset($item['arena']) ? ' AND ID != '.$item['arena'] : ''));
while ($arene = mysql_fetch_array($arenes)) {
Expand Down
2 changes: 1 addition & 1 deletion php/includes/grlp.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<script async type="text/javascript" src="scripts/grlp.js"></script>
<script async type="text/javascript" src="scripts/grlp.js?reload=1"></script>
125 changes: 94 additions & 31 deletions php/includes/mk/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,101 @@
require_once(__DIR__.'/../circuitImgUtils.php');
$printCircuitData = function($circuit) {
global $circuitMainData, $circuitPayload;
$id = $circuit['ID'];
$circuitPayload = json_decode(gzuncompress($circuit['data']));
if (!$circuitPayload)
return;
$circuitMainData = $circuitPayload->main;
$circuitImg = json_decode($circuit['img_data']);
echo '{';
printCircuitPart($circuit, 0,$circuitPayload);
if (isset($circuitPayload->lapOverrides)) {
echo ',"lapOverrides":[';
$v = '';
$lapKey = 1;
foreach ($circuitPayload->lapOverrides as $lapData) {
echo $v.'{';
printCircuitPart($circuit, $lapKey,$lapData);
echo '}';
$v = ',';
$lapKey++;
}
echo ']';
}
echo '}';
};
if (!function_exists('printCircuitPart')) {
function printCircuitPart($circuit, $lapId,$circuitPayload) {
$circuitMainData = $circuitPayload->main;
$circuitImg = isset($circuit['img_data']) ? json_decode($circuit['img_data']) : null;
if ($lapId) {
if (isset($circuitImg->lapOverrides->$lapId))
$circuitImg = $circuitImg->lapOverrides->$lapId;
else
$circuitImg = null;
}
if (!$lapId && isset($circuit['ID'])) echo '"map": '.$circuit['ID'].',';
if ($circuitImg) {
?>
"map" : <?php echo $id; ?>,
"ext" : "<?php echo $circuitImg->ext; ?>",
"img" : "<?php echo getCircuitImgUrl($circuitImg); ?>",
"bgcolor" : [<?php echo implode(',',$circuitMainData->bgcolor) ?>],
"smartjump": 1,
"w" : <?php echo $circuitImg->w; ?>,
"h" : <?php echo $circuitImg->h; ?>,
<?php
if (isset($circuit['icon']))
<?php
}
if ($lapId) {
echo '"lap":'.$circuitPayload->meta->lap.',';
if (isset($circuitPayload->meta->cp))
echo '"cp":'.$circuitPayload->meta->cp.',';
}
if (isset($circuitMainData->bgcolor))
echo '"bgcolor":['.implode(',',$circuitMainData->bgcolor).'],';
if (!$lapId && isset($circuit['icon']))
echo '"icon":'.json_encode($circuit['icon']).',';
if (isset($circuitMainData->bgcustom))
echo '"custombg":'.$circuitMainData->bgimg.',';
else {
elseif (isset($circuitMainData->bgimg)) {
echo '"fond":["';
include(__DIR__.'/../circuitEnums.php');
$getInfos = $bgImgs[$circuitMainData->bgimg];
echo implode('","',$getInfos);
echo '"],';
}
?>
"tours" : <?php echo $circuitMainData->tours; ?>,
<?php
if (isset($circuitMainData->tours))
echo '"tours":'.$circuitMainData->tours.',';
if (isset($circuitMainData->sections)) {
?>
"sections" : [<?php echo implode(',',$circuitMainData->sections); ?>],
<?php
}
?>
"music" : <?php echo $circuitMainData->music; ?>,
<?php
if (!$circuitMainData->music) {
if (!empty($circuitMainData->music))
echo '"music":'.$circuitMainData->music.',';
elseif (isset($circuitMainData->youtube)) {
?>
"yt" : "<?php if (isset($circuitMainData->youtube)) echo addslashes($circuitMainData->youtube); ?>",
"yt" : "<?php echo addslashes($circuitMainData->youtube); ?>",
<?php
if (isset($circuitMainData->youtube_opts)) {
?>
"yt_opts" : <?php echo json_encode($circuitMainData->youtube_opts); ?>,
<?php
}
}
?>
elseif (!$lapId)
echo '"music":1,';
if (isset($circuitMainData->startposition)) {
?>
"startposition" : [<?php echo ($circuitMainData->startposition[0]+5).','.($circuitMainData->startposition[1]-6); ?>],
"startrotation" : <?php echo $circuitMainData->startrotation; ?>,
"startdirection" : <?php echo empty($circuitMainData->startdirection)?1:0; ?>,
"aipoints" : <?php echo json_encode($circuitPayload->aipoints); ?>,
<?php if (isset($circuitPayload->aishortcuts)) echo '"aishortcuts":'. json_encode($circuitPayload->aishortcuts) .','; ?>
<?php
}
if (isset($circuitPayload->aipoints)) {
echo '"aipoints":'.json_encode($circuitPayload->aipoints).',';
if (isset($circuitPayload->aishortcuts)) echo '"aishortcuts":'. json_encode($circuitPayload->aishortcuts) .',';
elseif ($lapId) echo '"aishortcuts":undefined,';
if (isset($circuitPayload->airoutesmeta)) echo '"airoutesmeta":'. json_encode($circuitPayload->airoutesmeta) .',';
elseif ($lapId) echo '"airoutesmeta":undefined,';
}
if (isset($circuitPayload->collision)) {
?>
"collision" : <?php
foreach ($circuitPayload->collision as &$collisionData) {
if (isset($collisionData[3]) && is_numeric($collisionData[3])) {
Expand All @@ -66,7 +107,12 @@
unset($collisionData);
echo json_encode($circuitPayload->collision);
?>,
<?php if (isset($circuitPayload->collisionProps)) echo '"collisionProps":'. json_encode($circuitPayload->collisionProps) .','; ?>
<?php
if (isset($circuitPayload->collisionProps)) echo '"collisionProps":'. json_encode($circuitPayload->collisionProps) .',';
elseif ($lapId) echo '"collisionProps":undefined,';
}
if (isset($circuitPayload->horspistes)) {
?>
"horspistes" : <?php
foreach ($circuitPayload->horspistes as &$hpsData) {
foreach ($hpsData as &$hpData) {
Expand All @@ -80,6 +126,10 @@
unset($hpsData);
echo json_encode($circuitPayload->horspistes);
?>,
<?php
}
if (isset($circuitPayload->trous)) {
?>
"trous" : <?php
foreach ($circuitPayload->trous as &$trousData) {
foreach ($trousData as &$trouData) {
Expand All @@ -93,8 +143,14 @@
unset($trousData);
echo json_encode($circuitPayload->trous);
?>,
"checkpoint" : <?php echo json_encode($circuitPayload->checkpoint); ?>,
"arme" : <?php echo json_encode($circuitPayload->arme); ?>,
<?php
}
if (isset($circuitPayload->checkpoint))
echo '"checkpoint":'.json_encode($circuitPayload->checkpoint).',';
if (isset($circuitPayload->arme))
echo '"arme":'.json_encode($circuitPayload->arme).',';
if (isset($circuitPayload->sauts)) {
?>
"sauts" : <?php
foreach ($circuitPayload->sauts as &$sautsData) {
if (count($sautsData) > 3) {
Expand All @@ -107,21 +163,30 @@
unset($sautsData);
echo json_encode($circuitPayload->sauts);
?>,
"accelerateurs" : <?php echo json_encode($circuitPayload->accelerateurs); ?>,
"decor" : <?php echo json_encode($circuitPayload->decor);
<?php
}
if (isset($circuitPayload->accelerateurs))
echo '"accelerateurs":'.json_encode($circuitPayload->accelerateurs).',';
if (isset($circuitPayload->decor)) {
echo '"decor":'.json_encode($circuitPayload->decor).',';
if (!empty($circuitPayload->decorparams)) {
?>,
"decorparams" : <?php echo json_encode($circuitPayload->decorparams);
?>
"decorparams" : <?php echo json_encode($circuitPayload->decorparams).',';
}
elseif ($lapId)
echo '"decorparams":undefined,';
}
if (!empty($circuitPayload->assets)) {
$assetTypes = array('pointers', 'flippers', 'bumpers','oils');
foreach ($assetTypes as $assetType) {
if (!empty($circuitPayload->assets->{$assetType})) {
?>,
"<?php echo $assetType; ?>" : <?php echo json_encode($circuitPayload->assets->{$assetType});
?>
"<?php echo $assetType; ?>" : <?php echo json_encode($circuitPayload->assets->{$assetType}); ?>,
<?php
}
}
}
echo '"smartjump": 1';
if (!empty($circuitPayload->cannons)) {
?>,
"cannons" : <?php echo json_encode($circuitPayload->cannons);
Expand All @@ -144,8 +209,6 @@
"elevators" : <?php echo json_encode($circuitPayload->elevators); ?>
<?php
}
?>
}
<?php
}
}
?>
4 changes: 4 additions & 0 deletions php/includes/suppr.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
require_once('circuitImgUtils.php');
$circuitImg = json_decode($circuit['img_data']);
deleteCircuitFile($circuitImg);
if (isset($circuitImg->lapOverrides)) {
foreach ($circuitImg->lapOverrides as $lapOverride)
deleteCircuitFile($lapOverride);
}
include('postCircuitUpdate.php');
postCircuitDelete('circuits', $cID);
if (hasRight('moderator'))
Expand Down
Loading

0 comments on commit 2dc8cbb

Please sign in to comment.