diff --git a/de.peeeq.wurstscript/build.gradle b/de.peeeq.wurstscript/build.gradle index ff04fb0c9..c97b9444c 100644 --- a/de.peeeq.wurstscript/build.gradle +++ b/de.peeeq.wurstscript/build.gradle @@ -102,7 +102,7 @@ dependencies { compile group: 'net.sourceforge.jchardet', name: 'jchardet', version: '1.0' // Crigges' jmpq - compile 'com.github.inwc3:jmpq3:f40e2121a1' + compile 'com.github.inwc3:jmpq3:1.7.11' // Water's wc3 libs compile 'com.github.inwc3:wc3libs:3f4c317de3' diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstCommands.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstCommands.java index 78f2bcfa1..d2ee158a7 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstCommands.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/WurstCommands.java @@ -80,13 +80,14 @@ private static CompletableFuture buildmap(WurstLanguageServer server, Ex } JsonObject options = (JsonObject) params.getArguments().get(0); String mapPath = getString(options, "mappath"); + String wc3Path = getString(options, "wc3path"); if (mapPath == null) { throw new RuntimeException("No mappath given"); } File map = new File(mapPath); List compileArgs = getCompileArgs(workspaceRoot); - return server.worker().handle(new BuildMap(server.getConfigProvider(), workspaceRoot, map, compileArgs)).thenApply(x -> x); + return server.worker().handle(new BuildMap(server.getConfigProvider(), workspaceRoot, wc3Path, map, compileArgs)).thenApply(x -> x); } private static CompletableFuture startmap(WurstLanguageServer server, ExecuteCommandParams params, String... additionalArgs) { diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java index 09d2474e7..6e7c19da7 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java @@ -11,6 +11,7 @@ import de.peeeq.wurstscript.attributes.CompileError; import de.peeeq.wurstscript.gui.WurstGui; import org.eclipse.lsp4j.MessageType; +import org.jetbrains.annotations.Nullable; import systems.crigges.jmpq3.JMpqEditor; import systems.crigges.jmpq3.MPQOpenOption; @@ -25,11 +26,10 @@ */ public class BuildMap extends MapRequest { - public BuildMap(ConfigProvider configProvider, WFile workspaceRoot, File map, List compileArgs) { - super(configProvider, map, compileArgs, workspaceRoot); + public BuildMap(ConfigProvider configProvider, WFile workspaceRoot, @Nullable String wc3Path, File map, List compileArgs) { + super(configProvider, map, compileArgs, workspaceRoot, wc3Path); } - @Override public Object execute(ModelManager modelManager) throws IOException { if (modelManager.hasErrors()) { diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java index 85eeb6085..775c2b4fe 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java @@ -10,6 +10,7 @@ import de.peeeq.wurstio.languageserver.WFile; import de.peeeq.wurstio.mpq.MpqEditor; import de.peeeq.wurstio.mpq.MpqEditorFactory; +import de.peeeq.wurstio.utils.W3Utils; import de.peeeq.wurstscript.RunArgs; import de.peeeq.wurstscript.WLogger; import de.peeeq.wurstscript.ast.CompilationUnit; @@ -50,6 +51,7 @@ public abstract class MapRequest extends UserRequest { protected final List compileArgs; protected final WFile workspaceRoot; protected final RunArgs runArgs; + @Nullable protected final String wc3Path; /** * makes the compilation slower, but more safe by discarding results from the editor and working on a copy of the model @@ -60,12 +62,13 @@ enum SafetyLevel { QuickAndDirty, KindOfSafe } - public MapRequest(ConfigProvider configProvider, @Nullable File map, List compileArgs, WFile workspaceRoot) { + public MapRequest(ConfigProvider configProvider, @Nullable File map, List compileArgs, WFile workspaceRoot, String wc3Path) { this.configProvider = configProvider; this.map = map; this.compileArgs = compileArgs; this.workspaceRoot = workspaceRoot; this.runArgs = new RunArgs(compileArgs); + this.wc3Path = wc3Path; } @Override @@ -350,6 +353,8 @@ protected File compileScript(ModelManager modelManager, WurstGui gui, @Nullable Files.copy(map, testMap); } + parseCustomPatchVersion(); + // first compile the script: File compiledScript = compileScript(gui, modelManager, compileArgs, testMap); @@ -361,4 +366,13 @@ protected File compileScript(ModelManager modelManager, WurstGui gui, @Nullable } return compiledScript; } + + private void parseCustomPatchVersion() { + if (wc3Path != null) { + W3Utils.parsePatchVersion(new File(wc3Path)); + if (W3Utils.getWc3PatchVersion() == null) { + throw new RequestFailedException(MessageType.Error, "Could not find Warcraft III installation at specified path: " + wc3Path); + } + } + } } diff --git a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java index 7a5710e14..d9e0fbc9d 100644 --- a/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java +++ b/de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java @@ -41,14 +41,12 @@ * Created by peter on 16.05.16. */ public class RunMap extends MapRequest { - private final @Nullable - String wc3Path; + private File customTarget = null; public RunMap(ConfigProvider configProvider, WFile workspaceRoot, @Nullable String wc3Path, @Nullable File map, List compileArgs) { - super(configProvider, map, compileArgs, workspaceRoot); - this.wc3Path = wc3Path; + super(configProvider, map, compileArgs, workspaceRoot, wc3Path); } @Override @@ -74,13 +72,6 @@ public Object execute(ModelManager modelManager) throws IOException { WLogger.info("received runMap command: map=" + map + ", wc3dir=" + wc3Path + ", args=" + compileArgs); WurstGui gui = new WurstGuiImpl(getWorkspaceAbsolute()); try { - if (wc3Path != null) { - W3Utils.parsePatchVersion(new File(wc3Path)); - if (W3Utils.getWc3PatchVersion() == null) { - throw new RequestFailedException(MessageType.Error, "Could not find Warcraft III installation!"); - } - } - if (map != null && !map.exists()) { throw new RequestFailedException(MessageType.Error, map.getAbsolutePath() + " does not exist."); } @@ -141,13 +132,11 @@ public Object execute(ModelManager modelManager) throws IOException { } List cmd = Lists.newArrayList(gameExe.getAbsolutePath()); String wc3RunArgs = configProvider.getWc3RunArgs(); - if (wc3RunArgs == null || StringUtils.isBlank(wc3RunArgs)) { - if (W3Utils.getWc3PatchVersion().compareTo(VERSION_1_32) >= 0) { - cmd.add("-launch"); - } + if (StringUtils.isBlank(wc3RunArgs)) { if (W3Utils.getWc3PatchVersion().compareTo(VERSION_1_31) < 0) { cmd.add("-window"); } else { + cmd.add("-launch"); cmd.add("-windowmode"); cmd.add("windowed"); } @@ -163,7 +152,7 @@ public Object execute(ModelManager modelManager) throws IOException { } gui.sendProgress("running " + cmd); - Process p = Runtime.getRuntime().exec(cmd.toArray(new String[0])); + Runtime.getRuntime().exec(cmd.toArray(new String[0])); } } } catch (CompileError e) {