mirror of
https://github.com/sirjonasxx/G-Earth.git
synced 2024-11-23 08:50:52 +01:00
some scheduler stuff
This commit is contained in:
parent
e7d7e243a7
commit
1c4c7b03c0
@ -11,6 +11,7 @@ import javafx.beans.property.SimpleObjectProperty;
|
||||
import gearth.misc.StringifyAble;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
/**
|
||||
* Created by Jonas on 07/04/18.
|
||||
@ -20,20 +21,20 @@ public class ScheduleItem {
|
||||
private SimpleIntegerProperty indexProperty;
|
||||
private SimpleBooleanProperty pausedProperty;
|
||||
private SimpleObjectProperty<Interval> delayProperty;
|
||||
private SimpleObjectProperty<HPacket> packetProperty;
|
||||
private SimpleObjectProperty<HMessage.Direction> destinationProperty;
|
||||
private SimpleStringProperty packetAsStringProperty;
|
||||
|
||||
|
||||
public ScheduleItem() {}
|
||||
public ScheduleItem (int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
|
||||
construct(index, paused, delay, packet, destination);
|
||||
public ScheduleItem (int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) {
|
||||
construct(index, paused, delay, packetAsString, destination);
|
||||
}
|
||||
|
||||
protected void construct(int index, boolean paused, Interval delay, HPacket packet, HMessage.Direction destination) {
|
||||
protected void construct(int index, boolean paused, Interval delay, String packetAsString, HMessage.Direction destination) {
|
||||
this.indexProperty = new SimpleIntegerProperty(index);
|
||||
this.pausedProperty = new SimpleBooleanProperty(paused);
|
||||
this.delayProperty = new SimpleObjectProperty<>(delay);
|
||||
this.packetProperty = new SimpleObjectProperty<>(packet);
|
||||
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
|
||||
this.destinationProperty = new SimpleObjectProperty<>(destination);
|
||||
}
|
||||
|
||||
@ -49,8 +50,8 @@ public class ScheduleItem {
|
||||
return delayProperty;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<HPacket> getPacketProperty() {
|
||||
return packetProperty;
|
||||
public SimpleStringProperty getPacketAsStringProperty() {
|
||||
return packetAsStringProperty;
|
||||
}
|
||||
|
||||
public SimpleObjectProperty<HMessage.Direction> getDestinationProperty() {
|
||||
|
@ -2,6 +2,7 @@ package gearth.services.scheduler;
|
||||
|
||||
import gearth.protocol.HConnection;
|
||||
import gearth.protocol.HMessage;
|
||||
import gearth.protocol.HPacket;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
@ -36,11 +37,13 @@ public class Scheduler<T extends ScheduleItem> {
|
||||
Interval cur = item.getDelayProperty().get();
|
||||
for (int i = 0; i < changed; i++) {
|
||||
if ((t - i) % cur.getDelay() == cur.getOffset()) {
|
||||
HPacket hPacket = new HPacket(item.getPacketAsStringProperty().getName());
|
||||
|
||||
if (item.getDestinationProperty().get() == HMessage.Direction.TOSERVER) {
|
||||
connection.sendToServerAsync(item.getPacketProperty().get());
|
||||
connection.sendToServer(hPacket);
|
||||
}
|
||||
else {
|
||||
connection.sendToClientAsync(item.getPacketProperty().get());
|
||||
connection.sendToClient(hPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,21 +15,15 @@ import javafx.beans.property.SimpleStringProperty;
|
||||
|
||||
public class InteractableScheduleItem extends ScheduleItem implements StringifyAble {
|
||||
|
||||
private SimpleStringProperty packetAsStringProperty;
|
||||
|
||||
public InteractableScheduleItem(int index, boolean paused, Interval delay, HPacket packet, String inputPacket, HMessage.Direction destination) {
|
||||
super(index, paused, delay, packet, destination);
|
||||
this.packetAsStringProperty = new SimpleStringProperty(inputPacket);
|
||||
public InteractableScheduleItem(int index, boolean paused, Interval delay, String inputPacket, HMessage.Direction destination) {
|
||||
super(index, paused, delay, inputPacket, destination);
|
||||
}
|
||||
|
||||
public InteractableScheduleItem(String stringifyAbleRepresentation) {
|
||||
constructFromString(stringifyAbleRepresentation);
|
||||
}
|
||||
|
||||
public SimpleStringProperty getPacketAsStringProperty() {
|
||||
return packetAsStringProperty;
|
||||
}
|
||||
|
||||
private Observable<OnDeleteListener> onDeleteObservable = new Observable<>(OnDeleteListener::onDelete);
|
||||
public void onDelete(OnDeleteListener listener) {
|
||||
onDeleteObservable.addListener(listener);
|
||||
@ -72,8 +66,6 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
|
||||
.append("\t")
|
||||
.append(getDelayProperty().get().toString())
|
||||
.append("\t")
|
||||
// .append(getPacketProperty().get().toString())
|
||||
// .append("\t")
|
||||
.append(getDestinationProperty().get().name())
|
||||
.append("\t")
|
||||
.append(getPacketAsStringProperty().get());
|
||||
@ -87,13 +79,10 @@ public class InteractableScheduleItem extends ScheduleItem implements StringifyA
|
||||
int index = Integer.parseInt(parts[0]);
|
||||
boolean paused = parts[1].equals("true");
|
||||
Interval delay = new Interval(parts[2]);
|
||||
// HPacket packet = new HPacket(parts[3]);
|
||||
HMessage.Direction direction = parts[3].equals(HMessage.Direction.TOSERVER.name()) ? HMessage.Direction.TOSERVER : HMessage.Direction.TOCLIENT;
|
||||
String packetAsString = parts[4];
|
||||
HPacket packet = new HPacket(packetAsString);
|
||||
|
||||
construct(index, paused, delay, packet, direction);
|
||||
this.packetAsStringProperty = new SimpleStringProperty(packetAsString);
|
||||
construct(index, paused, delay, packetAsString, direction);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user