public static bool IsEmpty(CellDefinition cell)
        {
            if (cell == null) {
                return true;
            }

            return cell.wall == null && cell.floor == null && cell.containedObject == null;
        }
 public static bool IsWalkable(CellDefinition cell)
 {
     return cell == null ? false :
         cell.floor != null && cell.containedObject == null;
 }
        public static SerializedCellDefinition Serialize(CellDefinition cell)
        {
            if (cell == null) {
                return null;
            }

            var serializedCell = new SerializedCellDefinition();

            if (cell.wall != null) {
                serializedCell.wall = cell.wall.Serialize();
            }

            if (cell.floor != null) {
                serializedCell.floor = cell.floor.Serialize();
            }

            if (cell.containedObject != null) {
                serializedCell.containedObject = cell.containedObject.Serialize();
            }

            return serializedCell;
        }
        public static CellDefinition Deserialize(IntVector3 position, Chunk parentChunk, SerializedCellDefinition serializedCell)
        {
            var cell = new CellDefinition(position, parentChunk);

            if (serializedCell.wall != null) {
                cell.wall = new WallObject();
                cell.wall.Deserialize(position, serializedCell.wall);
            }

            if (serializedCell.floor != null) {
                cell.floor = new FloorObject();
                cell.floor.Deserialize(position, serializedCell.floor);
            }

            if (serializedCell.containedObject != null) {
                var type = GameRegistry.Instance.GetObjectType(serializedCell.containedObject.Id);

                cell.containedObject = (BaseObject) Activator.CreateInstance(type);
                cell.containedObject.Deserialize(position, serializedCell.containedObject);
            }

            parentChunk.SetCellAt(position, cell);

            return cell;
        }
        public void SetCellAt(IntVector3 position, CellDefinition cell)
        {
            var targetChunk = activeRegion.GetChunkAt(position);

            targetChunk.SetCellAt(position, cell);
        }
Ejemplo n.º 6
0
        public CellDefinition CreateCell(IntVector3 position)
        {
            var index = ConvertAbsPositionToIndex(position);

            if (cells[index] != null) {
                Logger.Warn("CreateCell", "Cell at {0} already exists.", position);
                return cells[index];
            }

            cells[index] = new CellDefinition(position, this);

            return cells[index];
        }
Ejemplo n.º 7
0
 public void SetCellDirty(CellDefinition cell)
 {
     if (cell != null && !dirtyCells.Contains(cell)) {
         dirtyCells.Add(cell);
     }
 }
Ejemplo n.º 8
0
        public void SetCellAt(IntVector3 absPos, CellDefinition cell)
        {
            var index = ConvertAbsPositionToIndex(absPos);

            if (this.cells[index] != cell) {
                this.cells[index] = cell;
            }
        }