public DirectoryNodeViewModel(IEventAggregator events, IDirectoryTreeViewModel rootModel, IEntryModel curDirModel,
                                      IDirectoryNodeViewModel parentModel)
            : base(curDirModel)
        {
            _events    = events;
            _rootModel = rootModel;

            Entries = new EntriesHelper <IDirectoryNodeViewModel>(loadEntriesTask)
            {
                ClearBeforeLoad = true
            };
            Selection = new TreeSelector <IDirectoryNodeViewModel, IEntryModel>(curDirModel, this,
                                                                                parentModel == null ? rootModel.Selection : parentModel.Selection, Entries);
            Selection.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "IsSelected")
                {
                    IsSelected = Selection.IsSelected;
                }
            };
            DropHelper = new DirectoryNodeDropHelper(curDirModel, Entries, Selection)
            {
                DisplayName = curDirModel.Label
            };
        }
Пример #2
0
        public TreeNodeViewModel(string value, string header, TreeViewModel root, TreeNodeViewModel parentNode)
        {
            if (root == null || value == null)
            {
                throw new ArgumentException();
            }
            _path   = value;
            _root   = root;
            _parent = parentNode;
            _header = header;


            Entries = new EntriesHelper <TreeNodeViewModel>((ct) => Task.Run(() =>
            {
                return((IEnumerable <TreeNodeViewModel>) new List <TreeNodeViewModel>(
                           from i in Enumerable.Range(1, 9)
                           select new TreeNodeViewModel(
                               (Path + "\\Sub" + i.ToString()).TrimStart('\\'),
                               "Sub" + i.ToString(),
                               _root, this)
                           ));
            }));

            Selection = new TreeSelector <TreeNodeViewModel, string>(value, this,
                                                                     parentNode == null ? root.Selection : parentNode.Selection, Entries);
        }
Пример #3
0
        private static TreeSelector CreateSelectorFromComposed(Core core,
                                                               ComposedBehavior target)
        {
            TreeSelector            selector;
            List <ModularBehaviour> modularBehaviours;

            modularBehaviours = new List <ModularBehaviour>();
            selector          = new TreeSelector(true, target.Weight);

            if (target.IsRandomSelector)
            {
                foreach (Type t in GetAllTypesIn(target))
                {
                    Debug.Log("Adding \"" + t.Name + " from \"" + target.Name + "\"");
                    selector.AddNewOption(GetModularBehaviourInCore(core, t));
                }
            }
            else
            {
                foreach (Type t in GetAllTypesIn(target))
                {
                    ModularBehaviour behaviour = GetModularBehaviourInCore(core, t);
                    selector.AddNewOption(behaviour);
                }
            }

            return(selector);
        }
Пример #4
0
    private IEnumerator getValueMultiLayerPurge(int layer, float purgeRate)
    {
        _PM = TreeSelector.getBestMethodMultiLayerPurge(layer, purgeRate);

        _HasEnded = true;

        yield return(new WaitForEndOfFrame());
    }
Пример #5
0
    private IEnumerator getMinValueOnce()
    {
        _PM = TreeSelector.getMinPlaceMethod_OL();

        _HasEnded = true;

        yield return(new WaitForEndOfFrame());
    }
Пример #6
0
        public BreadcrumbItemViewModel(IEventAggregator events, IBreadcrumbViewModel rootModel,
                                       IEntryModel curDirModel, IBreadcrumbItemViewModel parentModel)
            : base(curDirModel)
        {
            _events    = events;
            _rootModel = rootModel;

            Entries   = new EntriesHelper <IBreadcrumbItemViewModel>(loadEntriesTask);
            Selection = new TreeSelector <IBreadcrumbItemViewModel, IEntryModel>(curDirModel, this,
                                                                                 parentModel == null ? rootModel.Selection : parentModel.Selection, Entries);
        }
Пример #7
0
        public DirectoryViewModel(DirectoryTreeViewModel rootViewModel, DirectoryViewModel parentViewModel,
                                  DirectoryEntry directoryEntry, IFileSystem fileSystem, IUiTools uiTools) : this(directoryEntry, fileSystem,
                                                                                                                  uiTools, true)
        {
            _rootViewModel = rootViewModel;
            Parent         = parentViewModel;

            Entries   = new EntriesHelper <DirectoryViewModel>(LoadEntriesAsync);
            Selection = new TreeSelector <DirectoryViewModel, FileExplorerEntry>(Source, this,
                                                                                 parentViewModel?.Selection ?? rootViewModel.Selection, Entries);

            if (!directoryEntry.HasSubFolder)
            {
                Entries.SetEntries(ImmutableList <DirectoryViewModel> .Empty);
            }
        }
Пример #8
0
        public SubKeyNodeViewModel(RegistryTreeViewModel rootTreeViewModel, AdvancedRegistrySubKey currentEntry,
                                   SubKeyNodeViewModel parentViewModel, RegistryCommand registryCommand)
        {
            _rootTreeViewModel = rootTreeViewModel;
            _registryCommand   = registryCommand;
            Parent             = parentViewModel;
            Value          = currentEntry;
            IsRegistryHive = string.IsNullOrEmpty(Value.RelativePath);

            Entries   = new EntriesHelper <SubKeyNodeViewModel>(LoadSubEntries);
            Selection = new TreeSelector <SubKeyNodeViewModel, AdvancedRegistrySubKey>(Value, this,
                                                                                       parentViewModel == null ? rootTreeViewModel.Selection : parentViewModel.Selection, Entries);

            if (Value.IsEmpty)
            {
                Entries.SetEntries(UpdateMode.Update);
            }
        }
Пример #9
0
        public DirectoryNodeViewModel(DirectoryTreeViewModel rootTreeViewModel, PackedDirectoryEntry currentEntry,
                                      DirectoryNodeViewModel parentModel, IFileSystem fileSystem, Func <IWindowService> getWindow) : this(currentEntry, fileSystem)
        {
            _rootModel = rootTreeViewModel;
            _getWindow = getWindow;

            Parent    = parentModel;
            Entries   = new EntriesHelper <DirectoryNodeViewModel>(LoadEntriesTask);
            Selection = new TreeSelector <DirectoryNodeViewModel, IFileExplorerEntry>(Value, this,
                                                                                      parentModel == null ? rootTreeViewModel.Selection : parentModel.Selection, Entries);

            _isNodeViewModel = true;

            if (!Value.HasSubFolder)
            {
                Entries.SetEntries(UpdateMode.Update);
            }
        }
Пример #10
0
        public RegistryKeyViewModel(RegistryTreeViewModel rootTreeViewModel, IntegratedRegistryKey registryKey, ITargetedRestClient restClient,
                                    IShellStatusBar statusBar, RegistryKeyViewModel parentViewModel)
        {
            RegistryKey        = registryKey;
            _rootTreeViewModel = rootTreeViewModel;
            _restClient        = restClient;
            _statusBar         = statusBar;
            Parent             = parentViewModel;

            Entries   = new EntriesHelper <RegistryKeyViewModel>(LoadSubKeys);
            Selection = new TreeSelector <RegistryKeyViewModel, IntegratedRegistryKey>(registryKey, this,
                                                                                       parentViewModel == null ? rootTreeViewModel.Selection : parentViewModel.Selection, Entries);

            if (!registryKey.HasSubKeys)
            {
                Entries.SetEntries(Enumerable.Empty <RegistryKeyViewModel>());
            }
        }
Пример #11
0
        /// <summary>
        /// Will generate a behaviour tree to the given core using the limbs
        /// and core's behaviours
        /// </summary>
        /// <param name="core">Target core</param>
        public static void GenerateTree(Core core)
        {
            /*
             * The tree works as follows:
             *
             * [X] - Random Selector
             * [>] - Sequential Selector
             *
             *            [>]Main Selector          --> Layer 0
             *             /            \
             *       [X]Attack          Idle        --> Layer 1
             *         Selector         Leaf
             *    /      |     \
             * [X]Shooter  [X]Brawler  [X]Tank             --> Layer 2
             * Selector    Selector    Selector
             |          |         |
             | ...        ...       ...               --> Layer 3...
             |
             | - All the behaviours and composed behaviours will be added to the
             | respective selector.
             |
             | - If a core has all limbs of its type it will be considered an elite
             | and add the type special composed behaviour.
             |
             | - The Layer 2 Selector chances will be determined by taking into
             | account the core type and limbs, the core having an weight of 0.8
             | while limbs have 0.2 (Do not mix weights with influences. Influences
             | were supposed to be the stats influence on the core, having nothing
             | to do with the tree).
             */

            BehaviourTree           tree;
            List <Type>             addedTypes;
            List <ComposedBehavior> composedBehaviors;

            tree              = core.gameObject.AddComponent <BehaviourTree>();
            addedTypes        = new List <Type>();
            composedBehaviors = new List <ComposedBehavior>();

            // Go through all the parts
            foreach (ModulariuPartProfile p in core.GetLimbProfiles())
            {
                // Gather the required types
                for (int i = 0; i < p.TypeToggles.Length; i++)
                {
                    TypeToggle toggle = p.TypeToggles[i];

                    // Is it selected?
                    if (!toggle.Toggle)
                    {
                        continue;
                    }

                    Debug.Log("Adding: " + toggle.Name);

                    Type[] profileTypes = toggle.GetAllChildTypes();

                    // Go through all the types
                    for (int j = 0; j < profileTypes.Length; j++)
                    {
                        Type t = profileTypes[j];
                        // Add it if it was not already added
                        if (!addedTypes.Contains(t))
                        {
                            addedTypes.Add(t);
                            AddTypeToCore(t, core);
                        }
                    }

                    if (!toggle.IsRaw)
                    {
                        if (!composedBehaviors.Contains(toggle.ComposedBehavior))
                        {
                            composedBehaviors.Add(toggle.ComposedBehavior);
                        }
                    }
                }
            }

            //TODO: Put bellow in another method

            float shooterChance;
            float brawlerChance;
            float tankChance;

            TreeSelector shooterSelector;
            TreeSelector brawlerSelector;
            TreeSelector tankSelector;

            TreeSelector   attackSelector;
            ITreeComponent idleBehaviour;

            TreeSelector mainSelector;

            idleBehaviour = core.gameObject.AddComponent <IdleBehaviour>();

            // Get the chances of each selector
            shooterChance =
                core.IsOfType(ModulariuType.Shooter) ?
                0.8f :
                0.1f;
            brawlerChance =
                core.IsOfType(ModulariuType.Brawler) ?
                0.8f :
                0.1f;
            tankChance =
                core.IsOfType(ModulariuType.Tank) ?
                0.8f :
                0.1f;

            if (core.HasShooterLimb)
            {
                shooterChance += 0.2f * core.ShooterLimbs;
            }
            if (core.HasBrawlerLimb)
            {
                brawlerChance += 0.2f * core.BrawlerLimbs;
            }
            if (core.HasTankLimb)
            {
                tankChance += 0.2f * core.TankLimbs;
            }

            // Initialize selectors
            shooterSelector = new TreeSelector(true, shooterChance);
            brawlerSelector = new TreeSelector(true, brawlerChance);
            tankSelector    = new TreeSelector(true, tankChance);
            attackSelector  = new TreeSelector(true, 1,
                                               shooterSelector, brawlerSelector, tankSelector);
            mainSelector = new TreeSelector(false, 1, attackSelector, idleBehaviour);

            // Set defaults and determine special abilities
            //Is Shooter?
            if (core.IsOfType(ModulariuType.Shooter))
            {
                // Is elite shooter
                if (core.ShooterLimbs > 2)
                {
                    shooterSelector
                    .AddNewOption(
                        CreateITreeComponentFromComposed(
                            core, _shooterSpecial));
                }
                shooterSelector
                .AddNewOption(
                    CreateITreeComponentFromComposed(
                        core, _shooterDefault));
            }
            // Is Brawler?
            else if (core.IsOfType(ModulariuType.Brawler))
            {
                // Is elite brawler
                if (core.BrawlerLimbs > 2)
                {
                    brawlerSelector
                    .AddNewOption(
                        CreateITreeComponentFromComposed(
                            core, _brawlerSpecial));
                }
                brawlerSelector
                .AddNewOption(
                    CreateITreeComponentFromComposed(
                        core, _brawlerDefault));
            }
            // Is Tank?
            else if (core.IsOfType(ModulariuType.Tank))
            {
                // Is elite tank
                if (core.TankLimbs > 2)
                {
                    tankSelector
                    .AddNewOption(
                        CreateITreeComponentFromComposed(
                            core, _tankSpecial));
                }
                tankSelector
                .AddNewOption(
                    CreateITreeComponentFromComposed(
                        core, _tankDefault));
            }

            // Run through limb's behaviours and add them
            foreach (ComposedBehavior c in composedBehaviors)
            {
                ITreeComponent component;
                if (c.ComposedType == TreeComponentType.Selector)
                {
                    component = CreateSelectorFromComposed(core, c);
                }
                else
                {
                    component = CreateSequenceFromComposed(core, c);
                }

                switch (c.BehaviourType)
                {
                case ModulariuType.Shooter:
                    shooterSelector.AddNewOption(component);
                    break;

                case ModulariuType.Brawler:
                    brawlerSelector.AddNewOption(component);
                    break;

                case ModulariuType.Tank:
                    tankSelector.AddNewOption(component);
                    break;
                }
            }

            // Initialize the tree with the default selector
            tree.Initialize(mainSelector, true);
            core.TreeCreationFinished();
        }