1
0
mirror of https://github.com/Anuken/Mindustry.git synced 2024-11-10 15:05:23 +03:00
This commit is contained in:
Anuken 2019-11-01 12:48:42 -04:00
parent 91dc25f69d
commit 6f19685255
2 changed files with 19 additions and 3 deletions

View File

@ -180,15 +180,13 @@ public class TypeIO{
byte[] bytes = string.getBytes(charset);
buffer.putInt(bytes.length);
buffer.put(bytes);
writeString(buffer, JsonIO.write(rules));
}
@ReadClass(Rules.class)
public static Rules readRules(ByteBuffer buffer){
int length = buffer.getInt();
byte[] bytes = new byte[length];
buffer.get(length);
buffer.get(bytes);
String string = new String(bytes, charset);
return JsonIO.read(Rules.class, string);
}

View File

@ -1,3 +1,4 @@
import io.anuke.mindustry.game.*;
import io.anuke.mindustry.io.TypeIO;
import org.junit.jupiter.api.Test;
@ -32,4 +33,21 @@ public class IOTests{
assertNull(TypeIO.readString(buffer));
}
@Test
void writeRules(){
ByteBuffer buffer = ByteBuffer.allocate(500);
Rules rules = new Rules();
rules.attackMode = true;
rules.buildSpeedMultiplier = 99f;
TypeIO.writeRules(buffer, rules);
buffer.position(0);
Rules res = TypeIO.readRules(buffer);
assertEquals(rules.buildSpeedMultiplier, res.buildSpeedMultiplier);
assertEquals(rules.attackMode, res.attackMode);
}
}