コード例 #1
0
ファイル: XMLBase.cs プロジェクト: Dazmo/Terraria-Map-Editor
 public PointShort XMLConvert(PointShort v, XAttribute attr)
 {
     if (attr == null) return v;
     var ps = PointShort.TryParseInline((string)attr);
     if (attr.Name == "size" && ps == new PointShort()) ps = new PointShort(1, 1);
     return ps;
 }
コード例 #2
0
 public TileProperty(byte id)
 {
     // ID + Default values
     ID = id;
     Name = "UNKNOWN";
     Color = Colors.Magenta;
     Size = new PointShort(1, 1);
 }
コード例 #3
0
ファイル: Tile.cs プロジェクト: Dazmo/Terraria-Map-Editor
 public Tile()
 {
     IsActive = false;
     Type = 0;
     Frame = new PointShort(-1, -1);
     Wall = 0;
     IsLighted = false;
     Liquid = 0;
     IsLava = false;
 }
コード例 #4
0
        public static bool TryParse(string point, out PointShort pointShort)
        {
            short x = 0;
            short y = 0;

            if (string.IsNullOrWhiteSpace(point))
            {
                pointShort = new PointShort(x, y);
                return(false);
            }

            string[] split = point.Split(',', 'x');
            if (split.Length == 2)
            {
                short.TryParse(split[0], out x);
                short.TryParse(split[1], out y);
                pointShort = new PointShort(x, y);
                return(true);
            }

            pointShort = new PointShort(x, y);
            return(false);
        }
コード例 #5
0
 private void SetTileSprite(PointInt32 point, PointShort frame, byte type)
 {
     var curTile = _world.Tiles[point.X, point.Y];
     if (curTile != null)
     {
         curTile.IsActive = true;
         curTile.Type = type;
         curTile.Frame = frame;
         _renderer.UpdateWorldImage(point);
     }
 }
コード例 #6
0
        private void PlaceSprite(PointInt32 location, byte type, PointShort size, PointShort upperLeft = new PointShort())
        {
            for (int x = 0; x < size.X; x++)
            {
                for (int y = 0; y < size.Y; y++)
                {
                    var curTile = _world.Tiles[location.X + x, location.Y + y];
                    curTile.IsActive = true;
                    curTile.Type = type;
                    curTile.Frame = new PointShort((short)(upperLeft.X + (x * 18)), (short)(upperLeft.Y + (y * 18)));
                    _renderer.UpdateWorldImage(new PointInt32(location.X + x, location.Y + y));
                }
            }

            if (type == 21)
                _world.Chests.Add(new Chest { Location = location });
            else if (type == 55 || type == 85)
                _world.Signs.Add(new Sign{Location =  location});
        }
コード例 #7
0
 private static bool MatchFields(PointShort a, PointShort m)
 {
     return (a.X == m.X && a.Y == m.Y);
 }
コード例 #8
0
 public bool Equals(PointShort p)
 {
     return MatchFields(this, p);
 }
コード例 #9
0
 public PointShort(PointShort p)
 {
     _x = p.X;
     _y = p.Y;
 }
コード例 #10
0
        public static bool TryParse(string point, out PointShort pointShort)
        {
            short x = 0;
            short y = 0;

            if (string.IsNullOrWhiteSpace(point))
            {
                pointShort = new PointShort(x, y);
                return false;
            }

            string[] split = point.Split(',', 'x');
            if (split.Length == 2)
            {
                short.TryParse(split[0], out x);
                short.TryParse(split[1], out y);
                pointShort = new PointShort(x, y);
                return true;
            }

            pointShort = new PointShort(x, y);
            return false;
        }
コード例 #11
0
ファイル: Tile.cs プロジェクト: Dazmo/Terraria-Map-Editor
        public void UpdateTile(bool? isActive = null,
            byte? wall = null,
            byte? type = null,
            byte? liquid = null,
            bool? isLava = null,
            PointShort? frame = null)
        {
            if (isActive != null)
                IsActive = (bool) isActive;

            if (wall != null)
                Wall = (byte) wall;

            if (type != null)
                Type = (byte) type;

            if (liquid != null)
                Liquid = (byte) liquid;

            if (isLava != null)
                IsLava = (bool) isLava;

            if (frame != null)
                Frame = (PointShort) frame;
        }
コード例 #12
0
 private static bool MatchFields(PointShort a, PointShort m)
 {
     return(a.X == m.X && a.Y == m.Y);
 }
コード例 #13
0
 public bool Equals(PointShort p)
 {
     return(MatchFields(this, p));
 }
コード例 #14
0
 public PointShort(PointShort p)
 {
     _x = p.X;
     _y = p.Y;
 }
コード例 #15
0
        // using FP = FramePlacement;
        private bool ValidatePlacement(PointInt32 location, PointShort size, FramePlacement frame)
        {
            // TODO: Support for attachesTo with placement

            // quick short-circuits
            if (frame.Is(FP.None))   return false;   // hey, if it can't attach to anything, it's invalid
            if (frame.Is(FP.Any))    return true;
            if (frame.Has(FP.Float)) return true;  // ...for now; this behavior may change if we actually get a "float only" object

            /// Look at surrounding area for objects ///
            FramePlacement area   = FP.Float;
            RectI areaRect = new RectI(location - 1, location + size);
            // (only used for x/y loop)
            RectI areaRectBnd = new RectI(areaRect);

            // skip tests that don't apply
            // (frame = multiples)
            if (frame.HasNo(FP.Ceiling))      areaRectBnd.Top++;
            if (frame.HasNo(FP.FloorSurface)) areaRectBnd.Bottom--;
            if (frame.HasNo(FP.Wall)) {
                areaRectBnd.Left++;
                areaRectBnd.Right--;
            }

            // (shorter cuts for singular terms; using HasNoneOf to factor in MustHaveAll)
            if (frame.HasNoneOf(FP.WallCeiling))      areaRectBnd.Top    = areaRect.Bottom;  // Floor/Surface/both
            if (frame.HasNoneOf(FP.WallFloorSurface)) areaRectBnd.Bottom = areaRect.Top;     // Ceiling
                                                                                             // Wall already covered in multiples checks

            // boundary checks
            if ( areaRectBnd.Left  < 0)                  areaRectBnd.Left   = 0;
            if ( areaRectBnd.Top   < 0)                  areaRectBnd.Top    = 0;
            if (areaRectBnd.Right  > Header.WorldBounds.Right)  areaRectBnd.Right  = Header.WorldBounds.Right;
            if (areaRectBnd.Bottom > Header.WorldBounds.Bottom) areaRectBnd.Bottom = Header.WorldBounds.Bottom;

            for (int y = areaRectBnd.Top; y <= areaRectBnd.Bottom; y++)
            {
                for (int x = areaRectBnd.Left; x <= areaRectBnd.Right; x++)
                {
                    // skip dead zone (the item itself) & corners (wow, xor use...)
                    bool valid = (x == areaRect.Left || x == areaRect.Right) ^ (y == areaRect.Top || y == areaRect.Bottom);
                    if (!valid) continue;

                    var t = Tiles[x, y];
                    var w = WorldSettings.Tiles[t.Type];

                    // skip non-solid objects
                    if (! (t.IsActive && w.IsSolid || w.IsSolidTop)) continue;

                    // FIXME: Assuming that a single tile will hold the object //
                    // (Maybe this is true in Terraria as well....)

                    // at this point, only one of these will hit
                    if      (y ==  areaRect.Top) {
                        area = area.Add(FP.Ceiling);
                        break;  // done with this Y-axis
                    }
                    else if (x ==  areaRect.Left || x == areaRect.Right) {
                        area = area.Add(FP.Wall);
                        y = areaRect.Bottom - 1;  // -1 = for loop will re-adjust, or kick out if LRB was truncated
                        break;  // done with all except bottom
                    }
                    else if (y == areaRect.Bottom) {  // special case for floor/surface
                        if (w.IsSolidTop) area = area.Add(FP.Surface);
                        else              area = area.Add(FP.Floor);
                        if (area.HasAllOf(FP.FloorSurface)) break;  // done with everything else
                    }
                }
            }

            // Now let's compare the object in question
            if (frame.Has(FP.MustHaveAll)) {
                area = area.Add(FP.MustHaveAll);  // add bit for bitwise math to work
                if (area.Filter(frame) != frame) return false;
            }
            else {
                if (frame.HasNoneOf(area))       return false;
            }

            return true;
        }