Beispiel #1
0
        public void OnInit(Player player, TableApi tableApi, BallManager ballManager)
        {
            _player = player;
            _switchIds.Clear();
            foreach (var sw in availableSwitches)
            {
                _switchIds[sw.Id] = sw.InternalId;
                _switchNames[sw.InternalId.ToString()] = sw.Id;
            }
            _coilNames.Clear();
            foreach (var coil in availableCoils)
            {
                _coilNames[coil.InternalId.ToString()] = coil.Id;
            }
            _lampNames.Clear();
            foreach (var lamp in availableLamps)
            {
                _lampNames[lamp.InternalId.ToString()] = lamp.Id;
            }
            _api = new MpfApi(machineFolder);
            _api.Launch(new MpfConsoleOptions {
                ShowLogInsteadOfConsole = false,
                VerboseLogging          = true,
                UseMediaController      = true,
            });

            _api.Client.OnEnableCoil            += OnEnableCoil;
            _api.Client.OnDisableCoil           += OnDisableCoil;
            _api.Client.OnPulseCoil             += OnPulseCoil;
            _api.Client.OnConfigureHardwareRule += OnConfigureHardwareRule;
            _api.Client.OnRemoveHardwareRule    += OnRemoveHardwareRule;
            _api.Client.OnFadeLight             += OnFadeLight;
            _api.Client.OnDmdFrame += OnDmdFrame;

            // map initial switches
            var mappedSwitchStatuses = new Dictionary <string, bool>();

            foreach (var swName in player.SwitchStatusesClosed.Keys)
            {
                if (_switchIds.ContainsKey(swName))
                {
                    mappedSwitchStatuses[_switchIds[swName].ToString()] = player.SwitchStatusesClosed[swName];
                }
                else
                {
                    Logger.Warn($"Unknown intial switch name \"{swName}\".");
                }
            }
            _api.StartGame(mappedSwitchStatuses);
            Logger.Info("Game started.");
        }
Beispiel #2
0
        public static async Task Main(string[] args)
        {
            var machineFolder = Path.GetFullPath(@"../../../../VisualPinball.Engine.Mpf/machine");

            // Console.WriteLine("Starting...");
            // var client = new MpfClient();
            // client.Connect();
            // client.StartGame(new Dictionary<string, bool> {
            //  { "sw11", true }
            // });
            // Console.WriteLine("Description = " + client.GetMachineDescription());
            // Console.WriteLine("Done!");


            var s      = Stopwatch.StartNew();
            var mpfApi = new MpfApi(machineFolder);

            mpfApi.Launch(new MpfConsoleOptions {
                //ShowLogInsteadOfConsole = true,
                //CatchStdOut = true,
            });

            mpfApi.StartGame(new Dictionary <string, bool> {
                { "1", true },
                { "2", true },
                { "3", true },
                { "4", true },
                { "5", true },
                { "6", true },
            });
            mpfApi.Client.OnConfigureHardwareRule += (_, request) => {
                Console.WriteLine($"[MPF] configure hw/rule: sw{request.SwitchNumber} -> c{request.CoilNumber} @{request.HoldPower} | pulse: {request.PulseMs}ms @{request.PulsePower}");
            };
            mpfApi.Client.OnRemoveHardwareRule += (_, request) => {
                Console.WriteLine($"[MPF] remove hw/rule: sw{request.SwitchNumber} -> c{request.CoilNumber}");
            };
            mpfApi.Client.OnEnableCoil += (_, request) => {
                Console.WriteLine($"[MPF] enable coil c{request.CoilNumber} @{request.HoldPower} | pulse: {request.PulseMs}ms @{request.PulsePower}");
            };
            mpfApi.Client.OnDisableCoil += (_, request) => {
                Console.WriteLine($"[MPF] disable coil c{request.CoilNumber}");
            };
            mpfApi.Client.OnPulseCoil += (_, request) => {
                Console.WriteLine($"[MPF] pulse coil c{request.CoilNumber} {request.PulseMs}ms @{request.PulsePower}");
            };
            mpfApi.Client.OnFadeLight += (_, request) => {
                Console.WriteLine($"[MPF] light fades ({request.CommonFadeMs}ms):");
            };
            mpfApi.Client.OnDmdFrame += (_, request) => {
                Console.WriteLine($"[MPF] new DMD frame!");
            };

            var descr = mpfApi.GetMachineDescription();

            Console.WriteLine($"Description: {descr} in {s.ElapsedMilliseconds}ms");

            ConsoleKeyInfo key;

            do
            {
                key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.A:
                    await mpfApi.Switch("0", true);

                    break;

                case ConsoleKey.S:
                    await mpfApi.Switch("0", false);

                    break;
                }
            } while (key.Key != ConsoleKey.Escape);

            mpfApi.Dispose();
        }