using AxibugProtobuf;
using System;
using System.Collections.Generic;
namespace AxibugEmuOnline.Client.Settings
{
///
/// 管理键位映射设置
///
public class KeyMapperSetting
{
Dictionary m_binders = new Dictionary();
Dictionary m_bindersByType = new Dictionary();
public KeyMapperSetting()
{
var baseType = typeof(InternalEmuCoreBinder);
foreach (var t in baseType.Assembly.ExportedTypes)
{
if (t.IsAbstract) continue;
if (!baseType.IsAssignableFrom(t)) continue;
var binderIns = Activator.CreateInstance(t) as InternalEmuCoreBinder;
m_binders.Add(binderIns.Platform, binderIns);
m_bindersByType.Add(binderIns.GetType(), binderIns);
}
}
public T GetBinder() where T : InternalEmuCoreBinder
{
m_bindersByType.TryGetValue(typeof(T), out var binder);
return binder as T;
}
public T GetBinder(RomPlatformType romType) where T : InternalEmuCoreBinder
{
m_binders.TryGetValue(romType, out var binder);
return binder as T;
}
}
}