Skip to content

Commit

Permalink
update jmpq, parse custom patch version also on buildmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Frotty committed Dec 31, 2019
1 parent 2c46847 commit feabdf1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ private static CompletableFuture<Object> 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<String> 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<Object> startmap(WurstLanguageServer server, ExecuteCommandParams params, String... additionalArgs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -25,11 +26,10 @@
*/
public class BuildMap extends MapRequest {

public BuildMap(ConfigProvider configProvider, WFile workspaceRoot, File map, List<String> compileArgs) {
super(configProvider, map, compileArgs, workspaceRoot);
public BuildMap(ConfigProvider configProvider, WFile workspaceRoot, @Nullable String wc3Path, File map, List<String> compileArgs) {
super(configProvider, map, compileArgs, workspaceRoot, wc3Path);
}


@Override
public Object execute(ModelManager modelManager) throws IOException {
if (modelManager.hasErrors()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,6 +51,7 @@ public abstract class MapRequest extends UserRequest<Object> {
protected final List<String> 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
Expand All @@ -60,12 +62,13 @@ enum SafetyLevel {
QuickAndDirty, KindOfSafe
}

public MapRequest(ConfigProvider configProvider, @Nullable File map, List<String> compileArgs, WFile workspaceRoot) {
public MapRequest(ConfigProvider configProvider, @Nullable File map, List<String> 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
Expand Down Expand Up @@ -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);

Expand All @@ -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);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> compileArgs) {
super(configProvider, map, compileArgs, workspaceRoot);
this.wc3Path = wc3Path;
super(configProvider, map, compileArgs, workspaceRoot, wc3Path);
}

@Override
Expand All @@ -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.");
}
Expand Down Expand Up @@ -141,13 +132,11 @@ public Object execute(ModelManager modelManager) throws IOException {
}
List<String> 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");
}
Expand All @@ -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) {
Expand Down

0 comments on commit feabdf1

Please sign in to comment.