コード例 #1
0
 private void readSoundList(JsonObject element, String field, List<StaticSound> sounds)
     throws IOException {
   if (element.has(field) && element.get(field).isJsonArray()) {
     sounds.clear();
     for (JsonElement item : element.getAsJsonArray(field)) {
       Optional<StaticSound> sound = assetManager.getAsset(item.getAsString(), StaticSound.class);
       if (sound.isPresent()) {
         sounds.add(sound.get());
       } else {
         throw new IOException("Unable to resolve sound '" + item.getAsString() + "'");
       }
     }
   }
 }
コード例 #2
0
  @Override
  public BlockSoundsData load(ResourceUrn resourceUrn, List<AssetDataFile> list)
      throws IOException {
    JsonElement rawJson = readJson(list.get(0));
    JsonObject blockDefJson = rawJson.getAsJsonObject();

    BlockSoundsData data = new BlockSoundsData();
    if (blockDefJson.has("basedOn")) {
      Optional<BlockSounds> parentBlockSounds =
          assetManager.getAsset(blockDefJson.get("basedOn").getAsString(), BlockSounds.class);
      if (parentBlockSounds.isPresent()) {
        data.getStepSounds().addAll(parentBlockSounds.get().getStepSounds());
        data.getStepSounds().addAll(parentBlockSounds.get().getDestroySounds());
        data.getStepSounds().addAll(parentBlockSounds.get().getDigSounds());
      } else {
        throw new IOException(
            "Unable to resolve parent '" + blockDefJson.get("basedOn").getAsString() + "'");
      }
    }

    loadBlockSounds(blockDefJson, data);
    return data;
  }