Package com.badlogic.gdx.utils

Examples of com.badlogic.gdx.utils.SerializationException


    data = new SkinData();
    data.texture = new Texture(textureFile);
    try {
      getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
    } catch (SerializationException ex) {
      throw new SerializationException("Error reading file: " + skinFile, ex);
    }
  }
View Full Code Here


    this.data = data;
    data.texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    try {
      getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
    } catch (SerializationException ex) {
      throw new SerializationException("Error reading file: " + skinFile, ex);
    }
  }
View Full Code Here

          if (entry.value.equals(object)) {
            json.writeValue(entry.key);
            return;
          }
        }
        throw new SerializationException(object.getClass().getSimpleName() + " not found: " + object);
      }

      public Object read (Json json, Object jsonData, Class type) {
        String name = (String)jsonData;
        Object object = map.get(name);
        if (object == null) {
          ObjectMap<String, Object> regions = data.resources.get(TextureRegion.class);
          if (regions != null) {
            object = regions.get(name);
            if (object != null) object = new NinePatch((TextureRegion)object)
          }
          if (object == null)
            throw new SerializationException("Skin has a " + type.getSimpleName()
              + " that could not be found in the resources: " + jsonData);
        }
        return object;
      }
    }

    json.setSerializer(Skin.class, new Serializer<Skin>() {
      public void write (Json json, Skin skin, Class valueType) {
        json.writeObjectStart();
        json.writeValue("resources", skin.data.resources);
        for (Entry<Class, ObjectMap<String, Object>> entry : data.resources.entries())
          json.setSerializer(entry.key, new AliasSerializer(entry.value));
        json.writeField(skin, "styles");
        json.writeObjectEnd();
      }

      public Skin read (Json json, Object jsonData, Class ignored) {
        ObjectMap map = (ObjectMap)jsonData;
        readTypeMap(json, (ObjectMap)map.get("resources"), true);
        for (Entry<Class, ObjectMap<String, Object>> entry : data.resources.entries())
          json.setSerializer(entry.key, new AliasSerializer(entry.value));
        readTypeMap(json, (ObjectMap)map.get("styles"), false);
        return skin;
      }

      private void readTypeMap (Json json, ObjectMap<String, ObjectMap> typeToValueMap, boolean isResource) {
        if (typeToValueMap == null)
          throw new SerializationException("Skin file is missing a \"" + (isResource ? "resources" : "styles")
            + "\" section.");
        for (Entry<String, ObjectMap> typeEntry : typeToValueMap.entries()) {
          Class type;
          try {
            type = Class.forName(typeEntry.key);
          } catch (ClassNotFoundException ex) {
            throw new SerializationException(ex);
          }
          ObjectMap<String, ObjectMap> valueMap = (ObjectMap)typeEntry.value;
          for (Entry<String, ObjectMap> valueEntry : valueMap.entries()) {
            try {
              if (isResource)
                addResource(valueEntry.key, json.readValue(type, valueEntry.value));
              else
                addStyle(valueEntry.key, json.readValue(type, valueEntry.value));
            } catch (Exception ex) {
              throw new SerializationException("Error reading " + type.getSimpleName() + ": " + valueEntry.key, ex);
            }
          }
        }
      }
    });
View Full Code Here

          if (entry.value.equals(object)) {
            json.writeValue(entry.key);
            return;
          }
        }
        throw new SerializationException(object.getClass().getSimpleName() + " not found: " + object);
      }
View Full Code Here

          if (regions != null) {
            object = regions.get(name);
            if (object != null) object = new NinePatch((TextureRegion)object)
          }
          if (object == null)
            throw new SerializationException("Skin has a " + type.getSimpleName()
              + " that could not be found in the resources: " + jsonData);
        }
        return object;
      }
View Full Code Here

        String name = input.readString();
        BoneData parent = null;
        String parentName = input.readString();
        if (parentName != null) {
          parent = skeletonData.findBone(parentName);
          if (parent == null) throw new SerializationException("Parent bone not found: " + parentName);
        }
        BoneData boneData = new BoneData(name, parent);
        boneData.x = input.readFloat() * scale;
        boneData.y = input.readFloat() * scale;
        boneData.scaleX = input.readFloat();
        boneData.scaleY = input.readFloat();
        boneData.rotation = input.readFloat();
        boneData.length = input.readFloat() * scale;
        boneData.inheritScale = input.readByte() == 1;
        boneData.inheritRotation = input.readByte() == 1;
        skeletonData.addBone(boneData);
      }

      // Slots.
      for (int i = 0, n = input.readInt(true); i < n; i++) {
        String slotName = input.readString();
        String boneName = input.readString();
        BoneData boneData = skeletonData.findBone(boneName);
        if (boneData == null) throw new SerializationException("Bone not found: " + boneName);
        SlotData slotData = new SlotData(slotName, boneData);
        Color.rgba8888ToColor(slotData.getColor(), input.readInt());
        slotData.setAttachmentName(input.readString());
        slotData.additiveBlending = input.readByte() == 1;
        skeletonData.addSlot(slotData);
      }

      // Default skin.
      Skin defaultSkin = readSkin(input, "default");
      if (defaultSkin != null) {
        skeletonData.setDefaultSkin(defaultSkin);
        skeletonData.addSkin(defaultSkin);
      }

      // Skins.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        skeletonData.addSkin(readSkin(input, input.readString()));

      // Animations.
      for (int i = 0, n = input.readInt(true); i < n; i++)
        readAnimation(input.readString(), input, skeletonData);

    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    } finally {
      try {
        input.close();
      } catch (IOException ignored) {
      }
View Full Code Here

    try {
      int boneCount = input.readInt(true);
      for (int i = 0; i < boneCount; i++) {
        String boneName = input.readString();
        int boneIndex = skeletonData.findBoneIndex(boneName);
        if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneName);
        int itemCount = input.readInt(true);
        for (int ii = 0; ii < itemCount; ii++) {
          int timelineType = input.readByte();
          int keyCount = input.readInt(true);
          switch (timelineType) {
          case TIMELINE_ROTATE: {
            RotateTimeline timeline = new RotateTimeline(keyCount);
            timeline.setBoneIndex(boneIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat());
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 2 - 2]);
            break;
          }
          case TIMELINE_TRANSLATE:
          case TIMELINE_SCALE:
            TranslateTimeline timeline;
            float timelineScale = 1;
            if (timelineType == TIMELINE_SCALE)
              timeline = new ScaleTimeline(keyCount);
            else {
              timeline = new TranslateTimeline(keyCount);
              timelineScale = scale;
            }
            timeline.setBoneIndex(boneIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readFloat() * timelineScale, input.readFloat()
                * timelineScale);
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 3 - 3]);
            break;
          default:
            throw new RuntimeException("Invalid timeline type for a bone: " + timelineType + " (" + boneName + ")");
          }
        }
      }

      int slotCount = input.readInt(true);
      for (int i = 0; i < slotCount; i++) {
        String slotName = input.readString();
        int slotIndex = skeletonData.findSlotIndex(slotName);
        int itemCount = input.readInt(true);
        for (int ii = 0; ii < itemCount; ii++) {
          int timelineType = input.readByte();
          int keyCount = input.readInt(true);
          switch (timelineType) {
          case TIMELINE_COLOR: {
            ColorTimeline timeline = new ColorTimeline(keyCount);
            timeline.setSlotIndex(slotIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++) {
              float time = input.readFloat();
              Color.rgba8888ToColor(tempColor, input.readInt());
              timeline.setFrame(keyframeIndex, time, tempColor.r, tempColor.g, tempColor.b, tempColor.a);
              if (keyframeIndex < keyCount - 1) readCurve(input, keyframeIndex, timeline);
            }
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount * 5 - 5]);
            break;
          }
          case TIMELINE_ATTACHMENT:
            AttachmentTimeline timeline = new AttachmentTimeline(keyCount);
            timeline.setSlotIndex(slotIndex);
            for (int keyframeIndex = 0; keyframeIndex < keyCount; keyframeIndex++)
              timeline.setFrame(keyframeIndex, input.readFloat(), input.readString());
            timelines.add(timeline);
            duration = Math.max(duration, timeline.getFrames()[keyCount - 1]);
            break;
          default:
            throw new RuntimeException("Invalid timeline type for a slot: " + timelineType + " (" + slotName + ")");
          }
        }
      }
    } catch (IOException ex) {
      throw new SerializationException("Error reading skeleton file.", ex);
    }

    timelines.shrink();
    skeletonData.addAnimation(new Animation(name, timelines, duration));
  }
View Full Code Here

    for (JsonValue boneMap = root.getChild("bones"); boneMap != null; boneMap = boneMap.next()) {
      BoneData parent = null;
      String parentName = boneMap.getString("parent", null);
      if (parentName != null) {
        parent = skeletonData.findBone(parentName);
        if (parent == null) throw new SerializationException("Parent bone not found: " + parentName);
      }
      BoneData boneData = new BoneData(boneMap.getString("name"), parent);
      boneData.length = boneMap.getFloat("length", 0) * scale;
      boneData.x = boneMap.getFloat("x", 0) * scale;
      boneData.y = boneMap.getFloat("y", 0) * scale;
      boneData.rotation = boneMap.getFloat("rotation", 0);
      boneData.scaleX = boneMap.getFloat("scaleX", 1);
      boneData.scaleY = boneMap.getFloat("scaleY", 1);
      boneData.inheritScale = boneMap.getBoolean("inheritScale", true);
      boneData.inheritRotation = boneMap.getBoolean("inheritRotation", true);
      skeletonData.addBone(boneData);
    }

    // Slots.
    for (JsonValue slotMap = root.getChild("slots"); slotMap != null; slotMap = slotMap.next()) {
      String slotName = slotMap.getString("name");
      String boneName = slotMap.getString("bone");
      BoneData boneData = skeletonData.findBone(boneName);
      if (boneData == null) throw new SerializationException("Slot bone not found: " + boneName);
      SlotData slotData = new SlotData(slotName, boneData);

      String color = slotMap.getString("color", null);
      if (color != null) slotData.getColor().set(Color.valueOf(color));

View Full Code Here

    Array<Timeline> timelines = new Array();
    float duration = 0;

    for (JsonValue boneMap = map.getChild("bones"); boneMap != null; boneMap = boneMap.next()) {
      int boneIndex = skeletonData.findBoneIndex(boneMap.name());
      if (boneIndex == -1) throw new SerializationException("Bone not found: " + boneMap.name());

      for (JsonValue timelineMap = boneMap.child(); timelineMap != null; timelineMap = timelineMap.next()) {
        String timelineName = timelineMap.name();
        if (timelineName.equals(TIMELINE_ROTATE)) {
          RotateTimeline timeline = new RotateTimeline(timelineMap.size());
View Full Code Here

  /** Adds all resources in the specified skin JSON file. */
  public void load (FileHandle skinFile) {
    try {
      getJsonLoader(skinFile).fromJson(Skin.class, skinFile);
    } catch (SerializationException ex) {
      throw new SerializationException("Error reading file: " + skinFile, ex);
    }
  }
View Full Code Here

TOP

Related Classes of com.badlogic.gdx.utils.SerializationException

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.