Boat Names Change. Colors Change too. Updates clients during lobby when a change is made.

tags: #story[1142]
This commit is contained in:
Alistair McIntyre
2017-08-16 19:31:27 +12:00
parent 6d045e9976
commit 02a7b804c1
9 changed files with 67 additions and 15 deletions
@@ -6,6 +6,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import javafx.scene.paint.Color;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.slf4j.Logger; import org.slf4j.Logger;
@@ -578,9 +579,14 @@ public class GameState implements Runnable {
if (requestType.equals(CustomizeRequestType.NAME)) { if (requestType.equals(CustomizeRequestType.NAME)) {
String name = new String(customizeData); String name = new String(customizeData);
System.out.println(playerYacht.getBoatName());
playerYacht.setBoatName(name); playerYacht.setBoatName(name);
System.out.println(playerYacht.getBoatName()); } else if (requestType.equals(CustomizeRequestType.COLOR)) {
System.out.println(customizeData.length);
int red = customizeData[0] & 0xFF;
int green = customizeData[1] & 0xFF;
int blue = customizeData[2] & 0xFF;
Color yachtColor = Color.rgb(red, green, blue);
playerYacht.setBoatColor(yachtColor);
} }
} }
@@ -1,6 +1,5 @@
package seng302.gameServer; package seng302.gameServer;
import gherkin.lexer.Fi;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@@ -8,8 +7,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import seng302.gameServer.server.messages.BoatSubMessage;
import seng302.gameServer.server.messages.*; import seng302.gameServer.server.messages.Message;
import seng302.gameServer.server.messages.RaceStartNotificationType;
import seng302.gameServer.server.messages.RaceStartStatusMessage;
import seng302.gameServer.server.messages.RaceStatus;
import seng302.gameServer.server.messages.RaceStatusMessage;
import seng302.gameServer.server.messages.RaceType;
import seng302.model.GeoPoint; import seng302.model.GeoPoint;
import seng302.model.Player; import seng302.model.Player;
import seng302.model.PolarTable; import seng302.model.PolarTable;
@@ -73,6 +77,14 @@ public class MainServerThread implements Runnable, ClientConnectionDelegate {
serverLog("Interrupted exception in Main Server Thread thread sleep", 1); serverLog("Interrupted exception in Main Server Thread thread sleep", 1);
} }
if (GameState.getCurrentStage() == GameStages.LOBBYING) {
// TODO: 16/08/17 ajm412: This can probably be done in a nicer way via those fancy functional interfaces.
for (ServerToClientThread thread : serverToClientThreads) {
thread.sendSetupMessages();
}
}
if (GameState.getCurrentStage() == GameStages.PRE_RACE) { if (GameState.getCurrentStage() == GameStages.PRE_RACE) {
updateClients(); updateClients();
} }
@@ -211,6 +211,7 @@ public class ServerToClientThread implements Runnable, Observer {
new StreamPacket(type, payloadLength, timeStamp, payload)); new StreamPacket(type, payloadLength, timeStamp, payload));
GameState.customizePlayer(sourceID, requestType, GameState.customizePlayer(sourceID, requestType,
Arrays.copyOfRange(payload, 6, payload.length)); Arrays.copyOfRange(payload, 6, payload.length));
sendSetupMessages();
break; break;
} }
} else { } else {
@@ -3,6 +3,7 @@ package seng302.model;
import java.util.HashMap; import java.util.HashMap;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import javafx.scene.paint.Color;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
@@ -30,6 +31,8 @@ public class ServerYacht extends Observable {
private String country; private String country;
private BoatStatus boatStatus; private BoatStatus boatStatus;
private Color boatColor;
//Location //Location
private Double lastHeading; private Double lastHeading;
@@ -65,6 +68,7 @@ public class ServerYacht extends Observable {
this.heading = 120.0; //In degrees this.heading = 120.0; //In degrees
this.currentVelocity = 0d; //in mms-1 this.currentVelocity = 0d; //in mms-1
this.currentMarkSeqID = 0; this.currentMarkSeqID = 0;
this.boatColor = Color.rgb(0, 0, 0);
this.hasEnteredRoundingZone = false; this.hasEnteredRoundingZone = false;
this.hasPassedLine = false; this.hasPassedLine = false;
@@ -385,5 +389,12 @@ public class ServerYacht extends Observable {
return hasPassedLine; return hasPassedLine;
} }
public void setBoatColor(Color color) {
this.boatColor = color;
}
public Color getBoatColor() {
return boatColor;
}
} }
@@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javafx.scene.paint.Color;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@@ -142,6 +143,7 @@ public class XMLParser {
XMLParser.getNodeAttributeString(currentBoat, "ShortName"), XMLParser.getNodeAttributeString(currentBoat, "ShortName"),
XMLParser.getNodeAttributeString(currentBoat, "BoatName"), XMLParser.getNodeAttributeString(currentBoat, "BoatName"),
XMLParser.getNodeAttributeString(currentBoat, "Country")); XMLParser.getNodeAttributeString(currentBoat, "Country"));
yacht.setColour(Color.web(getNodeAttributeString(currentBoat, "Color")));
if (yacht.getBoatType().equals("Yacht")) { if (yacht.getBoatType().equals("Yacht")) {
competingBoats.put(yacht.getSourceId(), yacht); competingBoats.put(yacht.getSourceId(), yacht);
} }
@@ -23,9 +23,8 @@ import javafx.scene.paint.Paint;
import javafx.scene.shape.Circle; import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon; import javafx.scene.shape.Polygon;
import javafx.scene.text.Text; import javafx.scene.text.Text;
import seng302.model.ClientYacht;
import javafx.util.Duration; import javafx.util.Duration;
import seng302.model.Colors; import seng302.model.ClientYacht;
import seng302.model.GeoPoint; import seng302.model.GeoPoint;
import seng302.model.Limit; import seng302.model.Limit;
import seng302.model.mark.CompoundMark; import seng302.model.mark.CompoundMark;
@@ -351,7 +350,7 @@ public class GameView extends Pane {
BoatObject newBoat; BoatObject newBoat;
final List<Group> wakes = new ArrayList<>(); final List<Group> wakes = new ArrayList<>();
for (ClientYacht clientYacht : clientYachts) { for (ClientYacht clientYacht : clientYachts) {
Paint colour = Colors.getColor(); Paint colour = clientYacht.getColour();
newBoat = new BoatObject(); newBoat = new BoatObject();
newBoat.setFill(colour); newBoat.setFill(colour);
boatObjects.put(clientYacht, newBoat); boatObjects.put(clientYacht, newBoat);
@@ -4,6 +4,8 @@ import javafx.fxml.FXML;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker; import javafx.scene.control.ColorPicker;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import seng302.gameServer.server.messages.CustomizeRequestType; import seng302.gameServer.server.messages.CustomizeRequestType;
import seng302.visualiser.ClientToServerThread; import seng302.visualiser.ClientToServerThread;
@@ -19,6 +21,7 @@ public class CustomizationController {
private Button customizeSubmit; private Button customizeSubmit;
private ClientToServerThread socketThread; private ClientToServerThread socketThread;
private Stage windowStage;
public void initialize() { public void initialize() {
@@ -33,8 +36,24 @@ public class CustomizationController {
System.out.println("Attempting to send"); System.out.println("Attempting to send");
socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, nameField.getText().getBytes()); socketThread.sendCustomizationRequest(CustomizeRequestType.NAME, nameField.getText().getBytes());
// TODO: 16/08/17 ajm412: Turn colors into byte array. // TODO: 16/08/17 ajm412: Turn colors into byte array.
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, Color color = boatColorPicker.getValue();
boatColorPicker.getValue().toString().getBytes());
short red = (short) (color.getRed() * 255);
short green = (short) (color.getGreen() * 255);
short blue = (short) (color.getBlue() * 255);
byte[] colorArray = new byte[3];
colorArray[0] = (byte) red;
colorArray[1] = (byte) green;
colorArray[2] = (byte) blue;
socketThread.sendCustomizationRequest(CustomizeRequestType.COLOR, colorArray);
windowStage.close();
}
public void setStage(Stage stage) {
this.windowStage = stage;
} }
@@ -1,7 +1,10 @@
package seng302.visualiser.controllers; package seng302.visualiser.controllers;
import java.util.*; import com.sun.media.jfxmedia.logging.Logger;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
@@ -18,9 +21,7 @@ import javafx.stage.Stage;
import seng302.gameServer.GameStages; import seng302.gameServer.GameStages;
import seng302.gameServer.GameState; import seng302.gameServer.GameState;
import seng302.model.RaceState; import seng302.model.RaceState;
import seng302.visualiser.GameClient;
import seng302.visualiser.ClientToServerThread; import seng302.visualiser.ClientToServerThread;
import seng302.visualiser.GameView;
/** /**
* A class describing the actions of the lobby screen * A class describing the actions of the lobby screen
@@ -153,6 +154,7 @@ public class LobbyController {
cc.setServerThread(this.socketThread); cc.setServerThread(this.socketThread);
customizeStage.setTitle("Customize Boat"); customizeStage.setTitle("Customize Boat");
customizeStage.setScene(new Scene(root, 700, 450)); customizeStage.setScene(new Scene(root, 700, 450));
cc.setStage(customizeStage); // pass the stage through so it can be closed later.
customizeStage.show(); customizeStage.show();
} catch (IOException e) { } catch (IOException e) {
Logger.logMsg(4, "Failed to load Customization View from resources."); Logger.logMsg(4, "Failed to load Customization View from resources.");
@@ -13,7 +13,7 @@
<Boats> <Boats>
<#list boats as boat> <#list boats as boat>
<Boat Type="Yacht" SourceID="${boat.sourceId}" ShapeID="4" HullNum="${boat.hullID}" StoweName="${boat.shortName}" ShortName="${boat.shortName}" <Boat Type="Yacht" SourceID="${boat.sourceId}" ShapeID="4" HullNum="${boat.hullID}" StoweName="${boat.shortName}" ShortName="${boat.shortName}"
BoatName="${boat.boatName}" Country="${boat.country}"> BoatName="${boat.boatName}" Country="${boat.country}" Color="${boat.boatColor}">
<GPSposition Z="0" Y="3.7" X="0" /> <GPSposition Z="0" Y="3.7" X="0" />
<MastTop Z="0" Y="6.2" X="0" /> <MastTop Z="0" Y="6.2" X="0" />
</Boat> </Boat>