• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

wurstscript / WurstScript / 228

29 Nov 2023 05:00PM UTC coverage: 62.48% (-0.09%) from 62.574%
228

push

circleci

web-flow
Show dialog for choosing game path, cleanup (#1083)

* show dialog for choosing game path

* cleanup code

* remove logs and refactor

* remove confusing mpq error, make some mpq loads readonly

17295 of 27681 relevant lines covered (62.48%)

0.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/BuildMap.java
1
package de.peeeq.wurstio.languageserver.requests;
2

3
import config.WurstProjectConfig;
4
import config.WurstProjectConfigData;
5
import de.peeeq.wurstio.gui.WurstGuiImpl;
6
import de.peeeq.wurstio.languageserver.ModelManager;
7
import de.peeeq.wurstio.languageserver.WFile;
8
import de.peeeq.wurstio.languageserver.WurstLanguageServer;
9
import de.peeeq.wurstio.mpq.MpqEditor;
10
import de.peeeq.wurstio.mpq.MpqEditorFactory;
11
import de.peeeq.wurstscript.WLogger;
12
import de.peeeq.wurstscript.attributes.CompileError;
13
import de.peeeq.wurstscript.gui.WurstGui;
14
import org.eclipse.lsp4j.MessageType;
15

16
import java.io.File;
17
import java.io.IOException;
18
import java.util.List;
19
import java.util.Optional;
20

21
import static de.peeeq.wurstio.languageserver.ProjectConfigBuilder.FILE_NAME;
22

23
/**
24
 * Created by peter on 16.05.16.
25
 */
26
public class BuildMap extends MapRequest {
27

28
    public BuildMap(WurstLanguageServer languageServer, WFile workspaceRoot, Optional<String> wc3Path, Optional<File> map,
29
                    List<String> compileArgs) {
30
        super(languageServer, map, compileArgs, workspaceRoot, wc3Path);
×
31
    }
×
32

33
    @Override
34
    public Object execute(ModelManager modelManager) throws IOException {
35
        if (modelManager.hasErrors()) {
×
36
            throw new RequestFailedException(MessageType.Error, "Fix errors in your code before building a release.\n" + modelManager.getFirstErrorDescription());
×
37
        }
38

39
        WurstProjectConfigData projectConfig = WurstProjectConfig.INSTANCE.loadProject(workspaceRoot.getFile().toPath().resolve(FILE_NAME));
×
40
        if (projectConfig == null) {
×
41
            throw new RequestFailedException(MessageType.Error, FILE_NAME + " file doesn't exist or is invalid. " +
×
42
                "Please install your project using grill or the wurst setup tool.");
43
        }
44

45
        WLogger.info("buildMap " + map + " " + compileArgs);
×
46
        WurstGui gui = new WurstGuiImpl(workspaceRoot.getFile().getAbsolutePath());
×
47
        try {
48
            if (!map.isPresent()) {
×
49
                throw new RequestFailedException(MessageType.Error, "Map is null");
×
50
            }
51
            if (!map.get().exists()) {
×
52
                throw new RequestFailedException(MessageType.Error, map.get().getAbsolutePath() + " does not exist.");
×
53
            }
54

55
            gui.sendProgress("Copying map");
×
56

57
            // first we copy in same location to ensure validity
58
            File buildDir = getBuildDir();
×
59
            String fileName = projectConfig.getBuildMapData().getFileName();
×
60
            Optional<File> targetMap = Optional.of(
×
61
                new File(buildDir, fileName.isEmpty() ? projectConfig.getProjectName() + ".w3x" : fileName + ".w3x"));
×
62
            CompilationResult result = compileScript(modelManager, gui, targetMap, projectConfig, buildDir, true);
×
63

64
            injectMapData(gui, targetMap, result);
×
65

66
            //noinspection EmptyTryBlock
67
            try(MpqEditor ignored = MpqEditorFactory.getEditor(targetMap)) {
×
68
                // Just finalization
69
            }
×
70

71
            gui.sendProgress("Done.");
×
72
        } catch (CompileError e) {
×
73
            WLogger.info(e);
×
74
            throw new RequestFailedException(MessageType.Error, "A compilation error occurred when building the map:\n" + e);
×
75
        } catch (Exception e) {
×
76
            WLogger.warning("Exception occurred", e);
×
77
            throw new RequestFailedException(MessageType.Error, "An exception was thrown when building the map:\n" + e);
×
78
        } finally {
79
            if (gui.getErrorCount() == 0) {
×
80
                gui.sendFinished();
×
81
            }
82
        }
83
        return "ok"; // TODO
×
84
    }
85
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc