mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
Move hologram-related fields to proper class. Breaks existing database saves!
This commit is contained in:
parent
b361583252
commit
54ed05b86c
@ -15,39 +15,14 @@ import org.bson.Document;
|
|||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.*;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class Cubot extends GameObject implements Updatable, ControllableUnit, MessageReceiver,
|
public class Cubot extends GameObject implements Updatable, ControllableUnit, MessageReceiver,
|
||||||
Attackable, Rechargeable, HardwareHost {
|
Attackable, Rechargeable, HardwareHost {
|
||||||
|
|
||||||
private static final char MAP_INFO = 0x0080;
|
private static final char MAP_INFO = 0x0080;
|
||||||
|
|
||||||
/**
|
|
||||||
* Hologram value that is displayed
|
|
||||||
* <br>TODO: Move to CubotHologram class
|
|
||||||
*/
|
|
||||||
private int hologram = 0;
|
|
||||||
/**
|
|
||||||
* Hologram string that is displayed
|
|
||||||
* <br>TODO: Move to CubotHologram class
|
|
||||||
*/
|
|
||||||
private String hologramString = "";
|
|
||||||
/**
|
|
||||||
* Hologram mode that was set during this tick
|
|
||||||
* <br>TODO: Move to CubotHologram class
|
|
||||||
*/
|
|
||||||
private HologramMode hologramMode = HologramMode.CLEARED;
|
|
||||||
/**
|
|
||||||
* Hologram mode at the end of the last tick
|
|
||||||
* <br>TODO: Move to CubotHologram class
|
|
||||||
*/
|
|
||||||
private HologramMode lastHologramMode = HologramMode.CLEARED;
|
|
||||||
/**
|
|
||||||
* Hologram color code. Format is handled by the client
|
|
||||||
* <br>TODO: Move to CubotHologram class
|
|
||||||
*/
|
|
||||||
private int hologramColor = 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hit points
|
* Hit points
|
||||||
@ -148,29 +123,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
*/
|
*/
|
||||||
private CPU cpu;
|
private CPU cpu;
|
||||||
|
|
||||||
/**
|
|
||||||
* Display mode of the hologram hardware
|
|
||||||
* <br>TODO: move this inside CubotHologram class
|
|
||||||
*/
|
|
||||||
public enum HologramMode {
|
|
||||||
/**
|
|
||||||
* Display nothing
|
|
||||||
*/
|
|
||||||
CLEARED,
|
|
||||||
/**
|
|
||||||
* Display value as hexadecimal in format 0x0000
|
|
||||||
*/
|
|
||||||
HEX,
|
|
||||||
/**
|
|
||||||
* Display string
|
|
||||||
*/
|
|
||||||
STRING,
|
|
||||||
/**
|
|
||||||
* Display value as decimal
|
|
||||||
*/
|
|
||||||
DEC
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ConsoleMode {
|
public enum ConsoleMode {
|
||||||
/**
|
/**
|
||||||
* Used by the ComPort hardware - clears the console screen (client-side)
|
* Used by the ComPort hardware - clears the console screen (client-side)
|
||||||
@ -247,8 +199,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
currentAction = Action.IDLE;
|
currentAction = Action.IDLE;
|
||||||
|
|
||||||
//Same principle for hologram
|
//Same principle for hologram
|
||||||
lastHologramMode = hologramMode;
|
|
||||||
hologramMode = HologramMode.CLEARED;
|
|
||||||
|
|
||||||
//And the console
|
//And the console
|
||||||
lastConsoleMode = consoleMode;
|
lastConsoleMode = consoleMode;
|
||||||
@ -260,6 +210,10 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
//And the status..
|
//And the status..
|
||||||
lastStatus = currentStatus;
|
lastStatus = currentStatus;
|
||||||
currentStatus = 0;
|
currentStatus = 0;
|
||||||
|
|
||||||
|
for (HardwareModule module : hardwareAddresses.values()) {
|
||||||
|
module.update();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -272,16 +226,19 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
json.put("hp", hp);
|
json.put("hp", hp);
|
||||||
json.put("shield", shield);
|
json.put("shield", shield);
|
||||||
json.put("action", lastAction.ordinal());
|
json.put("action", lastAction.ordinal());
|
||||||
json.put("holo", hologram);
|
|
||||||
json.put("holoStr", hologramString);
|
|
||||||
json.put("holoMode", lastHologramMode.ordinal());
|
|
||||||
json.put("holoC", hologramColor);
|
|
||||||
json.put("energy", energy);
|
json.put("energy", energy);
|
||||||
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
json.put("parent", parent.getUsername()); //Only used client-side for now
|
json.put("parent", parent.getUsername()); //Only used client-side for now
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (HardwareModule module : hardwareAddresses.values()) {
|
||||||
|
JSONObject hwJson = module.jsonSerialise();
|
||||||
|
if (hwJson != null) {
|
||||||
|
json.put(module.getClass().getName(), hwJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -293,10 +250,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
dbObject.put("hp", hp);
|
dbObject.put("hp", hp);
|
||||||
dbObject.put("shield", shield);
|
dbObject.put("shield", shield);
|
||||||
dbObject.put("action", lastAction.ordinal());
|
dbObject.put("action", lastAction.ordinal());
|
||||||
dbObject.put("holo", hologram);
|
|
||||||
dbObject.put("holoStr", hologramString);
|
|
||||||
dbObject.put("holoMode", lastHologramMode.ordinal());
|
|
||||||
dbObject.put("holoC", hologramColor);
|
|
||||||
dbObject.put("energy", energy);
|
dbObject.put("energy", energy);
|
||||||
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
@ -331,17 +284,17 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
clearKeyboardBuffer();
|
clearKeyboardBuffer();
|
||||||
consoleMessagesBuffer.clear();
|
consoleMessagesBuffer.clear();
|
||||||
lastConsoleMessagesBuffer.clear();
|
lastConsoleMessagesBuffer.clear();
|
||||||
hologramColor = 0;
|
|
||||||
currentStatus = 0;
|
currentStatus = 0;
|
||||||
lastStatus = 0;
|
lastStatus = 0;
|
||||||
addStatus(CubotStatus.FACTORY_NEW);
|
addStatus(CubotStatus.FACTORY_NEW);
|
||||||
|
|
||||||
|
for (HardwareModule module : hardwareAddresses.values()) {
|
||||||
|
module.reset();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDeadCallback() {
|
public boolean onDeadCallback() {
|
||||||
//TODO make death event instead
|
|
||||||
// LogManager.LOGGER.info(getParent().getUsername() + "'s Cubot died");
|
|
||||||
|
|
||||||
reset();
|
reset();
|
||||||
|
|
||||||
//Teleport to spawn point
|
//Teleport to spawn point
|
||||||
@ -401,15 +354,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
return currentAction;
|
return currentAction;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHologram(int hologram) {
|
|
||||||
this.hologram = hologram;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setHologramString(String hologramString) {
|
|
||||||
this.hologramString = hologramString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getEnergy() {
|
public int getEnergy() {
|
||||||
return energy;
|
return energy;
|
||||||
}
|
}
|
||||||
@ -494,10 +438,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHologramMode(HologramMode hologramMode) {
|
|
||||||
this.hologramMode = hologramMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAction(Action action) {
|
public void setAction(Action action) {
|
||||||
currentAction = action;
|
currentAction = action;
|
||||||
@ -527,10 +467,6 @@ public class Cubot extends GameObject implements Updatable, ControllableUnit, Me
|
|||||||
this.consoleMode = consoleMode;
|
this.consoleMode = consoleMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHologramColor(int hologramColor) {
|
|
||||||
this.hologramColor = hologramColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addStatus(CubotStatus status) {
|
public void addStatus(CubotStatus status) {
|
||||||
|
|
||||||
currentStatus |= status.val;
|
currentStatus |= status.val;
|
||||||
|
@ -3,15 +3,14 @@ package net.simon987.cubotplugin;
|
|||||||
import net.simon987.server.assembly.Status;
|
import net.simon987.server.assembly.Status;
|
||||||
import net.simon987.server.game.objects.ControllableUnit;
|
import net.simon987.server.game.objects.ControllableUnit;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
public class CubotHologram extends CubotHardwareModule {
|
public class CubotHologram extends CubotHardwareModule {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hardware ID (Should be unique)
|
* Hardware ID (Should be unique)
|
||||||
*/
|
*/
|
||||||
static final char HWID = 0x0009;
|
static final char HWID = 0x0009;
|
||||||
|
|
||||||
public static final int DEFAULT_ADDRESS = 9;
|
public static final int DEFAULT_ADDRESS = 9;
|
||||||
|
|
||||||
private static final int HOLO_CLEAR = 0;
|
private static final int HOLO_CLEAR = 0;
|
||||||
@ -22,12 +21,27 @@ public class CubotHologram extends CubotHardwareModule {
|
|||||||
|
|
||||||
private static final int STR_MAX_LEN = 8;
|
private static final int STR_MAX_LEN = 8;
|
||||||
|
|
||||||
|
private int displayValue = 0;
|
||||||
|
private String displayString = "";
|
||||||
|
private HologramMode mode = HologramMode.CLEARED;
|
||||||
|
private HologramMode lastMode = HologramMode.CLEARED;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hologram color code. Format is handled by the client
|
||||||
|
*/
|
||||||
|
private int displayColor = 0;
|
||||||
|
|
||||||
public CubotHologram(Cubot cubot) {
|
public CubotHologram(Cubot cubot) {
|
||||||
super(cubot);
|
super(cubot);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CubotHologram(Document document, ControllableUnit cubot) {
|
public CubotHologram(Document document, ControllableUnit cubot) {
|
||||||
super(document, cubot);
|
super(document, cubot);
|
||||||
|
|
||||||
|
displayValue = document.getInteger("value");
|
||||||
|
displayColor = document.getInteger("color");
|
||||||
|
displayString = document.getString("string");
|
||||||
|
mode = HologramMode.values()[document.getInteger("mode")];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -36,11 +50,10 @@ public class CubotHologram extends CubotHardwareModule {
|
|||||||
char a = getCpu().getRegisterSet().getRegister("A").getValue();
|
char a = getCpu().getRegisterSet().getRegister("A").getValue();
|
||||||
|
|
||||||
if (a == HOLO_CLEAR) {
|
if (a == HOLO_CLEAR) {
|
||||||
cubot.setHologramMode(Cubot.HologramMode.CLEARED);
|
mode = HologramMode.CLEARED;
|
||||||
} else if (a == HOLO_DISPLAY_HEX) {
|
} else if (a == HOLO_DISPLAY_HEX) {
|
||||||
char b = getCpu().getRegisterSet().getRegister("B").getValue();
|
displayValue = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||||
cubot.setHologram(b);
|
mode = HologramMode.HEX;
|
||||||
cubot.setHologramMode(Cubot.HologramMode.HEX);
|
|
||||||
} else if (a == HOLO_DISPLAY_STRING) {
|
} else if (a == HOLO_DISPLAY_STRING) {
|
||||||
char x = getCpu().getRegisterSet().getRegister("X").getValue();
|
char x = getCpu().getRegisterSet().getRegister("X").getValue();
|
||||||
//Display zero-terminated string starting at X (max 8 chars)
|
//Display zero-terminated string starting at X (max 8 chars)
|
||||||
@ -58,13 +71,12 @@ public class CubotHologram extends CubotHardwareModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cubot.setHologramString(holoString.toString());
|
displayString = holoString.toString();
|
||||||
cubot.setHologramMode(Cubot.HologramMode.STRING);
|
mode = HologramMode.STRING;
|
||||||
} else if (a == HOLO_DISPLAY_DEC) {
|
} else if (a == HOLO_DISPLAY_DEC) {
|
||||||
//Display decimal number
|
//Display decimal number
|
||||||
char b = getCpu().getRegisterSet().getRegister("B").getValue();
|
displayValue = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||||
cubot.setHologram(b);
|
mode = HologramMode.DEC;
|
||||||
cubot.setHologramMode(Cubot.HologramMode.DEC);
|
|
||||||
|
|
||||||
} else if (a == HOLO_DISPLAY_COLOR) {
|
} else if (a == HOLO_DISPLAY_COLOR) {
|
||||||
|
|
||||||
@ -72,7 +84,7 @@ public class CubotHologram extends CubotHardwareModule {
|
|||||||
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
int b = getCpu().getRegisterSet().getRegister("B").getValue();
|
||||||
int c = getCpu().getRegisterSet().getRegister("C").getValue();
|
int c = getCpu().getRegisterSet().getRegister("C").getValue();
|
||||||
|
|
||||||
cubot.setHologramColor((c | (b << 16))); //B:C
|
displayColor = (c | (b << 16)); //B:C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,4 +95,69 @@ public class CubotHologram extends CubotHardwareModule {
|
|||||||
return HWID;
|
return HWID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Document mongoSerialise() {
|
||||||
|
Document document = super.mongoSerialise();
|
||||||
|
|
||||||
|
document.put("color", displayColor);
|
||||||
|
document.put("value", displayValue);
|
||||||
|
document.put("string", displayString);
|
||||||
|
document.put("mode", lastMode.ordinal());
|
||||||
|
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
JSONObject json = jsonSerialise();
|
||||||
|
|
||||||
|
json.put("lastmode", mode);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject jsonSerialise() {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
|
||||||
|
json.put("color", displayColor);
|
||||||
|
json.put("value", displayValue);
|
||||||
|
json.put("string", displayString);
|
||||||
|
json.put("mode", lastMode.ordinal());
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum HologramMode {
|
||||||
|
/**
|
||||||
|
* Display nothing
|
||||||
|
*/
|
||||||
|
CLEARED,
|
||||||
|
/**
|
||||||
|
* Display value as hexadecimal in format 0x0000
|
||||||
|
*/
|
||||||
|
HEX,
|
||||||
|
/**
|
||||||
|
* Display string
|
||||||
|
*/
|
||||||
|
STRING,
|
||||||
|
/**
|
||||||
|
* Display value as decimal
|
||||||
|
*/
|
||||||
|
DEC
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void reset() {
|
||||||
|
displayValue = 0;
|
||||||
|
displayColor = 0;
|
||||||
|
displayString = "";
|
||||||
|
mode = HologramMode.CLEARED;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void update() {
|
||||||
|
lastMode = mode;
|
||||||
|
mode = HologramMode.CLEARED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,11 +2,13 @@ package net.simon987.server.assembly;
|
|||||||
|
|
||||||
|
|
||||||
import net.simon987.server.game.objects.ControllableUnit;
|
import net.simon987.server.game.objects.ControllableUnit;
|
||||||
|
import net.simon987.server.io.JSONSerialisable;
|
||||||
import net.simon987.server.io.MongoSerializable;
|
import net.simon987.server.io.MongoSerializable;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
|
||||||
public abstract class HardwareModule implements MongoSerializable {
|
public abstract class HardwareModule implements MongoSerializable, JSONSerialisable {
|
||||||
|
|
||||||
private CPU cpu;
|
private CPU cpu;
|
||||||
|
|
||||||
@ -35,6 +37,25 @@ public abstract class HardwareModule implements MongoSerializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("{%s}", getClass().getSimpleName());
|
JSONObject hwJson = jsonSerialise();
|
||||||
|
return String.format("{%s: {%s}}", getClass().getSimpleName(), hwJson == null ? "" : hwJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject jsonSerialise() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
5
Server/src/main/resources/static/js/mar.js
vendored
5
Server/src/main/resources/static/js/mar.js
vendored
@ -1023,7 +1023,8 @@ var Cubot = (function (_super) {
|
|||||||
this.makeLaserAttack();
|
this.makeLaserAttack();
|
||||||
}
|
}
|
||||||
this.updateDirection();
|
this.updateDirection();
|
||||||
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
|
var holoHw = json["net.simon987.cubotplugin.CubotHologram"];
|
||||||
|
this.updateHologram(holoHw.mode, holoHw.color, holoHw.value, holoHw.string);
|
||||||
this.setShield(this.shield > 0);
|
this.setShield(this.shield > 0);
|
||||||
};
|
};
|
||||||
Cubot.prototype.updateHologram = function (holoMode, holoColor, holoValue, holoStr) {
|
Cubot.prototype.updateHologram = function (holoMode, holoColor, holoValue, holoStr) {
|
||||||
@ -1579,7 +1580,6 @@ var FluidTile = (function (_super) {
|
|||||||
}(Tile));
|
}(Tile));
|
||||||
var MagneticTile = (function (_super) {
|
var MagneticTile = (function (_super) {
|
||||||
__extends(MagneticTile, _super);
|
__extends(MagneticTile, _super);
|
||||||
|
|
||||||
function MagneticTile(x, y) {
|
function MagneticTile(x, y) {
|
||||||
var _this = _super.call(this, x, y, config.magneticSprite, 0) || this;
|
var _this = _super.call(this, x, y, config.magneticSprite, 0) || this;
|
||||||
_this.baseTint = 0xFFFFFF;
|
_this.baseTint = 0xFFFFFF;
|
||||||
@ -1588,7 +1588,6 @@ var MagneticTile = (function (_super) {
|
|||||||
_this.tileType = "Magnetic tile";
|
_this.tileType = "Magnetic tile";
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MagneticTile.prototype.onHover = function () {
|
MagneticTile.prototype.onHover = function () {
|
||||||
mar.game.add.tween(this).to({isoZ: this.baseZ + 30}, 200, Phaser.Easing.Quadratic.InOut, true);
|
mar.game.add.tween(this).to({isoZ: this.baseZ + 30}, 200, Phaser.Easing.Quadratic.InOut, true);
|
||||||
mar.tileIndicator.tileX = this.tileX;
|
mar.tileIndicator.tileX = this.tileX;
|
||||||
|
@ -326,7 +326,8 @@ class Cubot extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.updateDirection();
|
this.updateDirection();
|
||||||
this.updateHologram(json.holoMode, json.holoC, json.holo, json.holoStr);
|
let holoHw = json["net.simon987.cubotplugin.CubotHologram"];
|
||||||
|
this.updateHologram(holoHw.mode, holoHw.color, holoHw.value, holoHw.string);
|
||||||
|
|
||||||
//Update shield
|
//Update shield
|
||||||
this.setShield(this.shield > 0)
|
this.setShield(this.shield > 0)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user