JSONSerialisable objects now have a debug function #156

This commit is contained in:
Simon
2018-06-04 17:07:20 -04:00
parent 92008e553a
commit 78f98c8227
8 changed files with 50 additions and 3 deletions

View File

@@ -42,6 +42,11 @@ public abstract class Item implements JSONSerialisable, MongoSerializable {
return json;
}
@Override
public JSONObject debugJsonSerialise() {
return jsonSerialise();
}
@Override
public Document mongoSerialise() {
Document document = new Document();

View File

@@ -234,6 +234,11 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
return json;
}
@Override
public JSONObject debugJsonSerialise() {
return jsonSerialise();
}
public boolean isAt(int x, int y) {
return this.x == x && this.y == y;

View File

@@ -139,6 +139,11 @@ public class TileMap implements JSONSerialisable, MongoSerializable {
return json;
}
@Override
public JSONObject debugJsonSerialise() {
return jsonSerialise();
}
@Override
public Document mongoSerialise() {

View File

@@ -6,4 +6,6 @@ public interface JSONSerialisable {
JSONObject jsonSerialise();
JSONObject debugJsonSerialise();
}

View File

@@ -15,14 +15,14 @@ public class ObjectsRequestHandler implements MessageHandler {
@Override
public void handle(OnlineUser user, JSONObject json) throws IllegalStateException, IOException {
if (json.get("t").equals("object")) {
// LogManager.LOGGER.fine("(WS) Objects request from " + user.getUser().getUsername());
int x, y;
String dimension;
boolean sendDebugInfo;
try {
x = Long.valueOf((long) json.get("x")).intValue();
y = Long.valueOf((long) json.get("y")).intValue();
dimension = (String) json.get("dimension");
sendDebugInfo = json.containsKey("debug") && (boolean) json.get("debug");
} catch (Exception e) {
LogManager.LOGGER.severe("(WS) Malformed Objects request from " + user.getUser().getUsername());
return;
@@ -37,7 +37,11 @@ public class ObjectsRequestHandler implements MessageHandler {
for (GameObject object : world.getGameObjects()) {
objects.add(object.jsonSerialise());
if (sendDebugInfo) {
objects.add(object.debugJsonSerialise());
} else {
objects.add(object.jsonSerialise());
}
}
response.put("t", "object");

View File

@@ -105,6 +105,7 @@ public class SocketServer {
*/
public void tick() {
//TODO: refactor this function (1. Create json instance for each user 2. Extract functions 3. rename variables)
JSONObject json = new JSONObject();
json.put("t", "tick");