Пример #1
1
  void setVerticalWall(WallData wall, int level, boolean undo) {
    if (wall != null && wall.houseWall) {
      if (!(isFlat() || map.getTile(this, -1, 0).isFlat())) {
        return;
      }
    }

    final EntityData entityData;
    if (wall != null && wall.houseWall) {
      entityData = new EntityData(level, EntityType.VWALL);
    } else if (wall != null) {
      entityData = new EntityData(level, EntityType.VFENCE);
    } else {
      entityData = null;
    }

    final EntityData wallEntity = new EntityData(level, EntityType.VWALL);
    final EntityData fenceEntity = new EntityData(level, EntityType.VFENCE);
    final Wall currentWall = (Wall) entities.get(wallEntity);
    final Wall currentFence = (Wall) entities.get(fenceEntity);

    boolean reversed;
    if (wall != null && wall.houseWall) {
      if (Globals.autoReverseWall) {
        reversed =
            getTileContent(level) == null && map.getTile(this, -1, 0).getTileContent(level) != null;
        if (reversed == false) {
          reversed = Globals.reverseWall;
        }
      } else {
        reversed = Globals.reverseWall;
      }
    } else {
      reversed = false;
    }

    if (!(new Wall(wall, reversed).equals(entities.get(entityData)))) {
      Tile oldTile = new Tile(this);
      if (wall != null) {
        entities.put(entityData, new Wall(wall, reversed));
        if (wall.houseWall
            && !(wall.arch && currentFence != null && currentFence.data.archBuildable)) {
          entities.remove(fenceEntity);
        } else if (!wall.houseWall
            && !(wall.archBuildable && currentWall != null && currentWall.data.arch)) {
          entities.remove(wallEntity);
        }
      } else {
        entities.remove(wallEntity);
        entities.remove(fenceEntity);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Пример #2
1
  void setTileContent(TileEntity entity, int level, boolean undo) {
    if (!isFlat()) {
      return;
    }

    if (entity instanceof Roof) {
      for (TileEntity e : entities.values()) {
        if (e instanceof Roof) {
          return;
        }
      }
    }

    final EntityData entityData = new EntityData(level, EntityType.FLOORROOF);
    if (entity != entities.get(entityData)) {
      Tile oldTile = new Tile(this);

      if (entity != null) {
        entities.put(entityData, entity);
      } else {
        entities.remove(entityData);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Пример #3
1
  void setVerticalBorder(BorderData border, boolean undo) {
    final EntityData entityData = new EntityData(0, EntityType.VBORDER);
    if (border != entities.get(entityData)) {
      Tile oldTile = new Tile(this);

      if (border != null) {
        entities.put(entityData, border);
      } else {
        entities.remove(entityData);
      }

      if (undo) {
        map.addUndo(this, oldTile);
      }
    }
  }
Пример #4
0
 public GameObject getGameObject(int level, ObjectLocation location) {
   // assumption - ObjectEntityData key always have GameObject value.
   return (GameObject) entities.get(new ObjectEntityData(level, location));
 }
Пример #5
0
 public BorderData getVerticalBorder() {
   return (BorderData) entities.get(new EntityData(0, EntityType.VBORDER));
 }
Пример #6
0
 public BorderData getHorizontalBorder() {
   return (BorderData) entities.get(new EntityData(0, EntityType.HBORDER));
 }
Пример #7
0
 public Wall getVerticalFence(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.VFENCE));
 }
Пример #8
0
 public Wall getVerticalWall(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.VWALL));
 }
Пример #9
0
 public Wall getHorizontalFence(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.HFENCE));
 }
Пример #10
0
 public Wall getHorizontalWall(int level) {
   return (Wall) entities.get(new EntityData(level, EntityType.HWALL));
 }
Пример #11
0
 public TileEntity getTileContent(int level) {
   return entities.get(new EntityData(level, EntityType.FLOORROOF));
 }
Пример #12
0
  public void serialize(Document doc, Element root) {
    Element tile = doc.createElement("tile");
    tile.setAttribute("x", Integer.toString(x));
    tile.setAttribute("y", Integer.toString(y));
    tile.setAttribute("height", Float.toString(height));
    tile.setAttribute("caveHeight", Float.toString(caveHeight));
    tile.setAttribute("caveSize", Float.toString(caveSize));
    root.appendChild(tile);

    ground.serialize(doc, tile);
    cave.serialize(doc, tile);
    if (label != null) {
      label.serialize(doc, tile, false);
    }
    if (caveLabel != null) {
      caveLabel.serialize(doc, tile, true);
    }

    final HashMap<Integer, Element> levels = new HashMap<>();

    for (Entry<EntityData, TileEntity> e : entities.entrySet()) {
      final EntityData key = e.getKey();
      final TileEntity entity = e.getValue();
      final int floor = key.getFloor();

      Element level = levels.get(floor);
      if (level == null) {
        level = doc.createElement("level");
        level.setAttribute("value", Integer.toString(key.getFloor()));
        levels.put(key.getFloor(), level);
        tile.appendChild(level);
      }

      switch (key.getType()) {
        case FLOORROOF:
          entity.serialize(doc, level);
          break;
        case HWALL:
        case HFENCE:
          Element hWall = doc.createElement("hWall");
          entity.serialize(doc, hWall);
          level.appendChild(hWall);
          break;
        case VWALL:
        case VFENCE:
          Element vWall = doc.createElement("vWall");
          entity.serialize(doc, vWall);
          level.appendChild(vWall);
          break;
        case HBORDER:
          Element hDeco = doc.createElement("hBorder");
          entity.serialize(doc, hDeco);
          level.appendChild(hDeco);
          break;
        case VBORDER:
          Element vDeco = doc.createElement("vBorder");
          entity.serialize(doc, vDeco);
          level.appendChild(vDeco);
          break;
        case OBJECT:
          ObjectEntityData objectData = (ObjectEntityData) key;
          Element objectElement = doc.createElement("object");
          objectElement.setAttribute("position", objectData.getLocation().toString());
          entity.serialize(doc, objectElement);
          level.appendChild(objectElement);
          break;
      }
    }
  }