コード例 #1
0
        /// <summary>
        ///     Restore the state of this Map from the specified MapState
        /// </summary>
        /// <param name="state">
        ///     Mapstate POCO (Plain Old C# Object) which represents this Map and can be easily serialized and
        ///     deserialized
        /// </param>
        /// <exception cref="ArgumentNullException">Thrown on null map state</exception>
        public void Restore(MapState state)
        {
            if (state == null)
            {
                throw new ArgumentNullException("state", "Map state cannot be null");
            }

            var inFov = new HashSet <int>();

            Initialize(state.Width, state.Height);
            foreach (var cell in GetAllCells())
            {
                var cellProperties = state.Cells[cell.Y * Width + cell.X];
                if (cellProperties.HasFlag2(MapState.CellProperties.Visible))
                {
                    inFov.Add(IndexFor(cell.X, cell.Y));
                }
                _isTransparent[cell.X, cell.Y] = cellProperties.HasFlag2(MapState.CellProperties.Transparent);
                _isWalkable[cell.X, cell.Y]    = cellProperties.HasFlag2(MapState.CellProperties.Walkable);
            }

            _fieldOfView = new FieldOfView(this, inFov);
        }