mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Keybinding now works in the actual race. A map of keybind is shared between GameClient and KeyBindDialogController.
#story[1278]
This commit is contained in:
@@ -7,6 +7,7 @@ import java.time.ZoneOffset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
@@ -28,6 +29,7 @@ import seng302.gameServer.messages.BoatAction;
|
||||
import seng302.gameServer.messages.BoatStatus;
|
||||
import seng302.gameServer.messages.YachtEventType;
|
||||
import seng302.model.ClientYacht;
|
||||
import seng302.model.GameClientAction;
|
||||
import seng302.model.RaceState;
|
||||
import seng302.model.stream.packets.StreamPacket;
|
||||
import seng302.model.stream.parser.MarkRoundingData;
|
||||
@@ -65,6 +67,7 @@ public class GameClient {
|
||||
private RaceViewController raceViewController;
|
||||
|
||||
private ArrayList<ClientYacht> finishedBoats = new ArrayList<>();
|
||||
private Map<GameClientAction, KeyCode> keyBind = new HashMap<>();
|
||||
|
||||
private ObservableList<String> clientLobbyList = FXCollections.observableArrayList();
|
||||
|
||||
@@ -75,6 +78,21 @@ public class GameClient {
|
||||
*/
|
||||
public GameClient(Pane holder) {
|
||||
this.holderPane = holder;
|
||||
initialiseKeyBind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise default keybind.
|
||||
*/
|
||||
private void initialiseKeyBind() {
|
||||
keyBind = new HashMap<>();
|
||||
keyBind.put(GameClientAction.ZOOM_IN, KeyCode.Z);
|
||||
keyBind.put(GameClientAction.ZOOM_OUT, KeyCode.X);
|
||||
keyBind.put(GameClientAction.VMG, KeyCode.SPACE);
|
||||
keyBind.put(GameClientAction.SAILS_STATE, KeyCode.SHIFT);
|
||||
keyBind.put(GameClientAction.TACK_GYBE, KeyCode.ENTER);
|
||||
keyBind.put(GameClientAction.UPWIND, KeyCode.PAGE_UP);
|
||||
keyBind.put(GameClientAction.DOWNWIND, KeyCode.PAGE_DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -373,16 +391,16 @@ public class GameClient {
|
||||
}
|
||||
return;
|
||||
}
|
||||
switch (e.getCode()) {
|
||||
case SPACE: // align with vmg
|
||||
socketThread.sendBoatAction(BoatAction.VMG); break;
|
||||
case PAGE_UP: // upwind
|
||||
socketThread.sendBoatAction(BoatAction.UPWIND); break;
|
||||
case PAGE_DOWN: // downwind
|
||||
socketThread.sendBoatAction(BoatAction.DOWNWIND); break;
|
||||
case ENTER: // tack/gybe
|
||||
// if chat box is active take whatever is in there and send it to server
|
||||
socketThread.sendBoatAction(BoatAction.TACK_GYBE); break;
|
||||
|
||||
if (keyBind.get(GameClientAction.VMG) == e.getCode()) { // align with vmg
|
||||
socketThread.sendBoatAction(BoatAction.VMG);
|
||||
} else if (keyBind.get(GameClientAction.UPWIND) == e.getCode()) { // upwind
|
||||
socketThread.sendBoatAction(BoatAction.UPWIND);
|
||||
} else if (keyBind.get(GameClientAction.DOWNWIND) == e.getCode()) { // downwind
|
||||
socketThread.sendBoatAction(BoatAction.DOWNWIND);
|
||||
} else if (keyBind.get(GameClientAction.TACK_GYBE) == e.getCode()) { // tack/gybe
|
||||
// if chat box is active take whatever is in there and send it to server
|
||||
socketThread.sendBoatAction(BoatAction.TACK_GYBE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -391,15 +409,13 @@ public class GameClient {
|
||||
if (raceView.isChatInputFocused()) {
|
||||
return;
|
||||
}
|
||||
switch (e.getCode()) {
|
||||
//TODO 12/07/17 Determine the sail state and send the appropriate packet (eg. if sails are in, send a sail out packet)
|
||||
case SHIFT: // sails in/sails out
|
||||
socketThread.sendBoatAction(BoatAction.SAILS_IN);
|
||||
allBoatsMap.get(socketThread.getClientId()).toggleSail();
|
||||
break;
|
||||
case PAGE_UP:
|
||||
case PAGE_DOWN:
|
||||
socketThread.sendBoatAction(BoatAction.MAINTAIN_HEADING); break;
|
||||
|
||||
if (keyBind.get(GameClientAction.SAILS_STATE) == e.getCode()) { // sails in/sails out
|
||||
socketThread.sendBoatAction(BoatAction.SAILS_IN);
|
||||
allBoatsMap.get(socketThread.getClientId()).toggleSail();
|
||||
} else if (keyBind.get(GameClientAction.UPWIND) == e.getCode()
|
||||
|| keyBind.get(GameClientAction.DOWNWIND) == e.getCode()) {
|
||||
socketThread.sendBoatAction(BoatAction.MAINTAIN_HEADING);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,4 +472,8 @@ public class GameClient {
|
||||
public Map<Integer, ClientYacht> getAllBoatsMap() {
|
||||
return allBoatsMap;
|
||||
}
|
||||
|
||||
public Map<GameClientAction, KeyCode> getKeyBind() {
|
||||
return keyBind;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user