示例#1
0
 public static Weapon load(String id) {
   Weapon w;
   Json j = new Json(OutputType.json);
   w = j.fromJson(Weapon.class, Gdx.files.internal("core/assets/json/weapons/" + id + ".json"));
   w.weaponID = id;
   return w;
 }
 // Json read
 @Override
 public void read(Json json, JsonValue jsonData) {
   logger.debug("Deserializing");
   PhysicsConfig config = json.fromJson(PhysicsConfig.class, jsonData.toString());
   collisionEffect = config.collisionEffect;
   this.buildFromModel(config.sceneModel);
 }
示例#3
0
 @Override
 public SceneVO getSceneVO(String name) {
   SceneDataManager sceneDataManager = facade.retrieveProxy(SceneDataManager.NAME);
   // TODO: this should be cached
   FileHandle file = Gdx.files.internal(sceneDataManager.getCurrProjectScenePathByName(name));
   Json json = new Json();
   json.setIgnoreUnknownFields(true);
   return json.fromJson(SceneVO.class, file.readString());
 }
示例#4
0
  @Override
  public void undoAction() {
    Json json = new Json();
    CompositeVO compositeVO = json.fromJson(CompositeVO.class, backup);
    Set<Entity> newEntitiesList = PasteItemsCommand.createEntitiesFromVO(compositeVO);

    for (Entity entity : newEntitiesList) {
      Overlap2DFacade.getInstance().sendNotification(ItemFactory.NEW_ITEM_ADDED, entity);
    }

    sandbox.getSelector().setSelections(newEntitiesList, true);
  }
 private void loadWeapons() {
   logger.debug("Loading Weapons");
   Json json = new Json();
   for (String s : manifest.weapons) {
     try {
       WeaponConfig config = json.fromJson(WeaponConfig.class, Gdx.files.internal(s));
       weaponConfigs.put(config.name, config);
     } catch (SerializationException ex) {
       logger.error("Failed to load weapons file: " + s);
       logger.error(ex.getMessage());
     }
   }
 }
  /**
   * This method accumulates objects defined in a scene, allowing several separate RUBE .json files
   * to be combined. Objects are added to the scene's data, as well as within the Box2D world that
   * is ultimately returned.
   *
   * @param _file The JSON file to parse
   * @return The cumulative scene
   */
  public RubeScene addScene(FileHandle _file) {
    RubeScene scene = null;

    if ((mRubeWorldSerializer != null) && (mWorld != null)) {
      mRubeWorldSerializer.usePreexistingWorld(mWorld);
    }
    try {
      scene = json.fromJson(RubeScene.class, _file);
    } catch (SerializationException ex) {
      throw new SerializationException("Error reading file: " + _file, ex);
    }
    return scene;
  }
  private void loadEntities() {
    logger.debug("Loading Entities");

    Json json = new Json();
    for (String s : manifest.entities) {
      try {
        EntityConfig config = json.fromJson(EntityConfig.class, Gdx.files.internal(s));
        entityConfigs.put(config.name, config);
      } catch (SerializationException ex) {
        logger.error("Failed to load entity file: " + s);
        logger.error(ex.getMessage());
      }
    }
  }
示例#8
0
  @Override
  public es.danirod.rectball.model.Statistics loadStatistics() {
    try {
      // Read stats from file and decode them.
      FileHandle handle = getStatistics();
      String encodedJson = handle.readString();
      String decodedJson = Base64Coder.decodeString(encodedJson);

      // Convert JSON to statistics
      Json json = new Json();
      return json.fromJson(es.danirod.rectball.model.Statistics.class, decodedJson);
    } catch (Exception ex) {
      return new es.danirod.rectball.model.Statistics();
    }
  }
  public static <T> T read(FileHandle path, Class<T> clazz, Consumer<Json> setupJson)
      throws IOException {

    Json json = new Json();

    json.setSerializer(clazz, new AnnotatedJsonSerializer<>(json, clazz));

    if (setupJson != null) {
      setupJson.accept(json);
    }

    try {
      return json.fromJson(clazz, path);
    } catch (RuntimeException e) {
      throw new IOException(e);
    }
  }
  public static void Initialize() {

    FileHandle file = Gdx.files.local("saves/savedata.json");
    if (!file.exists()) {

      String savestring =
          json.prettyPrint(
              new SaveData(
                  new PlayerData(
                      PlayerData.AbilityType.NONE, 0, 0, 0, 0, PlayerData.SkinType.HUMAN),
                  new LevelSaveData[] {
                    new LevelSaveData(0, 0, true), new LevelSaveData(0, 0, false)
                  },
                  0));
      file.writeString(savestring, true);
    }
    saveData = json.fromJson(SaveData.class, file);
  }
示例#11
0
 public static void readExample() {
   Levels levels = json.fromJson(Levels.class, Gdx.files.internal(PATH));
   System.out.println("read:");
   System.out.println(json.prettyPrint(levels));
 }
示例#12
0
 public static Levels loadFromFile(FileHandle file) {
   Levels levels = json.fromJson(Levels.class, file);
   levels.index();
   return levels;
 }
 private TutorialHelper() {
   FileHandle handle = Gdx.files.internal(getAssetDirPath() + "tutorial/tutorials.json");
   Json json = new Json();
   tutorials = json.fromJson(ArrayList.class, handle.readString());
 }
示例#14
0
 public Array<FileHandle> loadFavorites() {
   String data = prefs.getString(keyName, null);
   if (data == null) return new Array<FileHandle>();
   else return json.fromJson(FavouriteData.class, data).toFileHandleArray();
 }
 private void loadManifest() {
   Json json = new Json();
   FileHandle file = Gdx.files.internal("data/assetManifest");
   manifest = json.fromJson(AssetManifest.class, file);
 }
 public static AreaDetails fromJson(final FileHandle file) {
   final AreaDetails res = json.fromJson(AreaDetails.class, file);
   return res;
 }