Package game

Examples of game.Tag


  public String playerName;
  public File file;

  public WorldPreview(String path) {
    File f = new File(path);
    Tag worldTag = null;
    if (!f.exists()) {
      Game.debug(DebugLevel.WARNING, "File \"" + f.getAbsolutePath()
          + "\" does not exist!");
      return;
    }
    try {
      worldTag = Tag.readFrom(new FileInputStream(f));
    } catch (IOException e) {
      Game.debug(
          Game.DebugLevel.ERROR,
          "An error occured while loading world from \""
              + f.getAbsolutePath()
              + "\"! The file may be corrupted or ist not a valid save file.");
      e.printStackTrace();
    }
    this.name = worldTag.findTagByName("NAME").getValue().toString();
    this.timePlayed = getDisplayTimeFromMillis((long) worldTag
        .findTagByName("TIME_PLAYED").getValue());
    this.playerName = worldTag.findTagByName("PLAYER")
        .findTagByName("NAME").getValue().toString();
  }
View Full Code Here


    }
    return items;
  }

  public void saveToNBT(Tag tag) {
    tag.addTag(new Tag(Tag.Type.TAG_Compound, "INVENTORY", new Tag[] {
        new Tag(Tag.Type.TAG_Int, "ID", this.id),
        new Tag(Tag.Type.TAG_String, "NAME", this.name),
        new Tag(Tag.Type.TAG_Int, "SIZE", this.size),
        new Tag(Tag.Type.TAG_Int_Array, "CONTENTS", Inventory
            .getIdList(this.contents)),
        new Tag(Tag.Type.TAG_End, null, null) }));
  }
View Full Code Here

  public int[] pixels;

  public SpriteSheet(String path) {
    if (path.toLowerCase().endsWith(".dat")) {
      Tag tag = null;
      try {
        tag = Tag.readFrom(SpriteSheet.class.getResourceAsStream(path));
      } catch (IOException e) {
        e.printStackTrace();
      }

      if (tag == null) {
        return;
      }

      name = tag.findTagByName("NAME").getValue().toString();
      pixels = (int[]) tag.findTagByName("PIXELS").getValue();
    } else {
      BufferedImage image = null;
      try {
        image = ImageIO.read(SpriteSheet.class
            .getResourceAsStream(path));
View Full Code Here

    }
    return ent;
  }

  public static Tag saveObject(Entity o) {
    Tag tag = new Tag(Tag.Type.TAG_Compound, "ENTITY_" + o.getId(), new Tag[] {new Tag(Tag.Type.TAG_Int, "dump", 0)});
    tag.addTag(new Tag(Tag.Type.TAG_String, "CLASSNAME", o.getClass().getName()));
//    try {
//      if (doesArrayContain(o.getClass().getMethods(),
//          NBTCapable.class.getMethod("saveToNBT", Tag.class))) {
        o.saveToNBT(tag);
//      }
//    } catch (SecurityException | NoSuchMethodException e) {
//      e.printStackTrace();
//    }
    tag.addTag(new Tag(Tag.Type.TAG_End, null, null));
   
    return tag;
  }
View Full Code Here

        1);
  }
 
  @Override
  public Tag saveToNBT(Tag notused) {
    Tag tag = new Tag(Tag.Type.TAG_Compound, "ENTITY_" + id, new Tag[1]);
    super.saveToNBT(tag);
    tag.addTag(new Tag(Tag.Type.TAG_Byte, "ITEM_ID", item.getId()));
    return tag;
  }
View Full Code Here

    }
    return false;
  }

  public Tag saveToNBT(Tag tag) {
    tag.addTag(new Tag(Tag.Type.TAG_Int, "ID", this.id));
    tag.addTag(new Tag(Tag.Type.TAG_Int, "POS_X", this.x));
    tag.addTag(new Tag(Tag.Type.TAG_Int, "POS_Y", this.y));
    tag.addTag(new Tag(Tag.Type.TAG_Int, "TICKS", this.tickCount));
    return tag;
  }
View Full Code Here

  public void writeToFile() {
    if (path == null) {
      return;
    }
    Tag tag = saveToNBT(null);
    File file = new File(path);
    // File path = file.getParentFile();
    // if(!path.exists()) {
    // Game.debug(Game.DebugLevel.INFO, "Save file directory created.");
    // path.mkdir();
    // }
    if (!file.exists()) {
      try {
        file.createNewFile();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    try {
      tag.writeTo(new FileOutputStream(file));
      this.timeStartThisSesson = System.currentTimeMillis();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
View Full Code Here

  }

  @Override
  public Tag saveToNBT(Tag notused) {
    timePlayed += (System.currentTimeMillis() - this.timeStartThisSesson);
    Tag tag = new Tag(Tag.Type.TAG_Compound, new StringBuilder()
        .append("WORLD_")
        .append((this.name).toUpperCase().replaceAll(" ", "_"))
        .toString(), new Tag[1]);
    tag.addTag(new Tag(Tag.Type.TAG_String, "NAME", this.name));
    tag.addTag(new Tag(Tag.Type.TAG_Long, "TIME_PLAYED", this.timePlayed));
    tag.addTag(new Tag(Tag.Type.TAG_String, "STARTLEVEL", level.getName()));
    tag.addTag(player.saveToNBT(new Tag(Tag.Type.TAG_Compound, "PLAYER",
        new Tag[] { new Tag(Tag.Type.TAG_Int, "dump", 0) })));
    // tag.addTag(game.level.saveToNBT(null));
    Tag levels = new Tag(Tag.Type.TAG_Compound, "LEVELS",
        new Tag[] { new Tag(Tag.Type.TAG_Int, "dump", 0) });
    // Tag levels = new Tag("LEVELS", Tag.Type.TAG_Compound);
    if (this.levels != null) {
      for (Level l : this.levels) {
        if (l != null) {
          levels.addTag(l.saveToNBT(new Tag(Tag.Type.TAG_Compound, l
              .getName().toUpperCase(), new Tag[] { new Tag(
              Tag.Type.TAG_Int, "dump", 0) })));
        }
      }
    } else {
      levels.addTag(level.saveToNBT(null));
    }
    levels.addTag(new Tag(Tag.Type.TAG_End, null, null));
    tag.addTag(levels);
    tag.addTag(new Tag(Tag.Type.TAG_End, null, null));
    return tag;
  }
View Full Code Here

  }

  @Override
  public Tag saveToNBT(Tag tag) {
    super.saveToNBT(tag);
    tag.addTag(new Tag(Tag.Type.TAG_String, "NAME", this.name));
    tag.addTag(new Tag(Tag.Type.TAG_Int, "SPEED", this.speed));
    return tag;
  }
View Full Code Here

    // if (overlay.length != width * height) {
    // Game.debug(Game.DebugLevel.WARNING, "Overlay data corrupted!");
    // Game.debug(Game.DebugLevel.ERROR, "Error while loading level \""
    // + name + "\"!");
    // }
    Tag ents = tag.findTagByName("ENTITIES");
    for (Tag t : (Tag[]) ents.getValue()) {
      System.out.println("Loading " + t.getName());
      if (t.getType() == Tag.Type.TAG_Compound) {
        this.addEntity(EntityLoader.loadEntity(this, t));
      }
    }
View Full Code Here

TOP

Related Classes of game.Tag

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.