예제 #1
0
        public Project(string citprojPath)
        {
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current         = this;
            CitprojPath     = citprojPath;
            UserprefsPath   = Path.ChangeExtension(citprojPath, ".userprefs");
            AssetsDirectory = Path.Combine(Path.GetDirectoryName(CitprojPath), "Data");
            UntitledPath    = Path.Combine(AssetsDirectory, ".untitled");
            if (!Directory.Exists(AssetsDirectory))
            {
                throw new InvalidOperationException($"Assets directory {AssetsDirectory} doesn't exist.");
            }
            var di = Directory.CreateDirectory(UntitledPath);

            di.Attributes |= FileAttributes.Hidden;
            var untitledCookingRulePath = Path.Combine(UntitledPath, "#CookingRules.txt");

            if (!File.Exists(untitledCookingRulePath))
            {
                using (var writer = File.CreateText(untitledCookingRulePath)) {
                    writer.WriteLine("Ignore Yes");
                }
            }
            The.Workspace.Open(citprojPath);
            UpdateTextureParams();

            Opening?.Invoke(CitprojPath);
            Preferences = new ProjectPreferences();
            Preferences.Initialize();
            FileSystemWatcher = new FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerinePersistence.Instance.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            if (GetFullPath(path, out string fullPath))
                            {
                                OpenDocument(path, delayLoad: true);
                            }
                        } catch (Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    try {
                        Document.SetCurrent(currentDoc);
                    } catch (Exception e) {
                        if (currentDoc != null)
                        {
                            CloseDocument(currentDoc);
                        }
                        throw;
                    }
                } catch (Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            SetLocale(Locale);
            FileSystemWatcher.Changed += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Created += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Deleted += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Renamed += (previousPath, path) => {
                // simulating rename as pairs of deleted / created events
                HandleFileSystemWatcherEvent(path);
                if (File.Exists(path))
                {
                    HandleFileSystemWatcherEvent(previousPath);
                    HandleFileSystemWatcherEvent(path);
                }
                else if (Directory.Exists(path))
                {
                    foreach (var f in new ScanOptimizedFileEnumerator(path, null).Enumerate())
                    {
                        HandleFileSystemWatcherEvent(Path.Combine(previousPath, f.Path));
                        HandleFileSystemWatcherEvent(Path.Combine(path, f.Path));
                    }
                }
            };
            if (Directory.Exists(AssetBundle.Current.ToSystemPath("Overlays")))
            {
                foreach (var file in AssetBundle.Current.EnumerateFiles("Overlays", ".tan"))
                {
                    Current.Overlays.Add(Path.GetFileNameWithoutExtension(file),
                                         (Widget)Node.CreateFromAssetBundle(Path.ChangeExtension(file, null), null, TangerinePersistence.Instance));
                }
            }
            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
            if (PluginLoader.CurrentPlugin != null)
            {
                foreach (var action in PluginLoader.CurrentPlugin.TangerineProjectOpened)
                {
                    action?.Invoke();
                }
            }
        }
예제 #2
0
파일: Project.cs 프로젝트: x5f3759df/Citrus
        public void Open()
        {
            Opening?.Invoke(CitprojPath);
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current = this;
            TangerineAssetBundle tangerineAssetBundle = new TangerineAssetBundle(AssetsDirectory);

            if (!tangerineAssetBundle.IsActual())
            {
                tangerineAssetBundle.CleanupBundle();
            }
            AssetBundle.Current = tangerineAssetBundle;
            Preferences         = new ProjectPreferences();
            Preferences.Initialize();
            FileSystemWatcher = new FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerinePersistence.Instance.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            if (GetFullPath(path, out string fullPath))
                            {
                                OpenDocument(path, delayLoad: true);
                            }
                        } catch (Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    try {
                        Document.SetCurrent(currentDoc);
                    } catch (Exception e) {
                        if (currentDoc != null)
                        {
                            CloseDocument(currentDoc);
                        }
                        throw;
                    }
                } catch (Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            SetLocale(Locale);
            FileSystemWatcher.Changed += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Created += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Deleted += HandleFileSystemWatcherEvent;
            FileSystemWatcher.Renamed += (previousPath, path) => {
                // simulating rename as pairs of deleted / created events
                HandleFileSystemWatcherEvent(path);
                if (File.Exists(path))
                {
                    HandleFileSystemWatcherEvent(previousPath);
                    HandleFileSystemWatcherEvent(path);
                }
                else if (Directory.Exists(path))
                {
                    foreach (var f in new ScanOptimizedFileEnumerator(path, null).Enumerate())
                    {
                        HandleFileSystemWatcherEvent(Path.Combine(previousPath, f.Path));
                        HandleFileSystemWatcherEvent(Path.Combine(path, f.Path));
                    }
                }
            };
            var overlaysPath = Path.Combine(Current.AssetsDirectory, "Overlays");

            if (Directory.Exists(overlaysPath))
            {
                var files = Directory.EnumerateFiles(overlaysPath)
                            .Where(file => file.EndsWith(".tan", StringComparison.OrdinalIgnoreCase));
                foreach (var file in files)
                {
                    Current.Overlays.Add(Path.GetFileNameWithoutExtension(file),
                                         (Widget)Node.CreateFromAssetBundle(Path.ChangeExtension(file, null), null, TangerinePersistence.Instance));
                }
            }

            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
            if (PluginLoader.CurrentPlugin != null)
            {
                foreach (var action in PluginLoader.CurrentPlugin.TangerineProjectOpened)
                {
                    action?.Invoke();
                }
            }
        }
예제 #3
0
        public void Open()
        {
            Opening?.Invoke(CitprojPath);
            if (Current != Null)
            {
                throw new InvalidOperationException();
            }
            Current = this;
            TangerineAssetBundle tangerineAssetBundle;

            AssetBundle.Current = tangerineAssetBundle = new TangerineAssetBundle(AssetsDirectory);
            if (!tangerineAssetBundle.IsActual())
            {
                tangerineAssetBundle.CleanupBundle();
            }
            Preferences = new ProjectPreferences();
            Preferences.Initialize();
            if (File.Exists(UserprefsPath))
            {
                try {
                    UserPreferences = TangerineYuzu.Instance.Value.ReadObjectFromFile <ProjectUserPreferences>(UserprefsPath);
                    foreach (var path in UserPreferences.Documents)
                    {
                        try {
                            OpenDocument(path);
                        } catch (System.Exception e) {
                            Debug.Write($"Failed to open document '{path}': {e.Message}");
                        }
                    }
                    var currentDoc = documents.FirstOrDefault(d => d.Path == UserPreferences.CurrentDocument) ?? documents.FirstOrDefault();
                    Document.SetCurrent(currentDoc);
                } catch (System.Exception e) {
                    Debug.Write($"Failed to load the project user preferences: {e}");
                }
            }
            fsWatcher          = new Lime.FileSystemWatcher(AssetsDirectory, includeSubdirectories: true);
            fsWatcher.Changed += HandleFileSystemWatcherEvent;
            fsWatcher.Created += HandleFileSystemWatcherEvent;
            fsWatcher.Deleted += HandleFileSystemWatcherEvent;
            fsWatcher.Renamed += HandleFileSystemWatcherEvent;
            var overlaysPath = Path.Combine(Project.Current.AssetsDirectory, "Overlays");

            if (Directory.Exists(overlaysPath))
            {
                var files = Directory.EnumerateFiles(overlaysPath)
                            .Where(file => Path.GetExtension(file) == ".tan" || Path.GetExtension(file) == ".scene");
                foreach (var file in files)
                {
                    Project.Current.Overlays.Add(Path.GetFileNameWithoutExtension(file), new Frame(file));
                }
            }

            registeredNodeTypes.AddRange(GetNodesTypesOrdered("Lime"));
            registeredComponentTypes.AddRange(GetComponentsTypes("Lime"));
            foreach (var type in Orange.PluginLoader.EnumerateTangerineExportedTypes())
            {
                if (typeof(Node).IsAssignableFrom(type))
                {
                    registeredNodeTypes.Add(type);
                }
                else if (typeof(NodeComponent).IsAssignableFrom(type))
                {
                    registeredComponentTypes.Add(type);
                }
            }
        }