Ejemplo n.º 1
0
  public static KeyBinding loadKeyBindingFromTsv(String filepath, String colkey, String colvalue) {
    KeyBinding ret = new KeyBinding(colkey, colvalue);

    Input in_key = new InputFile(filepath, colkey, colvalue);
    new Pusher("loadKeyBindingFromTsv").always(new OutputKeyBinding(ret)).push(in_key);

    System.err.println("[KeyBinding.loadFromFile] loaded: " + filepath + " -> " + ret.toString());
    return ret;
  }
Ejemplo n.º 2
0
 public static KeyBinding loadStrict(String filename, String keyname, String valuename)
     throws LoadingException, SchemaException {
   KeyBinding ret = load(filename);
   List<String> sch = ret.getSchemaIn();
   if (keyname.equals(sch.get(0)) && valuename.equals(sch.get(1))) {
     return ret;
   } else {
     throw new SchemaException("[" + keyname + "," + valuename + "] != " + sch);
   }
 }
  /**
   * Loads the options from the options file. It appears that this has replaced the previous
   * 'loadOptions'
   */
  public void loadOptions() {
    try {
      if (!optionsFile.exists()) {
        return;
      }

      BufferedReader bufferedreader = new BufferedReader(new FileReader(optionsFile));

      for (String s = ""; (s = bufferedreader.readLine()) != null; ) {
        try {
          String as[] = s.split(":");

          if (as[0].equals("music")) {
            musicVolume = parseFloat(as[1]);
          }

          if (as[0].equals("sound")) {
            soundVolume = parseFloat(as[1]);
          }

          if (as[0].equals("mouseSensitivity")) {
            mouseSensitivity = parseFloat(as[1]);
          }

          if (as[0].equals("fov")) {
            fovSetting = parseFloat(as[1]);
          }

          if (as[0].equals("gamma")) {
            gammaSetting = parseFloat(as[1]);
          }

          if (as[0].equals("invertYMouse")) {
            invertMouse = as[1].equals("true");
          }

          if (as[0].equals("viewDistance")) {
            renderDistance = Integer.parseInt(as[1]);
          }

          if (as[0].equals("guiScale")) {
            guiScale = Integer.parseInt(as[1]);
          }

          if (as[0].equals("particles")) {
            particleSetting = Integer.parseInt(as[1]);
          }

          if (as[0].equals("bobView")) {
            viewBobbing = as[1].equals("true");
          }

          if (as[0].equals("anaglyph3d")) {
            anaglyph = as[1].equals("true");
          }

          if (as[0].equals("advancedOpengl")) {
            advancedOpengl = as[1].equals("true");
          }

          if (as[0].equals("fpsLimit")) {
            limitFramerate = Integer.parseInt(as[1]);
          }

          if (as[0].equals("difficulty")) {
            difficulty = Integer.parseInt(as[1]);
          }

          if (as[0].equals("fancyGraphics")) {
            fancyGraphics = as[1].equals("true");
          }

          if (as[0].equals("ao")) {
            ambientOcclusion = as[1].equals("true");
          }

          if (as[0].equals("clouds")) {
            clouds = as[1].equals("true");
          }

          if (as[0].equals("skin")) {
            skin = as[1];
          }

          if (as[0].equals("lastServer") && as.length >= 2) {
            lastServer = as[1];
          }

          if (as[0].equals("lang") && as.length >= 2) {
            language = as[1];
          }

          int i = 0;

          while (i < keyBindings.length) {
            if (as[0].equals(
                (new StringBuilder())
                    .append("key_")
                    .append(keyBindings[i].keyDescription)
                    .toString())) {
              keyBindings[i].keyCode = Integer.parseInt(as[1]);
            }

            i++;
          }
        } catch (Exception exception1) {
          System.out.println(
              (new StringBuilder()).append("Skipping bad option: ").append(s).toString());
        }
      }

      KeyBinding.resetKeyBindingArrayAndHash();
      bufferedreader.close();
    } catch (Exception exception) {
      System.out.println("Failed to load options");
      exception.printStackTrace();
    }
  }
Ejemplo n.º 4
0
  public static void main(String[] args) {
    KeyBinding bind;
    if ("-tsv".equals(args[0])) {
      bind = loadKeyBindingFromTsv(args[1], args[2], args[3]);
      bind.save(args[4]);
      return;
    } else {
      try {
        bind = KeyBinding.load(args[0]);
      } catch (LoadingException ex) {
        throw new RuntimeException(ex);
      }
    }

    if ("-value".equals(args[1])) {
      KeyBinding ret = KeyBinding.newLike(bind);
      Output out = new OutputKeyBinding(ret);

      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), out);
      }
      p.push(new InputKeyBinding(bind));
      ret.dumpTsv(System.out);
    } else if ("-count".equals(args[1])) {
      Pusher p = new Pusher();
      for (int i = 2; i < args.length; i++) {
        p.onlyIf(new IfEquals(bind.getColumnName(1), args[i]), new BreakAfter(args[i]));
      }
      p.push(new InputKeyBinding(bind));
    } else if ("-dump".equals(args[1])) {
      bind.dumpTsv(System.out);
    } else if ("-prompt".equals(args[1])) {
      try {
        jline.ConsoleReader reader = new jline.ConsoleReader();
        reader.setBellEnabled(false);
        reader.getHistory().setHistoryFile(new File(".KeyBinding.history"));
        String line = null;
        System.err.println("=== Enter Keys ===");
        while ((line = reader.readLine("keys> ")) != null) {
          if (!line.trim().isEmpty()) {
            for (String k : line.split("\\s+")) {
              System.out.print(k);
              System.out.print('\t');
              if (bind.contains(k)) {
                System.out.print(bind.get(k));
              } else {
                System.out.print("false");
              }
              System.out.println();
            }
          }
        }
      } catch (IOException ioex) {
        ioex.printStackTrace();
      }
    } else {
      int i = 1;
      if ("-key".equals(args[1])) {
        i = 2;
      }
      for (; i < args.length; i++) {
        System.out.print(args[i]);
        System.out.print('\t');
        if (bind.contains(args[i])) {
          System.out.print(bind.get(args[i]));
        } else {
          System.out.print("false");
        }
        System.out.println();
      }
    }
  }
Ejemplo n.º 5
0
 public static KeyBinding newLike(KeyBinding like) {
   return new KeyBinding(like.getColumnName(0), like.getColumnName(1));
 }