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;
|
||||
|
||||
|
||||
/**
|
||||
* 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
|
||||
public void initialize(URL location, ResourceBundle resources) {
|
||||
// TODO - replace with config file
|
||||
@@ -104,12 +111,17 @@ public class ConnectionController extends Controller {
|
||||
*/
|
||||
public void addLocal() {
|
||||
try {
|
||||
Event game = Event.getEvent();
|
||||
urlField.textProperty().set(game.getAddress());
|
||||
portField.textProperty().set(Integer.toString(game.getPort()));
|
||||
//We don't want to host more than one game.
|
||||
if (!currentlyHostingGame) {
|
||||
Event game = Event.getEvent();
|
||||
urlField.textProperty().set(game.getAddress());
|
||||
portField.textProperty().set(Integer.toString(game.getPort()));
|
||||
|
||||
game.start();
|
||||
addConnection();
|
||||
game.start();
|
||||
addConnection();
|
||||
|
||||
currentlyHostingGame = true;
|
||||
}
|
||||
} catch (InvalidRaceDataException e) {
|
||||
e.printStackTrace();
|
||||
} catch (XMLReaderException e) {
|
||||
|
||||
Reference in New Issue
Block a user