Skip to content

Commit

Permalink
WIP #12: Exposed APIs for getting and setting auto damcon on/off
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Brindamour committed Sep 18, 2016
1 parent 5426563 commit b8ace3e
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public interface EngineeringConsoleManager {
Property<Boolean> getShieldsActive();

Property<Map<OrdnanceType, Integer>> getOrdnanceCount();

Property<Boolean> getAutoDamcon();

void setSystemEnergyAllocated(ShipSystem system, int amount);

Expand All @@ -65,11 +67,14 @@ public interface EngineeringConsoleManager {
void incrementSystemCoolantAllocated(ShipSystem system, int amount);

void moveDamconTeam(int teamId, GridCoord coord);

void setAutoDamcon(boolean autoDamcon);

void resetEnergy();

void resetCoolant();


public enum GameState {
DISCONNECTED, PREGAME, INGAME, GAMEOVER
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ public Property<Map<OrdnanceType, Integer>> getOrdnanceCount() {
}
private final SettableProperty<Map<OrdnanceType, Integer>> ordnanceCount = new SettableProperty<>(DEFAULT_ORDNANCE_COUNT);

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

@Override
protected void updateSystemEnergyAllocated(ShipSystem system, int amount) {
Map<ShipSystem, Integer> energyAllocated = new HashMap<>(FakeEngineeringConsoleManager.this.systemEnergyAllocated.get());
Expand All @@ -199,6 +205,11 @@ protected void updateSystemCoolantAllocated(ShipSystem system, int amount) {

}

@Override
public void setAutoDamcon(boolean autoDamcon) {
this.autoDamcon.set(autoDamcon);
}

@Override
public void moveDamconTeam(int teamId, GridCoord coord) {
System.out.println("Moving DAMCON team " + teamId + " to grid " + coord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.walkertribe.ian.enums.ShipSystem;
import com.walkertribe.ian.protocol.core.eng.EngGridUpdatePacket.DamconStatus;
import com.walkertribe.ian.protocol.core.eng.EngSendDamconPacket;
import com.walkertribe.ian.protocol.core.eng.EngSetAutoDamconPacket;
import com.walkertribe.ian.protocol.core.eng.EngSetCoolantPacket;
import com.walkertribe.ian.protocol.core.eng.EngSetEnergyPacket;
import com.walkertribe.ian.util.GridCoord;
Expand Down Expand Up @@ -55,8 +56,7 @@ public void connect(String host, int port) {
connectionStateChangeObservable.triggerChange();
this.worldAwareServer.onEvent(WorldAwareServer.Events.CONNECTION_STATE_CHANGE, () -> connectionStateChangeObservable.triggerChange());
this.worldAwareServer.getSystemManager().events.on(EnhancedSystemManager.Events.CHANGE, () -> systemManagerChangeObservable.triggerChange());
this.worldAwareServer.getSystemManager().setPermanantSystemGrid(getShipSystemGrid());

this.worldAwareServer.getSystemManager().setPermanantSystemGrid(getShipSystemGrid());
}

public void disconnect() {
Expand Down Expand Up @@ -327,6 +327,18 @@ public Property<Map<OrdnanceType, Integer>> getOrdnanceCount() {
return result;
}, systemManagerChangeObservable);

@Override
public Property<Boolean> getAutoDamcon() {
return autoDamcon;
}
private final DerivedProperty<Boolean> autoDamcon = new DerivedProperty<>( () -> {
if (this.worldAwareServer == null || this.worldAwareServer.getSystemManager().getPlayerShip(1) == null) {
return true;
}

return this.worldAwareServer.getSystemManager().getAutoDamcon();
}, systemManagerChangeObservable);


@Override
public void incrementSystemEnergyAllocated(ShipSystem system, int amount) {
Expand Down Expand Up @@ -358,4 +370,8 @@ public void moveDamconTeam(int teamId, GridCoord coord) {
System.out.println("Moving DAMCON team " + teamId + " to grid " + coord);
this.worldAwareServer.getServer().send(new EngSendDamconPacket(teamId, coord));
}

public void setAutoDamcon(boolean autoDamcon) {
this.worldAwareServer.getServer().send(new EngSetAutoDamconPacket(autoDamcon));
}
}
1 change: 1 addition & 0 deletions src/com/brindyblitz/artemis/engconsole/ui/InGamePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public void handleKeyPress(KeyEvent e) {
System.out.println("Warp: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(WARP_JUMP_DRIVE) + "%");
System.out.println("Front Shields: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(FORE_SHIELDS) + "%");
System.out.println("Rear Shields: " + this.engineeringConsoleManager.getSystemEnergyAllocated().get().get(AFT_SHIELDS) + "%");
System.out.println("Auto Damcon: " + this.engineeringConsoleManager.getAutoDamcon().get());

// for (Entry<GridCoord, Float> entry : this.engineeringConsoleManager.getGridHealth().entrySet()) {
// System.out.println(entry.getKey() + " = " + entry.getValue());
Expand Down
12 changes: 12 additions & 0 deletions src/com/brindyblitz/artemis/protocol/EnhancedSystemManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.brindyblitz.artemis.utils.EventSubscriber;
import com.walkertribe.ian.iface.Listener;
import com.walkertribe.ian.protocol.core.GameOverPacket;
import com.walkertribe.ian.protocol.core.eng.EngAutoDamconUpdatePacket;
import com.walkertribe.ian.protocol.core.eng.EngGridUpdatePacket;
import com.walkertribe.ian.protocol.core.world.DestroyObjectPacket;
import com.walkertribe.ian.protocol.core.world.IntelPacket;
Expand All @@ -24,6 +25,7 @@ public class EnhancedSystemManager extends SystemManager {
private boolean gameOverScreen;
private ScheduledFuture<?> objectUpdateTimeout = null;
private ShipSystemGrid permanantGrid;
private boolean autoDamcon = true;

public EnhancedSystemManager() {
scheduler = Executors.newSingleThreadScheduledExecutor();
Expand Down Expand Up @@ -60,6 +62,16 @@ public void onPacket(ObjectUpdatePacket pkt) {
this.fireChange();
}

@Listener
public void onAutoDamconUpdate(EngAutoDamconUpdatePacket pkt) {
this.autoDamcon = pkt.isOn();
this.fireChange();
}

public boolean getAutoDamcon() {
return this.autoDamcon;
}

@Listener
public void onCompletelyGameOver(GameOverPacket pkt) {
this.gameOverScreen = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.walkertribe.ian.iface.Listener;
import com.walkertribe.ian.iface.ThreadedArtemisNetworkInterface;
import com.walkertribe.ian.protocol.core.TogglePerspectivePacket;
import com.walkertribe.ian.protocol.core.eng.EngSetAutoDamconPacket;
import com.walkertribe.ian.protocol.core.setup.ReadyPacket;
import com.walkertribe.ian.protocol.core.setup.ReadyPacket2;
import com.walkertribe.ian.protocol.core.setup.SetConsolePacket;
Expand Down Expand Up @@ -46,6 +47,7 @@ public void onConnectSuccess(ConnectionSuccessEvent event) {
server.send(new ReadyPacket());
server.send(new ReadyPacket2());
server.send(new TogglePerspectivePacket());
server.send(new EngSetAutoDamconPacket(true));
}

@Override
Expand Down

0 comments on commit b8ace3e

Please sign in to comment.