public void Insert(MineralNode node) { var compressedValues = CompressNodeValues(node.Values); Db.Query().CommandText("insert into mineralnodes (zoneid,materialtype,x,y,width,height,data) values (@zoneId,@materialType,@x,@y,@width,@height,@data)") .SetParameter("@zoneId", _zone.Id) .SetParameter("@materialType", _materialType) .SetParameter("@x", node.Area.X1) .SetParameter("@y", node.Area.Y1) .SetParameter("@width", node.Area.Width) .SetParameter("@height", node.Area.Height) .SetParameter("@data", compressedValues) .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLInsertError); }
public void Update(MineralNode node) { var compressedValues = CompressNodeValues(node.Values); Db.Query().CommandText("update mineralnodes set data = @data where zoneid = @zoneId and materialtype = @materialType and x = @x and y = @y and width = @width and height = @height") .SetParameter("@zoneId", _zone.Id) .SetParameter("@materialType", _materialType) .SetParameter("@x", node.Area.X1) .SetParameter("@y", node.Area.Y1) .SetParameter("@width", node.Area.Width) .SetParameter("@height", node.Area.Height) .SetParameter("@data", compressedValues) #if RELEASE .ExecuteNonQuery().ThrowIfEqual(0, ErrorCodes.SQLUpdateError);
public void AddNode(MineralNode node) { ImmutableInterlocked.Update(ref _nodes, nodes => { var result = new List <MineralNode>(nodes) { node }; return(result.ToArray()); }); node.Updated += OnNodeUpdated; node.Expired += OnNodeExpired; }
private bool TryGetNode(int x, int y, out MineralNode node) { foreach (var n in _nodes) { if (!n.Area.Contains(x, y)) { continue; } node = n; return(true); } node = null; return(false); }
public List <MineralNode> GetAll() { var bmp = (Bitmap)Image.FromFile(_fileSystem.CreatePath(Path.Combine("layers", "mineral_gravel.0045.png"))); var minerals = new Dictionary <Point, uint>(); int minx = int.MaxValue, miny = int.MaxValue, maxx = 0, maxy = 0; for (int y = 0; y < bmp.Height; y++) { for (int x = 0; x < bmp.Width; x++) { var c = bmp.GetPixel(x, y); var b = c.GetBrightness() * 350000; if (b > 0) { minx = Math.Min(minx, x); miny = Math.Min(miny, y); maxx = Math.Max(maxx, x); maxy = Math.Max(maxy, y); var point = new Point(x, y); minerals.Add(point, (uint)b); } } } var area = new Area(minx, miny, maxx, maxy); var node = new MineralNode(MaterialType.Gravel, area) { Expirable = false }; foreach (var t in minerals) { node.SetValue(t.Key, t.Value); } return(new List <MineralNode> { node }); }
public void RemoveNode(MineralNode node) { ImmutableInterlocked.Update(ref _nodes, nodes => { var result = new List <MineralNode>(); foreach (var n in nodes) { if (n == node) { continue; } result.Add(n); } return(result.ToArray()); }); }
public MineralNode GetNearestNode(Point p) { MineralNode nearestNode = null; var nearestDistSq = double.MaxValue; foreach (var node in _nodes) { var distSqr = node.Area.SqrDistance(p); if (distSqr >= nearestDistSq) { continue; } nearestNode = node; nearestDistSq = distSqr; } return(nearestNode); }
public void Delete(MineralNode node) { }
public void Update(MineralNode node) { }
public void Insert(MineralNode node) { }
public bool TryGetNode(Point p, out MineralNode node) { return(TryGetNode(p.X, p.Y, out node)); }
private void OnNodeExpired(MineralNode node) { RunAction(new DeleteMineralNode(node)); }
private void OnNodeUpdated(MineralNode node) { RunAction(new SaveMineralNode(node)); }