Beispiel #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);
            }
        }
        protected override void ProcessResource( RoomCollection aRooms )
        {
            if ( !aRooms.Any() )
            return;

              OnCategoryProcessing( ResourceTypes.Rooms );
              Directory.CreateDirectory( Directories.Rooms );
              var previous = SetCurrentDirectory( Directories.Rooms );

              foreach ( var room in aRooms ) {
            var document =
              new XElement( "Room",
            CreateIndexedResourceNodes( room ),
            new XElement( "RoomCaption", room.RoomCaption ),
            new XElement( "Width", room.Width ),
            new XElement( "Height", room.Height ),
            new XElement( "SnapX", room.SnapX ),
            new XElement( "SnapY", room.SnapY ),
            new XElement( "Speed", room.Speed ),
            new XElement( "CreationCode", EscapeText( room.CreationCode ) ),
            new XElement( "IsometricGrid", room.IsometricGrid ),
            new XElement( "Persistent", room.Persistent ),
            new XElement( "ViewsEnabled", room.ViewsEnabled ),
            new XElement( "DrawBackgroundColor", room.DrawBackgroundColor ),
            new XElement( "BackgroundColor", ColorTranslator.ToHtml( room.BackgroundColor ) ),
            new XElement( "Backgrounds",
              from background in room.Backgrounds select
              new XElement( "Background",
                new XComment( "Node below refers to: " + FindResourceName( m_gmk.Backgrounds, background.BackgroundIndex ) ),
                new XElement( "BackgroundIndex", background.BackgroundIndex ),
                new XElement( "X", background.X ),
                new XElement( "Y", background.Y ),
                new XElement( "HorizontalSpeed", background.HorizontalSpeed ),
                new XElement( "VerticalSpeed", background.VerticalSpeed ),
                new XElement( "Visible", background.Visible ),
                new XElement( "ForegroundImage", background.ForegroundImage ),
                new XElement( "TileHorizontally", background.TileHorizontally ),
                new XElement( "TileVertically", background.TileVertically ),
                new XElement( "Stretch", background.Stretch )
              )
            ),
            new XElement( "Views",
              from view in room.Views select
              new XElement( "View",
                new XElement( "Visible", view.Visible ),
                new XElement( "X", view.X ),
                new XElement( "Y", view.Y ),
                new XElement( "Width", view.Width ),
                new XElement( "Height", view.Height ),
                new XElement( "PortX", view.PortX ),
                new XElement( "PortY", view.PortY ),
                new XElement( "PortWidth", view.PortWidth ),
                new XElement( "PortHeight", view.PortHeight ),
                new XElement( "HorizontalBorder", view.HorizontalBorder ),
                new XElement( "VerticalBorder", view.VerticalBorder ),
                new XElement( "HorizontalSpacing", view.HorizontalSpacing ),
                new XElement( "VerticalSpacing", view.VerticalSpacing ),
                new XComment( "Node below refers to: " + FindResourceName( m_gmk.Objects, view.FollowedObject ) ),
                new XElement( "FollowedObject", view.FollowedObject )
              )
            ),
            new XElement( "Instances",
              from instance in room.Instances select
              new XElement( "Instance",
                new XElement( "ID", instance.ID ),
                new XComment( "Node below refers to: " + FindResourceName( m_gmk.Objects, instance.ObjectIndex ) ),
                new XElement( "ObjectIndex", instance.ObjectIndex ),
                new XElement( "X", instance.X ),
                new XElement( "Y", instance.Y ),
                new XElement( "Locked", instance.Locked ),
                new XElement( "CreationCode", EscapeText( instance.CreationCode ) )
              )
            ),
            new XElement( "Tiles",
              from tile in room.Tiles select
                new XElement( "Tile",
                  new XElement( "ID", tile.ID ),
                  new XComment( "Node below refers to: " + FindResourceName( m_gmk.Backgrounds, tile.BackgroundIndex ) ),
                  new XElement( "BackgroundIndex", tile.BackgroundIndex ),
                  new XElement( "X", tile.X ),
                  new XElement( "Y", tile.Y ),
                  new XElement( "TileX", tile.TileX ),
                  new XElement( "TileY", tile.TileY ),
                  new XElement( "Width", tile.Width ),
                  new XElement( "Height", tile.Height ),
                  new XElement( "Depth", tile.Depth ),
                  new XElement( "Locked", tile.Locked )
                )
            ),
            new XElement( "RememberRoomSettings", room.RememberRoomSettings ),
            new XElement( "RoomEditorTab", room.RoomEditorTab ),
            new XElement( "RoomEditorWidth", room.RoomEditorWidth ),
            new XElement( "RoomEditorHeight", room.RoomEditorHeight ),
            new XElement( "ShowGrid", room.ShowGrid ),
            new XElement( "ShowObjects", room.ShowObjects ),
            new XElement( "ShowTiles", room.ShowTiles ),
            new XElement( "ShowBackgrounds", room.ShowBackgrounds ),
            new XElement( "ShowForegrounds", room.ShowForegrounds ),
            new XElement( "ShowViews", room.ShowViews ),
            new XElement( "DeleteObjectsOutsideOfRoom", room.DeleteObjectsOutsideOfRoom ),
            new XElement( "DeleteTilesOutsideOfRoom", room.DeleteTilesOutsideOfRoom ),
            new XElement( "HorizontalScrollbarPosition", room.HorizontalScrollbarPosition ),
            new XElement( "VerticalScrollbarPosition", room.VerticalScrollbarPosition )
              );

            SaveDocument( document, SafeResourceFilename( room ) + ".xml" );
            OnResourceProcessed( room.Name );
              }

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