Beispiel #1
0
        static RoomBackground DeserializeRoomBg(JsonData j, BackgroundInfo[] bgs)
        {
            var r = new RoomBackground
            {
                IsEnabled     = (bool)j["enabled"],
                IsForeground  = (bool)j["foreground"],
                TileX         = (bool)j["tilex"],
                TileY         = (bool)j["tiley"],
                StretchSprite = (bool)j["stretch"],

                Position = DeserializePoint(j["pos"]),
                Speed    = DeserializePoint(j["speed"])
            };

            if (j.Has("bg"))
            {
                var i = Array.FindIndex(bgs, b => b.Name == (string)j["bg"]);

                if (i > -1)
                {
                    r.BgIndex = (uint)i;
                }
                //TODO: emit warning instead
            }

            return(r);
        }
Beispiel #2
0
        static RoomBackground DeserializeRoomBg(dynamic j, BackgroundInfo[] bgs)
        {
            var r = new RoomBackground
            {
                IsEnabled     = j.enabled,
                IsForeground  = j.foreground,
                TileX         = j.tilex,
                TileY         = j.tiley,
                StretchSprite = j.stretch,

                Position = DeserializePoint(j.pos),
                Speed    = DeserializePoint(j.speed)
            };

            if (((JsonData)j).Has("bg"))
            {
                var i = Array.FindIndex(bgs, b => b.Name == (string)j.bg);

                if (i > -1)
                {
                    r.BgIndex = (uint)i;
                }
                //TODO: emit warning instead
            }

            return(r);
        }
Beispiel #3
0
        private static void WriteRoomBg(BBData data, RoomBackground rb)
        {
            data.Buffer.Write(new RoomBgEntry
            {
                IsEnabled    = rb.IsEnabled ? DwordBool.True : DwordBool.False,
                IsForeground = rb.IsForeground ? DwordBool.True : DwordBool.False,
                Position     = rb.Position,
                TileX        = rb.TileX ? DwordBool.True : DwordBool.False,
                TileY        = rb.TileY ? DwordBool.True : DwordBool.False,
                Speed        = rb.Speed,
                Stretch      = rb.StretchSprite ? DwordBool.True : DwordBool.False,

                DefIndex = rb.BgIndex ?? 0xFFFFFFFF
            });
        }
Beispiel #4
0
 public Room(uint roomID, RoomBackground roomBackground, string roomName,
             BlockedExits blockedExits, bool castingAllowed = true)
 {
     this.RoomID           = roomID;
     this.Background       = roomBackground;
     this.IsCastingEnabled = castingAllowed;
     this.Decorations      = new List <RoomDecoration>();
     this.Npcs             = new List <Mobile>();
     this.Items            = new List <BaseGameItem>();
     this.Players          = new List <Character>();
     this.BlockedRoomExits = blockedExits;
     this.RoomName         = roomName;
     this.RoomsIDsInUse    = new List <uint>();
     this.AllowCasting     = castingAllowed;
     this.ApplyRoomLayout();
 }
Beispiel #5
0
        static RoomBackground ReadRoomBg(GMFileContent content, IntPtr p)
        {
            var entry = (RoomBgEntry *)p;

            var b = new RoomBackground();

            b.IsEnabled     = entry->IsEnabled.IsTrue();
            b.IsForeground  = entry->IsForeground.IsTrue();
            b.Position      = entry->Position;
            b.TileX         = entry->TileX.IsTrue();
            b.TileY         = entry->TileY.IsTrue();
            b.Speed         = entry->Speed;
            b.StretchSprite = entry->Stretch.IsTrue();

            b.BgIndex = entry->DefIndex == 0xFFFFFFFF ? null : (uint?)entry->DefIndex;

            return(b);
        }
Beispiel #6
0
        static JsonData SerializeRoomBg(RoomBackground bg, LazyArray <BackgroundInfo> bgs)
        {
            var r = CreateObj();

            r["enabled"]    = bg.IsEnabled;
            r["foreground"] = bg.IsForeground;
            r["pos"]        = SerializePoint(bg.Position);
            r["tilex"]      = bg.TileX;
            r["tiley"]      = bg.TileY;
            r["speed"]      = SerializePoint(bg.Speed);
            r["stretch"]    = bg.StretchSprite;

            if (bg.BgIndex.HasValue)
            {
                r["bg"] = bgs[bg.BgIndex.Value].Name;
            }

            return(r);
        }
Beispiel #7
0
 private void Awake()
 {
     Background = Instantiate(BackgroundPrefab);
     GameState.RegisterMainRoom(this);
 }
        private void ReadRooms()
        {
            var version = ReadInt();

            var count = ReadInt();

            for (var i = 0; i < count; i++)
            {
                Project.Rooms.NextIndex = i;

                if (ReadInt() != 0)
                {
                    var room = Project.Rooms.Create();

                    room.Name = ReadString();

                    version = ReadInt();

                    room.Caption             = ReadString();
                    room.Width               = ReadInt();
                    room.Height              = ReadInt();
                    room.SnapY               = ReadInt();
                    room.SnapX               = ReadInt();
                    room.Isometric           = ReadBool();
                    room.Speed               = ReadInt();
                    room.Persistent          = ReadBool();
                    room.BackgroundColor     = ReadInt();
                    room.DrawBackgroundColor = ReadBool();
                    room.CreationCode        = ReadString();

                    var backgroundCount = ReadInt();
                    room.Backgrounds = new List <RoomBackground>(backgroundCount);
                    for (var j = 0; j < backgroundCount; j++)
                    {
                        var bg = new RoomBackground
                        {
                            VisibleWhenRoomStarts = ReadBool(),
                            ForegroundImage       = ReadBool(),
                            BackgroundImageIndex  = ReadInt(),
                            X = ReadInt(),
                            Y = ReadInt(),
                            TileHorizontally = ReadBool(),
                            TileVertically   = ReadBool(),
                            HorizontalSpeed  = ReadInt(),
                            VerticalSpeed    = ReadInt(),
                            Stretch          = ReadBool()
                        };

                        room.Backgrounds.Add(bg);
                    }

                    room.EnableViews = ReadBool();

                    room.Views = new List <RoomView>(8);
                    for (int viewc = ReadInt(), j = 0; j < viewc; j++)
                    {
                        var view = new RoomView();
                        view.VisibleWhenRoomStarts = ReadBool();
                        if (version == 520)
                        {
                            view.Left   = ReadInt();
                            view.Top    = ReadInt();
                            view.Width  = ReadInt();
                            view.Height = ReadInt();
                            view.X      = ReadInt();
                            view.Y      = ReadInt();
                        }
                        else if (version >= 541)
                        {
                            view.X              = ReadInt();
                            view.Y              = ReadInt();
                            view.Width          = ReadInt();
                            view.Height         = ReadInt();
                            view.ViewportX      = ReadInt();
                            view.ViewportY      = ReadInt();
                            view.ViewportWidth  = ReadInt();
                            view.ViewportHeight = ReadInt();
                        }
                        view.HorizontalBorder = ReadInt();
                        view.VerticalBorder   = ReadInt();
                        view.HorizontalSpeed  = ReadInt();
                        view.VerticalSpeed    = ReadInt();
                        view.ObjectFollowing  = ReadInt();

                        room.Views.Add(view);
                    }

                    room.Instances = new List <InstanceResource>();
                    for (int instanceCount = ReadInt(), j = 0; j < instanceCount; j++)
                    {
                        var instance = new InstanceResource
                        {
                            X            = ReadInt(),
                            Y            = ReadInt(),
                            ObjectIndex  = ReadInt(),
                            Id           = ReadInt(),
                            CreationCode = ReadString(),
                            Locked       = ReadBool()
                        };

                        Project.Instances[instance.Id] = instance;

                        room.Instances.Add(instance);
                    }

                    room.Tiles = new List <TileResource>();
                    for (int tileCount = ReadInt(), j = 0; j < tileCount; j++)
                    {
                        var tile = new TileResource
                        {
                            X = ReadInt(),
                            Y = ReadInt(),
                            BackgroundIndex = ReadInt(),
                            TileX           = ReadInt(),
                            TileY           = ReadInt(),
                            Width           = ReadInt(),
                            Height          = ReadInt(),
                            Layer           = ReadInt(),
                            Id     = ReadInt(),
                            Locked = ReadBool()
                        };

                        Project.Tiles[tile.Id] = tile;

                        room.Tiles.Add(tile);
                    }

                    room.RememberRoomEditorInfo = ReadBool();
                    room.EditorWidth            = ReadInt();
                    room.EditorHeight           = ReadInt();
                    room.ShowGrid                = ReadBool();
                    room.ShowObjects             = ReadBool();
                    room.ShowTiles               = ReadBool();
                    room.ShowBackgrounds         = ReadBool();
                    room.ShowForegrounds         = ReadBool();
                    room.ShowViews               = ReadBool();
                    room.DeleteUnderlyingObjects = ReadBool();
                    room.DeleteUnderlyingTiles   = ReadBool();

                    if (version == 520)
                    {
                        room.TileWidth  = ReadInt();
                        room.TileHeight = ReadInt();
                        room.TileHorizontalSeparation = ReadInt();
                        room.TileVerticalSeparation   = ReadInt();
                        room.TileHorizontalOffset     = ReadInt();
                        room.TileVerticalOffset       = ReadInt();
                    }

                    room.CurrentTab = ReadInt();
                    room.ScrollbarX = ReadInt();
                    room.ScrollbarY = ReadInt();
                }
            }
        }
Beispiel #9
0
 public InstancedRoom(uint roomId, RoomBackground backGround, string roomName, BlockedExits blocked, bool castingAllowed = true)
     : base(roomId, backGround, roomName, blocked, castingAllowed)
 {
 }
Beispiel #10
0
        public GMRoom(ProjectReader reader, GMProject proj)
        {
            Name        = reader.ReadString();
            LastChanged = reader.ReadDate();
            Version     = reader.ReadInt32();
            Caption     = reader.ReadString();
            Width       = reader.ReadUInt32();
            Height      = reader.ReadUInt32();
            int _snx = reader.ReadInt32();
            int _sny = reader.ReadInt32();

            Snap            = new Point(_snx, _sny);
            Isometric       = reader.ReadBoolean();
            Speed           = reader.ReadUInt32();
            Persistent      = reader.ReadBoolean();
            BackgroundColor = reader.ReadColor();
            int val = reader.ReadInt32();

            DrawBackgroundColor    = (val & 1) != 0;
            ClearBGWithWindowColor = (val & 0b10) == 0;
            CreationCode           = reader.ReadString();

            // Read room backgrounds.
            int bgcount = reader.ReadInt32();

            Backgrounds = new List <RoomBackground>(bgcount);
            for (int i = 0; i < bgcount; i++)
            {
                var bgstruct = new RoomBackground();
                bgstruct.Load(reader, proj);
                Backgrounds.Add(bgstruct);
            }

            // Read views.
            EnableViews = reader.ReadBoolean();
            int viewcount = reader.ReadInt32();

            Views = new List <RoomView>(viewcount);
            for (int i = 0; i < viewcount; i++)
            {
                var viewstruct = new RoomView();
                viewstruct.Load(reader, proj);
                Views.Add(viewstruct);
            }

            // Read room instances.
            int instcount = reader.ReadInt32();

            Instances = new List <RoomInstance>(instcount);
            for (int i = 0; i < instcount; i++)
            {
                var inststruct = new RoomInstance();
                inststruct.Load(reader, proj);
                Instances.Add(inststruct);
            }

            // Read room tiles.
            int tilecount = reader.ReadInt32();

            Tiles = new List <RoomTile>(tilecount);
            for (int i = 0; i < tilecount; i++)
            {
                var tilestruct = new RoomTile();
                tilestruct.Load(reader, proj);
                Tiles.Add(tilestruct);
            }

            // weird editor settings (aren't really important unless you make an IDE)
            REI                 = reader.ReadBoolean();
            EditorWidth         = reader.ReadInt32();
            EditorHeight        = reader.ReadInt32();
            ShowGrid            = reader.ReadBoolean();
            ShowObjects         = reader.ReadBoolean();
            ShowTiles           = reader.ReadBoolean();
            ShowBGs             = reader.ReadBoolean();
            ShowFGs             = reader.ReadBoolean();
            ShowViews           = reader.ReadBoolean();
            DeleteUnderlyingObj = reader.ReadBoolean();
            DeleteUnderlyingTil = reader.ReadBoolean();
            Tab                 = (EditorTab)reader.ReadInt32();
            int _hx = reader.ReadInt32();
            int _hy = reader.ReadInt32();

            Scrollbar = new Point(_hx, _hy);

            reader.Dispose();
        }
Beispiel #11
0
        public Room FromBytes(byte[] buffer)
        {
            Room         result = new Room();
            MemoryStream m      = new MemoryStream(buffer);
            BinaryReader r      = new BinaryReader(m);

            r.ReadBytes(17); // past bs
            short namelen = r.ReadInt16();

            result.RoomName = Encoding.ASCII.GetString(r.ReadBytes(namelen));
            //mainForm.WriteLine("2");
            r.ReadInt16(); // bs
            result.RoomID = r.ReadUInt32();
            ushort bckgrnd = r.ReadUInt16();


            RoomBackground b = RoomBackground.BeachLeft;

            foreach (RoomBackground rb in Enum.GetValues(typeof(RoomBackground)))
            {
                if (bckgrnd == (short)rb)
                {
                    b = rb;
                    break;
                }
            }
            result.Background = b;
            r.ReadByte(); //bs
            int          block = r.ReadByte();
            BlockedExits be    = BlockedExits.None;

            foreach (BlockedExits rb in Enum.GetValues(typeof(BlockedExits)))
            {
                if (block == (short)rb)
                {
                    be = rb;
                    break;
                }
            }
            result.Blocked = be;
            r.ReadByte(); // bs
            int allow = r.ReadByte();

            if (allow == 7)
            {
                result.CastingAllowed = false;
            }
            else
            {
                result.CastingAllowed = true;
            }
            // Ok now we have the decorations
            int totaldec = r.ReadByte();
            int current  = 0;

            while (current != totaldec)
            {
                RoomDecoration d = RoomDecoration.FromCode(r.ReadUInt16(), r.ReadUInt16(), r.ReadUInt16(), r.ReadUInt16(), result.RoomID);
                result.Decorations.Add(d);
                current++;
            }

            return(result);
        }
Beispiel #12
0
 /// <summary>
 /// Returns a roombackground converted into 2 bytes
 /// </summary>
 /// <param name="background"></param>
 /// <returns></returns>
 public byte[] ToBytes(RoomBackground background)
 {
     return(BitConverter.GetBytes(ToUshort(background)));
 }
Beispiel #13
0
 /// <summary>
 /// Returns the room background converted into a ushort
 /// </summary>
 /// <param name="background"></param>
 /// <returns></returns>
 public ushort ToUshort(RoomBackground background)
 {
     return((ushort)background);
 }