Exemple #1
0
        public static Project FromXProxy(ProjectX proxy, ProjectResolver resolver, Project project)
        {
            if (proxy == null)
                return null;

            if (proxy.PropertyGroup != null) {
                project.Uid = proxy.PropertyGroup.ProjectGuid;
                project.Name = proxy.PropertyGroup.ProjectName;
                project._defaultLibraryUid = proxy.PropertyGroup.DefaultLibrary;
                project.Extra = new List<XmlElement>(proxy.PropertyGroup.Extra ?? new XmlElement[0]);
            }

            project._texturePool = new MetaTexturePool();

            project._tilePools = new MetaTilePoolManager(project._texturePool);
            project._objectPools = new MetaObjectPoolManager(project._texturePool);
            project._tileBrushes = new MetaTileBrushManager();

            foreach (var itemGroup in proxy.ItemGroups) {
                if (itemGroup.Libraries != null) {
                    foreach (var libProxy in itemGroup.Libraries) {
                        using (Stream stream = resolver.InputStream(libProxy.Include)) {
                            project.AddLibrary(new Library(stream) {
                                FileName = libProxy.Include,
                            });
                        }
                    }
                }

                if (itemGroup.Levels != null) {
                    foreach (var level in itemGroup.Levels) {
                        using (Stream stream = resolver.InputStream(level.Include)) {
                            project.Levels.Add(new Level(stream, project) {
                                FileName = level.Include,
                            });
                        }
                    }
                }
            }

            //project._tilePools.Pools.PropertyChanged += project.TilePoolsModifiedHandler;
            //project._objectPools.Pools.PropertyChanged += project.HandleObjectPoolManagerPropertyChanged;

            return project;
        }
Exemple #2
0
        public void Save(Stream stream, ProjectResolver resolver)
        {
            List<ProjectX.LibraryX> libraries = new List<ProjectX.LibraryX>();
            List<ProjectX.LevelX> levels = new List<ProjectX.LevelX>();

            foreach (Library library in _libraryManager.Libraries) {
                if (library.FileName == null)
                    library.FileName = FormatSafeFileName(library.Name + ".tlbx");

                using (Stream libStream = resolver.OutputStream(library.FileName)) {
                    library.Save(libStream);
                }

                libraries.Add(new ProjectX.LibraryX() {
                    Include = library.FileName,
                });
            }

            foreach (Level level in Levels) {
                if (level.FileName == null)
                    level.FileName = FormatSafeFileName(level.Name + ".tlvx");

                using (Stream levStream = resolver.OutputStream(level.FileName)) {
                    level.Save(levStream);
                }

                levels.Add(new ProjectX.LevelX() {
                    Include = level.FileName,
                });
            }

            XmlWriterSettings settings = new XmlWriterSettings() {
                CloseOutput = true,
                Indent = true,
            };

            XmlWriter writer = XmlTextWriter.Create(stream, settings);

            ProjectX proxy = new ProjectX() {
                ItemGroups = new List<ProjectX.ItemGroupX>(),
                PropertyGroup = new ProjectX.PropertyGroupX() {
                    ProjectGuid = Uid,
                    ProjectName = Name,
                    DefaultLibrary = _defaultLibraryUid,
                    Extra = (Extra != null && Extra.Count > 0) ? Extra.ToArray() : null,
                },
            };

            proxy.ItemGroups.Add(new ProjectX.ItemGroupX() {
                Libraries = libraries,
            });
            proxy.ItemGroups.Add(new ProjectX.ItemGroupX() {
                Levels = levels,
            });

            XmlSerializer serializer = new XmlSerializer(typeof(ProjectX));
            serializer.Serialize(writer, proxy);

            writer.Close();

            ResetModified();
        }
Exemple #3
0
        public static Project FromXProxy(ProjectX proxy, ProjectResolver resolver)
        {
            if (proxy == null)
                return null;

            return FromXProxy(proxy, resolver, new Project());
        }