示例#1
0
        public static EffectsVM GetEffectViewModels()
        {
            var all = GetEffectTypes();
            var groupEffectsTypes = GetGroupEffectTypes();
            var groups            = GroupService.GetAll();

            List <EffectViewModel> baseEffects  = new List <EffectViewModel>();
            List <EffectViewModel> shortEffects = new List <EffectViewModel>();
            List <EffectViewModel> groupEffects = new List <EffectViewModel>();

            foreach (var type in all)
            {
                var hueEffectAtt = type.GetCustomAttribute <HueEffectAttribute>();

                var effect = new EffectViewModel();
                effect.Name           = hueEffectAtt.Name;
                effect.TypeName       = type.Name;
                effect.HasColorPicker = hueEffectAtt.HasColorPicker;

                if (!string.IsNullOrEmpty(hueEffectAtt.DefaultColor))
                {
                    effect.Color    = hueEffectAtt.DefaultColor;
                    effect.IsRandom = false;
                }

                if (hueEffectAtt.IsBaseEffect)
                {
                    baseEffects.Add(effect);
                }
                else
                {
                    shortEffects.Add(effect);
                }
            }

            foreach (var type in groupEffectsTypes)
            {
                var hueEffectAtt = type.GetCustomAttribute <HueEffectAttribute>();

                var effect = new EffectViewModel();
                effect.Name           = hueEffectAtt.Name;
                effect.TypeName       = type.Name;
                effect.HasColorPicker = hueEffectAtt.HasColorPicker;

                if (!string.IsNullOrEmpty(hueEffectAtt.DefaultColor))
                {
                    effect.Color    = hueEffectAtt.DefaultColor;
                    effect.IsRandom = false;
                }

                groupEffects.Add(effect);
            }

            List <string> iteratorNames = new List <string>();

            foreach (var name in Enum.GetNames(typeof(IteratorEffectMode)))
            {
                iteratorNames.Add(name);
            }

            List <string> secondaryIteratorNames = new List <string>()
            {
                IteratorEffectMode.All.ToString(),
                          IteratorEffectMode.AllIndividual.ToString(),
                          IteratorEffectMode.Bounce.ToString(),
                          IteratorEffectMode.Single.ToString(),
                          IteratorEffectMode.Random.ToString(),
            };

            var vm = new EffectsVM();

            vm.BaseEffects  = baseEffects;
            vm.ShortEffects = shortEffects;
            vm.GroupEffects = groupEffects;
            vm.Groups       = groups.Select(x => new GroupInfoViewModel()
            {
                Name = x.Name
            }).ToList();
            vm.IteratorModes          = iteratorNames;
            vm.SecondaryIteratorModes = secondaryIteratorNames;

            return(vm);
        }