Schematic tweaks and improvements

This commit is contained in:
Anuken
2020-03-04 19:21:40 -05:00
parent 3eea0ea065
commit c02c00cdfb
7 changed files with 35 additions and 21 deletions

View File

@@ -266,7 +266,7 @@ public class Schematics implements Loadable{
tile.set(st.block, state.rules.defaultTeam);
tile.rotation(st.rotation);
Object config = BuildRequest.pointConfig(st.config, point -> point.add(tile.x - st.x, tile.y - st.y));
Object config = st.config;
tile.configureAny(config);
if(st.block instanceof Drill){
@@ -350,7 +350,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")))){
Object config = BuildRequest.pointConfig(tile.entity.config(), point -> point.add(offsetX, offsetY));
Object config = tile.entity.config();
tiles.add(new Stile(tile.block(), tile.x + offsetX, tile.y + offsetY, config, tile.rotation()));
counted.add(tile.pos());
@@ -422,7 +422,7 @@ public class Schematics implements Loadable{
for(int i = 0; i < total; i++){
Block block = blocks.get(stream.readByte());
int position = stream.readInt();
Object config = ver == 0 ? mapConfig(block, stream.readInt()) : TypeIO.readObject(Reads.get(stream));
Object config = ver == 0 ? mapConfig(block, stream.readInt(), position) : TypeIO.readObject(Reads.get(stream));
byte rotation = stream.readByte();
if(block != Blocks.air){
tiles.add(new Stile(block, Point2.x(position), Point2.y(position), config, rotation));
@@ -473,10 +473,10 @@ public class Schematics implements Loadable{
}
/** Maps legacy int configs to new config objects. */
private static Object mapConfig(Block block, int value){
private static Object mapConfig(Block block, int value, int position){
if(block instanceof Sorter || block instanceof Unloader || block instanceof ItemSource) return content.item(value);
if(block instanceof MassDriver || block instanceof ItemBridge) return Point2.unpack(value);
if(block instanceof LiquidSource) return content.liquid(value);
if(block instanceof MassDriver || block instanceof ItemBridge) return Point2.unpack(value).sub(Point2.x(position), Point2.y(position));
if(block instanceof LightBlock || block instanceof CommandCenter) return value;
return null;

View File

@@ -115,6 +115,10 @@ public class DesktopInput extends InputHandler{
drawRequest(request);
}
for(BuildRequest request : selectRequests){
drawOverRequest(request);
}
if(sreq != null){
boolean valid = validPlace(sreq.x, sreq.y, sreq.block, sreq.rotation, sreq);
if(sreq.block.rotate){

View File

@@ -265,7 +265,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
requests.each(req -> {
req.pointConfig(p -> {
int cx = p.x - req.originalX, cy = p.y - req.originalY;
int cx = p.x, cy = p.y;
int lx = cx;
if(direction >= 0){
@@ -275,7 +275,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
cx = cy;
cy = -lx;
}
p.set(cx + req.originalX, cy + req.originalY);
p.set(cx, cy);
});
//rotate actual request, centered on its multiblock position
@@ -308,7 +308,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
req.pointConfig(p -> {
int corigin = x ? req.originalWidth/2 : req.originalHeight/2;
int nvalue = -((x ? p.x : p.y) - corigin) + corigin;
int nvalue = -(x ? p.x : p.y);
if(x){
req.originalX = -(req.originalX - corigin) + corigin;
p.x = nvalue;
@@ -449,12 +449,21 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
for(BuildRequest req : requests){
if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){
BuildRequest copy = req.copy();
copy.pointConfig(p -> p.add(copy.x - copy.originalX, copy.y - copy.originalY));
player.builder().addBuild(copy);
}
}
}
protected void drawOverRequest(BuildRequest request){
boolean valid = validPlace(request.x, request.y, request.block, request.rotation);
Draw.reset();
Draw.mixcol(!valid ? Pal.breakInvalid : Color.white, (!valid ? 0.4f : 0.24f) + Mathf.absin(Time.globalTime(), 6f, 0.28f));
Draw.alpha(1f);
request.block.drawRequestConfigTop(request, selectRequests);
Draw.reset();
}
protected void drawRequest(BuildRequest request){
request.block.drawRequest(request, allRequests(), validPlace(request.x, request.y, request.block, request.rotation));
}

View File

@@ -222,8 +222,6 @@ public class MobileInput extends InputHandler implements GestureListener{
BuildRequest other = getRequest(request.x, request.y, request.block.size, null);
BuildRequest copy = request.copy();
copy.pointConfig(p -> p.add(copy.x - copy.originalX, copy.y - copy.originalY));
if(other == null){
player.builder().addBuild(copy);
}else if(!other.breaking && other.x == request.x && other.y == request.y && other.block.size == request.block.size){
@@ -340,7 +338,6 @@ public class MobileInput extends InputHandler implements GestureListener{
if(request.block.rotate) drawArrow(request.block, tile.x, tile.y, request.rotation);
}
//Draw.mixcol(Tmp.c1, 1f);
Draw.reset();
drawRequest(request);

View File

@@ -41,7 +41,9 @@ public class ItemBridge extends Block{
group = BlockGroup.transportation;
entityType = ItemBridgeEntity::new;
config(Point2.class, (tile, i) -> tile.<ItemBridgeEntity>ent().link = i.pack());
//point2 config is relative
config(Point2.class, (tile, i) -> tile.<ItemBridgeEntity>ent().link = Point2.pack(i.x + tile.x, i.y + tile.y));
//integer is not
config(Integer.class, (tile, i) -> tile.<ItemBridgeEntity>ent().link = i);
}
@@ -58,7 +60,7 @@ public class ItemBridge extends Block{
public void drawRequestConfigTop(BuildRequest req, Eachable<BuildRequest> list){
otherReq = null;
list.each(other -> {
if(other.block == this && req.config instanceof Point2 && ((Point2)req.config).equals(other.x, other.y)){
if(other.block == this && req != other && req.config instanceof Point2 && ((Point2)req.config).equals(other.x - req.x, other.y - req.y)){
otherReq = other;
}
});
@@ -367,7 +369,7 @@ public class ItemBridge extends Block{
@Override
public Point2 config(){
return Point2.unpack(link);
return Point2.unpack(link).sub(tile.x, tile.y);
}
@Override

View File

@@ -42,7 +42,8 @@ public class MassDriver extends Block{
outlineIcon = true;
entityType = MassDriverEntity::new;
config(Point2.class, (tile, point) -> tile.<MassDriverEntity>ent().link = point.pack());
//point2 is relative
config(Point2.class, (tile, point) -> tile.<MassDriverEntity>ent().link = Point2.pack(point.x + tile.x, point.y + tile.y));
config(Integer.class, (tile, point) -> tile.<MassDriverEntity>ent().link = point);
}
@@ -325,7 +326,7 @@ public class MassDriver extends Block{
@Override
public Point2 config(){
return Point2.unpack(link);
return Point2.unpack(link).sub(tile.x, tile.y);
}
@Override

View File

@@ -80,7 +80,9 @@ public class PowerNode extends PowerBlock{
config(Point2[].class, (tile, value) -> {
tile.entity.power().links.clear();
for(Point2 p : value){
tile.entity.power().links.add(p.pack());
if(tile.entity.power().links.size < maxNodes){
tile.entity.power().links.add(Point2.pack(p.x + tile.x, p.y + tile.y));
}
}
});
}
@@ -295,8 +297,7 @@ public class PowerNode extends PowerBlock{
for(Point2 point : (Point2[])req.config){
otherReq = null;
list.each(other -> {
if(other.x == point.x && other.y == point.y){
Log.info("found match " + other);
if((other.x == req.x + point.x && other.y == req.y + point.y) && other != req){
otherReq = other;
}
});
@@ -396,7 +397,7 @@ public class PowerNode extends PowerBlock{
public Point2[] config(){
Point2[] out = new Point2[power.links.size];
for(int i = 0; i < out.length; i++){
out[i] = Point2.unpack(power.links.get(i));
out[i] = Point2.unpack(power.links.get(i)).sub(tile.x, tile.y);
}
return out;
}