Beispiel #1
0
        /// <summary>this is the ONLY correct public way of creating any switch</summary>
        public static void AssignSwitch(int index, Types type, int param)
        {
            if (g_Switches == null)
            {
                throw new InvalidOperationException("Initialise not called on Physical switch");
            }
            if (index < 0 || index > 7)
            {
                throw (new ArgumentException("Switch index should be 0-7"));                 // could be increased, this is just arbitrary sanity limit
            }
            while (g_Switches.Count <= index)
            {
                g_Switches.Add(null);
            }
            if (g_Switches[index] != null)
            {
                if (g_SelectedSwitch == g_Switches[index])
                {
                    g_SelectedSwitch = null;
                }
                g_Switches[index].Destroy();
                g_Switches[index] = null;
            }
            PhysicalSwitch create = null;

            switch (type)
            {
            case Types.Null:                     // leave as nothing
                break;

            case Types.Joystick:
                create = (PhysicalSwitch)JoySwitch.CreateSwitch(param);
                break;

            case Types.Keyboard:
                create = KeySwitch.CreateSwitch((Keys)param);
                break;

            case Types.Pointer:
                create = PointerSwitch.Create(param);
                break;

            default:
                throw new ArgumentException("Invalid switch type: " + type);
            }
            g_Switches[index] = create;
        }