public void AddMappings(IControllerElementMappings mappings, string profileName)
 {
     using (var context = new DatabaseContext(this.Options.Options))
     {
         context.ControllerElementMappings.Add(mappings.AsModel(profileName));
         context.SaveChanges();
     }
 }
Exemplo n.º 2
0
 public EmulatedController(int portIndex,
                           IInputDevice physicalDevice,
                           IControllerLayout targetLayout,
                           IControllerElementMappings layoutMapping)
 {
     this.PortIndex      = portIndex;
     this.PhysicalDevice = physicalDevice;
     this.TargetLayout   = targetLayout;
     this.LayoutMapping  = layoutMapping;
 }
Exemplo n.º 3
0
 public static ControllerElementMappingsModel AsModel(this IControllerElementMappings @this, string profileName)
 {
     return(new ControllerElementMappingsModel
     {
         ProfileName = profileName,
         ControllerID = @this.ControllerId,
         DeviceID = @this.DeviceId,
         MappedElements = @this.Select(e => e.AsModel(@this.ControllerId, @this.DeviceId, profileName)).ToList()
     });
 }
Exemplo n.º 4
0
        public InputTemplate(IControllerElementMappings mappedElements, int playerIndex = 0)
        {
            this.PlayerIndex = playerIndex;
            ProxyGenerator generator = new ProxyGenerator();

            this._Options = (from prop in typeof(T).GetProperties()
                             let inputOptionAttribute = prop.GetCustomAttribute <InputOptionAttribute>()
                                                        where inputOptionAttribute != null
                                                        let name = prop.Name
                                                                   select new KeyValuePair <string, IInputOption>(name, new InputOption(inputOptionAttribute, name)))
                            .ToDictionary(o => o.Key,
                                          o => o.Value);
            var overrides = (from element in mappedElements
                             from key in this._Options.Keys
                             let option = this._Options[key]
                                          let target = option.TargetElement
                                                       where element.LayoutElement == target
                                                       where option.InputOptionType.HasFlag(InputOptionType.Keyboard) == element.DeviceElement.IsKeyboardKey()
                                                       where option.InputOptionType.HasFlag(InputOptionType.ControllerAxes) == element.DeviceElement.IsAxis()
                                                       select new { key, element.DeviceElement }).ToDictionary(d => d.key, d => d.DeviceElement);
            var map = from key in this._Options.Keys
                      let value = overrides.ContainsKey(key) ? overrides[key] : ControllerElement.NoElement
                                  select new KeyValuePair <string, ControllerElement>(key, value);

            //this.configurationOptions = (from prop in typeof(T).GetProperties()
            //              let configAttribute = prop.GetCustomAttribute<ConfigurationOptionAttribute>()
            //              where configAttribute != null
            //              let name = prop.Name
            //              let metadata = prop.GetCustomAttributes<CustomMetadataAttribute>()
            //              select new ConfigurationOptionDescriptor(configAttribute, metadata, name) as IConfigurationOptionDescriptor).ToList();

            this.ValueCollection = new ConfigurationValueCollection();

            var configDescriptor = new ConfigurationSectionDescriptor <T>(typeof(T).Name);

            ((ConfigurationValueCollection)this.ValueCollection).EnsureSectionDefaults(configDescriptor);

            var attr = typeof(T).GetTypeInfo().GetCustomAttribute <InputTemplateAttribute>();

            this.inputTemplateInterceptor = new InputTemplateInterceptor <T>(map.ToDictionary(m => m.Key, m => m.Value),
                                                                             this.ValueCollection,
                                                                             configDescriptor);
            var circular = new InputTemplateCircularInterceptor <T>(this);

            this.Configuration = new InputConfigurationSection <T>(circular, this.inputTemplateInterceptor);
            this.Template      = generator.CreateInterfaceProxyWithoutTarget <T>(circular, this.inputTemplateInterceptor);
        }
        public void UpdateMappings(IControllerElementMappings mappings, string profileName)
        {
            using var context = new DatabaseContext(this.Options.Options);
            var retrievedMappings = context.ControllerElementMappings
                                    .Include(p => p.MappedElements)
                                    .SingleOrDefault(p => p.ControllerID == mappings.ControllerId &&
                                                     p.DeviceID == mappings.DeviceId && p.ProfileName == profileName);

            foreach (var mapping in retrievedMappings.MappedElements)
            {
                if (mappings[mapping.LayoutElement] == mapping.DeviceElement)
                {
                    continue;
                }
                mapping.DeviceElement        = mappings[mapping.LayoutElement];
                context.Entry(mapping).State = EntityState.Modified;
            }

            context.SaveChanges();
        }