Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions de.peeeq.wurstscript/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ dependencies {
implementation 'commons-lang:commons-lang:2.6'
implementation 'com.github.albfernandez:juniversalchardet:2.4.0'
implementation 'org.xerial:sqlite-jdbc:3.46.1.3'
implementation 'com.github.inwc3:jmpq3:29b55f2c32'
implementation 'com.github.inwc3:jmpq3:e28f6999c0'
implementation 'com.github.inwc3:wc3libs:6a96a79595'
implementation('com.github.wurstscript:wurstsetup:393cf5ea39') {
exclude group: 'org.eclipse.jgit', module: 'org.eclipse.jgit'
Expand Down Expand Up @@ -291,11 +291,17 @@ shadowJar {
def fatJar = shadowJar.archiveFile.map { it.asFile }

tasks.register('make_for_userdir', Copy) {
dependsOn 'shadowJar'
dependsOn 'shadowJar', 'make_for_userdir_wurst_compiler'
from fatJar
into "${System.properties['user.home']}/.wurst/"
}

tasks.register('make_for_userdir_wurst_compiler', Copy) {
dependsOn 'shadowJar'
from fatJar
into "${System.properties['user.home']}/.wurst/wurst-compiler/"
}

tasks.register('make_for_wurstpack', Copy) {
dependsOn 'shadowJar'
from fatJar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public CompilationProcess(WurstGui gui, RunArgs runArgs) {

if (runArgs.isRunTests()) {
timeTaker.measure("Run tests",
() -> runTests(compiler.getImTranslator(), compiler, runArgs.getTestTimeout()));
() -> runTests(compiler.getImTranslator(), compiler, runArgs.getTestTimeout(), runArgs.getTestFilter()));
}

timeTaker.measure("Run compiletime functions", () ->compiler.runCompiletime(new WurstProjectConfigData(), isProd, false));
Expand Down Expand Up @@ -153,12 +153,12 @@ private File writeMapscript(CharSequence mapScript) {
}
}

private void runTests(ImTranslator translator, WurstCompilerJassImpl compiler, int testTimeout) {
private void runTests(ImTranslator translator, WurstCompilerJassImpl compiler, int testTimeout, Optional<String> testFilter) {
PrintStream out = System.out;
// tests
gui.sendProgress("Running tests");
System.out.println("Running tests");
RunTests runTests = new RunTests(Optional.empty(), 0, 0, Optional.empty(), testTimeout) {
RunTests runTests = new RunTests(Optional.empty(), 0, 0, Optional.empty(), testTimeout, testFilter) {
@Override
protected void print(String message) {
out.print(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ReflectionNativeProvider implements NativesProvider {
private final HashMap<String, NativeJassFunction> methodMap = new HashMap<>();

public ReflectionNativeProvider(AbstractInterpreter interpreter) {
addProvider(new AbilityProvider(interpreter));
addProvider(new GamecacheProvider(interpreter));
addProvider(new ForceProvider(interpreter));
addProvider(new HandleProvider(interpreter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
import de.peeeq.wurstscript.intermediatelang.ILconstInt;
import de.peeeq.wurstscript.intermediatelang.ILconstNull;

import java.util.HashMap;

public class PlayerMock {
public final ILconstInt id;
public ILconst playerColor = ILconstNull.instance();
public final HashMap<Integer, ILconstInt> techMaxAllowed = new HashMap<>();

public PlayerMock(ILconstInt p) {
this.id = p;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package de.peeeq.wurstio.jassinterpreter.providers;

import de.peeeq.wurstscript.intermediatelang.ILconstInt;
import de.peeeq.wurstscript.intermediatelang.ILconstString;
import de.peeeq.wurstscript.intermediatelang.interpreter.AbstractInterpreter;

public class AbilityProvider extends Provider {
public AbilityProvider(AbstractInterpreter interpreter) {
super(interpreter);
}

public ILconstString BlzGetAbilityIcon(ILconstInt abilCode) {
return new ILconstString("");
}

public ILconstString BlzGetAbilityExtendedTooltip(ILconstInt abilCode, ILconstInt level) {
return new ILconstString("");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ public IlConstHandle ConvertUnitState(ILconstInt i) {
return new IlConstHandle("unitstate" + i, new LinkedHashSet<>());
}

public IlConstHandle ConvertUnitIntegerField(ILconstInt i) {
return new IlConstHandle("unitintegerfield" + i, i.getVal());
}

public IlConstHandle ConvertUnitWeaponIntegerField(ILconstInt i) {
return new IlConstHandle("unitweaponintegerfield" + i, i.getVal());
}

public IlConstHandle ConvertAIDifficulty(ILconstInt i) {
return new IlConstHandle("aidifficulty" + i, new LinkedHashSet<>());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public void ForceClear(IlConstHandle force) {
}

public ILconstBool IsPlayerInForce(IlConstHandle player, IlConstHandle force) {
if (player == null || force == null) {
return ILconstBool.FALSE;
}
LinkedHashSet<IlConstHandle> forceList = (LinkedHashSet<IlConstHandle>) force.getObj();
return ILconstBool.instance(forceList.contains(player));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ public OutputProvider(AbstractInterpreter interpreter) {
super(interpreter);
}

public void DisplayTextToForce(IlConstHandle force, ILconstString msg) {
outStream.println(msg.getVal());
}

public void DisplayTimedTextToForce(IlConstHandle force, ILconstReal duration, ILconstString msg) {
outStream.println(msg.getVal());
}

public void DisplayTextToPlayer(IlConstHandle player, ILconstReal x, ILconstReal y, ILconstString msg) {
outStream.println(msg.getVal());
}

public void DisplayTimedTextToPlayer(IlConstHandle player, ILconstReal x, ILconstReal y, ILconstReal duration, ILconstString msg) {
outStream.println(msg.getVal());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public ILconstInt GetPlayerNeutralAggressive() {


public IlConstHandle GetLocalPlayer() {
return new IlConstHandle("Local Player", "local player");
return Player(ILconstInt.create(0));
}

public ILconstInt GetBJMaxPlayerSlots() {
Expand All @@ -53,4 +53,12 @@ public void SetPlayerColor(IlConstHandle player, IlConstHandle playercolor) {
public ILconst GetPlayerColor(IlConstHandle player) {
return ((PlayerMock) player.getObj()).playerColor;
}

public void SetPlayerTechMaxAllowed(IlConstHandle player, ILconstInt techid, ILconstInt maximum) {
((PlayerMock) player.getObj()).techMaxAllowed.put(techid.getVal(), maximum);
}

public ILconstInt GetPlayerTechMaxAllowed(IlConstHandle player, ILconstInt techid) {
return ((PlayerMock) player.getObj()).techMaxAllowed.getOrDefault(techid.getVal(), ILconstInt.create(0));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.peeeq.wurstio.jassinterpreter.providers;

import de.peeeq.wurstio.objectreader.ObjectHelper;
import de.peeeq.wurstio.jassinterpreter.mocks.UnitMock;
import de.peeeq.wurstscript.intermediatelang.ILconstBool;
import de.peeeq.wurstscript.intermediatelang.ILconstInt;
import de.peeeq.wurstscript.intermediatelang.ILconstReal;
import de.peeeq.wurstscript.intermediatelang.ILconstString;
import de.peeeq.wurstscript.intermediatelang.IlConstHandle;
import de.peeeq.wurstscript.intermediatelang.interpreter.AbstractInterpreter;

Expand All @@ -23,11 +26,58 @@ public ILconstInt GetUnitTypeId(IlConstHandle unit) {
return ((UnitMock)unit.getObj()).unitid;
}

public ILconstString GetUnitName(IlConstHandle unit) {
if (unit == null) {
return new ILconstString("");
}
UnitMock unitMock = (UnitMock) unit.getObj();
return new ILconstString(ObjectHelper.objectIdIntToString(unitMock.unitid.getVal()));
}

public ILconstInt GetUnitGoldCost(ILconstInt unitid) {
return ILconstInt.create(0);
}

public ILconstInt GetUnitWoodCost(ILconstInt unitid) {
return ILconstInt.create(0);
}

public ILconstInt GetUnitPointValueByType(ILconstInt unitid) {
return ILconstInt.create(0);
}

public ILconstInt GetFoodUsed(ILconstInt unitid) {
return ILconstInt.create(0);
}

public ILconstInt GetUnitBuildTime(ILconstInt unitid) {
return ILconstInt.create(0);
}

public ILconstInt BlzGetUnitIntegerField(IlConstHandle whichUnit, IlConstHandle whichField) {
return ILconstInt.create(0);
}

public ILconstInt BlzGetUnitWeaponIntegerField(IlConstHandle whichUnit, IlConstHandle whichField, ILconstInt index) {
return ILconstInt.create(0);
}

public ILconstBool IsUnitType(IlConstHandle whichUnit, IlConstHandle whichUnitType) {
return ILconstBool.FALSE;
}

public void RemoveUnit(IlConstHandle unit) {
userDataMap.remove(unit);
}

public ILconstInt GetUnitUserData(IlConstHandle unit) {
return userDataMap.get(unit);
return unit == null ? ILconstInt.create(0) : userDataMap.getOrDefault(unit, ILconstInt.create(0));
}

public void SetUnitUserData(IlConstHandle unit, ILconstInt userData) {
if (unit == null) {
return;
}
userDataMap.put(unit, userData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ protected boolean canUseCachedMap(File cachedMap) {
}

// Check if source map is newer
if (map.isPresent() && map.get().lastModified() > cachedMap.lastModified()) {
if (map.isPresent() && getSourceMapLastModified(map.get()) > cachedMap.lastModified()) {
WLogger.info("Source map is newer than cache");
return false;
}
Expand Down Expand Up @@ -514,16 +514,69 @@ protected File ensureCachedMap(WurstGui gui) throws IOException {

File sourceMap = map.get();

long sourceLastModified = getSourceMapLastModified(sourceMap);
// If cached map doesn't exist or source is newer, update cache
if (!cachedMap.exists() || sourceMap.lastModified() > cachedMap.lastModified()) {
if (!cachedMap.exists() || sourceLastModified > cachedMap.lastModified()) {
WLogger.info("Updating cached map from source");
gui.sendProgress("Updating cached map");
Files.copy(sourceMap, cachedMap);
if (sourceMap.isDirectory()) {
buildArchiveFromFolder(sourceMap, cachedMap);
} else {
Files.copy(sourceMap, cachedMap);
}
}

return cachedMap;
}

protected static long getSourceMapLastModified(File sourceMap) {
if (!sourceMap.isDirectory()) {
return sourceMap.lastModified();
}
try (java.util.stream.Stream<Path> files = java.nio.file.Files.walk(sourceMap.toPath())) {
return files
.map(Path::toFile)
.mapToLong(File::lastModified)
.max()
.orElse(sourceMap.lastModified());
} catch (IOException e) {
WLogger.warning("Could not inspect folder map timestamp: " + sourceMap + " (" + e.getMessage() + ")");
return sourceMap.lastModified();
}
}

private static void buildArchiveFromFolder(File sourceFolder, File cachedMap) throws IOException {
try {
java.nio.file.Files.deleteIfExists(cachedMap.toPath());
MpqEditorFactory.createEmptyArchive(cachedMap);
try (MpqEditor mpqEditor = MpqEditorFactory.getEditor(Optional.of(cachedMap))) {
try (java.util.stream.Stream<Path> files = java.nio.file.Files.walk(sourceFolder.toPath())) {
List<Path> regularFiles = files
.filter(java.nio.file.Files::isRegularFile)
.sorted(Comparator.comparing(path -> sourceFolder.toPath().relativize(path).toString().replace('\\', '/')))
.collect(Collectors.toList());
for (Path file : regularFiles) {
String filenameInMpq = sourceFolder.toPath().relativize(file).toString().replace('/', '\\');
if (isInternalMpqMetadataFile(filenameInMpq)) {
continue;
}
mpqEditor.insertFile(filenameInMpq, file.toFile());
}
}
}
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw new IOException("Could not build MPQ archive from folder map: " + sourceFolder.getAbsolutePath(), e);
}
}

private static boolean isInternalMpqMetadataFile(String filenameInMpq) {
return filenameInMpq.equals("(listfile)")
|| filenameInMpq.equals("(attributes)")
|| filenameInMpq.equals("(signature)");
}

private void cleanupOppositeModeCacheAndOutputs() {
if (cachedMapFileName.isEmpty()) {
File cacheDir = new File(getBuildDir(), "cache");
Expand Down Expand Up @@ -685,7 +738,7 @@ protected File executeBuildMapPipeline(ModelManager modelManager, WurstGui gui,
throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
}

mapLastModified = map.get().lastModified();
mapLastModified = getSourceMapLastModified(map.get());
mapPath = map.get().getAbsolutePath();

gui.sendProgress("Copying map");
Expand Down Expand Up @@ -830,6 +883,17 @@ protected byte[] extractMapScript(Optional<File> mapCopy) throws Exception {
if (!mapCopy.isPresent()) {
return null;
}
if (mapCopy.get().isDirectory()) {
File rootScript = new File(mapCopy.get(), "war3map.j");
if (rootScript.exists()) {
return java.nio.file.Files.readAllBytes(rootScript.toPath());
}
File scriptsScript = new File(new File(mapCopy.get(), "scripts"), "war3map.j");
if (scriptsScript.exists()) {
return java.nio.file.Files.readAllBytes(scriptsScript.toPath());
}
return null;
}
try (@Nullable MpqEditor mpqEditor = MpqEditorFactory.getEditor(mapCopy, true)) {
if (mpqEditor.hasFile("war3map.j")) {
return mpqEditor.extractFile("war3map.j");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private String compileMap(ModelManager modelManager, WurstGui gui, WurstProjectC
// first we copy in same location to ensure validity
File buildDir = getBuildDir();
if (map.isPresent()) {
mapLastModified = map.get().lastModified();
mapLastModified = getSourceMapLastModified(map.get());
mapPath = map.get().getAbsolutePath();
}
if (!runArgs.isHotReload()) {
Expand Down
Loading
Loading