Added Units class, removed writeString() from SaveFileVersion
This commit is contained in:
32
core/src/io/anuke/mindustry/entities/Units.java
Normal file
32
core/src/io/anuke/mindustry/entities/Units.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package io.anuke.mindustry.entities;
|
||||
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import io.anuke.mindustry.entities.units.BaseUnit;
|
||||
import io.anuke.mindustry.game.Team;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
|
||||
import static io.anuke.mindustry.Vars.playerGroup;
|
||||
import static io.anuke.mindustry.Vars.unitGroups;
|
||||
|
||||
/**Utility class for unit-based interactions.*/
|
||||
public class Units {
|
||||
|
||||
public static void allUnits(Consumer<Unit> cons){
|
||||
for(EntityGroup<BaseUnit> group : unitGroups){
|
||||
if(!group.isEmpty()){
|
||||
for(BaseUnit unit : group.all()){
|
||||
cons.accept(unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(Player player : playerGroup.all()){
|
||||
cons.accept(player);
|
||||
}
|
||||
}
|
||||
|
||||
public static void getNearbyEnemies(Team team, Rectangle rect, Consumer<Unit> cons){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -23,16 +23,4 @@ public abstract class SaveFileVersion {
|
||||
|
||||
public abstract void read(DataInputStream stream) throws IOException;
|
||||
public abstract void write(DataOutputStream stream) throws IOException;
|
||||
|
||||
public static void writeString(DataOutputStream stream, String string) throws IOException{
|
||||
stream.writeByte(string.length());
|
||||
stream.writeBytes(string);
|
||||
}
|
||||
|
||||
public static String readString(DataInputStream stream) throws IOException{
|
||||
int length = stream.readByte();
|
||||
byte[] result = new byte[length];
|
||||
stream.read(result);
|
||||
return new String(result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class Save16 extends SaveFileVersion {
|
||||
IntMap<Block> map = new IntMap<>();
|
||||
|
||||
for(int i = 0; i < blocksize; i ++){
|
||||
String name = readString(stream);
|
||||
String name = stream.readUTF();
|
||||
int id = stream.readShort();
|
||||
|
||||
map.put(id, Block.getByName(name));
|
||||
@@ -221,7 +221,7 @@ public class Save16 extends SaveFileVersion {
|
||||
|
||||
for(int i = 0; i < Block.getAllBlocks().size; i ++){
|
||||
Block block = Block.getAllBlocks().get(i);
|
||||
writeString(stream, block.name);
|
||||
stream.writeUTF(block.name);
|
||||
stream.writeShort(block.id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user