From b7e788d52967885cc28e4653e042e0613dc7221f Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 25 Oct 2019 12:58:07 -0400 Subject: [PATCH] Fixed #877 / Fixed #871 / Other fixes --- android/AndroidManifest.xml | 1 + .../io/anuke/mindustry/core/NetClient.java | 2 +- .../io/anuke/mindustry/core/NetServer.java | 3 +- .../io/anuke/mindustry/game/Schematics.java | 2 ++ .../anuke/mindustry/input/DesktopInput.java | 4 +-- .../anuke/mindustry/input/InputHandler.java | 5 +++ core/src/io/anuke/mindustry/io/TypeIO.java | 7 ++++ core/src/io/anuke/mindustry/mod/Mods.java | 9 ++--- .../mindustry/ui/dialogs/ModsDialog.java | 36 ++++++++++++------- core/src/io/anuke/mindustry/world/Build.java | 2 +- .../world/blocks/sandbox/LiquidSource.java | 2 +- 11 files changed, 50 insertions(+), 23 deletions(-) diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index a4202d4364..1e5b0141a9 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -14,6 +14,7 @@ android:roundIcon="@mipmap/ic_launcher_round" android:isGame="true" android:appCategory="game" + android:usesCleartextTraffic="true" android:label="@string/app_name" android:theme="@style/GdxTheme" android:fullBackupContent="@xml/backup_rules"> diff --git a/core/src/io/anuke/mindustry/core/NetClient.java b/core/src/io/anuke/mindustry/core/NetClient.java index eb1734fa94..20270a3cf9 100644 --- a/core/src/io/anuke/mindustry/core/NetClient.java +++ b/core/src/io/anuke/mindustry/core/NetClient.java @@ -472,7 +472,7 @@ public class NetClient implements ApplicationListener{ player.pointerX, player.pointerY, player.rotation, player.baseRotation, player.velocity().x, player.velocity().y, player.getMineTile(), - player.isBoosting, player.isShooting, ui.chatfrag.chatOpen(), + player.isBoosting, player.isShooting, ui.chatfrag.chatOpen(), player.isBuilding, requests, Core.camera.position.x, Core.camera.position.y, Core.camera.width * viewScale, Core.camera.height * viewScale); diff --git a/core/src/io/anuke/mindustry/core/NetServer.java b/core/src/io/anuke/mindustry/core/NetServer.java index 6bae988f24..cadab029a7 100644 --- a/core/src/io/anuke/mindustry/core/NetServer.java +++ b/core/src/io/anuke/mindustry/core/NetServer.java @@ -450,7 +450,7 @@ public class NetServer implements ApplicationListener{ float rotation, float baseRotation, float xVelocity, float yVelocity, Tile mining, - boolean boosting, boolean shooting, boolean chatting, + boolean boosting, boolean shooting, boolean chatting, boolean building, BuildRequest[] requests, float viewX, float viewY, float viewWidth, float viewHeight ){ @@ -477,6 +477,7 @@ public class NetServer implements ApplicationListener{ player.isTyping = chatting; player.isBoosting = boosting; player.isShooting = shooting; + player.isBuilding = building; player.buildQueue().clear(); for(BuildRequest req : requests){ if(req == null) continue; diff --git a/core/src/io/anuke/mindustry/game/Schematics.java b/core/src/io/anuke/mindustry/game/Schematics.java index 9b1bda5470..24e2721694 100644 --- a/core/src/io/anuke/mindustry/game/Schematics.java +++ b/core/src/io/anuke/mindustry/game/Schematics.java @@ -76,6 +76,8 @@ public class Schematics implements Loadable{ target.tiles.clear(); target.tiles.addAll(newSchematic.tiles); + target.width = newSchematic.width; + target.height = newSchematic.height; newSchematic.tags.putAll(target.tags); newSchematic.file = target.file; diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index b66bc7068f..571071d2dc 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -302,12 +302,12 @@ public class DesktopInput extends InputHandler{ player.clearBuilding(); } - if(Core.input.keyTap(Binding.schematic_select)){ + if(Core.input.keyTap(Binding.schematic_select) && !ui.chatfrag.chatOpen()){ schemX = rawCursorX; schemY = rawCursorY; } - if(Core.input.keyTap(Binding.schematic_menu)){ + if(Core.input.keyTap(Binding.schematic_menu) && !ui.chatfrag.chatOpen()){ ui.schematics.show(); } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 9d38b20592..fef5509f7d 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -401,6 +401,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ protected void flushSelectRequests(Array requests){ for(BuildRequest req : requests){ if(req.block != null && validPlace(req.x, req.y, req.block, req.rotation)){ + BuildRequest other = getRequest(req.x, req.y); + if(other != null){ + selectRequests.remove(other); + } + selectRequests.add(req.copy()); } } diff --git a/core/src/io/anuke/mindustry/io/TypeIO.java b/core/src/io/anuke/mindustry/io/TypeIO.java index 87dc8d5766..d499d71cfd 100644 --- a/core/src/io/anuke/mindustry/io/TypeIO.java +++ b/core/src/io/anuke/mindustry/io/TypeIO.java @@ -126,6 +126,8 @@ public class TypeIO{ if(!request.breaking){ buffer.putShort(request.block.id); buffer.put((byte)request.rotation); + buffer.put(request.hasConfig ? (byte)1 : 0); + buffer.putInt(request.config); } } } @@ -148,7 +150,12 @@ public class TypeIO{ }else{ //place short block = buffer.getShort(); byte rotation = buffer.get(); + boolean hasConfig = buffer.get() == 1; + int config = buffer.getInt(); currentRequest = new BuildRequest(Pos.x(position), Pos.y(position), rotation, content.block(block)); + if(hasConfig){ + currentRequest.configure(config); + } } reqs[i] = (currentRequest); diff --git a/core/src/io/anuke/mindustry/mod/Mods.java b/core/src/io/anuke/mindustry/mod/Mods.java index 785b3596cd..53d3de8821 100644 --- a/core/src/io/anuke/mindustry/mod/Mods.java +++ b/core/src/io/anuke/mindustry/mod/Mods.java @@ -62,7 +62,7 @@ public class Mods implements Loadable{ file.copyTo(dest); try{ - loaded.add(loadMod(dest, false)); + loaded.add(loadMod(dest)); requiresReload = true; }catch(IOException e){ dest.delete(); @@ -172,7 +172,7 @@ public class Mods implements Loadable{ Log.debug("[Mods] Loading mod {0}", file); try{ - LoadedMod mod = loadMod(file, false); + LoadedMod mod = loadMod(file); if(mod.enabled() || headless){ loaded.add(mod); }else{ @@ -187,12 +187,13 @@ public class Mods implements Loadable{ //load workshop mods now for(FileHandle file : platform.getWorkshopContent(LoadedMod.class)){ try{ - LoadedMod mod = loadMod(file, true); + LoadedMod mod = loadMod(file); if(mod.enabled()){ loaded.add(mod); }else{ disabled.add(mod); } + mod.addSteamID(file.parent().name()); }catch(Exception e){ Log.err("Failed to load mod workshop file {0}. Skipping.", file); Log.err(e); @@ -399,7 +400,7 @@ public class Mods implements Loadable{ /** Loads a mod file+meta, but does not add it to the list. * Note that directories can be loaded as mods.*/ - private LoadedMod loadMod(FileHandle sourceFile, boolean workshop) throws Exception{ + private LoadedMod loadMod(FileHandle sourceFile) throws Exception{ FileHandle zip = sourceFile.isDirectory() ? sourceFile : new ZipFileHandle(sourceFile); if(zip.list().length == 1 && zip.list()[0].isDirectory()){ zip = zip.list()[0]; diff --git a/core/src/io/anuke/mindustry/ui/dialogs/ModsDialog.java b/core/src/io/anuke/mindustry/ui/dialogs/ModsDialog.java index 7471bac8f5..b06ed064f2 100644 --- a/core/src/io/anuke/mindustry/ui/dialogs/ModsDialog.java +++ b/core/src/io/anuke/mindustry/ui/dialogs/ModsDialog.java @@ -1,7 +1,9 @@ package io.anuke.mindustry.ui.dialogs; import io.anuke.arc.*; +import io.anuke.arc.Net.*; import io.anuke.arc.collection.*; +import io.anuke.arc.files.*; import io.anuke.arc.util.*; import io.anuke.arc.util.io.*; import io.anuke.mindustry.gen.*; @@ -34,19 +36,27 @@ public class ModsDialog extends FloatingDialog{ ui.loadfrag.show(); Core.net.httpGet("http://api.github.com/repos/" + text + "/zipball/master", loc -> { Core.net.httpGet(loc.getHeader("Location"), result -> { - try{ - Streams.copyStream(result.getResultAsStream(), modDirectory.child(text.replace("/", "") + ".zip").write(false)); - Core.app.post(() -> { - try{ - mods.reloadContent(); - setup(); - ui.loadfrag.hide(); - }catch(Throwable e){ - ui.showException(e); - } - }); - }catch(Throwable e){ - ui.showException(e); + if(result.getStatus() != HttpStatus.OK){ + ui.showErrorMessage(Core.bundle.format("connectfail", result.getStatus())); + ui.loadfrag.hide(); + }else{ + try{ + FileHandle file = tmpDirectory.child(text.replace("/", "") + ".zip"); + Streams.copyStream(result.getResultAsStream(), file.write(false)); + mods.importMod(file); + file.delete(); + Core.app.post(() -> { + try{ + mods.reloadContent(); + setup(); + ui.loadfrag.hide(); + }catch(Throwable e){ + ui.showException(e); + } + }); + }catch(Throwable e){ + ui.showException(e); + } } }, t -> Core.app.post(() -> ui.showException(t))); }, t -> Core.app.post(() -> ui.showException(t))); diff --git a/core/src/io/anuke/mindustry/world/Build.java b/core/src/io/anuke/mindustry/world/Build.java index 7d1441314f..c8a137f520 100644 --- a/core/src/io/anuke/mindustry/world/Build.java +++ b/core/src/io/anuke/mindustry/world/Build.java @@ -69,7 +69,7 @@ public class Build{ /** Returns whether a tile can be placed at this location by this team. */ public static boolean validPlace(Team team, int x, int y, Block type, int rotation){ - if(!type.isVisible() || type.isHidden()){ + if(type == null || !type.isVisible() || type.isHidden()){ return false; } diff --git a/core/src/io/anuke/mindustry/world/blocks/sandbox/LiquidSource.java b/core/src/io/anuke/mindustry/world/blocks/sandbox/LiquidSource.java index 4310bd0524..03f1c0d82d 100644 --- a/core/src/io/anuke/mindustry/world/blocks/sandbox/LiquidSource.java +++ b/core/src/io/anuke/mindustry/world/blocks/sandbox/LiquidSource.java @@ -113,7 +113,7 @@ public class LiquidSource extends Block{ @Override public void configured(Tile tile, Player player, int value){ - tile.entity().source = content.liquid(value); + tile.entity().source = value == -1 ? null : content.liquid(value); } class LiquidSourceEntity extends TileEntity{