feat: implemented NPC serialization properly
This commit is contained in:
@ -43,8 +43,9 @@ public class EntitySerializer extends StdSerializer<Entity> {
|
||||
private void serializeNPC(NPC value, JsonGenerator gen, SerializerProvider provider)
|
||||
throws IOException {
|
||||
gen.writeNumberField("ID", value.id.id);
|
||||
// gen.writeNumberField("MP",value.MP); // TODO: Doesn't exist yet?
|
||||
// gen.writeArray(value.); // TODO: Put values here
|
||||
gen.writeNumberField("MP", value.mp.getValue());
|
||||
gen.writeFieldName("stones");
|
||||
gen.writeArray(inventoryToIntArray(value.inventory), 0, value.inventory.getSize());
|
||||
}
|
||||
|
||||
private void serializeCharacter(Character value, JsonGenerator gen, SerializerProvider provider)
|
||||
@ -57,10 +58,7 @@ public class EntitySerializer extends StdSerializer<Entity> {
|
||||
|
||||
gen.writeFieldName("stones");
|
||||
gen.writeArray(
|
||||
Arrays.stream(value.inventory.getStonesAsArray())
|
||||
.mapToInt(StoneType::getID)
|
||||
.sorted()
|
||||
.toArray(),
|
||||
inventoryToIntArray(value.inventory),
|
||||
0, value.inventory.getSize());
|
||||
}
|
||||
|
||||
@ -74,4 +72,12 @@ public class EntitySerializer extends StdSerializer<Entity> {
|
||||
throws IOException {
|
||||
gen.writeNumberField("ID", value.id.id);
|
||||
}
|
||||
|
||||
/** Returns an int[] with the sorted integer representations of the stones in the given Inventory */
|
||||
private int[] inventoryToIntArray(Inventory inventory) {
|
||||
return Arrays.stream(inventory.getStonesAsArray())
|
||||
.mapToInt(StoneType::getID)
|
||||
.sorted()
|
||||
.toArray();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user