コード例 #1
0
        /// <summary>
        /// Auto-matches the coils provided by the gamelogic engine with the
        /// coils on the playfield.
        /// </summary>
        /// <param name="engineCoils">List of coils provided by the gamelogic engine</param>
        /// <param name="tableComponent">Table component</param>
        public void PopulateCoils(GamelogicEngineCoil[] engineCoils, TableComponent tableComponent)
        {
            var coilDevices = tableComponent.GetComponentsInChildren <ICoilDeviceComponent>();
            var lamps       = tableComponent.GetComponentsInChildren <ILampDeviceComponent>().OrderBy(LampTypePriority).ToArray();

            foreach (var engineCoil in GetCoils(engineCoils))
            {
                var coilMapping = Coils.FirstOrDefault(mappingsCoilData => mappingsCoilData.Id == engineCoil.Id);
                if (coilMapping != null || engineCoil.IsUnused)
                {
                    continue;
                }

                var destination = GuessCoilDestination(engineCoil, lamps);
                var description = string.IsNullOrEmpty(engineCoil.Description) ? string.Empty : engineCoil.Description;

                var deviceAdded = false;

                if (destination == CoilDestination.Playfield)
                {
                    foreach (var device in GuessCoilDevices(coilDevices, engineCoil))
                    {
                        var matchedDevice = device;
                        var deviceItem    = GuessCoilDeviceItem(engineCoil, matchedDevice);

                        // if there was a device match, device has only one item and there was a hint that didn't match, clear the device.
                        if (deviceItem == null && !string.IsNullOrEmpty(engineCoil.DeviceItemHint) && matchedDevice.AvailableCoils.Count() == 1)
                        {
                            matchedDevice = null;
                        }

                        AddCoil(new CoilMapping
                        {
                            Id          = engineCoil.Id,
                            Description = description,
                            Destination = destination,
                            Device      = matchedDevice,
                            DeviceItem  = deviceItem != null ? deviceItem.Id : string.Empty,
                        });

                        deviceAdded = true;
                    }
                }

                if (!deviceAdded)
                {
                    AddCoil(new CoilMapping
                    {
                        Id          = engineCoil.Id,
                        Description = description,
                        Destination = destination,
                        Device      = null,
                        DeviceItem  = string.Empty,
                    });
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Auto-matches the lamps provided by the gamelogic engine with the
        /// lamps on the playfield.
        /// </summary>
        /// <param name="engineLamps">List of lamps provided by the gamelogic engine</param>
        /// <param name="tableComponent">Table component</param>
        public void PopulateLamps(GamelogicEngineLamp[] engineLamps, TableComponent tableComponent)
        {
            var lamps = tableComponent.GetComponentsInChildren <ILampDeviceComponent>().OrderBy(LampTypePriority).ToArray();

            foreach (var engineLamp in GetLamps(engineLamps))
            {
                var lampMapping = Lamps.FirstOrDefault(mappingsLampData => mappingsLampData.Id == engineLamp.Id && mappingsLampData.Channel == engineLamp.Channel && !mappingsLampData.IsCoil);
                if (lampMapping != null)
                {
                    continue;
                }

                var description = string.IsNullOrEmpty(engineLamp.Description) ? string.Empty : engineLamp.Description;
                var deviceAdded = false;

                foreach (var device in GuessLampDevices(lamps, engineLamp))
                {
                    var deviceItem = GuessLampDeviceItem(engineLamp, device);

                    AddLamp(new LampMapping {
                        Id          = engineLamp.Id,
                        Channel     = engineLamp.Channel,
                        Source      = engineLamp.Source,
                        Description = description,
                        Device      = device,
                        DeviceItem  = deviceItem != null ? deviceItem.Id : string.Empty,
                        Type        = engineLamp.Type,
                        FadingSteps = engineLamp.FadingSteps,
                    });

                    deviceAdded = true;
                }

                if (!deviceAdded)
                {
                    AddLamp(new LampMapping {
                        Id          = engineLamp.Id,
                        Channel     = engineLamp.Channel,
                        Source      = engineLamp.Source,
                        Description = description,
                        Device      = null,
                        DeviceItem  = string.Empty,
                        Type        = engineLamp.Type,
                        FadingSteps = engineLamp.FadingSteps,
                    });
                }
            }
        }
コード例 #3
0
        public void PopulateSwitches(GamelogicEngineSwitch[] engineSwitches, TableComponent tableComponent)
        {
            var switchDevices = tableComponent.GetComponentsInChildren <ISwitchDeviceComponent>();

            foreach (var engineSwitch in GetSwitchIds(engineSwitches))
            {
                var switchMapping = Switches.FirstOrDefault(mappingsSwitchData => mappingsSwitchData.Id == engineSwitch.Id);
                if (switchMapping != null)
                {
                    continue;
                }

                var description = engineSwitch.Description ?? string.Empty;
                var source      = GuessSwitchSource(engineSwitch);

                var inputActionMap = source == SwitchSource.InputSystem
                                        ? string.IsNullOrEmpty(engineSwitch.InputMapHint) ? InputConstants.MapCabinetSwitches : engineSwitch.InputMapHint
                                        : string.Empty;
                var inputAction = source == SwitchSource.InputSystem
                                        ? string.IsNullOrEmpty(engineSwitch.InputActionHint) ? string.Empty : engineSwitch.InputActionHint
                                        : string.Empty;

                bool deviceAdded = false;

                if (source == SwitchSource.Playfield)
                {
                    foreach (var device in GuessSwitchDevices(switchDevices, engineSwitch))
                    {
                        var matchedDevice = device;

                        var deviceItem = GuessSwitchDeviceItem(engineSwitch, matchedDevice);

                        // if there was a device match, device has only one item and there was a hint that didn't match, clear the device.
                        if (deviceItem == null && !string.IsNullOrEmpty(engineSwitch.DeviceItemHint) && matchedDevice.AvailableSwitches.Count() == 1)
                        {
                            matchedDevice = null;
                        }

                        AddSwitch(new SwitchMapping
                        {
                            Id = engineSwitch.Id,
                            IsNormallyClosed = engineSwitch.NormallyClosed,
                            Description      = description,
                            Source           = source,
                            InputActionMap   = inputActionMap,
                            InputAction      = inputAction,
                            Device           = matchedDevice,
                            DeviceItem       = deviceItem != null ? deviceItem.Id : string.Empty,
                            Constant         = engineSwitch.ConstantHint == SwitchConstantHint.AlwaysOpen ? SwitchConstant.Open : SwitchConstant.Closed
                        });

                        deviceAdded = true;
                    }
                }

                if (!deviceAdded)
                {
                    AddSwitch(new SwitchMapping
                    {
                        Id = engineSwitch.Id,
                        IsNormallyClosed = engineSwitch.NormallyClosed,
                        Description      = description,
                        Source           = source,
                        InputActionMap   = inputActionMap,
                        InputAction      = inputAction,
                        Device           = null,
                        DeviceItem       = string.Empty,
                        Constant         = engineSwitch.ConstantHint == SwitchConstantHint.AlwaysOpen ? SwitchConstant.Open : SwitchConstant.Closed
                    });
                }
            }
        }