Beispiel #1
0
        /// <summary>
        /// Contruct the complete macro base on user selection
        /// </summary>
        /// <param name="template"></param>
        /// <param name="aEActionList"></param>
        /// <returns></returns>
        public MacroTemplate ConstructCompleteMacro(MacroTemplate template, IList <IAEActionViewModel> aEActionList)
        {
            //Copy the macro so subsequence convert start on fresh macro
            var copiedMacro = CopyMacro(template);

            var offset = 0;
            var lastActionGroupIndex = -1;

            foreach (var action in aEActionList)
            {
                var actionList          = ScaleActionsToMacroResolution(template, action.UserChoicesToActionList());
                var actionIndexToInsert = action.ActionIndex;

                //Fix index to insert if placeholder in the same actiongroup
                if (action.ActionGroupIndex == lastActionGroupIndex)
                {
                    actionIndexToInsert += offset;
                    offset += actionList.Count;
                }
                else
                {
                    offset = actionList.Count;
                }

                (copiedMacro.ActionGroupList[action.ActionGroupIndex] as ActionGroup).ActionList.InsertRange(actionIndexToInsert, actionList);

                lastActionGroupIndex = action.ActionGroupIndex;
            }

            return(copiedMacro);
        }
        public void Generate()
        {
            Prepare();

            var template = new MacroTemplate(_random);

            Land = template;

            //Fully generate Macro Map
            Macro = template.CreateMacroMap(this);

            var microtimer = Stopwatch.StartNew();

            Micro = new MicroMap(Macro, this);

            foreach (var zone in Macro.Zones)
            {
                template.GenerateMicroZone(Macro, zone, Micro);
            }
            Micro.GenerateHeightmap();

            microtimer.Stop();

            Micro.Changed += MicroOnChanged;

            Debug.LogFormat("Created micromap in {0} msec", microtimer.ElapsedMilliseconds);
        }
Beispiel #3
0
        public IEnumerable <IAEActionViewModel> ScanMacroForPlaceHolder(MacroTemplate macro)
        {
            for (int i = 0; i < macro.ActionGroupList.Count; i++)
            {
                if (!(macro.ActionGroupList[i] is ActionGroup actionGroup))
                {
                    throw new InvalidOperationException("Can not cast ActionGroup");
                }

                if (actionGroup.IsDisable)
                {
                    continue;
                }


                for (int j = 0; j < actionGroup.ActionList.Count; j++)
                {
                    if (!(actionGroup.ActionList[j] is AE ae) || ae.IsDisable)
                    {
                        continue;
                    }

                    var aeaction = this.factory.NewAEActionViewModel(ae.AnotherEdenAction);
                    aeaction.ActionDescription = ae.ActionDescription;
                    aeaction.ActionGroupIndex  = i;
                    aeaction.ActionIndex       = j;
                    yield return(aeaction);
                }
            }
        }
        private IList <IAction> ScaleActionsToMacroResolution(MacroTemplate macro, IList <IAction> actionList)
        {
            var    newList = new List <IAction>();
            double scaleX  = macro.OriginalX / 1280.0;
            double scaleY  = macro.OriginalY / 720.0;

            foreach (var action in actionList)
            {
                switch (action.BasicAction)
                {
                case BasicAction.Click:
                    var copied = this.autoMapper.SimpleAutoMap <Click, Click>(action as Click);
                    copied.ClickPoint = new System.Windows.Point(Math.Round((action as Click).ClickPoint.X * scaleX), Math.Round((action as Click).ClickPoint.Y * scaleY));
                    newList.Add(copied);
                    break;

                case BasicAction.Swipe:
                    var copiedSwipe = this.autoMapper.SimpleAutoMap <Swipe, Swipe>(action as Swipe);
                    copiedSwipe.PointList = copiedSwipe.PointList.Select(sp => new SwipePoint
                    {
                        HoldTime   = sp.HoldTime,
                        SwipeSpeed = sp.SwipeSpeed,
                        Point      = new System.Windows.Point(Math.Round(sp.Point.X * scaleX), Math.Round(sp.Point.Y * scaleY))
                    }).ToList();
                    newList.Add(copiedSwipe);
                    break;

                default:
                    newList.Add(action);
                    break;
                }
            }

            return(newList);
        }
Beispiel #5
0
        private MacroTemplate CopyMacro(MacroTemplate macro)
        {
            if (macro == null)
            {
                throw new ArgumentNullException();
            }

            var temp       = Guid.NewGuid().ToString();
            var tempFolder = Path.Combine(Environment.CurrentDirectory, temp);

            Directory.CreateDirectory(tempFolder);
            var tempFilePath = Path.Combine(tempFolder, temp + ".emm");

            dataIO.SaveToFile(macro, tempFilePath);
            try
            {
                return(dataIO.LoadMacroFileFromPath(tempFilePath).MacroTemplate);
            }
            finally
            {
                if (Directory.Exists(tempFolder))
                {
                    Directory.Delete(tempFolder, true);
                }
            }
        }
        private MacroTemplate ConstructCompleteMacro(MacroTemplate template, IList <IAEActionViewModel> aEActionList)
        {
            //Copy the macro so subsequence convert start on fresh macro
            var copiedMacro = this.autoMapper.SimpleAutoMap <MacroTemplate, MacroTemplate>(template);

            copiedMacro.ActionGroupList = copiedMacro.ActionGroupList.Select(ag => (IAction) new ActionGroup {
                Repeat = (ag as ActionGroup).Repeat, ActionList = new List <IAction>((ag as ActionGroup).ActionList)
            }).ToList();

            var offset = 0;
            var lastActionGroupIndex = -1;

            foreach (var action in aEActionList)
            {
                var actionList          = ScaleActionsToMacroResolution(template, action.UserChoicesToActionList());
                var actionIndexToInsert = action.ActionIndex;

                //Fix index to insert if placeholder in the same actiongroup
                if (action.ActionGroupIndex == lastActionGroupIndex)
                {
                    actionIndexToInsert += offset;
                    offset += actionList.Count;
                }
                else
                {
                    offset = actionList.Count;
                }

                (copiedMacro.ActionGroupList[action.ActionGroupIndex] as ActionGroup).ActionList.InsertRange(actionIndexToInsert, actionList);

                lastActionGroupIndex = action.ActionGroupIndex;
            }

            return(copiedMacro);
        }
Beispiel #7
0
        public void SetCurrentTemplate(MacroTemplate macro, string path)
        {
            var old = selectedMacro;

            selectedMacro = macro;

            SelectChanged?.Invoke(this, new MacroSelectionChangedEventArgs(old, selectedMacro, path));
        }
Beispiel #8
0
        /// <summary>
        /// Generate script
        /// </summary>
        /// <param name="macro">The macro template</param>
        /// <param name="aEActionList">AEAction list from user choice</param>
        /// <returns></returns>
        public bool?GenerateScript(MacroTemplate macro, IList <IAEActionViewModel> aEActionList)
        {
            if (!ApplyConvertSetting(macro))
            {
                return(false);
            }

            var macroTemplate = this.ConstructCompleteMacro(macro, aEActionList);

            var script = this.emulatorToScriptFactory.GetEmulatorScriptGenerator(setting.SelectedEmulator).MacroToScript(macroTemplate);

            return(scriptApplyFactory.GetScriptApplier(setting.SelectedEmulator).ApplyScriptTo(string.IsNullOrEmpty(setting.CustomName) ? macroTemplate.MacroName : setting.CustomName, setting.SelectedPath, script));
        }
Beispiel #9
0
        /// <summary>
        /// Generate script for the selected AEaction only
        /// </summary>
        /// <param name="macro">The macro template</param>
        /// <param name="aEActionList">the aeaction to generate script</param>
        /// <returns></returns>
        public bool?GenerateScript(MacroTemplate macro, IAEActionViewModel aEAction)
        {
            if (!ApplyConvertSetting(macro))
            {
                return(false);
            }

            var actionList = ScaleActionsToMacroResolution(macro, aEAction.UserChoicesToActionList());

            var script = this.emulatorToScriptFactory.GetEmulatorScriptGenerator(setting.SelectedEmulator).MacroToScript(actionList);

            return(scriptApplyFactory.GetScriptApplier(setting.SelectedEmulator).ApplyScriptTo(string.IsNullOrEmpty(setting.CustomName) ? macro.MacroName + "_Test" : setting.CustomName + "_Test", setting.SelectedPath, script, false));
        }
Beispiel #10
0
        /// <summary>
        /// Populate the properties of its self with an <see cref="MacroTemplate"/>
        /// </summary>
        /// <param name="actionGroup">The <see cref="MacroTemplate"/></param>
        public MacroViewModel PopulateProperties(MacroTemplate macroTemplate)
        {
            if (macroTemplate == null)
            {
                return(null);
            }

            this.autoMapper.SimpleAutoMap <MacroTemplate, MacroViewModel>(macroTemplate, this);

            foreach (var actionGroup in macroTemplate.ActionGroupList)
            {
                base.ViewModelList.Add(viewModelFactory.NewActionViewModel(BasicAction.ActionGroup).ConvertFromAction(actionGroup));
            }

            return(this);
        }
Beispiel #11
0
        /// <summary>
        /// Generate a temporary complete macro, return the path to the macro if success, null otherwise
        /// </summary>
        /// <param name="macro"></param>
        /// <param name="aEActionList"></param>
        /// <returns></returns>
        public string GenerateTempScript(MacroTemplate macro, IList <IAEActionViewModel> aEActionList)
        {
            try
            {
                if (!ApplyConvertSetting(macro))
                {
                    return(null);
                }

                var macroTemplate = this.ConstructCompleteMacro(macro, aEActionList);

                return(this.dataIO.SaveToFile(macroTemplate, Path.Combine(StaticVariables.TEMP_FOLDER, macro.MacroName + ".emm")));
            }
            catch
            {
                return(null);
            }
        }
Beispiel #12
0
        private bool ApplyConvertSetting(MacroTemplate macro)
        {
            if (macro.OriginalX == 0 || double.IsNaN(macro.OriginalX) || macro.OriginalY == 0 || double.IsNaN(macro.OriginalY))
            {
                messageBoxService.ShowMessageBox("The macro doesnt have any resolution set. Please set in in EMM", "Error", MessageButton.OK, MessageImage.Error);
                return(false);
            }

            GlobalData.CustomX   = setting.CustomX;
            GlobalData.CustomY   = setting.CustomY;
            GlobalData.OriginalX = macro.OriginalX;
            GlobalData.OriginalY = macro.OriginalY;
            GlobalData.Emulator  = setting.SelectedEmulator;
            GlobalData.Randomize = setting.Randomize;
            GlobalData.ScaleMode = setting.ScaleMode;

            return(true);
        }
Beispiel #13
0
        /// <summary>
        /// Populate the properties of its self with an <see cref="MacroTemplate"/>
        /// </summary>
        /// <param name="actionGroup">The <see cref="MacroTemplate"/></param>
        public MacroViewModel PopulateProperties(MacroTemplate macroTemplate)
        {
            if (macroTemplate == null)
            {
                return(null);
            }

            this.autoMapper.SimpleAutoMap(macroTemplate, this);
            var temp = new ObservableCollection <IActionViewModel>();

            foreach (var actionGroup in macroTemplate.ActionGroupList)
            {
                temp.Add(viewModelFactory.NewActionViewModel(BasicAction.ActionGroup).ConvertFromAction(actionGroup));
            }

            base.ViewModelList = temp;

            return(this);
        }
        /// <summary>
        /// Generate script for the selected AEaction only
        /// </summary>
        /// <param name="macro">The macro template</param>
        /// <param name="aEActionList">the aeaction to generate script</param>
        /// <returns></returns>
        public bool?GenerateScript(MacroTemplate macro, IAEActionViewModel aEAction)
        {
            var timer = 200;

            if (!ApplyConvertSetting(macro))
            {
                return(false);
            }

            var actionList = ScaleActionsToMacroResolution(macro, aEAction.UserChoicesToActionList());

            var script = new StringBuilder();

            foreach (var action in actionList)
            {
                script.Append(action.GenerateAction(ref timer));
            }

            return(scriptApplyFactory.GetScriptApplier(setting.SelectedEmulator).ApplyScriptTo(string.IsNullOrEmpty(setting.CustomName) ? macro.MacroName + "_Test": setting.CustomName + "_Test", setting.SelectedPath, script, false));
        }
        private bool ApplyConvertSetting(MacroTemplate macro)
        {
            GlobalData.CustomX   = setting.CustomX;
            GlobalData.CustomY   = setting.CustomY;
            GlobalData.Emulator  = setting.SelectedEmulator;
            GlobalData.Randomize = setting.Randomize;

            try
            {
                GlobalData.ScaleX = (double)setting.CustomX / macro.OriginalX;
                GlobalData.ScaleY = (double)setting.CustomY / macro.OriginalY;
            }
            catch
            {
                messageBoxService.ShowMessageBox("The macro doesnt have any resolution set. Please set in in EMM", "Error", MessageButton.OK, MessageImage.Error);
                return(false);
            }

            return(true);
        }
Beispiel #16
0
        /// <summary>
        /// Scale the default action to macro resolution
        /// </summary>
        /// <param name="macro"></param>
        /// <param name="actionList"></param>
        /// <returns></returns>
        private IList <IAction> ScaleActionsToMacroResolution(MacroTemplate macro, IList <IAction> actionList)
        {
            var newList = new List <IAction>();

            //double scaleX = macro.OriginalX / 1280.0;
            //double scaleY = macro.OriginalY / 720.0;
            GlobalData.CustomX   = macro.OriginalX;
            GlobalData.CustomY   = macro.OriginalY;
            GlobalData.OriginalX = actionProvider.GetDefaultActions().X;
            GlobalData.OriginalY = actionProvider.GetDefaultActions().Y;
            GlobalData.Emulator  = Emulator.Nox;

            foreach (var action in actionList)
            {
                switch (action.BasicAction)
                {
                case BasicAction.Click:
                    var copied = this.autoMapper.SimpleAutoMap <Click, Click>(action as Click);
                    //copied.ClickPoint = new System.Windows.Point(Math.Round((action as Click).ClickPoint.X * scaleX), Math.Round((action as Click).ClickPoint.Y * scaleY));
                    copied.Scale();
                    newList.Add(copied);
                    break;

                case BasicAction.Swipe:
                    var copiedSwipe = this.autoMapper.SimpleAutoMap <Swipe, Swipe>(action as Swipe);
                    //copiedSwipe.PointList = copiedSwipe.PointList.Select(sp => new SwipePoint(sp)).ToList();
                    copiedSwipe.Scale();
                    newList.Add(copiedSwipe);
                    break;

                default:
                    newList.Add(action);
                    break;
                }
            }

            ApplyConvertSetting(macro);

            return(newList);
        }
Beispiel #17
0
 public MacroSelectionChangedEventArgs(MacroTemplate oldMacro, MacroTemplate newMacro, string path)
 {
     OldMacro          = oldMacro;
     NewMacro          = newMacro;
     SelectedMacroPath = path;
 }
Beispiel #18
0
 public MacroProfileSelectedEventArgs(MacroTemplate currentTemplate, SavedAEProfile profile)
 {
     Macro   = currentTemplate;
     Profile = profile;
 }
Beispiel #19
0
 public object MacroToScript(MacroTemplate macro)
 {
     return(MacroToScript(macro.ActionGroupList));
 }