mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-19 18:46:43 +00:00
JSONSerialisable objects now have a debug function #156
This commit is contained in:
parent
92008e553a
commit
78f98c8227
@ -75,6 +75,15 @@ public class HarvesterNPC extends NonPlayerCharacter {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
JSONObject json = jsonSerialise();
|
||||||
|
|
||||||
|
json.put("taskCompleted", getTask().checkCompleted());
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document mongoSerialise() {
|
public Document mongoSerialise() {
|
||||||
Document dbObject = super.mongoSerialise();
|
Document dbObject = super.mongoSerialise();
|
||||||
|
@ -5,6 +5,8 @@ import net.simon987.server.game.objects.MessageReceiver;
|
|||||||
import net.simon987.server.game.objects.Structure;
|
import net.simon987.server.game.objects.Structure;
|
||||||
import net.simon987.server.game.objects.Updatable;
|
import net.simon987.server.game.objects.Updatable;
|
||||||
import org.bson.Document;
|
import org.bson.Document;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@ -61,4 +63,18 @@ public class RadioTower extends Structure implements MessageReceiver, Updatable
|
|||||||
return lastMessages;
|
return lastMessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
JSONObject json = super.debugJsonSerialise();
|
||||||
|
|
||||||
|
JSONArray messages = new JSONArray();
|
||||||
|
|
||||||
|
for (char[] message : this.messages) {
|
||||||
|
messages.add(new String(message));
|
||||||
|
}
|
||||||
|
|
||||||
|
json.put("messages", messages);
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,11 @@ public abstract class Item implements JSONSerialisable, MongoSerializable {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
return jsonSerialise();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document mongoSerialise() {
|
public Document mongoSerialise() {
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
|
@ -234,6 +234,11 @@ public abstract class GameObject implements JSONSerialisable, MongoSerializable
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
return jsonSerialise();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isAt(int x, int y) {
|
public boolean isAt(int x, int y) {
|
||||||
return this.x == x && this.y == y;
|
return this.x == x && this.y == y;
|
||||||
|
@ -139,6 +139,11 @@ public class TileMap implements JSONSerialisable, MongoSerializable {
|
|||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject debugJsonSerialise() {
|
||||||
|
return jsonSerialise();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Document mongoSerialise() {
|
public Document mongoSerialise() {
|
||||||
|
|
||||||
|
@ -6,4 +6,6 @@ public interface JSONSerialisable {
|
|||||||
|
|
||||||
JSONObject jsonSerialise();
|
JSONObject jsonSerialise();
|
||||||
|
|
||||||
|
JSONObject debugJsonSerialise();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,14 +15,14 @@ public class ObjectsRequestHandler implements MessageHandler {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(OnlineUser user, JSONObject json) throws IllegalStateException, IOException {
|
public void handle(OnlineUser user, JSONObject json) throws IllegalStateException, IOException {
|
||||||
if (json.get("t").equals("object")) {
|
if (json.get("t").equals("object")) {
|
||||||
// LogManager.LOGGER.fine("(WS) Objects request from " + user.getUser().getUsername());
|
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
String dimension;
|
String dimension;
|
||||||
|
boolean sendDebugInfo;
|
||||||
try {
|
try {
|
||||||
x = Long.valueOf((long) json.get("x")).intValue();
|
x = Long.valueOf((long) json.get("x")).intValue();
|
||||||
y = Long.valueOf((long) json.get("y")).intValue();
|
y = Long.valueOf((long) json.get("y")).intValue();
|
||||||
dimension = (String) json.get("dimension");
|
dimension = (String) json.get("dimension");
|
||||||
|
sendDebugInfo = json.containsKey("debug") && (boolean) json.get("debug");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogManager.LOGGER.severe("(WS) Malformed Objects request from " + user.getUser().getUsername());
|
LogManager.LOGGER.severe("(WS) Malformed Objects request from " + user.getUser().getUsername());
|
||||||
return;
|
return;
|
||||||
@ -37,8 +37,12 @@ public class ObjectsRequestHandler implements MessageHandler {
|
|||||||
|
|
||||||
|
|
||||||
for (GameObject object : world.getGameObjects()) {
|
for (GameObject object : world.getGameObjects()) {
|
||||||
|
if (sendDebugInfo) {
|
||||||
|
objects.add(object.debugJsonSerialise());
|
||||||
|
} else {
|
||||||
objects.add(object.jsonSerialise());
|
objects.add(object.jsonSerialise());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
response.put("t", "object");
|
response.put("t", "object");
|
||||||
response.put("objects", objects);
|
response.put("objects", objects);
|
||||||
|
@ -105,6 +105,7 @@ public class SocketServer {
|
|||||||
*/
|
*/
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
|
||||||
|
//TODO: refactor this function (1. Create json instance for each user 2. Extract functions 3. rename variables)
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("t", "tick");
|
json.put("t", "tick");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user