Support for color in hologram. Renamed classes: fixes #72

This commit is contained in:
simon 2017-12-30 19:58:47 -05:00
parent 1ed9e9e4db
commit 83f05efff6
10 changed files with 32 additions and 28 deletions

View File

@ -17,6 +17,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
private String hologramString = "";
private HologramMode hologramMode = HologramMode.CLEARED;
private HologramMode lastHologramMode = HologramMode.CLEARED;
private int hologramColor = 0;
/**
* Hit points
@ -34,8 +35,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
private ConsoleMode consoleMode = ConsoleMode.NORMAL;
private ConsoleMode lastConsoleMode = ConsoleMode.NORMAL;
private FloppyDisk floppyDisk;
private User parent;
private int energy;
@ -103,6 +102,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
json.put("holo", hologram);
json.put("holoStr", hologramString);
json.put("holoMode", lastHologramMode.ordinal());
json.put("holoC", hologramColor);
json.put("energy", energy);
if (parent != null) {
@ -236,8 +236,7 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
CLEARED,
HEX,
STRING,
DEC,
COLOR
DEC
}
public enum ConsoleMode {
@ -270,4 +269,8 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Pr
public void setConsoleMode(ConsoleMode consoleMode) {
this.consoleMode = consoleMode;
}
public void setHologramColor(int hologramColor) {
this.hologramColor = hologramColor;
}
}

View File

@ -10,7 +10,7 @@ import org.json.simple.JSONObject;
import java.awt.*;
import java.util.ArrayList;
public class ComPort extends CpuHardware {
public class CubotComPort extends CpuHardware {
public static final char HWID = 0xD;
public static final int DEFAULT_ADDRESS = 0xD;
@ -22,7 +22,7 @@ public class ComPort extends CpuHardware {
private static final int FRONT_PORT_OUT = 2;
private static final int SELF_OUT = 3;
public ComPort(Cubot cubot) {
public CubotComPort(Cubot cubot) {
this.cubot = cubot;
}
@ -126,7 +126,7 @@ public class ComPort extends CpuHardware {
return json;
}
public static ComPort deserialize(JSONObject json) {
return new ComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) json.get("cubot")));
public static CubotComPort deserialize(JSONObject json) {
return new CubotComPort((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) json.get("cubot")));
}
}

View File

@ -71,8 +71,7 @@ public class CubotHologram extends CpuHardware {
int b = getCpu().getRegisterSet().getRegister("B").getValue();
int c = getCpu().getRegisterSet().getRegister("C").getValue();
cubot.setHologramMode(Cubot.HologramMode.COLOR);
cubot.setHologram((c | (b << 16)) & 0x00FFFFFF); //B:C, ignore first byte
cubot.setHologramColor((c | (b << 16))); //B:C
}
}

View File

@ -5,7 +5,7 @@ import net.simon987.server.assembly.CpuHardware;
import net.simon987.server.assembly.Status;
import org.json.simple.JSONObject;
public class Keyboard extends CpuHardware {
public class CubotKeyboard extends CpuHardware {
public static final int DEFAULT_ADDRESS = 4;
@ -19,7 +19,7 @@ public class Keyboard extends CpuHardware {
private Cubot cubot;
public Keyboard(Cubot cubot) {
public CubotKeyboard(Cubot cubot) {
this.cubot = cubot;
}
@ -61,7 +61,7 @@ public class Keyboard extends CpuHardware {
return json;
}
public static Keyboard deserialize(JSONObject hwJSON) {
return new Keyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
public static CubotKeyboard deserialize(JSONObject hwJSON) {
return new CubotKeyboard((Cubot) GameServer.INSTANCE.getGameUniverse().getObject((int) (long) hwJSON.get("cubot")));
}
}

View File

@ -50,16 +50,16 @@ public class CubotPlugin extends ServerPlugin implements GameObjectDeserializer,
return CubotDrill.deserialize(hwJson);
case CubotInventory.HWID:
return CubotInventory.deserialize(hwJson);
case Keyboard.HWID:
return Keyboard.deserialize(hwJson);
case CubotKeyboard.HWID:
return CubotKeyboard.deserialize(hwJson);
case CubotHologram.HWID:
return CubotHologram.deserialize(hwJson);
case CubotBattery.HWID:
return CubotBattery.deserialize(hwJson);
case CubotFloppyDrive.HWID:
return CubotFloppyDrive.deserialize(hwJson);
case ComPort.HWID:
return ComPort.deserialize(hwJson);
case CubotComPort.HWID:
return CubotComPort.deserialize(hwJson);
}
return null;

View File

@ -26,7 +26,7 @@ public class CpuInitialisationListener implements GameEventListener {
laserHw.setCpu(cpu);
CubotLidar radarHw = new CubotLidar((Cubot) user.getControlledUnit());
radarHw.setCpu(cpu);
Keyboard keyboard = new Keyboard((Cubot) user.getControlledUnit());
CubotKeyboard keyboard = new CubotKeyboard((Cubot) user.getControlledUnit());
keyboard.setCpu(cpu);
CubotDrill drillHw = new CubotDrill((Cubot) user.getControlledUnit());
drillHw.setCpu(cpu);
@ -38,19 +38,19 @@ public class CpuInitialisationListener implements GameEventListener {
batteryHw.setCpu(cpu);
CubotFloppyDrive floppyHw = new CubotFloppyDrive((Cubot) user.getControlledUnit());
floppyHw.setCpu(cpu);
ComPort comPortHw = new ComPort((Cubot) user.getControlledUnit());
CubotComPort comPortHw = new CubotComPort((Cubot) user.getControlledUnit());
comPortHw.setCpu(cpu);
cpu.attachHardware(legHw, CubotLeg.DEFAULT_ADDRESS);
cpu.attachHardware(laserHw, CubotLaser.DEFAULT_ADDRESS);
cpu.attachHardware(radarHw, CubotLidar.DEFAULT_ADDRESS);
cpu.attachHardware(keyboard, Keyboard.DEFAULT_ADDRESS);
cpu.attachHardware(keyboard, CubotKeyboard.DEFAULT_ADDRESS);
cpu.attachHardware(drillHw, CubotDrill.DEFAULT_ADDRESS);
cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS);
cpu.attachHardware(invHw, CubotInventory.DEFAULT_ADDRESS);
cpu.attachHardware(emoteHw, CubotHologram.DEFAULT_ADDRESS);
cpu.attachHardware(batteryHw, CubotBattery.DEFAULT_ADDRESS);
cpu.attachHardware(floppyHw, CubotFloppyDrive.DEFAULT_ADDRESS);
cpu.attachHardware(comPortHw, ComPort.DEFAULT_ADDRESS);
cpu.attachHardware(comPortHw, CubotComPort.DEFAULT_ADDRESS);
}
}

View File

@ -6,6 +6,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
@ -15,5 +16,7 @@
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.42" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-text:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.7" level="project" />
</component>
</module>

View File

@ -22,6 +22,7 @@ public class Main {
GameServer.INSTANCE.setSocketServer(socketServer);
System.out.println(GameServer.INSTANCE.getGameUniverse().getWorld(0x7fff, 0x7fff));
(new Thread(socketServer)).start();
(new Thread(GameServer.INSTANCE)).start();

View File

@ -28,8 +28,8 @@ public class DivInstruction extends Instruction {
public Status execute(Target src, int srcIndex, Status status) {
//Source = Y:A
int source = ((((char) cpu.getRegisterSet().getRegister("Y").getValue() & 0xFFFF) << 16)) |
((char) cpu.getRegisterSet().getRegister("A").getValue() & 0xFFFF);
int source = (((cpu.getRegisterSet().getRegister("Y").getValue() & 0xFFFF) << 16)) |
(cpu.getRegisterSet().getRegister("A").getValue() & 0xFFFF);
if (src.get(srcIndex) == 0) {
//Division by 0
@ -48,8 +48,8 @@ public class DivInstruction extends Instruction {
//Source = Y:A
int source = ((((char) cpu.getRegisterSet().getRegister("Y").getValue() & 0xFFFF) << 16)) |
((char) cpu.getRegisterSet().getRegister("A").getValue() & 0xFFFF);
int source = (((cpu.getRegisterSet().getRegister("Y").getValue() & 0xFFFF) << 16)) |
(cpu.getRegisterSet().getRegister("A").getValue() & 0xFFFF);
if (src == 0) {
//Division by 0

View File

@ -180,8 +180,6 @@ public class SocketServer extends WebSocketServer {
try {
ControllableUnit unit = user.getUser().getControlledUnit();
System.out.println("Sent " + unit.getConsoleMessagesBuffer().size() + " messages to " + user.getUser().getUsername());
//Send keyboard updated buffer
ArrayList<Integer> kbBuffer = unit.getKeyboardBuffer();
JSONArray keys = new JSONArray();