From 1249eb3b001bbf02370bd37970cc82c9f816d0fa Mon Sep 17 00:00:00 2001 From: Anuken Date: Wed, 12 Aug 2020 21:24:00 -0400 Subject: [PATCH] Bugfixes --- core/src/mindustry/editor/MapView.java | 4 +- .../mindustry/entities/units/BuildPlan.java | 6 ++- core/src/mindustry/game/Schematics.java | 2 +- core/src/mindustry/world/Block.java | 4 ++ .../world/blocks/logic/LogicBlock.java | 44 +++++++++++++++++-- gradle.properties | 2 +- 6 files changed, 52 insertions(+), 10 deletions(-) diff --git a/core/src/mindustry/editor/MapView.java b/core/src/mindustry/editor/MapView.java index 45dfa8d73a..c1715a3d3b 100644 --- a/core/src/mindustry/editor/MapView.java +++ b/core/src/mindustry/editor/MapView.java @@ -213,9 +213,9 @@ public class MapView extends Element implements GestureListener{ y = (y - getHeight() / 2 + sclheight / 2 - offsety * zoom) / sclheight * editor.height(); if(editor.drawBlock.size % 2 == 0 && tool != EditorTool.eraser){ - return Tmp.g1.set((int)(x - 0.5f), (int)(y - 0.5f)); + return Tmp.p1.set((int)(x - 0.5f), (int)(y - 0.5f)); }else{ - return Tmp.g1.set((int)x, (int)y); + return Tmp.p1.set((int)x, (int)y); } } diff --git a/core/src/mindustry/entities/units/BuildPlan.java b/core/src/mindustry/entities/units/BuildPlan.java index 588c549a2c..1720bb6678 100644 --- a/core/src/mindustry/entities/units/BuildPlan.java +++ b/core/src/mindustry/entities/units/BuildPlan.java @@ -53,7 +53,7 @@ public class BuildPlan{ } - public static Object pointConfig(Object config, Cons cons){ + public static Object pointConfig(Block block, Object config, Cons cons){ if(config instanceof Point2){ config = ((Point2)config).cpy(); cons.get((Point2)config); @@ -65,6 +65,8 @@ public class BuildPlan{ cons.get(result[i++]); } config = result; + }else if(block != null){ + config = block.pointConfig(config, cons); } return config; } @@ -72,7 +74,7 @@ public class BuildPlan{ /** If this requests's config is a Point2 or an array of Point2s, this returns a copy of them for transformation. * Otherwise does nothing. */ public void pointConfig(Cons cons){ - this.config = pointConfig(this.config, cons); + this.config = pointConfig(block, this.config, cons); } public BuildPlan copy(){ diff --git a/core/src/mindustry/game/Schematics.java b/core/src/mindustry/game/Schematics.java index 95cbece27f..3c8063d1ac 100644 --- a/core/src/mindustry/game/Schematics.java +++ b/core/src/mindustry/game/Schematics.java @@ -583,7 +583,7 @@ public class Schematics implements Loadable{ int ox = schem.width/2, oy = schem.height/2; schem.tiles.each(req -> { - req.config = BuildPlan.pointConfig(req.config, p -> { + req.config = BuildPlan.pointConfig(req.block, req.config, p -> { int cx = p.x, cy = p.y; int lx = cx; diff --git a/core/src/mindustry/world/Block.java b/core/src/mindustry/world/Block.java index 025b24fb49..f48a5b40f3 100644 --- a/core/src/mindustry/world/Block.java +++ b/core/src/mindustry/world/Block.java @@ -405,6 +405,10 @@ public class Block extends UnlockableContent{ } + public Object pointConfig(Object config, Cons transformer){ + return config; + } + /** Configure when a null value is passed.*/ public void configClear(Cons cons){ configurations.put(void.class, (tile, value) -> cons.get((E)tile)); diff --git a/core/src/mindustry/world/blocks/logic/LogicBlock.java b/core/src/mindustry/world/blocks/logic/LogicBlock.java index 75ac6200d0..e5d6381cc7 100644 --- a/core/src/mindustry/world/blocks/logic/LogicBlock.java +++ b/core/src/mindustry/world/blocks/logic/LogicBlock.java @@ -1,7 +1,9 @@ package mindustry.world.blocks.logic; import arc.func.*; +import arc.math.geom.*; import arc.scene.ui.layout.*; +import arc.struct.Bits; import arc.struct.*; import arc.util.*; import arc.util.io.*; @@ -77,9 +79,11 @@ public class LogicBlock extends Block{ } static byte[] compress(String code, Seq links){ - try{ - byte[] bytes = code.getBytes(charset); + return compress(code.getBytes(charset), links); + } + static byte[] compress(byte[] bytes, Seq links){ + try{ ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream stream = new DataOutputStream(new DeflaterOutputStream(baos)); @@ -109,6 +113,39 @@ public class LogicBlock extends Block{ } } + @Override + public Object pointConfig(Object config, Cons transformer){ + if(config instanceof byte[]){ + byte[] data = (byte[])config; + + try(DataInputStream stream = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data)))){ + //discard version for now + stream.read(); + + int bytelen = stream.readInt(); + byte[] bytes = new byte[bytelen]; + stream.read(bytes); + + int total = stream.readInt(); + + Seq links = new Seq<>(); + + for(int i = 0; i < total; i++){ + String name = stream.readUTF(); + short x = stream.readShort(), y = stream.readShort(); + + transformer.get(Tmp.p1.set(x, y)); + links.add(new LogicLink(Tmp.p1.x, Tmp.p1.y, name, true)); + } + + return compress(bytes, links); + }catch(IOException e){ + Log.err(e); + } + } + return config; + } + public static class LogicLink{ public boolean active = true, valid; public int x, y; @@ -139,7 +176,6 @@ public class LogicBlock extends Block{ DataInputStream stream = new DataInputStream(new InflaterInputStream(new ByteArrayInputStream(data))); try{ - //discard version, there's only one int version = stream.read(); int bytelen = stream.readInt(); @@ -301,7 +337,7 @@ public class LogicBlock extends Block{ } public Seq relativeConnections(){ - Seq copy = new Seq<>(links); + Seq copy = new Seq<>(links.size); for(LogicLink l : links){ LogicLink c = l.copy(); c.x -= tileX(); diff --git a/gradle.properties b/gradle.properties index 25c9a98a53..387229d1ac 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ org.gradle.daemon=true org.gradle.jvmargs=-Xms256m -Xmx1024m -archash=363906fbb7e0ca5cb07660a8a818912d61691546 +archash=55e3f18ceeafc718d401b62d0129855f665920e4