Example #1
0
        /// <summary>
        /// Load existing region
        /// </summary>
        /// <param name="buffer"></param>
        public void Load(byte[] buffer)
        {
            try
            {
                using (MemoryReader mem = new MemoryReader(buffer))
                {
                    var regionCount = mem.ReadInt32();

                    for (int i = 0; i < regionCount; i++)
                    {
                        var region = new Region();
                        region.Priority = mem.ReadInt32();
                        region.X        = mem.ReadSingle();
                        region.Y        = mem.ReadSingle();
                        region.Z        = mem.ReadSingle();
                        region.Radius   = mem.ReadSingle();
                        var DescriptionSize = mem.ReadInt32();
                        region.Description = Encoding.Default.GetString(mem.ReadBytes(DescriptionSize));
                        var ScriptSize = mem.ReadInt32();
                        region.Scripts = Encoding.Default.GetString(mem.ReadBytes(ScriptSize));

                        var polygonCount = mem.ReadInt32();

                        for (int p = 0; p < polygonCount; p++)
                        {
                            var polygon  = new Polygon();
                            var pointNum = mem.ReadInt32();

                            for (int n = 0; n < pointNum; n++)
                            {
                                var vector = new Vector
                                {
                                    X = mem.ReadInt32() / Global.AttrLenght,
                                    Y = mem.ReadInt32() / Global.AttrLenght
                                };

                                polygon.Add(vector.Rotate180FlipY());
                            }

                            region.Polygons.Add(polygon);
                        }

                        Regions.Add(region);
                    }
                }

                Render();
                Parent.Log(Levels.Success, "Ok\n");
            }
            catch (Exception exception)
            {
                Dispose();
                Parent.Log(Levels.Error, "Failed\n");
                Parent.Log(Levels.Fatal, $"Nfc::Load<Exception> -> {exception}\n");
            }
        }
Example #2
0
        /// <summary>
        /// Add new regions
        /// </summary>
        /// <param name="points"></param>
        public void Add(PointF[] points)
        {
            var center = ((Polygon)points).GetCenterPoint();
            var region = new Region
            {
                X = center.X,
                Y = center.Y,
                Z = center.Z
            };

            region.Polygons.Add(points);
            Regions.Add(region);

            Added?.Invoke(this, new AddedArgs(region, typeof(Region)));
        }
Example #3
0
        /// <summary>
        /// Update a region
        /// </summary>
        /// <param name="index"></param>
        /// <param name="region"></param>
        public void Update(int index, Region region)
        {
            Regions[index] = region;

            Updated?.Invoke(this, new UpdatedArgs(index, region, typeof(Region)));
        }