$data = [];
$placed = [];
foreach ($locations as $location) {
// Hook
$location = (new Hook("alterModuleData"))->run([
"module" => "travel",
"user" => $this->user,
"data" => $location
], 1)["data"];
// Map
$map = (!empty($location['L_map']) && file_exists($location['L_map']))
? $location['L_map']
: "themes/" . _setting('theme') . "/assets/img/pages/travel/map.png";
[$width, $height] = getimagesize($map);
// Leader name
$leader = "None";
if ($location['L_leader']) {
$leader = (new Gang($location['L_leader']))->getGang()['name'];
}
// Random position (no overlap)
$pos = $this->randomPosition($width, $height, $placed);
$placed[] = $pos;
// Result
$data[] = [
"location" => $location["L_name"],
"color" => $location["L_color"],
"x" => $pos['x'],
"y" => $pos['y'],
"cost" => $location["L_cost"],
"id" => $location["L_id"],
"leader" => $leader,
"cooldown" => $this->timeLeft($location["L_cooldown"])
];
}