Objectification
This commit is contained in:
@@ -246,9 +246,9 @@ public class TileEntity extends BaseEntity implements TargetTrait, HealthTrait{
|
||||
return proximity;
|
||||
}
|
||||
|
||||
/** Tile configuration. Defaults to 0. Used for block rebuilding. */
|
||||
public int config(){
|
||||
return 0;
|
||||
/** Tile configuration. Defaults to null, which means 'no config'. Used for block rebuilding and schematics. */
|
||||
public Object config(){
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -186,9 +186,9 @@ public class EventType{
|
||||
public static class TapConfigEvent{
|
||||
public final Tile tile;
|
||||
public final Player player;
|
||||
public final int value;
|
||||
public final Object value;
|
||||
|
||||
public TapConfigEvent(Tile tile, Player player, int value){
|
||||
public TapConfigEvent(Tile tile, Player player, Object value){
|
||||
this.tile = tile;
|
||||
this.player = player;
|
||||
this.value = value;
|
||||
|
||||
@@ -345,7 +345,7 @@ public class Schematics implements Loadable{
|
||||
|
||||
if(tile != null && tile.entity != null && !counted.contains(tile.pos()) && !(tile.block() instanceof BuildBlock)
|
||||
&& (tile.entity.block.isVisible() || (tile.entity.block instanceof CoreBlock && Core.settings.getBool("coreselect")))){
|
||||
int config = tile.entity.config();
|
||||
Object config = tile.entity.config();
|
||||
if(tile.block().posConfig){
|
||||
config = Pos.get(Pos.x(config) + offsetX, Pos.y(config) + offsetY);
|
||||
}
|
||||
|
||||
@@ -170,9 +170,9 @@ public class Teams{
|
||||
* This does not include deconstructed blocks.*/
|
||||
public static class BrokenBlock{
|
||||
public final short x, y, rotation, block;
|
||||
public final int config;
|
||||
public final Object config;
|
||||
|
||||
public BrokenBlock(short x, short y, short rotation, short block, int config){
|
||||
public BrokenBlock(short x, short y, short rotation, short block, Object config){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.rotation = rotation;
|
||||
|
||||
@@ -151,19 +151,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||
public static void onTileTapped(Player player, Tile tile){
|
||||
if(tile == null || player == null) return;
|
||||
if(net.server() && (!Units.canInteract(player, tile) ||
|
||||
!netServer.admins.allowAction(player, ActionType.tapTile, tile, action -> {}))) throw new ValidateException(player, "Player cannot tap a tile.");
|
||||
tile.block().tapped(tile, player);
|
||||
Core.app.post(() -> Events.fire(new TapEvent(tile, player)));
|
||||
}
|
||||
|
||||
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
||||
public static void onTileConfig(Player player, Tile tile, int value){
|
||||
public static void onTileConfig(Player player, Tile tile, @Nullable Object value){
|
||||
if(tile == null) return;
|
||||
|
||||
if(net.server() && (!Units.canInteract(player, tile) ||
|
||||
!netServer.admins.allowAction(player, ActionType.configure, tile, action -> action.config = value))) throw new ValidateException(player, "Player cannot configure a tile.");
|
||||
tile.block().configured(tile, player, value);
|
||||
@@ -588,7 +578,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
//call tapped event
|
||||
if(!consumed && tile.interactable(player.getTeam())){
|
||||
Call.onTileTapped(player, tile);
|
||||
Call.onTileConfig(player, tile, null);
|
||||
}
|
||||
|
||||
//consume tap event if necessary
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package mindustry.io;
|
||||
|
||||
import arc.struct.*;
|
||||
import mindustry.annotations.Annotations.ReadClass;
|
||||
import mindustry.annotations.Annotations.WriteClass;
|
||||
import arc.graphics.Color;
|
||||
import mindustry.ctype.ContentType;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.Effects;
|
||||
import mindustry.entities.Effects.Effect;
|
||||
import mindustry.entities.type.Bullet;
|
||||
@@ -28,6 +29,54 @@ import static mindustry.Vars.*;
|
||||
@SuppressWarnings("unused")
|
||||
public class TypeIO{
|
||||
|
||||
@WriteClass(Object.class)
|
||||
public static void writeObject(ByteBuffer buffer, Object object){
|
||||
if(object == null){
|
||||
buffer.put((byte)0);
|
||||
}else if(object instanceof Integer){
|
||||
buffer.put((byte)1);
|
||||
buffer.putInt((Integer)object);
|
||||
}else if(object instanceof Long){
|
||||
buffer.put((byte)2);
|
||||
buffer.putLong((Long)object);
|
||||
}else if(object instanceof Float){
|
||||
buffer.put((byte)3);
|
||||
buffer.putFloat((Float)object);
|
||||
}else if(object instanceof String){
|
||||
buffer.put((byte)4);
|
||||
writeString(buffer, (String)object);
|
||||
}else if(object instanceof Content){
|
||||
Content map = (Content)object;
|
||||
buffer.put((byte)5);
|
||||
buffer.put((byte)map.getContentType().ordinal());
|
||||
buffer.putShort(map.id);
|
||||
}else if(object instanceof IntArray){
|
||||
buffer.put((byte)6);
|
||||
IntArray arr = (IntArray)object;
|
||||
buffer.putShort((short)arr.size);
|
||||
for(int i = 0; i < arr.size; i++){
|
||||
buffer.putInt(arr.items[i]);
|
||||
}
|
||||
}else{
|
||||
throw new IllegalArgumentException("Unknown object type: " + object.getClass());
|
||||
}
|
||||
}
|
||||
|
||||
@ReadClass(Object.class)
|
||||
public static Object readObject(ByteBuffer buffer){
|
||||
byte type = buffer.get();
|
||||
switch(type){
|
||||
case 0: return null;
|
||||
case 1: return buffer.getInt();
|
||||
case 2: return buffer.getLong();
|
||||
case 3: return buffer.getFloat();
|
||||
case 4: return readString(buffer);
|
||||
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;
|
||||
default: throw new IllegalArgumentException("Unknown object type: " + type);
|
||||
}
|
||||
}
|
||||
|
||||
@WriteClass(Player.class)
|
||||
public static void writePlayer(ByteBuffer buffer, Player player){
|
||||
if(player == null){
|
||||
|
||||
@@ -534,7 +534,7 @@ public class Administration{
|
||||
public int rotation;
|
||||
|
||||
/** valid for configure and rotation-type events only. */
|
||||
public int config;
|
||||
public Object config;
|
||||
|
||||
/** valid for item-type events only. */
|
||||
public @Nullable Item item;
|
||||
@@ -550,7 +550,8 @@ public class Administration{
|
||||
@Override
|
||||
public void reset(){
|
||||
item = null;
|
||||
itemAmount = config = 0;
|
||||
itemAmount = 0;
|
||||
config = null;
|
||||
player = null;
|
||||
type = null;
|
||||
tile = null;
|
||||
@@ -558,7 +559,7 @@ public class Administration{
|
||||
}
|
||||
|
||||
public enum ActionType{
|
||||
breakBlock, placeBlock, rotate, configure, tapTile, withdrawItem, depositItem
|
||||
breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -467,16 +467,26 @@ public class Block extends BlockStorage{
|
||||
return cacheRegions[id];
|
||||
}
|
||||
|
||||
/** Called when the block is tapped. */
|
||||
/** Called when the block is tapped. This is equivalent to being configured with null. */
|
||||
public void tapped(Tile tile, Player player){
|
||||
|
||||
}
|
||||
|
||||
/** Called when arbitrary configuration is applied to a tile. */
|
||||
public void configured(Tile tile, @Nullable Player player, int value){
|
||||
/** Called when arbitrary int configuration is applied to a tile. */
|
||||
protected void configured_(Tile tile, @Nullable Player player, int value){
|
||||
|
||||
}
|
||||
|
||||
/** Called when arbitrary configuration is applied to a tile.
|
||||
* The default behavior is to treat this as integer configuration. */
|
||||
public void configured(Tile tile, @Nullable Player player, @Nullable Object value){
|
||||
if(value instanceof Integer){
|
||||
configured_(tile, player, (int)value);
|
||||
}else if(value == null){
|
||||
tapped(tile, player);
|
||||
}
|
||||
}
|
||||
|
||||
/** Returns whether or not a hand cursor should be shown over this block. */
|
||||
public Cursor getCursor(Tile tile){
|
||||
return configurable ? SystemCursor.hand : SystemCursor.arrow;
|
||||
|
||||
Reference in New Issue
Block a user