private static MapTileSet DeserializeMapTileSet(BinaryReader Reader) { MapTileSet tileSet = new MapTileSet(); int Count = DeserializeLength(Reader); Dictionary <Guid, Guid> destroyedReferences = new Dictionary <Guid, Guid>(); for (int i = 0; i < Count; i++) { MapVisualObject tile = DeserializeMapObject(Reader, destroyedReferences) as MapVisualObject; if (tile != null) { tileSet.Add(tile); } } foreach (KeyValuePair <Guid, Guid> reference in destroyedReferences) { MapVisualObject tileSource = GetTile(reference.Key, tileSet); MapVisualObject tileTarget = GetTile(reference.Value, tileSet); //if ((tileSource is MapWall) && (tileTarget is MapWall)) // (tileSource as MapWall).DestroyedWall = tileTarget as MapWall; if ((tileSource is MapActiveObject) && (tileTarget is MapActiveObject)) { (tileSource as MapActiveObject).DestroyedActiveObject = tileTarget as MapActiveObject; } } return(tileSet); }
private static MapVisualObject GetTile(Guid Id, MapTileSet TileSet) { if ((TileSet != null) && TileSet.ContainsId(Id)) { return(TileSet[Id]); } return(null); }
public BitmapTileSet(MapPoint center, double zoom, BitmapSize totalSize, BitmapSize tileSize, MapTileSet <TTileCollection> tileSet) { _tileSet = tileSet; _totalSize = totalSize; _tileSize = tileSize; _center = center; _zoom = zoom; _collection = CreateCollection(EnumerateBitmapTiles()); }
public static void SerializeMapTileSet(BinaryWriter Writer, MapTileSet TileSet) { SerializeMapObject(Writer, TileSet); SerializeLength(Writer, TileSet.Count); foreach (MapVisualObject tile in TileSet.ToArray()) { Serialize(Writer, tile); } }
public TileSetViewModel(MapTileSet mapTileSet) : base(mapTileSet) { if (mapTileSet == null) throw new ArgumentNullException("mapTileSet"); Source = mapTileSet; Places = new ListCollectionView(Source.Where(t => t is MapPlace).Select(t => new PlaceViewModel(t as MapPlace)).ToList()); Walls = new ListCollectionView(Source.Where(t => t is MapWall).Select(t => new WallViewModel(t as MapWall)).ToList()); ActiveObjects = new ListCollectionView(Source.Where(t => t is MapActiveObject).Select(t => new ActiveObjectViewModel(t as MapActiveObject)).ToList()); }
static internal MapTileSet TileSetFromFlowSquares(FlowTileSet squares) { var result = new MapTileSet(); foreach (FlowTile fs in squares) { result.Add(Refs.m.TileByLoc(fs.loc)); } return(result); }
/// turns MapTileSets into FlowTileSets and back again, used by AI. // todo can these classes be better integrated? static internal FlowTileSet FlowSquaresFromTileSet(MapTileSet tiles, FlowMap fm) { var result = new FlowTileSet(); foreach (MapTile ti in tiles) { result.Add(fm.TileByLoc(ti.loc)); } return(result); }
public TileSetViewModel(MapTileSet mapTileSet) : base(mapTileSet) { if (mapTileSet == null) { throw new ArgumentNullException("mapTileSet"); } Source = mapTileSet; Places = new ListCollectionView(Source.Where(t => t is MapPlace).Select(t => new PlaceViewModel(t as MapPlace)).ToList()); Walls = new ListCollectionView(Source.Where(t => t is MapWall).Select(t => new WallViewModel(t as MapWall)).ToList()); ActiveObjects = new ListCollectionView(Source.Where(t => t is MapActiveObject).Select(t => new ActiveObjectViewModel(t as MapActiveObject)).ToList()); }
public MapGridSpaceInfo[,] GetGrid(MapTileSet[] tilesets) { MapGridSpaceInfo[,] grid = new MapGridSpaceInfo[width, height]; int i = 0; for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { grid[x, y] = new MapGridSpaceInfo(data[i], tilesets); ++i; } } return grid; }
public static MapActiveObjectState DeserializeMapActiveObjectState(BinaryReader Reader, MapTileSet mapTileSet) { Guid activeObjectId = DeserializeMapObjectReference(Reader); if (activeObjectId == Guid.Empty) return null; MapActiveObject activeObject = null; if ((mapTileSet != null) && mapTileSet.ContainsId(activeObjectId)) activeObject = mapTileSet[activeObjectId] as MapActiveObject; if (activeObject == null) return null; MapPoint position = DeserializeMapPoint(Reader); MapActiveObjectState state = new MapActiveObjectState(activeObject, position); state.Direction = DeserializeMapDirection(Reader); state.ArmorType = DeserializeMapArmorType(Reader); state.Health = Reader.ReadUInt16(); return state; }
public static MapTileSet LoadTiledTileset(XmlElement tileSetElement) { MapTileSet tileSetToReturn = new MapTileSet(); tileSetToReturn.FirstGrid = Convert.ToInt32(tileSetElement.GetAttribute("firstgid")); tileSetToReturn.Name = tileSetElement.GetAttribute("name"); tileSetToReturn.TileWidth = Convert.ToInt32(tileSetElement.GetAttribute("tilewidth")); tileSetToReturn.TileHeight = Convert.ToInt32(tileSetElement.GetAttribute("tileheight")); foreach (XmlElement currentEle in tileSetElement.ChildNodes) { #region Image if (currentEle.Name == "image") { tileSetToReturn.Images.Add(LoadImage(currentEle)); } #endregion if (currentEle.Name == "tile") { tileSetToReturn.Tiles.Add(LoadTileSetTile(currentEle)); } if (currentEle.Name == " tileoffset") { tileSetToReturn.Offset = LoadOffSet(currentEle); } if (currentEle.Name == "properties") { tileSetToReturn.Properties = LoadProperties(currentEle); } if (currentEle.Name == "image") { tileSetToReturn.Images.Add(LoadImage(currentEle)); } if (currentEle.Name == "terraintypes") { tileSetToReturn.TerrainTypes = LoadTerrainTypes(currentEle); } } return(tileSetToReturn); }
public byte[] SerializeMapTileSet(MapTileSet tileSet) { return Serialize(tileSet); }
private static MapVisualObject GetTile(Guid Id, MapTileSet TileSet) { if ((TileSet != null) && TileSet.ContainsId(Id)) return TileSet[Id]; return null; }
private static MapTileSet DeserializeMapTileSet(BinaryReader Reader) { MapTileSet tileSet = new MapTileSet(); int Count = DeserializeLength(Reader); Dictionary<Guid, Guid> destroyedReferences = new Dictionary<Guid, Guid>(); for (int i = 0; i < Count; i++) { MapVisualObject tile = DeserializeMapObject(Reader, destroyedReferences) as MapVisualObject; if (tile != null) tileSet.Add(tile); } foreach (KeyValuePair<Guid, Guid> reference in destroyedReferences) { MapVisualObject tileSource = GetTile(reference.Key, tileSet); MapVisualObject tileTarget = GetTile(reference.Value, tileSet); //if ((tileSource is MapWall) && (tileTarget is MapWall)) // (tileSource as MapWall).DestroyedWall = tileTarget as MapWall; if ((tileSource is MapActiveObject) && (tileTarget is MapActiveObject)) (tileSource as MapActiveObject).DestroyedActiveObject = tileTarget as MapActiveObject; } return tileSet; }
private static MapVisualObject DeserializeMapCellObjectReference(BinaryReader Reader, int IdIndexBytesCount, List<Guid> IdTable, MapTileSet TileSet) { return GetTile(DeserializeMapCellIdIndex(Reader, IdIndexBytesCount, IdTable), TileSet); }
private static MapCell DeserializeMapCell(BinaryReader Reader, List<Guid> IdTable, MapTileSet TileSet) { MapCell cell = new MapCell(); MapCellSerializationType cellType = DeserializeMapCellType(Reader); if (cellType == MapCellSerializationType.Null) return null; int idIndexBytesCount = 4; if ((cellType & MapCellSerializationType.IdIndex8) != 0) idIndexBytesCount = 1; else if ((cellType & MapCellSerializationType.IdIndex16) != 0) idIndexBytesCount = 3; else if ((cellType & MapCellSerializationType.IdIndex32) != 0) idIndexBytesCount = 4; if ((cellType & MapCellSerializationType.Place) != 0) cell.Place = DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapPlace; if ((cellType & MapCellSerializationType.NorthWall) != 0) cell.SetWall(MapDirection.North, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); if ((cellType & MapCellSerializationType.SouthWall) != 0) cell.SetWall(MapDirection.South, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); if ((cellType & MapCellSerializationType.WestWall) != 0) cell.SetWall(MapDirection.West, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); if ((cellType & MapCellSerializationType.EastWall) != 0) cell.SetWall(MapDirection.East, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); return cell; }
public byte[] SerializeMapTileSet(MapTileSet tileSet) { return(Serialize(tileSet)); }
public void Serialize(MapTileSet tileSet, Stream stream) { Serialize(tileSet, stream); }
public static void SaveTiledTileset(MapTileSet tileSetToSave) { // TODO: Finish save Tileset to file throw new Exception("Not yet implanted"); }
private static MapCell DeserializeMapCell(BinaryReader Reader, List <Guid> IdTable, MapTileSet TileSet) { MapCell cell = new MapCell(); MapCellSerializationType cellType = DeserializeMapCellType(Reader); if (cellType == MapCellSerializationType.Null) { return(null); } int idIndexBytesCount = 4; if ((cellType & MapCellSerializationType.IdIndex8) != 0) { idIndexBytesCount = 1; } else if ((cellType & MapCellSerializationType.IdIndex16) != 0) { idIndexBytesCount = 3; } else if ((cellType & MapCellSerializationType.IdIndex32) != 0) { idIndexBytesCount = 4; } if ((cellType & MapCellSerializationType.Place) != 0) { cell.Place = DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapPlace; } if ((cellType & MapCellSerializationType.NorthWall) != 0) { cell.SetWall(MapDirection.North, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); } if ((cellType & MapCellSerializationType.SouthWall) != 0) { cell.SetWall(MapDirection.South, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); } if ((cellType & MapCellSerializationType.WestWall) != 0) { cell.SetWall(MapDirection.West, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); } if ((cellType & MapCellSerializationType.EastWall) != 0) { cell.SetWall(MapDirection.East, DeserializeMapCellObjectReference(Reader, idIndexBytesCount, IdTable, TileSet) as MapWall); } return(cell); }
private static MapVisualObject DeserializeMapCellObjectReference(BinaryReader Reader, int IdIndexBytesCount, List <Guid> IdTable, MapTileSet TileSet) { return(GetTile(DeserializeMapCellIdIndex(Reader, IdIndexBytesCount, IdTable), TileSet)); }
public static MapActiveObjectState DeserializeMapActiveObjectState(BinaryReader Reader, MapTileSet mapTileSet) { Guid activeObjectId = DeserializeMapObjectReference(Reader); if (activeObjectId == Guid.Empty) { return(null); } MapActiveObject activeObject = null; if ((mapTileSet != null) && mapTileSet.ContainsId(activeObjectId)) { activeObject = mapTileSet[activeObjectId] as MapActiveObject; } if (activeObject == null) { return(null); } MapPoint position = DeserializeMapPoint(Reader); MapActiveObjectState state = new MapActiveObjectState(activeObject, position); state.Direction = DeserializeMapDirection(Reader); state.ArmorType = DeserializeMapArmorType(Reader); state.Health = Reader.ReadUInt16(); return(state); }