Visualiser ConnectionController:
Clicking the host button doesn't create more than one server.
This commit is contained in:
@@ -43,6 +43,13 @@ public class ConnectionController extends Controller {
|
|||||||
|
|
||||||
private ObservableList<RaceConnection> connections;
|
private ObservableList<RaceConnection> connections;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents whether the client is currently hosting a game already - this is to ensure they don't launch multiple servers.
|
||||||
|
*/
|
||||||
|
private boolean currentlyHostingGame = false;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
// TODO - replace with config file
|
// TODO - replace with config file
|
||||||
@@ -104,12 +111,17 @@ public class ConnectionController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public void addLocal() {
|
public void addLocal() {
|
||||||
try {
|
try {
|
||||||
|
//We don't want to host more than one game.
|
||||||
|
if (!currentlyHostingGame) {
|
||||||
Event game = Event.getEvent();
|
Event game = Event.getEvent();
|
||||||
urlField.textProperty().set(game.getAddress());
|
urlField.textProperty().set(game.getAddress());
|
||||||
portField.textProperty().set(Integer.toString(game.getPort()));
|
portField.textProperty().set(Integer.toString(game.getPort()));
|
||||||
|
|
||||||
game.start();
|
game.start();
|
||||||
addConnection();
|
addConnection();
|
||||||
|
|
||||||
|
currentlyHostingGame = true;
|
||||||
|
}
|
||||||
} catch (InvalidRaceDataException e) {
|
} catch (InvalidRaceDataException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (XMLReaderException e) {
|
} catch (XMLReaderException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user