Lobby controller list view is able to react to changes in client state boats and update the list view appropriately.

#story[1055]
This commit is contained in:
Zhi You Tan
2017-07-24 11:15:10 +12:00
parent 9d754c8819
commit df2efa3329
8 changed files with 609 additions and 27 deletions
@@ -66,6 +66,7 @@ public class ClientPacketParser {
* @param packet the packet to be looked at and processed
*/
public static void parsePacket(StreamPacket packet) {
System.out.println(packet.getType());
try {
switch (packet.getType()) {
case HEARTBEAT:
@@ -283,9 +284,9 @@ public class ClientPacketParser {
if (messageType == 7) { //7 is the boat XML
boats = xmlObject.getBoatXML().getCompetingBoats();
ClientState.setBoats(xmlObject.getBoatXML().getCompetingBoats());
ClientState.setDirtyState(true);
}
if (messageType == 6) { //6 is race info xml
newRaceXmlReceived = true;
}
}
@@ -8,7 +8,7 @@ import java.util.concurrent.ConcurrentHashMap;
import seng302.models.Yacht;
/**
* Created by zyt10 on 21/07/17.
* Used by the client to store static variables to be used in game.
*/
public class ClientState {
@@ -1,10 +1,10 @@
package seng302.client;
import java.util.List;
import java.util.Observable;
/**
* Created by zyt10 on 21/07/17.
* Used by LobbyController to run a separate thread-loop
* updates the controller when change is detected.
*/
public class ClientStateQueryingRunnable extends Observable implements Runnable {
@@ -15,9 +15,21 @@ public class ClientStateQueryingRunnable extends Observable implements Runnable
@Override
public void run() {
while(!terminate) {
if (ClientState.isRaceStarted() && ClientState.isConnectedToHost()) {
// if (ClientState.isRaceStarted() && ClientState.isConnectedToHost()) {
// setChanged();
// notifyObservers();
// }
// Sleeping the thread so it will respond to the if statement below
// if you know a better fix, pls tell me :) -ryan
try {
Thread.sleep(0);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (ClientState.isDirtyState()) {
setChanged();
notifyObservers();
ClientState.setDirtyState(false);
}
}
}