示例#1
0
 @Override
 public void write(JsonWriter out, QuestSet value) throws IOException {
   out.beginObject();
   out.name(NAME).value(value.getName());
   out.name(DESCRIPTION).value(value.getDescription());
   out.name(QUESTS).beginArray();
   for (Quest quest : value.getQuests()) {
     QUEST_ADAPTER.write(out, quest);
   }
   out.endArray().endObject();
 }
示例#2
0
 @Override
 public QuestSet read(JsonReader in) throws IOException {
   String name = null, description = null;
   requirementMapping.clear();
   optionMapping.clear();
   List<Quest> quests = new ArrayList<Quest>();
   in.beginObject();
   while (in.hasNext()) {
     String next = in.nextName();
     if (next.equalsIgnoreCase(NAME)) {
       name = in.nextString();
     } else if (next.equalsIgnoreCase(DESCRIPTION)) {
       description = in.nextString();
     } else if (next.equalsIgnoreCase(QUESTS)) {
       in.beginArray();
       QUEST_ID = Quest.size();
       while (in.hasNext()) {
         Quest quest = QUEST_ADAPTER.read(in);
         if (quest != null) {
           quests.add(quest);
         }
       }
       in.endArray();
     }
   }
   in.endObject();
   for (QuestSet set : Quest.getQuestSets()) {
     if (set.getName().equals(name)) {
       return removeQuests(quests);
     }
   }
   if (name != null && description != null) {
     QuestSet set = new QuestSet(name, description);
     Quest.getQuestSets().add(set);
     SaveHelper.add(SaveHelper.EditType.SET_CREATE);
     for (Quest quest : quests) {
       quest.setQuestSet(set);
     }
     for (Map.Entry<Quest, List<Integer>> entry : requirementMapping.entrySet()) {
       for (int i : entry.getValue()) entry.getKey().addRequirement(i);
     }
     for (Map.Entry<Quest, List<Integer>> entry : optionMapping.entrySet()) {
       for (int i : entry.getValue()) entry.getKey().addOptionLink(i);
     }
     return set;
   }
   return removeQuests(quests);
 }