Skip to content

Commit 55812d7

Browse files
committed
fix map script caching
1 parent e17502c commit 55812d7

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ public Object execute(ModelManager modelManager) throws IOException {
5252
throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
5353
}
5454

55+
MapRequest.mapLastModified = map.get().lastModified();
56+
MapRequest.mapPath = map.get().getAbsolutePath();
57+
5558
gui.sendProgress("Copying map");
5659

5760
// first we copy in same location to ensure validity

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ public abstract class MapRequest extends UserRequest<Object> {
6262
protected final W3InstallationData w3data;
6363
protected final TimeTaker timeTaker;
6464

65+
public static long mapLastModified = 0L;
66+
public static String mapPath = "";
67+
68+
private static Long lastMapModified = 0L;
69+
private static String lastMapPath = "";
70+
6571
/**
6672
* makes the compilation slower, but more safe by discarding results from the editor and working on a copy of the model
6773
*/
@@ -378,7 +384,6 @@ protected CompilationResult compileScript(ModelManager modelManager, WurstGui gu
378384
return result;
379385
}
380386

381-
private static Long lastMapModified = 0L;
382387

383388
private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, WurstGui gui) throws Exception {
384389
File scriptFile = new File(new File(workspaceRoot.getFile(), "wurst"), "war3map.j");
@@ -393,10 +398,10 @@ private File loadMapScript(Optional<File> mapCopy, ModelManager modelManager, Wu
393398
"RunArg noExtractMapScript is set but no mapscript is provided inside the wurst folder");
394399
}
395400
}
396-
long mapLastModified = mapCopy.get().lastModified();
397-
if (mapLastModified > lastMapModified) {
398-
lastMapModified = mapLastModified;
399-
WLogger.info("extracting mapscript");
401+
if (MapRequest.mapLastModified > lastMapModified || !MapRequest.mapPath.equals(lastMapPath)) {
402+
lastMapModified = MapRequest.mapLastModified;
403+
lastMapPath = MapRequest.mapPath;
404+
System.out.println("Map not cached yet, extracting script");
400405
byte[] extractedScript = null;
401406
try (@Nullable MpqEditor mpqEditor = MpqEditorFactory.getEditor(mapCopy, true)) {
402407
if (mpqEditor.hasFile("war3map.j")) {

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/RunMap.java

+2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectC
9898

9999
// first we copy in same location to ensure validity
100100
File buildDir = getBuildDir();
101+
mapLastModified = map.get().lastModified();
102+
mapPath = map.get().getAbsolutePath();
101103
Optional<File> testMap = map.map($ -> new File(buildDir, "WurstRunMap.w3x"));
102104
CompilationResult result = compileScript(modelManager, gui, testMap, projectConfig, buildDir, false);
103105

0 commit comments

Comments
 (0)