Configuration

This commit is contained in:
Anuken 2020-01-14 16:18:26 -05:00
parent ae2dd5732a
commit 2dd95a62ca
2 changed files with 19 additions and 16 deletions

View File

@ -1,27 +1,25 @@
package mindustry.io; package mindustry.io;
import arc.graphics.*;
import arc.math.geom.*;
import arc.struct.*; import arc.struct.*;
import mindustry.annotations.Annotations.ReadClass; import mindustry.annotations.Annotations.*;
import mindustry.annotations.Annotations.WriteClass;
import arc.graphics.Color;
import mindustry.ctype.*; import mindustry.ctype.*;
import mindustry.entities.Effects; import mindustry.entities.*;
import mindustry.entities.Effects.Effect; import mindustry.entities.Effects.*;
import mindustry.entities.type.Bullet; import mindustry.entities.bullet.*;
import mindustry.entities.bullet.BulletType; import mindustry.entities.traits.BuilderTrait.*;
import mindustry.entities.traits.BuilderTrait.BuildRequest; import mindustry.entities.traits.*;
import mindustry.entities.traits.ShooterTrait;
import mindustry.entities.type.*; import mindustry.entities.type.*;
import mindustry.entities.units.*; import mindustry.entities.units.*;
import mindustry.game.*; import mindustry.game.*;
import mindustry.net.Administration.TraceInfo; import mindustry.net.Administration.*;
import mindustry.net.Packets.AdminAction; import mindustry.net.Packets.*;
import mindustry.net.Packets.KickReason;
import mindustry.type.*; import mindustry.type.*;
import mindustry.world.*; import mindustry.world.*;
import java.io.*; import java.io.*;
import java.nio.ByteBuffer; import java.nio.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@ -57,6 +55,10 @@ public class TypeIO{
for(int i = 0; i < arr.size; i++){ for(int i = 0; i < arr.size; i++){
buffer.putInt(arr.items[i]); buffer.putInt(arr.items[i]);
} }
}else if(object instanceof Point2){
buffer.put((byte)7);
buffer.putInt(((Point2)object).x);
buffer.putInt(((Point2)object).y);
}else{ }else{
throw new IllegalArgumentException("Unknown object type: " + object.getClass()); throw new IllegalArgumentException("Unknown object type: " + object.getClass());
} }
@ -73,6 +75,7 @@ public class TypeIO{
case 4: return readString(buffer); case 4: return readString(buffer);
case 5: return content.getByID(ContentType.all[buffer.get()], buffer.getShort()); case 5: return content.getByID(ContentType.all[buffer.get()], buffer.getShort());
case 6: short length = buffer.getShort(); IntArray arr = new IntArray(); for(int i = 0; i < length; i ++) arr.add(buffer.getInt()); return arr; case 6: short length = buffer.getShort(); IntArray arr = new IntArray(); for(int i = 0; i < length; i ++) arr.add(buffer.getInt()); return arr;
case 7: return new Point2(buffer.getInt(), buffer.getInt());
default: throw new IllegalArgumentException("Unknown object type: " + type); default: throw new IllegalArgumentException("Unknown object type: " + type);
} }
} }

View File

@ -95,8 +95,6 @@ public class Block extends BlockStorage{
public boolean consumesTap; public boolean consumesTap;
/** Whether to draw the glow of the liquid for this block, if it has one. */ /** Whether to draw the glow of the liquid for this block, if it has one. */
public boolean drawLiquidLight = true; public boolean drawLiquidLight = true;
/** Whether the config is positional and needs to be shifted. */
public boolean posConfig;
/** Whether to periodically sync this block across the network.*/ /** Whether to periodically sync this block across the network.*/
public boolean sync; public boolean sync;
/** Whether this block uses conveyor-type placement mode.*/ /** Whether this block uses conveyor-type placement mode.*/
@ -146,6 +144,7 @@ public class Block extends BlockStorage{
protected TextureRegion[] cacheRegions = {}; protected TextureRegion[] cacheRegions = {};
protected Array<String> cacheRegionStrings = new Array<>(); protected Array<String> cacheRegionStrings = new Array<>();
protected Prov<TileEntity> entityType = TileEntity::new; protected Prov<TileEntity> entityType = TileEntity::new;
protected ObjectMap<Class<?>, Cons2<Player, Object>> configurations = new ObjectMap<>();
protected Array<Tile> tempTiles = new Array<>(); protected Array<Tile> tempTiles = new Array<>();
protected TextureRegion[] generatedIcons; protected TextureRegion[] generatedIcons;
@ -473,12 +472,13 @@ public class Block extends BlockStorage{
} }
/** Called when arbitrary int configuration is applied to a tile. */ /** Called when arbitrary int configuration is applied to a tile. */
protected void configured_(Tile tile, @Nullable Player player, int value){ protected void configuredPos(Tile tile, @Nullable Player player, Point2 point){
} }
/** Called when arbitrary configuration is applied to a tile. /** Called when arbitrary configuration is applied to a tile.
* The default behavior is to treat this as integer configuration. */ * The default behavior is to treat this as integer configuration. */
@CallSuper
public void configured(Tile tile, @Nullable Player player, @Nullable Object value){ public void configured(Tile tile, @Nullable Player player, @Nullable Object value){
if(value instanceof Integer){ if(value instanceof Integer){
configured_(tile, player, (int)value); configured_(tile, player, (int)value);