-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
112 additions
and
7 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
fabric/src/main/java/com/lx862/jcm/mod/data/pids/scripting/ArrivalWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.lx862.jcm.mod.data.pids.scripting; | ||
|
||
import org.mtr.core.data.Platform; | ||
import org.mtr.core.data.Route; | ||
import org.mtr.core.operation.ArrivalResponse; | ||
import org.mtr.core.operation.CarDetails; | ||
import org.mtr.mod.client.MinecraftClientData; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public class ArrivalWrapper { | ||
public final ArrivalResponse arrivalResponse; | ||
|
||
public ArrivalWrapper(ArrivalResponse arrivalResponse) { | ||
this.arrivalResponse = arrivalResponse; | ||
} | ||
|
||
public String destination() { | ||
return arrivalResponse.getDestination(); | ||
} | ||
|
||
public long arrivalTime() { | ||
return arrivalResponse.getArrival(); | ||
} | ||
|
||
public long departureTime() { | ||
return arrivalResponse.getDeparture(); | ||
} | ||
|
||
public long deviation() { | ||
return arrivalResponse.getDeviation(); | ||
} | ||
|
||
public boolean realtime() { | ||
return arrivalResponse.getRealtime(); | ||
} | ||
|
||
public long departureIndex() { | ||
return arrivalResponse.getDepartureIndex(); | ||
} | ||
|
||
public boolean isTerminating() { | ||
return arrivalResponse.getIsTerminating(); | ||
} | ||
|
||
public Route route() { | ||
return MinecraftClientData.getInstance().routeIdMap.get(routeId()); | ||
} | ||
|
||
public long routeId() { | ||
return arrivalResponse.getRouteId(); | ||
} | ||
|
||
public String routeName() { | ||
return arrivalResponse.getRouteName(); | ||
} | ||
|
||
public String routeNumber() { | ||
return arrivalResponse.getRouteNumber(); | ||
} | ||
|
||
public int routeColor() { | ||
return arrivalResponse.getRouteColor(); | ||
} | ||
|
||
public Route.CircularState circularState() { | ||
return arrivalResponse.getCircularState(); | ||
} | ||
|
||
public Platform platform() { | ||
return MinecraftClientData.getInstance().platformIdMap.get(platformId()); | ||
} | ||
|
||
public long platformId() { | ||
return arrivalResponse.getPlatformId(); | ||
} | ||
|
||
public String platformName() { | ||
return arrivalResponse.getPlatformName(); | ||
} | ||
|
||
public int carCount() { | ||
return arrivalResponse.getCarCount(); | ||
} | ||
|
||
public void forEachCar(Consumer<CarDetails> consumer) { | ||
arrivalResponse.iterateCarDetails(consumer); | ||
} | ||
} |
30 changes: 23 additions & 7 deletions
30
fabric/src/main/java/com/lx862/jcm/mod/data/pids/scripting/ArrivalsWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,40 @@ | ||
package com.lx862.jcm.mod.data.pids.scripting; | ||
|
||
import org.mtr.core.data.Platform; | ||
import org.mtr.core.operation.ArrivalResponse; | ||
import org.mtr.libraries.it.unimi.dsi.fastutil.objects.ObjectArrayList; | ||
|
||
public class ArrivalsWrapper { | ||
public final ObjectArrayList<ArrivalResponse> arrivalsResponse; | ||
public final ObjectArrayList<ArrivalWrapper> arrivals; | ||
|
||
public ArrivalsWrapper(ObjectArrayList<ArrivalResponse> arrivalsResponse) { | ||
this.arrivalsResponse = arrivalsResponse; | ||
this.arrivals = new ObjectArrayList<>(); | ||
for(ArrivalResponse arrivalResponse : arrivalsResponse) { | ||
this.arrivals.add(new ArrivalWrapper(arrivalResponse)); | ||
} | ||
} | ||
|
||
public ArrivalResponse get(int i) { | ||
return i >= arrivalsResponse.size() ? null : arrivalsResponse.get(i); | ||
public ArrivalWrapper get(int i) { | ||
return i >= arrivals.size() ? null : arrivals.get(i); | ||
} | ||
|
||
public boolean mixedCarLength() { | ||
int car = -1; | ||
for(ArrivalResponse arrivalResponse : arrivalsResponse) { | ||
if(car == -1) car = arrivalResponse.getCarCount(); | ||
if(car != arrivalResponse.getCarCount()) return true; | ||
for(ArrivalWrapper arrivalResponse : arrivals) { | ||
if(car == -1) car = arrivalResponse.carCount(); | ||
if(car != arrivalResponse.carCount()) return true; | ||
} | ||
return false; | ||
} | ||
|
||
public ObjectArrayList<Platform> platforms() { | ||
ObjectArrayList<Platform> platforms = new ObjectArrayList<>(); | ||
for(ArrivalWrapper wrapper : arrivals) { | ||
Platform plat = wrapper.platform(); | ||
if(plat != null) { | ||
platforms.add(plat); | ||
} | ||
} | ||
return platforms; | ||
} | ||
} |