public virtual void CopyTurnList <TurnType>(ObservableCollection <TurnType> source) where TurnType : TurnViewModel, new()
        {
            var      tempTurnList = new List <TurnType>();
            TurnType previous     = null;

            foreach (var turn in source)
            {
                var newTurn = (TurnType)turnFactory.NewTurn(this.AEAction);
                autoMapper.SimpleAutoMap(turn, newTurn, ignoreTypes: new Type[] { typeof(TurnViewModel), typeof(ObservableCollection <Character>), typeof(Character), typeof(ICommand) });

                //copy character list
                var newBackline = turn.Backline.Select(c => new Character {
                    CharacterIMG = c.CharacterIMG, CurrentAction = c.CurrentAction
                }).ToList();
                var newFrontline = turn.Frontline.Select(c => new Character {
                    CharacterIMG = c.CharacterIMG, CurrentAction = c.CurrentAction, MoveIndex = c.MoveIndex, MoveCharacter = newBackline.Where(tc => tc.CharacterIMG == c.CharacterIMG).FirstOrDefault()
                });
                newTurn.Frontline = new ObservableCollection <Character>(newFrontline);
                newTurn.Backline  = new ObservableCollection <Character>(newBackline);

                newTurn.PreviousTurn = previous;
                previous             = newTurn;
                tempTurnList.Add(newTurn);
            }
            ;

            //replace list
            this.TurnList = new ObservableCollection <TurnViewModel>(tempTurnList);
        }
Exemple #2
0
        public virtual IAEActionViewModel ConvertFromAction(IAEAction action)
        {
            if (action.AEAction != AEAction)
            {
                return(null);
            }

            if (!(action is Battle battle))
            {
                return(null);
            }

            IList <TurnViewModel> turnList = new List <TurnViewModel>();

            foreach (var turn in battle.TurnList)
            {
                var turnVM = turnFactory.NewTurn(turn.TurnType);
                autoMapper.SimpleAutoMap <Turn, TurnViewModel>(turn, turnVM);

                //Convert backline first
                turnVM.Backline = new ObservableCollection <CharacterViewModel>(turn.Backline.Select(c =>
                {
                    var character = autoMapper.SimpleAutoMap <Character, CharacterViewModel>(c);

                    return(character);
                }));

                turnVM.Frontline = new ObservableCollection <CharacterViewModel>(turn.Frontline.Select(c =>
                {
                    var character = autoMapper.SimpleAutoMap <Character, CharacterViewModel>(c);

                    character.MoveCharacter = (c.MoveCharacterPosition == null) ? null : turnVM.Backline.Where(bc => bc.CharacterIMG == c.MoveCharacterPosition).FirstOrDefault();

                    return(character);
                }));


                turnList.Add(turnVM);
            }

            CopyTurnList(turnList);

            return(this);
        }