From 955dc5f48d899707fc6c5d66c26034bb63840d8a Mon Sep 17 00:00:00 2001 From: Anuken Date: Thu, 24 Oct 2019 18:04:39 -0400 Subject: [PATCH] Bugfixes / Copy over plugins to mod folder --- core/assets/bundles/bundle.properties | 1 + .../io/anuke/mindustry/game/Schematics.java | 19 +++++++++++++++++++ .../anuke/mindustry/input/DesktopInput.java | 18 +++++++++++++----- .../io/anuke/mindustry/mod/ContentParser.java | 2 ++ core/src/io/anuke/mindustry/mod/Mods.java | 6 ++++-- .../mindustry/server/MindustryServer.java | 11 +++++++++++ .../anuke/mindustry/server/ServerControl.java | 3 +-- 7 files changed, 51 insertions(+), 9 deletions(-) diff --git a/core/assets/bundles/bundle.properties b/core/assets/bundles/bundle.properties index bb172b075f..469961b52b 100644 --- a/core/assets/bundles/bundle.properties +++ b/core/assets/bundles/bundle.properties @@ -29,6 +29,7 @@ load.mod = Mods schematic = Schematic schematic.add = Save Schematic... schematics = Schematics +schematic.replace = A schematic by that name already exists. Replace it? schematic.import = Import Schematic... schematic.exportfile = Export File schematic.importfile = Import File diff --git a/core/src/io/anuke/mindustry/game/Schematics.java b/core/src/io/anuke/mindustry/game/Schematics.java index a81e10c6fb..9b1bda5470 100644 --- a/core/src/io/anuke/mindustry/game/Schematics.java +++ b/core/src/io/anuke/mindustry/game/Schematics.java @@ -68,6 +68,25 @@ public class Schematics implements Loadable{ }); } + public void overwrite(Schematic target, Schematic newSchematic){ + if(previews.containsKey(target)){ + previews.get(target).dispose(); + previews.remove(target); + } + + target.tiles.clear(); + target.tiles.addAll(newSchematic.tiles); + newSchematic.tags.putAll(target.tags); + newSchematic.file = target.file; + + try{ + write(newSchematic, target.file); + }catch(Exception e){ + Log.err(e); + ui.showException(e); + } + } + private void loadFile(FileHandle file){ if(!file.extension().equals(schematicExtension)) return; diff --git a/core/src/io/anuke/mindustry/input/DesktopInput.java b/core/src/io/anuke/mindustry/input/DesktopInput.java index cc97387579..b66bc7068f 100644 --- a/core/src/io/anuke/mindustry/input/DesktopInput.java +++ b/core/src/io/anuke/mindustry/input/DesktopInput.java @@ -60,7 +60,6 @@ public class DesktopInput extends InputHandler{ t.visible(() -> lastSchematic != null && !selectRequests.isEmpty()); t.bottom(); t.table(Styles.black6, b -> { - //b.touchable(Touchable.enabled); b.defaults().left(); b.add(Core.bundle.format("schematic.flip", Core.keybinds.get(Binding.schematic_flip_x).key.name(), @@ -69,10 +68,19 @@ public class DesktopInput extends InputHandler{ b.table(a -> { a.addImageTextButton("$schematic.add", Icon.saveSmall, () -> { ui.showTextInput("$schematic.add", "$name", "", text -> { - lastSchematic.tags.put("name", text); - schematics.add(lastSchematic); - ui.showInfoFade("$schematic.saved"); - ui.schematics.showInfo(lastSchematic); + Schematic replacement = schematics.all().find(s -> s.name().equals(text)); + if(replacement != null){ + ui.showConfirm("$confirm", "$schematic.replace", () -> { + schematics.overwrite(replacement, lastSchematic); + ui.showInfoFade("$schematic.saved"); + ui.schematics.showInfo(replacement); + }); + }else{ + lastSchematic.tags.put("name", text); + schematics.add(lastSchematic); + ui.showInfoFade("$schematic.saved"); + ui.schematics.showInfo(lastSchematic); + } }); }).colspan(2).size(250f, 50f).disabled(f -> lastSchematic == null || lastSchematic.file != null); }); diff --git a/core/src/io/anuke/mindustry/mod/ContentParser.java b/core/src/io/anuke/mindustry/mod/ContentParser.java index e7b8c26b3c..c19c22733c 100644 --- a/core/src/io/anuke/mindustry/mod/ContentParser.java +++ b/core/src/io/anuke/mindustry/mod/ContentParser.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.mod; import io.anuke.arc.*; import io.anuke.arc.audio.*; +import io.anuke.arc.audio.mock.*; import io.anuke.arc.collection.Array; import io.anuke.arc.collection.*; import io.anuke.arc.files.*; @@ -52,6 +53,7 @@ public class ContentParser{ }); put(Sound.class, (type, data) -> { if(fieldOpt(Sounds.class, data) != null) return fieldOpt(Sounds.class, data); + if(Vars.headless) return new MockSound(); String path = "sounds/" + data.asString() + (Vars.ios ? ".mp3" : ".ogg"); ModLoadingSound sound = new ModLoadingSound(); diff --git a/core/src/io/anuke/mindustry/mod/Mods.java b/core/src/io/anuke/mindustry/mod/Mods.java index 84ecb3bcb6..785b3596cd 100644 --- a/core/src/io/anuke/mindustry/mod/Mods.java +++ b/core/src/io/anuke/mindustry/mod/Mods.java @@ -169,9 +169,11 @@ public class Mods implements Loadable{ for(FileHandle file : modDirectory.list()){ if(!file.extension().equals("jar") && !file.extension().equals("zip") && !(file.isDirectory() && file.child("mod.json").exists())) continue; + + Log.debug("[Mods] Loading mod {0}", file); try{ LoadedMod mod = loadMod(file, false); - if(mod.enabled()){ + if(mod.enabled() || headless){ loaded.add(mod); }else{ disabled.add(mod); @@ -286,7 +288,7 @@ public class Mods implements Loadable{ try{ //this binds the content but does not load it entirely Content loaded = parser.parse(mod, file.nameWithoutExtension(), file.readString("UTF-8"), file, type); - Log.info("[{0}] Loaded '{1}'.", mod.meta.name, + Log.debug("[{0}] Loaded '{1}'.", mod.meta.name, (loaded instanceof UnlockableContent ? ((UnlockableContent)loaded).localizedName : loaded)); }catch(Exception e){ throw new RuntimeException("Failed to parse content file '" + file + "' for mod '" + mod.meta.name + "'.", e); diff --git a/server/src/io/anuke/mindustry/server/MindustryServer.java b/server/src/io/anuke/mindustry/server/MindustryServer.java index c42e695c1d..ad83a69eb7 100644 --- a/server/src/io/anuke/mindustry/server/MindustryServer.java +++ b/server/src/io/anuke/mindustry/server/MindustryServer.java @@ -1,6 +1,8 @@ package io.anuke.mindustry.server; import io.anuke.arc.*; +import io.anuke.arc.files.*; +import io.anuke.arc.util.*; import io.anuke.mindustry.*; import io.anuke.mindustry.core.*; import io.anuke.mindustry.mod.*; @@ -20,6 +22,15 @@ public class MindustryServer implements ApplicationListener{ loadLocales = false; headless = true; + FileHandle plugins = Core.settings.getDataDirectory().child("plugins"); + if(plugins.isDirectory() && plugins.list().length > 0 && !plugins.sibling("mods").exists()){ + Log.warn("[IMPORTANT NOTICE] &lrPlugins have been detected.&ly Automatically moving all contents of the plugin folder into the 'mods' folder. The original folder will not be removed; please do so manually."); + plugins.sibling("mods").mkdirs(); + for(FileHandle file : plugins.list()){ + file.copyTo(plugins.sibling("mods")); + } + } + Vars.loadSettings(); Vars.init(); content.createContent(); diff --git a/server/src/io/anuke/mindustry/server/ServerControl.java b/server/src/io/anuke/mindustry/server/ServerControl.java index af6e5f4734..3d5429d885 100644 --- a/server/src/io/anuke/mindustry/server/ServerControl.java +++ b/server/src/io/anuke/mindustry/server/ServerControl.java @@ -751,8 +751,7 @@ public class ServerControl implements ApplicationListener{ }); mods.each(p -> p.registerServerCommands(handler)); - //TODO - //plugins.each(p -> p.registerClientCommands(netServer.clientCommands)); + mods.each(p -> p.registerClientCommands(netServer.clientCommands)); } private void readCommands(){