Пример #1
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="tableLamps">List of lamps on the playfield</param>
        public void PopulateLamps(GamelogicEngineLamp[] engineLamps, IEnumerable <ILightable> tableLamps)
        {
            var lamps = tableLamps
                        .GroupBy(x => x.Name.ToLower())
                        .ToDictionary(x => x.Key, x => x.First());

            var gbLamps = new List <GamelogicEngineLamp>();

            foreach (var engineLamp in GetLamps(engineLamps))
            {
                var lampMapping = Data.Lamps.FirstOrDefault(mappingsLampData => mappingsLampData.Id == engineLamp.Id && mappingsLampData.Source != LampSource.Coils);
                if (lampMapping == null)
                {
                    // we'll handle those in a second loop when all the R lamps are added
                    if (!string.IsNullOrEmpty(engineLamp.MainLampIdOfGreen) || !string.IsNullOrEmpty(engineLamp.MainLampIdOfBlue))
                    {
                        gbLamps.Add(engineLamp);
                        continue;
                    }

                    var description   = string.IsNullOrEmpty(engineLamp.Description) ? string.Empty : engineLamp.Description;
                    var playfieldItem = GuessPlayfieldLamp(lamps, engineLamp);

                    Data.AddLamp(new MappingsLampData {
                        Id            = engineLamp.Id,
                        Description   = description,
                        Destination   = LampDestination.Playfield,
                        PlayfieldItem = playfieldItem != null ? playfieldItem.Name : string.Empty,
                    });
                }
            }

            foreach (var gbLamp in gbLamps)
            {
                var rLampId = !string.IsNullOrEmpty(gbLamp.MainLampIdOfGreen) ? gbLamp.MainLampIdOfGreen : gbLamp.MainLampIdOfBlue;
                var rLamp   = Data.Lamps.FirstOrDefault(c => c.Id == rLampId);
                if (rLamp == null)
                {
                    var playfieldItem = GuessPlayfieldLamp(lamps, gbLamp);
                    rLamp = new MappingsLampData {
                        Id            = rLampId,
                        Destination   = LampDestination.Playfield,
                        PlayfieldItem = playfieldItem != null ? playfieldItem.Name : string.Empty,
                    };
                    Data.AddLamp(rLamp);
                }

                rLamp.Type = LampType.RgbMulti;
                if (!string.IsNullOrEmpty(gbLamp.MainLampIdOfGreen))
                {
                    rLamp.Green = gbLamp.Id;
                }
                else
                {
                    rLamp.Blue = gbLamp.Id;
                }
            }
        }
Пример #2
0
 public void RemoveLamp(MappingsLampData data)
 {
     Lamps = Lamps.Except(new[] { data }).ToArray();
 }
Пример #3
0
 public void AddLamp(MappingsLampData data)
 {
     Lamps = Lamps.Append(data).ToArray();
 }