More objects

This commit is contained in:
Anuken
2020-01-15 11:28:44 -05:00
parent 2dd95a62ca
commit e5856cf73b
5 changed files with 28 additions and 25 deletions

View File

@@ -1,10 +1,11 @@
package mindustry.entities.traits; package mindustry.entities.traits;
import arc.*; import arc.*;
import arc.struct.Queue; import arc.struct.*;
import arc.graphics.g2d.*; import arc.graphics.g2d.*;
import arc.math.*; import arc.math.*;
import arc.math.geom.*; import arc.math.geom.*;
import arc.struct.Queue;
import arc.util.ArcAnnotate.*; import arc.util.ArcAnnotate.*;
import arc.util.*; import arc.util.*;
import mindustry.*; import mindustry.*;
@@ -289,10 +290,10 @@ public interface BuilderTrait extends Entity, TeamTrait{
public @Nullable Block block; public @Nullable Block block;
/** Whether this is a break request.*/ /** Whether this is a break request.*/
public boolean breaking; public boolean breaking;
/** Whether this request comes with a config int. If yes, any blocks placed with this request will not call playerPlaced.*/ /** Whether this request comes with a config. If yes, any blocks placed with this request will not call playerPlaced.*/
public boolean hasConfig; public boolean hasConfig;
/** Config int. Not used unless hasConfig is true.*/ /** Config int. Not used unless hasConfig is true.*/
public int config; public Object config;
/** Original position, only used in schematics.*/ /** Original position, only used in schematics.*/
public int originalX, originalY, originalWidth, originalHeight; public int originalX, originalY, originalWidth, originalHeight;
@@ -376,7 +377,7 @@ public interface BuilderTrait extends Entity, TeamTrait{
return y*tilesize + block.offset(); return y*tilesize + block.offset();
} }
public BuildRequest configure(int config){ public BuildRequest configure(Object config){
this.config = config; this.config = config;
this.hasConfig = true; this.hasConfig = true;
return this; return this;

View File

@@ -266,8 +266,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
requests.each(req -> { requests.each(req -> {
//rotate config position //rotate config position
if(req.block.posConfig){ if(req.config instanceof Point2){
int cx = Pos.x(req.config) - req.originalX, cy = Pos.y(req.config) - req.originalY; int cx = ((Point2)req.config).x - req.originalX, cy = ((Point2)req.config).y - req.originalY;
int lx = cx; int lx = cx;
if(direction >= 0){ if(direction >= 0){
@@ -277,7 +277,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
cx = cy; cx = cy;
cy = -lx; cy = -lx;
} }
req.config = Pos.get(cx + req.originalX, cy + req.originalY); req.config = new Point2(cx + req.originalX, cy + req.originalY);
} }
//rotate actual request, centered on its multiblock position //rotate actual request, centered on its multiblock position
@@ -308,7 +308,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
req.y = (int)((value - req.block.offset()) / tilesize); req.y = (int)((value - req.block.offset()) / tilesize);
} }
if(req.block.posConfig){ if(req.config instanceof Point2){
int corigin = x ? req.originalWidth/2 : req.originalHeight/2; int corigin = x ? req.originalWidth/2 : req.originalHeight/2;
int nvalue = -((x ? Pos.x(req.config) : Pos.y(req.config)) - corigin) + corigin; int nvalue = -((x ? Pos.x(req.config) : Pos.y(req.config)) - corigin) + corigin;
if(x){ if(x){

View File

@@ -144,7 +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 ObjectMap<Class<?>, ConfigHandler> configurations = new ObjectMap<>();
protected Array<Tile> tempTiles = new Array<>(); protected Array<Tile> tempTiles = new Array<>();
protected TextureRegion[] generatedIcons; protected TextureRegion[] generatedIcons;
@@ -471,20 +471,17 @@ public class Block extends BlockStorage{
} }
/** Called when arbitrary int configuration is applied to a tile. */ /** Called when arbitrary configuration is applied to a tile. */
protected void configuredPos(Tile tile, @Nullable Player player, Point2 point){ public void configured(Tile tile, @Nullable Player player, @Nullable Object value){
if(value == null){
tapped(tile, player);
}else if(configurations.containsKey(value.getClass())){
configurations.get(value.getClass()).configured(tile, player, value);
}
} }
/** Called when arbitrary configuration is applied to a tile. public <T> void config(Class<T> type, ConfigHandler<T> config){
* The default behavior is to treat this as integer configuration. */ configurations.put(type, config);
@CallSuper
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. */ /** Returns whether or not a hand cursor should be shown over this block. */
@@ -928,4 +925,8 @@ public class Block extends BlockStorage{
Arrays.sort(requirements, Structs.comparingInt(i -> i.item.id)); Arrays.sort(requirements, Structs.comparingInt(i -> i.item.id));
} }
public interface ConfigHandler<T>{
void configured(Tile tile, Player player, T value);
}
} }

View File

@@ -91,11 +91,11 @@ public class Tile implements Position, TargetTrait{
} }
/** Configure a tile with the current, local player. */ /** Configure a tile with the current, local player. */
public void configure(int value){ public void configure(Object value){
Call.onTileConfig(player, this, value); Call.onTileConfig(player, this, value);
} }
public void configureAny(int value){ public void configureAny(Object value){
Call.onTileConfig(null, this, value); Call.onTileConfig(null, this, value);
} }

View File

@@ -29,6 +29,7 @@ public class Sorter extends Block{
configurable = true; configurable = true;
unloadable = false; unloadable = false;
entityType = SorterEntity::new; entityType = SorterEntity::new;
config(Item.class, (tile, player, item) -> tile.<SorterEntity>ent().sortItem = item);
} }
@Override @Override
@@ -142,8 +143,8 @@ public class Sorter extends Block{
@Nullable Item sortItem; @Nullable Item sortItem;
@Override @Override
public int config(){ public Object config(){
return sortItem == null ? -1 : sortItem.id; return sortItem;
} }
@Override @Override