Esempio n. 1
0
  private ObjectFile getDataStore(ObjectFileType filetype) throws Error {
    ObjectFile dataStore = dataStoreMap.get(filetype);
    if (dataStore != null) {
      return dataStore;
    }
    if (mapFile == null) {
      throw new Error("Mapfile not set.");
    }

    try {
      // extract unit file:
      try {
        LadikMpq editor = MpqEditorFactory.getEditor();
        File w3u = editor.extractFile(mapFile, "war3map." + filetype.getExt());
        dataStore = new ObjectFile(w3u, filetype);
      } catch (Error e) {
        dataStore = new ObjectFile(filetype);
      }
      dataStoreMap.put(filetype, dataStore);

      // clean datastore, remove all objects created by wurst
      deleteWurstObjects(dataStore);
    } catch (Exception e) {
      WLogger.severe(e);
      throw new Error(e);
    }

    return dataStore;
  }
Esempio n. 2
0
  private void writebackObjectFile(ObjectFile dataStore, ObjectFileType fileType) throws Error {
    File w3u = new File("./temp/new_war3map." + fileType.getExt());
    if (w3u.exists()) {
      w3u.delete();
    }
    dataStore.writeTo(w3u);

    try {
      Files.write(
          dataStore.exportToWurst(),
          new File("./temp/exportedObjects_" + fileType.getExt() + ".wurst"),
          Charsets.UTF_8);
    } catch (IOException e1) {
      WLogger.severe(e1);
    }

    try {
      LadikMpq editor = MpqEditorFactory.getEditor();
      String filenameInMpq = "war3map." + fileType.getExt();
      editor.deleteFile(mapFile, filenameInMpq);
      int tries = 1;
      while (tries < 20) {
        editor.insertFile(mapFile, filenameInMpq, w3u);

        File extr;
        try {
          extr = editor.extractFile(mapFile, filenameInMpq);
        } catch (Error e) {
          extr = null;
        }
        if (extr != null && extr.exists()) {
          break;
        }
        System.gc();
        tries++;
      }
      if (tries >= 20) {
        JOptionPane.showMessageDialog(null, "Could not insert " + fileType.getExt());
      }
    } catch (Exception e) {
      WLogger.severe(e);
      throw new Error(e);
    }
  }
Esempio n. 3
0
  private void testCompletions(CompletionTestData testData, List<String> expectedCompletions) {
    GetCompletions getCompletions =
        new GetCompletions(1, "test", testData.buffer, testData.line, testData.column);

    ModelManager modelManager = new ModelManagerImpl(new File("."));

    Handler h = new ConsoleHandler();
    WLogger.setHandler(h);

    List<WurstCompletion> result = getCompletions.execute(modelManager);

    // debug output:
    System.out.println(new GsonBuilder().setPrettyPrinting().create().toJson(result));

    List<String> completionLabels =
        result
            .stream()
            .map(completion -> completion.getDisplayString())
            .collect(Collectors.toList());

    Assert.assertEquals(expectedCompletions, completionLabels);
  }
Esempio n. 4
0
 public static void addWarning(AstElement e, String msg) {
   WLogger.info("Adding warning: " + msg);
   addErrorOrWarning(e, msg, ErrorType.WARNING);
 }
Esempio n. 5
0
 public static void addError(AstElement e, String msg) {
   WLogger.info("Adding error: " + msg);
   addErrorOrWarning(e, msg, ErrorType.ERROR);
 }