mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-11-10 15:05:23 +03:00
Fixed #971
This commit is contained in:
parent
91dc25f69d
commit
6f19685255
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user