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 InputTemplate(IControllerElementMappingProfile 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(name, option: (IInputOption) new InputOption(inputOptionAttribute, name))) .ToDictionary(o => o.name, o => o.option); 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 FlagEnums.HasAnyFlags(option.OptionType, element.DeviceCapability.GetClass()) select(key, element.DeviceCapability)).ToDictionary(d => d.key, d => d.DeviceCapability); var map = from key in this._Options.Keys let value = overrides.ContainsKey(key) ? overrides[key] : DeviceCapability.None select new KeyValuePair <string, DeviceCapability>(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); 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); }
internal InputConfigurationSection(InputTemplateCircularInterceptor <T> interceptor, InputTemplateInterceptor <T> inputTemplate) { this.Descriptor = new ConfigurationSectionDescriptor <T>(typeof(T).Name); ProxyGenerator generator = new ProxyGenerator(); var options = from prop in typeof(T).GetProperties() let attr = prop.GetCustomAttribute <ConfigurationOptionAttribute>() where attr != null let name = prop.Name let metadata = prop.GetCustomAttributes <CustomMetadataAttribute>() select new ConfigurationOptionDescriptor(attr, metadata, name) as IConfigurationOptionDescriptor; this.Options = options.ToList(); // todo: fix this. this.ValueCollection = new ConfigurationValueCollection(); this.configurationInterceptor = new ConfigurationInterceptor(this.Descriptor, this.ValueCollection); this.Configuration = generator.CreateInterfaceProxyWithoutTarget <T>(interceptor, configurationInterceptor, inputTemplate); }