private void ComputeMinMaxValues() { MinLoc = null; MaxLoc = null; float? minX = null, maxX = null, minY = null, maxY = null, minZ = null, maxZ = null; foreach (var item in Items) { Utils.CheckAndSetMin(ref minX, item.Coord.X); Utils.CheckAndSetMin(ref minY, item.Coord.Y); Utils.CheckAndSetMin(ref minZ, item.Coord.Z); Utils.CheckAndSetMax(ref maxX, item.Coord.X); Utils.CheckAndSetMax(ref maxY, item.Coord.Y); Utils.CheckAndSetMax(ref maxZ, item.Coord.Z); } if ((minX != null) && (maxX != null) && (minY != null) && (maxY != null) && (minZ != null) && (maxZ != null)) { MinLoc = new MapCoord(minX.GetValueOrDefault(), minY.GetValueOrDefault(), minZ.GetValueOrDefault()); MaxLoc = new MapCoord(maxX.GetValueOrDefault(), maxY.GetValueOrDefault(), maxZ.GetValueOrDefault()); Log.WriteLine($"MinLoc={MinLoc}, MaxLoc={MaxLoc}"); } else { Log.WriteLine("unable to determine min/max map loc for map"); } }
public void ConvertMapToCanvas(MapCoord mapLoc, out double canvasX, out double canvasY) { // special case, if map scale is zero, just map all coordinates to the center if (_mapToCanvasScale == 0) { canvasX = _canvas.ActualWidth / 2.0; canvasY = _canvas.ActualHeight / 2.0; return; } // scale map loc to canvas, reverse direction, and map Z=>X and X=>Y if (_map.MapCoordSys == CoordSysType.XZ_NorthWest) { canvasX = -(mapLoc.Z - _mapUpperLeftZ) * _mapToCanvasScale; canvasY = -(mapLoc.X - _mapUpperLeftX) * _mapToCanvasScale; } else if (_map.MapCoordSys == CoordSysType.ZX_NorthEast) { canvasX = (mapLoc.X - _mapUpperLeftX) * _mapToCanvasScale; canvasY = -(mapLoc.Z - _mapUpperLeftZ) * _mapToCanvasScale; } else if (_map.MapCoordSys == CoordSysType.ZX_EastSouth) { canvasX = (mapLoc.Z - _mapUpperLeftZ) * _mapToCanvasScale; canvasY = (mapLoc.X - _mapUpperLeftX) * _mapToCanvasScale; } else if (_map.MapCoordSys == CoordSysType.ZX_SouthWest) { canvasX = -(mapLoc.X - _mapUpperLeftX) * _mapToCanvasScale; canvasY = (mapLoc.Z - _mapUpperLeftZ) * _mapToCanvasScale; } else { canvasX = _canvas.ActualWidth / 2.0; canvasY = _canvas.ActualHeight / 2.0; return; } // add render margin offfset canvasX += CanvasMarginX; canvasY += CanvasMarginY; }
/// <summary> /// Load up items from map data file /// </summary> public bool Load(string mapFile) { try { Log.WriteLine($"LOAD: {mapFile}"); MapFilePath = mapFile; Name = Path.GetFileNameWithoutExtension(mapFile); MapCoordSys = CoordSysType.XZ_NorthWest; _items = new List <MapItem>(); MinLoc = null; MaxLoc = null; var lines = File.ReadLines(mapFile); const int maxNumItemsToLog = 3; foreach (var line in lines) { var toks = line.Split(','); float x = 0, y = 0, z = 0; if ((toks.Length >= 2) && (string.Compare(toks[0].Trim(), "MapCoordSys", true) == 0)) { CoordSysType tmp; if (CoordSysType.TryParse(toks[1].Trim(), true, out tmp)) { MapCoordSys = tmp; Log.WriteLine("coord sys specified: " + MapCoordSys); } } else if ((toks.Length >= 4) && (toks[0].Trim().Length > 0) && float.TryParse(toks[1].Trim(), out x) && float.TryParse(toks[2].Trim(), out y) && float.TryParse(toks[3].Trim(), out z)) { var itemName = toks[0].Trim(); var mapItem = new MapItem(itemName, new MapCoord(x, y, z)); _items.Add(mapItem); if (_items.Count <= maxNumItemsToLog) { Log.WriteLine($"loaded map item: {mapItem}"); } if (_items.Count == (maxNumItemsToLog + 1)) { Log.WriteLine("... remaining items not logged"); } } } Log.WriteLine($"loaded {_items.Count} map items"); ComputeMinMaxValues(); } catch (Exception ex) { Log.WriteLine($"EXCEPTION: {ex.Message}"); return(false); } return(true); }
public MapItem(string name, MapCoord coord) { Name = name; Coord = coord; }
public PlayerData(string areaName, string mapName, MapCoord loc) { AreaName = areaName; MapName = mapName; Loc = loc; }
public PlayerData(PlayerData rhs) { AreaName = rhs.AreaName; MapName = rhs.MapName; Loc = rhs.Loc; }