示例#1
1
  @Override
  protected void actionPerformed(GuiButton button) throws IOException {
    switch (button.id) {
      case 0: // Means Done
        ErrorHandling.CleanErrors();
        /* Closes the text editor, saves the .oc file and attempts to compile and load it */
        mc.thePlayer.closeScreen();
        text.deleteCharAt(cursorLocation);
        saveFile();
        try {
          Compiler.main(
              String.format(System.getProperty("user.dir") + "/ObsidiCode/Test/SimpleMiner.oc"));
        } catch (Exception e) {
          e.printStackTrace();
        }
        ArrayList<String> currentErrors = (ArrayList<String>) ErrorHandling.GetErrors().clone();
        if (currentErrors.size() == 0) {
          loadRobot();
        } else {
          ErrorBook eb = ObsidiSkriveMaskineMod.errorBook();
          ObsidiCodingMachine.dropErrorLog(eb);
        }
        break;
      case 1: // Means reset
        // Resets the text on the screen.
        text = text.delete(0, text.toString().length());
        cursorLocation = 0;
        break;
      default:
        break;
    }

    super.actionPerformed(button);
  }
示例#2
1
  // Loads any preexisting file. Also sets the RobotName.
  void loadFile() {
    System.out.println();
    if (text.toString().equals("")) {
      try {
        obsidiFileReader = new FileReader(obsidiFile);
        BufferedReader br = new BufferedReader(obsidiFileReader);
        boolean firstLine = true;
        for (String line = br.readLine(); line != null; line = br.readLine()) {
          text.append(line + '\n');
          if (firstLine) {
            robotName = line.replace(":", "");
            firstLine = false;
          }
        }

        obsidiFileReader.close();
      } catch (FileNotFoundException e) {
        ErrorHandling.Error("Could not load file: " + obsidiFile);
      } catch (IOException e) {
        ErrorHandling.Error("Could not open the file; " + e.getMessage());
      }
    }
  }