From: CMDR furrycat Date: Tue, 7 Feb 2017 14:09:33 +0000 (-0500) Subject: Handle races which can be flown in any order. X-Git-Url: http://git.furryclan.net/?a=commitdiff_plain;h=2f5514d2430df39816ed38727a5bf5b5490965a9;p=furrycat%2Frace-o-matic.git Handle races which can be flown in any order. If the "reverse" field is set the start and finish stations can be swapped when adding an entry. --- diff --git a/entry.js b/entry.js index 86cc697..f18ac27 100644 --- a/entry.js +++ b/entry.js @@ -813,6 +813,17 @@ function changed_joker(event) { validate(get_table()); } +/* Callback when we swap start and finish. */ +function reversed(event) { + var input = event.target; + var table = get_table(); + /* Swap heading and rows. */ + for (var j = 0; j <= last_column(table); j++) { + if (j && ! valid_column(table, j)) continue; + swap_cells(table, first_row(table), j, last_row(table), j, true); + } +} + /* Create a new input element. */ function checkpoint(id) { var date = elite_date(); @@ -965,6 +976,9 @@ function loaded() { if (typeof optional_waypoints == 'number' && optional_waypoints) waypoints = optional_waypoints; else waypoints = total_waypoints; omitted_optional = total_waypoints - waypoints - 1; + for (var input of document.getElementsByClassName('reverse')) { + input.addEventListener('dblclick', reversed, true); + } validate(table); do_plot(table, document.getElementById('plot')); var stats = document.getElementById('stats').getElementsByTagName('table')[0]; diff --git a/images/reverse.png b/images/reverse.png new file mode 100644 index 0000000..d16778f Binary files /dev/null and b/images/reverse.png differ diff --git a/lib/entry.php b/lib/entry.php index e41abcd..761f805 100644 --- a/lib/entry.php +++ b/lib/entry.php @@ -86,11 +86,12 @@ return false; } - function show_leg($station, $start_finish, $station_id, $system_id, $order, $n) { + function show_leg($station, $start_finish, $station_id, $system_id, $order, $reverse, $n) { $td_class = $start_finish ? " class=\"$start_finish\"" : ''; echo "\n"; $classes = array("station$station_id", "system$system_id"); if (is_int($order)) $classes[] = "order$order"; + if ($start_finish && $reverse) $classes[] = "reverse"; $class_list = implode(' ', $classes); echo "

$station

\n"; echo "

\n"; @@ -133,6 +134,7 @@ } } $event = $race->getEvent(); + $reverse = $race->getReverse(); $allotted_time = 0 + $race->getAllottedTime(); $legs = array(); $system_ids = array(); @@ -183,6 +185,9 @@ } if ($entry) retrieve_entry($entry); if ($_POST['lap1station1']) { + /* Don't show the swap start/finish icon. */ + $reverse = false; + echo "var reverse = false;\n"; /* XXX: Trust client validation only because furrycat is the only user and he can vouch for himself. @@ -212,7 +217,10 @@ return true; } } - else echo "//-->\n"; + else { + echo "var reverse = " . json_encode($reverse) . ";\n"; + echo "//-->\n"; + } if (! $entry) { $sq = new ShipQuery; $sq->joinWith('Ship.Competitor'); @@ -237,14 +245,14 @@ $order = 0; } else $class = ''; - show_leg($station, $class, $station_id, $system_id, $order, ++$n); + show_leg($station, $class, $station_id, $system_id, $order, $reverse, ++$n); } foreach ($legs as $station => $attributes) { list($flags, $station_id, $system_id, $order) = $attributes; if (! ($flags & Course::FinishFlag())) continue; /* Last leg. */ $order = 0; - show_leg($station, 'finish_line', $station_id, $system_id, $order, ++$n); + show_leg($station, 'finish_line', $station_id, $system_id, $order, $reverse, ++$n); } echo "\n"; echo ""; diff --git a/lib/race.php b/lib/race.php index e3bf483..fd23fdd 100644 --- a/lib/race.php +++ b/lib/race.php @@ -476,9 +476,12 @@ $race->setClassName($name); $race->setEventId($event_id); if ($hull_id) $race->setHullId($hull_id); + else $race->setHullId(null); if ($allotted_time) $race->setAllottedTime($allotted_time); - $optional = $posted['optional']; + $optional = $_POST['optional']; if (is_int($optional) && $optional > 0) $race->setWaypoints($optional); + $reverse = $_POST['reverse']; + if ($reverse) $race->setReverse(true); $prizes = 0; foreach ($posted as $k => $v) { if (! preg_match('/^prize_(.+)$/', $k, $m)) continue; @@ -568,9 +571,13 @@ echo "

\n"; echo "

Waypoints

\n"; - echo "

Number of optional waypoints: "; + echo "

"; + echo "\n"; + echo "

\n"; + echo "