public DataFolderViewModel(AppFoldersViewModel appFolders)
 {
     _appFolders     = appFolders;
     MoveUpCommand   = new ScriptingCommand(() => appFolders.MoveUp(this));
     MoveDownCommand = new ScriptingCommand(() => appFolders.MoveDown(this));
     DeleteCommand   = new ScriptingCommand(() => appFolders.Delete(this));
 }
Example #2
0
 public SamplerCubeViewModel(ScriptViewModel script, ScriptNode node, UrhoContext context) : base(script, node)
 {
     _context            = context;
     PickTextureCommand  = new ScriptingCommand(PickTexture);
     ResetTextureCommand = new ScriptingCommand(ResetTexture);
     UpdateImageSource();
 }
Example #3
0
 public ScriptViewModel(INodeRegistry registry = null, INodeViewModelFactory viewModelFactory = null,
                        Script script          = null)
 {
     _registry            = registry ?? EmptyNodeRegistry.Instance;
     _viewModelFactory    = viewModelFactory ?? new NodeViewModelFactory(_registry);
     GroupSelectedCommand = new ScriptingCommand(() => GroupSelected())
     {
         CanExecute = false
     };
     UngroupSelectedCommand = new ScriptingCommand(UngroupSelected)
     {
         CanExecute = false
     };
     CopySelectedCommand = new ScriptingCommand(CopySelected)
     {
         CanExecute = false
     };
     CutSelectedCommand = new ScriptingCommand(CutSelected)
     {
         CanExecute = false
     };
     DuplicateSelectedCommand = new ScriptingCommand(DuplicateSelected)
     {
         CanExecute = false
     };
     PasteCommand = new ScriptingCommand(() => Paste())
     {
         CanExecute = true
     };
     UndoCommand = new ScriptingCommand(Undo)
     {
         CanExecute = false
     };
     RedoCommand = new ScriptingCommand(Redo)
     {
         CanExecute = false
     };
     //BindingOperations.SetBinding(UndoCommand, ScriptingCommand.CanExecuteProperty, new Binding
     //{
     //    Path = new PropertyPath(nameof(UndoStackViewModel.CanUndo)),
     //    Source = UndoStack
     //});
     //BindingOperations.SetBinding(RedoCommand, ScriptingCommand.CanExecuteProperty, new Binding
     //{
     //    Path = new PropertyPath(nameof(UndoStackViewModel.CanRedo)),
     //    Source = UndoStack
     //});
     SelectAllCommand      = new ScriptingCommand(SelectAll);
     DeleteSelectedCommand = new ScriptingCommand(DeleteSelected);
     ResetZoomCommand      = new ScriptingCommand(ResetZoom);
     if (script != null)
     {
         SetScript(script);
     }
 }
 public void LoadSetting(XElement settingRoot)
 {
     commands.Clear();
     foreach (XElement element in settingRoot.Elements("ScriptingCommand"))
     {
         IObjectEditorType type = provider.Types.Where(t => t.GetType().AssemblyQualifiedName == element.Attribute("Class").Value).FirstOrDefault();
         if (type != null)
         {
             ScriptingCommand command = (ScriptingCommand)type.CreateObject();
             command.LoadSetting(element);
             commands.Add(command);
         }
     }
 }
Example #5
0
 public GroupViewModel(ScriptViewModel script, NodeGroup nodeGroup)
 {
     Script    = script;
     NodeGroup = nodeGroup;
     CollapseOrExpandCommand = new ScriptingCommand(CollapseOrExpand);
     if (nodeGroup.IsCollapsed)
     {
         Collapse();
     }
     else
     {
         Expand();
     }
 }
            public Worker(ScriptingCommand c, ExecutedEventArgs e)
            {
                // Keep this worker alive after leaving local scope using a strong reference.
                Workers.Register(this);

                CancellationTokenSource = new CancellationTokenSource();

                // Store the current context;
                EntryContext = ScriptingContext.Current;

                // Keep strong references to the passed arguments.
                Callback = e.Arguments.ElementAt(0).ToFunction();
                Value = e.Arguments.ElementAt(1).ToInteger();

                // Keep a references to the command, so we'll be able to detach the event handler later.
                Command = c;
                Command.ScriptingContextReleased += OnScriptingContextReleased;
            }
        public MainViewModel(ScriptViewModel scriptViewModel, ShaderGenerator generator, UrhoContext context,
                             GraphValidator validator, ConfigurationRepository <AppConfiguration> config)
        {
            _backgroundScheduler = new EventLoopScheduler();
            _disposables.Add(_backgroundScheduler);
            _generator             = generator;
            _context               = context;
            _validator             = validator;
            _config                = config;
            NewCommand             = new ScriptingCommand(New);
            NewEmptyCommand        = new ScriptingCommand(NewEmpty);
            OpenCommand            = new ScriptingCommand(Open);
            MergeCommand           = new ScriptingCommand(Merge);
            SaveCommand            = new ScriptingCommand(Save);
            SaveAsCommand          = new ScriptingCommand(SaveAs);
            ExportCommand          = new ScriptingCommand(Export);
            OpenSceneCommand       = new ScriptingCommand <string>(OpenScene);
            OpenMDLCommand         = new ScriptingCommand <string>(OpenMDL);
            OpenAnimatedMDLCommand = new ScriptingCommand <string>(OpenAnimatedMDL);

            SetResourcePathCommand   = new ScriptingCommand(SetResourcePath);
            ExitCommand              = new ScriptingCommand(Exit);
            SetRenderPathCommand     = new ScriptingCommand <string>(SetRenderPath);
            SetShadowQualityCommand  = new ScriptingCommand <string>(SetShadowQuality);
            _rearrangeCommand        = new ScriptingCommand(() => ScriptViewModel.Rearrange());
            _centerGraphCommand      = new ScriptingCommand(() => ToCenter());
            SaveSelectedAsCommand    = new ScriptingCommand(SaveSelectedAs);
            RunScriptAnalizerCommand = new ScriptingCommand(RunScriptAnalizer);
            TestAllNodeTypesCommand  = new ScriptingCommand(TestAllNodeTypes);
            TestNodesCommand         = new ScriptingCommand(TestNodes);
            TestPerformanceCommand   = new ScriptingCommand(TestPerformance);
            ScriptViewModel          = scriptViewModel;

            _errors = new Subject <MaterialCompilationException>();
            _disposables.Add(_errors.ObserveOnDispatcher().Subscribe(HandleError));

            _preview = new Subject <PreviewData>();
            _disposables.Add(_preview.Throttle(TimeSpan.FromSeconds(0.1f)).ObserveOn(_backgroundScheduler)
                             .Subscribe(new Generator(this)));

            ScriptViewModel.ScriptChanged    += OnScriptViewModelOnScriptChanged;
            ScriptViewModel.SelectionChanged += OnScriptViewModelOnSelectionChanged;
            New();
        }
Example #8
0
        /// <summary>Creates a scripting command from action input.</summary>
        /// <param name="actionInput">The action input to transform into a ScriptingCommand instance.</param>
        /// <returns>A new ScriptingCommand instance for the specified input, if found, else null.</returns>
        public ScriptingCommand Create(ActionInput actionInput)
        {
            // TODO: Build targeting into command selection when there are multiple valid targets; IE if multiple
            //     openable things registered an "open" context command, then if the user said "open door" then we
            //     want to select the context command attached to the closest match for "door" as our command; if
            //     there are still multiple targets, we can start a conflict resolution prompt, etc.  Individual non-
            //     context commands may also wish to use such targeting code, so it should be built to be reusable.
            ScriptingCommand command = this.TryCreateMasterCommand(actionInput, 0) ??
                                       this.TryCreateMasterCommand(actionInput, 1) ??
                                       this.TryCreateContextCommand(actionInput, 0) ??
                                       this.TryCreateContextCommand(actionInput, 1);

            if (command == null)
            {
                actionInput.Controller.Write(unknownCommandResponse);
            }

            return(command);
        }
 public bool HandleCommand(string command, ref Exception error)
 {
     if (command == "edit command")
     {
         provider.Load(commands);
         using (ObjectEditorForm form = new ObjectEditorForm(provider, callback))
         {
             if (form.ShowDialog() == DialogResult.OK)
             {
                 provider.Save(commands);
                 callback.SaveSettings();
                 InvokeSuggestedCommandChanged();
             }
         }
         return(true);
     }
     else
     {
         ScriptingCommand scriptingCommand = commands.Where(c => c.Name == command).FirstOrDefault();
         if (scriptingCommand != null)
         {
             try
             {
                 scriptingCommand.ExecuteCommand(callback);
             }
             catch (Exception ex)
             {
                 error = ex;
             }
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Example #10
0
        /// <summary>Verifies that the proposed command can be performed by the acting entity.</summary>
        /// <param name="command">The issued command to be carried out.</param>
        /// <returns>A string defining why the permission was not given, else null if permission is given.</returns>
        public static string VerifyCommandPermission(ScriptingCommand command)
        {
            if (command.SecurityRole == SecurityRole.none)
            {
                // If you are debugging here after trying to set up your own action,
                // you probably forgot to assign an appropriate [ActionSecurity(...)]
                // attribute for your new GameAction class.
                return(string.Format("Nobody can use '{0}' right now!", command.Name));
            }

            Thing entity = command.ActionInput.Controller.Thing;

            if (entity == null)
            {
                return("You must exist before issuing commands!");
            }

            PlayerBehavior player = entity.Behaviors.FindFirst <PlayerBehavior>();

            if (player != null)
            {
                // @@@ TODO: Ascertain the ACTUAL player's specific permissions, so we can
                //     check for fullAdmin, fullBuilder, etc, instead of assuming just
                //     'SecurityRole.player'
                SecurityRole playerRoles = SecurityRole.player | SecurityRole.minorBuilder |
                                           SecurityRole.fullBuilder | SecurityRole.minorAdmin | SecurityRole.fullAdmin;

                // If any of the command's security roles and the player's security roles
                // overlap (such as the command is marked with 'minorBuilder' and the
                // player has the 'minorBuilder' flag) then we permit the command.
                if ((command.SecurityRole & playerRoles) != SecurityRole.none)
                {
                    return(null);
                }

                // Otherwise, this player does not have permission; we do not want to
                // check the mobile/item/room security role on players, so we're done.
                return(string.Format("You do not have permission to use '{0}' right now.", command.Name));
            }

            MobileBehavior mobile = entity.Behaviors.FindFirst <MobileBehavior>();

            if (mobile != null)
            {
                if ((command.SecurityRole & SecurityRole.mobile) != SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A mobile can not use '{0}' right now!", command.Name));
            }

            RoomBehavior room = entity.Behaviors.FindFirst <RoomBehavior>();

            if (room != null)
            {
                if ((command.SecurityRole & SecurityRole.room) == SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A room can not use '{0}' right now!", command.Name));
            }

            // @@@ For now, everything else which doesn't meet any above category will need the 'item' security
            //     role. (Do we need an ItemBehavior or is there something else relevant... CanPickupBehavior etc?)
            if ((command.SecurityRole & SecurityRole.item) != SecurityRole.none)
            {
                return(null);
            }

            return(string.Format("An item (or unrecognized entity) can not use '{0}' right now!", command.Name));
        }
Example #11
0
 public MainViewModel(ScriptViewModel scriptViewModel)
 {
     ScriptViewModel = scriptViewModel;
     OpenCommand     = new ScriptingCommand(Open);
 }
 public AppFoldersViewModel(ConfigurationRepository <AppConfiguration> configRepository)
 {
     _configRepository = configRepository;
     Reset();
     AddCommand = new ScriptingCommand(AddFolder);
 }
 public FactoryViewModel(ScriptViewModel script, INodeFactory factory)
 {
     _script       = script;
     _factory      = factory;
     CreateCommand = new ScriptingCommand(() => Create(script.CreateLocation));
 }
Example #14
0
        /// <summary>Verifies that the proposed command can be performed by the acting entity.</summary>
        /// <param name="command">The issued command to be carried out.</param>
        /// <returns>A string defining why the permission was not given, else null if permission is given.</returns>
        public static string VerifyCommandPermission(ScriptingCommand command)
        {
            if (command.SecurityRole == SecurityRole.none)
            {
                // If you are debugging here after trying to set up your own action,
                // you probably forgot to assign an appropriate [ActionSecurity(...)]
                // attribute for your new GameAction class.
                return(string.Format("Nobody can use '{0}' right now!", command.Name));
            }

            Thing entity = command.ActionInput.Actor;

            if (entity == null)
            {
                return("You must exist before issuing commands!");
            }

            var user = entity.FindBehavior <UserControlledBehavior>();

            if (user != null)
            {
                // If any of the command security roles and the user security roles overlap (such as the command is
                // marked with 'minorBuilder' and the user has the 'minorBuilder' flag) then we permit the command.
                if ((command.SecurityRole & user.SecurityRoles) != SecurityRole.none)
                {
                    return(null);
                }

                // Otherwise, this player does not have permission; we do not want to
                // check the mobile/item/room security role on players, so we're done.
                return(string.Format("You do not have permission to use '{0}' right now.", command.Name));
            }

            MobileBehavior mobile = entity.FindBehavior <MobileBehavior>();

            if (mobile != null)
            {
                if ((command.SecurityRole & SecurityRole.mobile) != SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A mobile can not use '{0}' right now!", command.Name));
            }

            RoomBehavior room = entity.FindBehavior <RoomBehavior>();

            if (room != null)
            {
                if ((command.SecurityRole & SecurityRole.room) == SecurityRole.none)
                {
                    return(null);
                }

                return(string.Format("A room can not use '{0}' right now!", command.Name));
            }

            // TODO: For now, everything else which doesn't meet any above category will need the 'item' security
            //       role. (Do we need an ItemBehavior or is there something else relevant... CanPickupBehavior etc?)
            if ((command.SecurityRole & SecurityRole.item) != SecurityRole.none)
            {
                return(null);
            }

            return(string.Format("An item (or unrecognized entity) can not use '{0}' right now!", command.Name));
        }