feat: deal with multiple eva-numbers for a "single" station; fixes
This commit is contained in:
40
index.html
40
index.html
@@ -466,8 +466,17 @@ function hideFocusDeparturePanel() {
|
||||
}
|
||||
domFocusedDeparturePanelCloseClickable.addEventListener("click", hideFocusDeparturePanel);
|
||||
|
||||
function goInGame() {
|
||||
async function goInGame() {
|
||||
isInGame = true;
|
||||
// make server get all eva numbers of the destination station
|
||||
let testDestinationDepartures = await (await fetch("./query_departures/" + encodeURIComponent(transportModesInteger) + "/" + encodeURIComponent(stationDestination.evaNumber) + "/")).json();
|
||||
if (testDestinationDepartures[1].length < 10) {
|
||||
if (!window.confirm("Warning: Low activity (" + testDestinationDepartures[1].length + ") at the specified destination. It may not be possible to win.")) {
|
||||
isInGame = false;
|
||||
return;
|
||||
}
|
||||
}
|
||||
stationDestination.relatedEvaNumbers = testDestinationDepartures[0];
|
||||
for (const elem of draggableElements) elem.style.cursor = "default";
|
||||
draggableElements = new Array();
|
||||
domWelcome.style.display = "none";
|
||||
@@ -480,20 +489,23 @@ domStartGameButton.onclick = () => goInGame();
|
||||
async function reloadDepartures() {
|
||||
domDeparturesList.replaceChildren();
|
||||
hideFocusDeparturePanel();
|
||||
let currentEvaNumber = stationCurrent.evaNumber;
|
||||
if (currentEvaNumber === stationDestination.evaNumber) {
|
||||
// TODO: obv
|
||||
alert("You won! Unfortunately, i haven't made a screen for that yet...");
|
||||
location.reload();
|
||||
if (stationDestination.evaNumber === stationCurrent.evaNumber || (stationDestination.relatedEvaNumbers && stationDestination.relatedEvaNumbers.includes(stationCurrent.evaNumber))) {
|
||||
endGameWin();
|
||||
return;
|
||||
}
|
||||
let response = await fetch("./query_departures/" + encodeURIComponent(transportModesInteger) + "/" + encodeURIComponent(currentEvaNumber) + "/");
|
||||
let response = await fetch("./query_departures/" + encodeURIComponent(transportModesInteger) + "/" + encodeURIComponent(stationCurrent.evaNumber) + "/");
|
||||
if (!response.ok) {
|
||||
let error = await response.text();
|
||||
console.warn("Query Departures: Got error " + response.status + " from server: " + error);
|
||||
} else {
|
||||
let result = await response.json();
|
||||
for (const [route, stops, routeId] of result) {
|
||||
let [stationRelatedEvaNumbers, result] = await response.json();
|
||||
for (let relatedEvaNumber of stationRelatedEvaNumbers) {
|
||||
if (stationDestination.evaNumber === relatedEvaNumber || (stationDestination.relatedEvaNumbers && stationDestination.relatedEvaNumbers.includes(relatedEvaNumber))) {
|
||||
endGameWin();
|
||||
return;
|
||||
}
|
||||
}
|
||||
for (const [route, stopEvaNumber, stops, routeId] of result) {
|
||||
if (stops.length > 0) {
|
||||
let departureElem = document.createElement("div");
|
||||
let departureElemHead = document.createElement("div");
|
||||
@@ -543,7 +555,7 @@ async function reloadDepartures() {
|
||||
let canceled = result[1];
|
||||
let foundCurrent = true;
|
||||
for (const [stop, evaNumber] of result[0]) {
|
||||
if (evaNumber === currentEvaNumber) foundCurrent = false;
|
||||
if (evaNumber === stopEvaNumber) foundCurrent = false;
|
||||
}
|
||||
for (const [stop, evaNumber] of result[0]) {
|
||||
console.log(stop, ": ", evaNumber);
|
||||
@@ -551,7 +563,7 @@ async function reloadDepartures() {
|
||||
stopElem.innerText = stop;
|
||||
stopElem.style.wordWrap = "nowrap";
|
||||
if (!foundCurrent) {
|
||||
if (evaNumber === currentEvaNumber) {
|
||||
if (evaNumber === stopEvaNumber) {
|
||||
foundCurrent = true;
|
||||
stopElem.classList.add("DetailedViewCurrentStop");
|
||||
} else {
|
||||
@@ -574,6 +586,12 @@ async function reloadDepartures() {
|
||||
}
|
||||
}
|
||||
|
||||
function endGameWin() {
|
||||
// TODO: obv
|
||||
alert("You won! Unfortunately, i haven't made a screen for that yet...");
|
||||
location.reload();
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user