Cubot object id is no longer stored inside every CpuHardware in the database. Renamed some fields in the database to make them more readable

This commit is contained in:
simon
2018-05-12 16:16:24 -04:00
parent 4cd58c86a5
commit 3368268924
27 changed files with 83 additions and 74 deletions

View File

@@ -376,14 +376,14 @@ public class CPU implements MongoSerializable {
CPU cpu = new CPU(GameServer.INSTANCE.getConfig(), user);
cpu.codeSectionOffset = (int) obj.get("codeSegmentOffset");
cpu.codeSectionOffset = obj.getInteger("codeSegmentOffset");
ArrayList hardwareList = (ArrayList) obj.get("hardware");
for (Object serialisedHw : hardwareList) {
CpuHardware hardware = GameServer.INSTANCE.getRegistry().deserializeHardware((Document) serialisedHw);
CpuHardware hardware = GameServer.INSTANCE.getRegistry().deserializeHardware((Document) serialisedHw, user.getControlledUnit());
hardware.setCpu(cpu);
cpu.attachHardware(hardware, (int) ((Document) serialisedHw).get("address"));
cpu.attachHardware(hardware, ((Document) serialisedHw).getInteger("address"));
}
cpu.memory = new Memory((Document) obj.get("memory"));

View File

@@ -1,6 +1,7 @@
package net.simon987.server.assembly;
import net.simon987.server.game.objects.ControllableUnit;
import net.simon987.server.io.MongoSerializable;
import org.bson.Document;
@@ -13,7 +14,7 @@ public abstract class CpuHardware implements MongoSerializable {
}
public CpuHardware(Document document) {
public CpuHardware(Document document, ControllableUnit unit) {
}

View File

@@ -171,9 +171,9 @@ public class RegisterSet implements Target, MongoSerializable {
for (Object sRegister : registers) {
Register register = new Register((String) ((Document) sRegister).get("name"));
register.setValue((int) ((Document) sRegister).get("value"));
register.setValue(((Document) sRegister).getInteger("value"));
registerSet.registers.put((int) ((Document) sRegister).get("index"), register);
registerSet.registers.put(((Document) sRegister).getInteger("index"), register);
}

View File

@@ -27,13 +27,13 @@ public class GameRegistry {
}
public CpuHardware deserializeHardware(Document document) {
public CpuHardware deserializeHardware(Document document, ControllableUnit controllableUnit) {
String type = document.getString("type");
if (hardware.containsKey(type)) {
try {
return hardware.get(type).getConstructor(Document.class).newInstance(document);
return hardware.get(type).getConstructor(Document.class, ControllableUnit.class).newInstance(document, controllableUnit);
} catch (InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException e) {
e.printStackTrace();
@@ -53,10 +53,14 @@ public class GameRegistry {
try {
return gameObjects.get(type).getConstructor(Document.class).newInstance(document);
} catch (InstantiationException | IllegalAccessException |
InvocationTargetException | NoSuchMethodException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException e) {
e.printStackTrace();
return null;
} catch (InvocationTargetException e) {
LogManager.LOGGER.severe("Error while trying to deserialize object of type " + type + ": " + e.getTargetException().getMessage());
LogManager.LOGGER.severe(document.toJson());
e.getTargetException().printStackTrace();
return null;
}
} else {
LogManager.LOGGER.severe("Trying to deserialize unknown GameObject type: " + type);

View File

@@ -200,27 +200,27 @@ public class World implements MongoSerializable {
@Override
public String toString() {
String str = "World (" + x + ", " + y + ")\n";
StringBuilder str = new StringBuilder("World (" + x + ", " + y + ")\n");
int[][] tileMap = this.tileMap.getTiles();
for (int x = 0; x < worldSize; x++) {
for (int y = 0; y < worldSize; y++) {
str += tileMap[x][y] + " ";
str.append(tileMap[x][y]).append(" ");
}
str += "\n";
str.append("\n");
}
return str;
return str.toString();
}
public static World deserialize(Document dbObject) {
World world = new World((int) dbObject.get("size"));
world.x = (int) dbObject.get("x");
world.y = (int) dbObject.get("y");
world.dimension = (String) dbObject.get("dimension");
world.updatable = (int) dbObject.get("updatable");
World world = new World(dbObject.getInteger("size"));
world.x = dbObject.getInteger("x");
world.y = dbObject.getInteger("y");
world.dimension = dbObject.getString("dimension");
world.updatable = dbObject.getInteger("updatable");
world.tileMap = TileMap.deserialize((Document) dbObject.get("terrain"), world.getWorldSize());
@@ -237,7 +237,6 @@ public class World implements MongoSerializable {
}
return world;
}
/**
@@ -518,6 +517,5 @@ public class World implements MongoSerializable {
}
}
}
}
}