Esempio n. 1
0
        private Scene CreateScene(ParseTreeNode node)
        {
            Scene scene = new Scene(grammar.GetName(node));

            foreach (Tuple<string, object> attribute in GetProperties(node))
            {
                ParseTreeNode attributeNode = (ParseTreeNode)attribute.Item2;
                scene.AddAttribute(new Attribute(attribute.Item1) { Value = new Value(getStrVal(attributeNode)) });
            }

            foreach (ParseTreeNode managerNode in grammar.GetOfType(node, grammar.Manager))
            {
                Manager manager = CreateManager(managerNode);
                scene.AddManager(manager);
            }

            foreach (ParseTreeNode entityNode in grammar.GetOfType(node, grammar.Entity))
            {
                Entity entity = CreateEntity(entityNode, scene, false);
                scene.AddEntity(entity);
            }

            return scene;
        }
Esempio n. 2
0
        private Workspace()
        {
            Plugins = new ObservableCollection<Plugin>();

            Services = new FilteredObservableCollection<Plugin>(Plugins, p => p.Type == PluginType.Service);
            Managers = new FilteredObservableCollection<Plugin>(Plugins, p => p.Type == PluginType.Manager);
            Components = new FilteredObservableCollection<Plugin>(Plugins, p => p.Type == PluginType.Component);

            Events = new ObservableCollection<StatementFactory>();
            Actions = new ObservableCollection<StatementFactory>();
            Statements = new ObservableCollection<StatementFactory>();

            NewProjectCommand = new DelegateCommand(null, p =>
            {
                var create = true;

                if (null != Project && CommandHistory.HasUnsavedChanges)
                {
                    DialogService.Warn(Messages.NewProject, Messages.UnsavedMessage, MessageBoxButton.YesNoCancel, r =>
                    {
                        if (r == MessageBoxResult.Yes)
                        {
                            SaveProject();
                        }
                        else if (r == MessageBoxResult.Cancel)
                        {
                            create = false;
                        }
                    });
                }

                if (create)
                {
                    Game game = new Game("Untitled Game");
                    KglGameStorage.AddDefaultUsings(game);

                    var service = new Service(GetPlugin(typeof(RenderService)));
                    service.SetProperty("Width", new Value(800, true));
                    service.SetProperty("Height", new Value(600, true));
                    game.AddService(service);

                    var scene = new Scene("Scene1");

                    var manager = new Manager(GetPlugin(typeof(RenderManager)));
                    scene.AddManager(manager);

                    game.AddScene(scene);
                    game.FirstScene = scene;

                    Project project = new Project();
                    project.Game = game;

                    DialogService.ShowDialog<ProjectDialog>(project, (result) =>
                    {
                        if (result == true)
                        {
                            ProjectStorage.CreateProject(project);
                            Project = project;
                        }
                    });
                }
            });

            LoadProjectCommand = new DelegateCommand(null, p =>
            {
                var load = true;

                if (null != Project && CommandHistory.HasUnsavedChanges)
                {
                    DialogService.Warn(Messages.LoadProject, Messages.UnsavedMessage, MessageBoxButton.YesNoCancel, r =>
                    {
                        if (r == MessageBoxResult.Yes)
                        {
                            SaveProject();
                        }
                        else if (r == MessageBoxResult.Cancel)
                        {
                            load = false;
                        }
                    });
                }

                if (load)
                {
                    DialogService.ShowLoadDialog((result, fileName) =>
                    {
                        if (result == true)
                        {
                            try
                            {
                                LoadProject(fileName);
                            }
                            catch (EditorException e)
                            {
                                DialogService.Warn(Messages.FailedToLoad, e.Message, MessageBoxButton.OK);
                            }
                        }
                    });
                }
            });

            SaveProjectCommand = new DelegateCommand(p => null != project, p =>
            {
                if (null == Project.Title)
                {
                    DialogService.ShowSaveDialog(
                        (result, fileName) =>
                        {
                            if (result == true)
                            {
                                Project.Title = fileName;
                            }
                        }
                    );
                }

                if (null != Project.Title)
                {
                    SaveProject();
                }
            });

            RevertProjectCommand = new DelegateCommand(p => null != Project, p => RevertProject());

            Assembly core = typeof(Kinectitude.Core.Base.Component).Assembly;
            RegisterPlugins(core);

            DirectoryInfo path = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, PluginDirectory));
            if (path.Exists)
            {
                FileInfo[] files = path.GetFiles("*.dll");
                foreach (FileInfo file in files)
                {
                    Assembly asm = Assembly.LoadFrom(file.FullName);
                    RegisterPlugins(asm);
                }
            }

            CommandHistory = new CommandHistory();
            DialogService = new DialogService();
        }