Skip to content

Commit

Permalink
WIP #4: Add APIs to mark a client ready and to set the ship the clien…
Browse files Browse the repository at this point in the history
…t will be using. Support for changing displayed model based on this still needed.
  • Loading branch information
Andrew Brindamour committed Oct 3, 2016
1 parent b8bb5db commit 2dc1215
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.brindyblitz.artemis.protocol.NonShittyShipSystemGrid;
import com.brindyblitz.artemis.utils.newton.DerivedProperty;
import com.brindyblitz.artemis.utils.newton.Property;
import com.brindyblitz.artemis.utils.newton.SettableProperty;
import com.walkertribe.ian.Context;
import com.walkertribe.ian.enums.ShipSystem;
import com.walkertribe.ian.protocol.core.eng.EngGridUpdatePacket.DamconStatus;
Expand All @@ -29,6 +30,8 @@ public abstract class BaseEngineeringConsoleManager implements EngineeringConsol
private Map<GridCoord, VesselNode> gridIndex;
private List<VesselNodeConnection> gridConnections;
protected final Context context;
protected int shipNumber = 1;
private boolean needsResetForNewGame = false;


public BaseEngineeringConsoleManager() {
Expand Down Expand Up @@ -56,7 +59,33 @@ public BaseEngineeringConsoleManager() {
}

this.shipSystemGrid = shipSystemGrid;

}

protected void afterChildConstructor() {
this.getGameState().onChange(() -> {
if (this.getGameState().get() == GameState.PREGAME) {
if (needsResetForNewGame) {
needsResetForNewGame = false;
resetForNewGame();
}
}
else if (this.getGameState().get() == GameState.INGAME) {
needsResetForNewGame = true;
}
});
}

public void resetForNewGame() {
System.out.println("Resetting for new game");
playerReady.set(false);
}

@Override
public Property<Boolean> getPlayerReady() {
return playerReady;
}
private final SettableProperty<Boolean> playerReady = new SettableProperty<>(true);


@Override
Expand Down Expand Up @@ -111,6 +140,16 @@ protected ShipSystemGrid getShipSystemGrid() {
return shipSystemGrid;
}

@Override
public void selectShip(int shipNumber) {
this.shipNumber = shipNumber;
}

@Override
public void ready() {
this.playerReady.set(true);
}

protected abstract void updateSystemEnergyAllocated(ShipSystem system, int amount);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public interface EngineeringConsoleManager {
/////////
// Get //
/////////
Property<Boolean> getPlayerReady();
Property<GameState> getGameState();
Property<Integer> getTotalShipCoolant();
Property<Map<ShipSystem, Integer>> getSystemEnergyAllocated();
Expand Down Expand Up @@ -51,6 +52,8 @@ public interface EngineeringConsoleManager {
/////////
// Set //
/////////
void selectShip(int shipNumber);
void ready();
void incrementSystemEnergyAllocated(ShipSystem system, int amount);
void incrementSystemCoolantAllocated(ShipSystem system, int amount);
void moveDamconTeam(int teamId, GridCoord coord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ public FakeEngineeringConsoleManager() {
this.gridHealth.set(gridHealth);

Executors.newSingleThreadScheduledExecutor().scheduleAtFixedRate(new HeatAndDamageGenerator(), 0, 1, TimeUnit.SECONDS);

//TODO remove once UI to invoke ready is done
Executors.newSingleThreadScheduledExecutor().schedule(() -> {
this.gameState.set(GameState.INGAME);
}, 2, TimeUnit.SECONDS);

afterChildConstructor();
}


Expand All @@ -71,6 +75,11 @@ public void disconnect() {
//intentionally do nothing
}

@Override
public void ready() {
super.ready();
this.gameState.set(GameState.INGAME);
}

@Override
public Property<GameState> getGameState() {
Expand Down
Loading

0 comments on commit 2dc1215

Please sign in to comment.