Beispiel #1
0
        public ForegroundBlock(Foreground.Id id, uint portalId, uint portalTarget, Morph.Id portalRotation)
        {
            ForegroundType type = WorldUtils.GetForegroundType(id);

            if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.Portal)
            {
                throw new ArgumentException("The given block is not a portal.", "id");
            }

            this._args = new PortalArgs(portalId, portalTarget, portalRotation);
            this._type = ForegroundType.Portal;
            this._id   = id;
        }
Beispiel #2
0
        public ForegroundBlock(Foreground.Id id)
        {
            ForegroundType type = WorldUtils.GetForegroundType(id);

            if (WorldUtils.GetBlockArgsType(type) != BlockArgsType.None)
            {
                throw new ArgumentException("The given block is missing required arguments.", "id");
            }

            this._args = null;
            this._type = ForegroundType.Normal;
            this._id   = id;
        }
Beispiel #3
0
        private ForegroundBlock(Foreground.Id id, BlockArgsType requiredArgsType)
        {
            var type     = WorldUtils.GetForegroundType(id);
            var argsType = WorldUtils.GetBlockArgsType(type);

            if (argsType != requiredArgsType)
            {
                throw WorldUtils.GetMissingArgsErrorMessage(argsType, nameof(id));
            }

            this.Id    = id;
            this.Type  = type;
            this._args = null;
        }
Beispiel #4
0
        public ForegroundBlock(Foreground.Id id, uint args)
        {
            var type     = WorldUtils.GetForegroundType(id);
            var argsType = WorldUtils.GetBlockArgsType(type);

            switch (argsType)
            {
            case BlockArgsType.Number:
                this._args = args;
                break;

            case BlockArgsType.SignedNumber:
                this._args = (int)args;
                break;

            default:
                throw WorldUtils.GetMissingArgsErrorMessage(argsType, nameof(id));
            }

            this.Type = type;
            this.Id   = id;
        }
Beispiel #5
0
        internal static BlockDataWorld GetWorld(Message m, int width, int height, uint offset = InitOffset)
        {
            var  world   = new BlockDataWorld(width, height);
            uint pointer = GetStart(m, offset);

            string strValue2;

            while ((strValue2 = m[pointer] as string) == null || strValue2 != "we")
            {
                var    block      = m.GetInteger(pointer++);
                var    l          = (Layer)m.GetInteger(pointer++);
                byte[] byteArrayX = m.GetByteArray(pointer++);
                byte[] byteArrayY = m.GetByteArray(pointer++);

                switch (l)
                {
                case Layer.Background:
                    var bgWorldBlock = new BackgroundBlock((Background.Id)block);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Background[pos.X, pos.Y] = new BlockData <BackgroundBlock>(bgWorldBlock);
                    }
                    break;

                case Layer.Foreground:
                    ForegroundBlock foregroundBlock;
                    BlockArgsType   blockArgsType = WorldUtils.GetBlockArgsType(WorldUtils.GetForegroundType(id: (Foreground.Id)block));

                    switch (blockArgsType)
                    {
                    case BlockArgsType.None:
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block);
                        break;

                    case BlockArgsType.Number:
                        uint i = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, i);
                        break;

                    case BlockArgsType.String:
                        string str = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, str);
                        break;

                    case BlockArgsType.Portal:
                        var  portalRotation = (Morph.Id)m.GetUInt(pointer++);
                        uint portalId       = m.GetUInt(pointer++);
                        uint portalTarget   = m.GetUInt(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, portalId, portalTarget, portalRotation);
                        break;

                    case BlockArgsType.Label:
                        string text      = m.GetString(pointer++);
                        string textcolor = m.GetString(pointer++);
                        foregroundBlock = new ForegroundBlock((Foreground.Id)block, text, textcolor);
                        break;

                    default:
                        throw new NotSupportedException("Invalid block.");
                    }

                    var fg = new BlockData <ForegroundBlock>(foregroundBlock);
                    foreach (Point pos in GetPos(byteArrayX, byteArrayY))
                    {
                        world.Foreground[pos.X, pos.Y] = fg;
                    }
                    break;
                }
            }

            return(world);
        }