Package se.llbit.json

Examples of se.llbit.json.JsonObject


      }
      return LibraryStatus.PASSED;
    }

    public JsonObject json() {
      JsonObject obj = new JsonObject();
      obj.add("name", name);
      obj.add("md5", md5);
      obj.add("url", url);
      obj.add("size", size);
      return obj;
    }
View Full Code Here


   * @param in input stream - will be closed
   */
  public void loadDescription(InputStream in) throws IOException {
    try {
      JsonParser parser = new JsonParser(in);
      JsonObject desc = parser.parse().object();
      fromJson(desc);
    } catch (SyntaxError e) {
      throw new IOException("JSON syntax error");
    } finally {
      in.close();
View Full Code Here

    out.close();
  }

  @Override
  public synchronized JsonObject toJson() {
    JsonObject desc = new JsonObject();
    desc.add("sdfVersion", SDF_VERSION);
    desc.add("name", name);
    desc.add("width", width);
    desc.add("height", height);
    desc.add("exposure", exposure);
    desc.add("postprocess", postprocess.ordinal());
    desc.add("renderTime", renderTime);
    desc.add("spp", spp);
    desc.add("sppTarget", sppTarget);
    desc.add("rayDepth", rayDepth);
    desc.add("pathTrace", pathTrace);
    desc.add("dumpFrequency", dumpFrequency);
    desc.add("saveSnapshots", saveSnapshots);

    desc.add("emittersEnabled", emittersEnabled);
    desc.add("emitterIntensity", emitterIntensity);
    desc.add("sunEnabled", sunEnabled);
    desc.add("stillWater", stillWater);
    desc.add("clearWater", clearWater);
    desc.add("biomeColorsEnabled", biomeColors);
    desc.add("atmosphereEnabled", atmosphereEnabled);
    desc.add("volumetricFogEnabled", volumetricFogEnabled);
    desc.add("waterHeight", waterHeight);

    // save world info
    if (!worldPath.isEmpty()) {
      JsonObject world = new JsonObject();
      world.add("path", worldPath);
      world.add("dimension", worldDimension);
      desc.add("world", world);
    }

    desc.add("camera", camera.toJson());
    desc.add("sun", sun.toJson());
View Full Code Here

        mode = Mode.NO_OP;
        if (args.length > i+3) {
          options.sceneName = args[i+3];
          try {
            File file = getSceneFile(options);
            JsonObject desc = readSceneJson(file);
            String name = args[i+1];
            String value = args[i+2];
            System.out.println(name + " <- " + value);
            String[] path = name.split("\\.");
            JsonObject obj = desc;
            for (int j = 0; j < path.length-1; ++j) {
              obj = obj.get(path[j]).object();
            }
            JsonValue jsonValue;
            try {
              jsonValue = new JsonNumber(Integer.parseInt(value));
            } catch (Exception e) {
              jsonValue = new JsonString(value);
            }
            obj.set(path[path.length-1], jsonValue);
            writeSceneJson(file, desc);
            System.out.println("Updated scene " + file.getAbsolutePath());
          } catch (SyntaxError e) {
            System.err.println("JSON syntax error");
          } catch (IOException e) {
            System.err.println("Failed to write/load Scene Description File: " +
                e.getMessage());
          }
          i += 3;
          return;
        } else if (args.length > i+2) {
          String name = args[i+1];
          String value = args[i+2];
          try {
            PersistentSettings.setIntOption(name, Integer.parseInt(value));
          } catch (Exception e) {
            PersistentSettings.setStringOption(name, value);
          }
          i += 2;
          return;
        } else {
          System.err.println("Too few arguments for -set option!");
          confError = true;
          break;
        }
      } else if (args[i].equals("-reset")) {
        mode = Mode.NO_OP;
        if (args.length > i+2) {
          options.sceneName = args[i+2];
          try {
            File file = getSceneFile(options);
            JsonObject desc = readSceneJson(file);
            String name = args[i+1];
            System.out.println("- " + name);
            String[] path = name.split("\\.");
            JsonObject obj = desc;
            for (int j = 0; j < path.length-1; ++j) {
              obj = obj.get(path[j]).object();
            }
            for (int j = 0; j < obj.getNumMember(); ++j) {
              if (obj.getMember(j).getName().equals(name)) {
                obj.getMemberList().removeChild(j);
                break;
              }
            }
            writeSceneJson(file, desc);
            System.out.println("Updated scene " + file.getAbsolutePath());
View Full Code Here

      e.printStackTrace(System.err);
    }
  }

  private static JsonObject libraryJson(File lib) {
    JsonObject library = new JsonObject();
    library.add("name", lib.getName());
    library.add("md5", Util.md5sum(lib));
    library.add("size", (int) Math.min(Integer.MAX_VALUE, lib.length()));
    return library;
  }
View Full Code Here

  private void addVersionInfoJson(JarOutputStream jar, File chunkyCore) throws IOException {
    File libDir = new File(LIBRARY_PATH);
    if (!libDir.isDirectory()) {
      System.err.println("Not a valid directory: "+LIBRARY_PATH);
    }
    JsonObject version = new JsonObject();
    version.add("name", versionName);
    version.add("timestamp", Util.ISO8601FromDate(new Date()));
    version.add("notes", notes);
    JsonArray libraries = new JsonArray();
    {
      libraries.add(libraryJson(chunkyCore));
    }
    for (File lib: libDir.listFiles()) {
      if (lib.getName().endsWith(".jar")) {
        libraries.add(libraryJson(lib));
      }
    }
    version.add("libraries", libraries);
    JarEntry entry = new JarEntry("version.json");
    entry.setTime(System.currentTimeMillis());
    jar.putNextEntry(entry);
    PrintStream out = new PrintStream(jar);
    PrettyPrinter pp = new PrettyPrinter("  ", out);
    version.prettyPrint(pp);
    out.flush();
    jar.closeEntry();

    File latest = new File("latest.json");
    out = new PrintStream(new FileOutputStream(latest));
    version.prettyPrint(new PrettyPrinter("  ", out));
    out.close();
  }
View Full Code Here

    return ((Brt + Bmt) / (Br + Bm)) * (1 - Fex);
  }

  @Override
  public JsonObject toJson() {
    JsonObject sun = new JsonObject();
    sun.add("altitude", altitude);
    sun.add("azimuth", azimuth);
    sun.add("intensity", intensity);
    JsonObject colorObj = new JsonObject();
    colorObj.add("red", color.x);
    colorObj.add("green", color.y);
    colorObj.add("blue", color.z);
    sun.add("color", colorObj);
    return sun;
  }
View Full Code Here

  public void fromJson(JsonObject obj) {
    azimuth = obj.get("azimuth").doubleValue(Math.PI / 2.5);
    altitude = obj.get("altitude").doubleValue(Math.PI / 3);
    intensity = obj.get("intensity").doubleValue(DEFAULT_INTENSITY);

    JsonObject colorObj = obj.get("color").object();
    color.x = colorObj.get("red").doubleValue(1);
    color.y = colorObj.get("green").doubleValue(1);
    color.z = colorObj.get("blue").doubleValue(1);
  }
View Full Code Here

        String releaseTime = "";
        try {
          File jsonFile = new File(dirs[i], dirs[i].getName() + ".json");
          FileInputStream in = new FileInputStream(jsonFile);
          JsonParser parser = new JsonParser(in);
          JsonObject obj = parser.parse().object();
          releaseTime =  obj.get("releaseTime").stringValue("");
        } catch (IOException e) {
          // Json parsing failed
        } catch (SyntaxError e) {
          // Json parsing failed
        } finally {
View Full Code Here

TOP

Related Classes of se.llbit.json.JsonObject

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.