Пример #1
0
  public static void writeExample() {
    Levels levels = new Levels();
    levels.levels = new ArrayList<LevelDefinition>();

    {
      LevelDefinition ld = new LevelDefinition();
      ld.start_time = 7;
      ld.groups = new ArrayList<ProbabilityGroup>();

      ProbabilityGroup pg1 = new ProbabilityGroup();
      pg1.chance = 0.3f;
      pg1.sequences = new ArrayList<String>();
      pg1.sequences.add("a");
      pg1.sequences.add("b");

      ProbabilityGroup pg2 = new ProbabilityGroup();
      pg2.chance = 0.7f;
      pg2.sequences = new ArrayList<String>();
      pg2.sequences.add("c");
      pg2.sequences.add("d");
      pg2.sequences.add("e");

      ld.groups.add(pg1);
      ld.groups.add(pg2);

      levels.levels.add(ld);
    }
    {
      LevelDefinition ld = new LevelDefinition();
      ld.start_time = 21;
      ld.groups = new ArrayList<ProbabilityGroup>();

      ProbabilityGroup pg1 = new ProbabilityGroup();
      pg1.chance = 0.4f;
      pg1.sequences = new ArrayList<String>();
      pg1.sequences.add("f");
      pg1.sequences.add("g");
      pg1.sequences.add("h");

      ProbabilityGroup pg2 = new ProbabilityGroup();
      pg2.chance = 0.6f;
      pg2.sequences = new ArrayList<String>();
      pg2.sequences.add("i");
      pg2.sequences.add("j");

      ld.groups.add(pg1);
      ld.groups.add(pg2);

      levels.levels.add(ld);
    }

    String s = json.prettyPrint(levels);
    Gdx.files.local(PATH).writeString(s, false);
  }
Пример #2
0
 public static Levels loadFromFile(FileHandle file) {
   Levels levels = json.fromJson(Levels.class, file);
   levels.index();
   return levels;
 }