Пример #1
0
        protected override void ProcessResource(RoomCollection aRooms)
        {
            var files = GetXmlFiles(Directories.Rooms);

            if (files.Any())
            {
                OnCategoryProcessing(ResourceTypes.Rooms);
                var previous = SetCurrentDirectory(Directories.Rooms);

                foreach (var file in files)
                {
                    var document = LoadXml(file);

                    if (document != null)
                    {
                        var room = new Room()
                        {
                            Name                        = GetElement(document, "Name").Value,
                            ID                          = GetElementValue <int>(document, "ID"),
                            RoomCaption                 = GetElement(document, "RoomCaption").Value,
                            Width                       = GetElementValue <int>(document, "Width"),
                            Height                      = GetElementValue <int>(document, "Height"),
                            SnapX                       = GetElementValue <int>(document, "SnapX"),
                            SnapY                       = GetElementValue <int>(document, "SnapY"),
                            Speed                       = GetElementValue <int>(document, "Speed"),
                            CreationCode                = GetElement(document, "CreationCode").Value,
                            IsometricGrid               = GetElementValue <bool>(document, "IsometricGrid"),
                            Persistent                  = GetElementValue <bool>(document, "Persistent"),
                            ViewsEnabled                = GetElementValue <bool>(document, "ViewsEnabled"),
                            DrawBackgroundColor         = GetElementValue <bool>(document, "DrawBackgroundColor"),
                            BackgroundColor             = Drawing.ColorTranslator.FromHtml(GetElement(document, "BackgroundColor").Value),
                            RememberRoomSettings        = GetElementValue <bool>(document, "RememberRoomSettings"),
                            RoomEditorTab               = GetElementValue <RoomEditorTabs>(document, "RoomEditorTab"),
                            RoomEditorWidth             = GetElementValue <int>(document, "RoomEditorWidth"),
                            RoomEditorHeight            = GetElementValue <int>(document, "RoomEditorHeight"),
                            ShowGrid                    = GetElementValue <bool>(document, "ShowGrid"),
                            ShowObjects                 = GetElementValue <bool>(document, "ShowObjects"),
                            ShowTiles                   = GetElementValue <bool>(document, "ShowTiles"),
                            ShowBackgrounds             = GetElementValue <bool>(document, "ShowBackgrounds"),
                            ShowForegrounds             = GetElementValue <bool>(document, "ShowForegrounds"),
                            ShowViews                   = GetElementValue <bool>(document, "ShowViews"),
                            DeleteObjectsOutsideOfRoom  = GetElementValue <bool>(document, "DeleteObjectsOutsideOfRoom"),
                            DeleteTilesOutsideOfRoom    = GetElementValue <bool>(document, "DeleteTilesOutsideOfRoom"),
                            HorizontalScrollbarPosition = GetElementValue <int>(document, "HorizontalScrollbarPosition"),
                            VerticalScrollbarPosition   = GetElementValue <int>(document, "VerticalScrollbarPosition")
                        };

                        room.Backgrounds.AddRange(from element in document.Element("Backgrounds").Elements("Background")
                                                  select new Room.Background()
                        {
                            BackgroundIndex = GetElementValue <int>(element, "BackgroundIndex"),
                            X = GetElementValue <int>(element, "X"),
                            Y = GetElementValue <int>(element, "Y"),
                            HorizontalSpeed  = GetElementValue <int>(element, "HorizontalSpeed"),
                            VerticalSpeed    = GetElementValue <int>(element, "VerticalSpeed"),
                            Visible          = GetElementValue <bool>(element, "Visible"),
                            ForegroundImage  = GetElementValue <bool>(element, "ForegroundImage"),
                            TileHorizontally = GetElementValue <bool>(element, "TileHorizontally"),
                            TileVertically   = GetElementValue <bool>(element, "TileVertically"),
                            Stretch          = GetElementValue <bool>(element, "Stretch")
                        });

                        room.Views.AddRange(from element in document.Element("Views").Elements("View")
                                            select new Room.View()
                        {
                            Visible        = GetElementValue <bool>(element, "Visible"),
                            FollowedObject = GetElementValue <int>(element, "FollowedObject"), // ?
                            X                 = GetElementValue <int>(element, "X"),
                            Y                 = GetElementValue <int>(element, "Y"),
                            Width             = GetElementValue <int>(element, "Width"),
                            Height            = GetElementValue <int>(element, "Height"),
                            PortX             = GetElementValue <int>(element, "PortX"),
                            PortY             = GetElementValue <int>(element, "PortY"),
                            PortWidth         = GetElementValue <int>(element, "PortWidth"),
                            PortHeight        = GetElementValue <int>(element, "PortHeight"),
                            HorizontalBorder  = GetElementValue <int>(element, "HorizontalBorder"),
                            VerticalBorder    = GetElementValue <int>(element, "VerticalBorder"),
                            HorizontalSpacing = GetElementValue <int>(element, "HorizontalSpacing"),
                            VerticalSpacing   = GetElementValue <int>(element, "VerticalSpacing")
                        });

                        room.Instances.AddRange(from element in document.Element("Instances").Elements("Instance")
                                                select new Room.Instance()
                        {
                            ID           = GetElementValue <int>(element, "ID"),
                            ObjectIndex  = GetElementValue <int>(element, "ObjectIndex"),
                            X            = GetElementValue <int>(element, "X"),
                            Y            = GetElementValue <int>(element, "Y"),
                            Locked       = GetElementValue <bool>(element, "Locked"),
                            CreationCode = GetElement(element, "CreationCode").Value
                        });

                        room.Tiles.AddRange(from element in document.Element("Tiles").Elements("Tile")
                                            select new Room.Tile()
                        {
                            ID = GetElementValue <int>(element, "ID"),
                            BackgroundIndex = GetElementValue <int>(element, "BackgroundIndex"),
                            X      = GetElementValue <int>(element, "X"),
                            Y      = GetElementValue <int>(element, "Y"),
                            TileX  = GetElementValue <int>(element, "TileX"),
                            TileY  = GetElementValue <int>(element, "TileY"),
                            Width  = GetElementValue <int>(element, "Width"),
                            Height = GetElementValue <int>(element, "Height"),
                            Depth  = GetElementValue <int>(element, "Depth"),
                            Locked = GetElementValue <bool>(element, "Locked")
                        });

                        aRooms.Add(room);
                    }

                    OnAbortProcessingCallback();
                }

                if (aRooms.Any())
                {
                    aRooms.LastInstanceID = aRooms.Max(room => {
                        if (room.Instances.Any())
                        {
                            return(room.Instances.Max(instance => instance.ID));
                        }
                        else
                        {
                            return(99999);
                        }
                    }) + 1;

                    aRooms.LastTileID = aRooms.Max(room => {
                        if (room.Tiles.Any())
                        {
                            return(room.Tiles.Max(tile => tile.ID));
                        }
                        else
                        {
                            return(999999);
                        }
                    }) + 1;
                }

                OnCategoryProcessed(ResourceTypes.Rooms);
                SetCurrentDirectory(previous);
            }
        }