Пример #1
0
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            try {
                var replayClient = new ReplayClient();
                Program.Client = replayClient;

                Program.IsHost = true;

                loadingView.UpdateStatus("Loading Replay..");
                ReplayReader reader = null;
                ReplayEngine engine = null;
                try {
                    reader = ReplayReader.FromStream(File.OpenRead(_replayPath));
                    engine = new ReplayEngine(reader, replayClient);

                    loadingView.UpdateStatus("Loading Game...");
                    var game = GameManager.Get().GetById(reader.Replay.GameId);

                    loadingView.UpdateStatus("Loading Game Engine...");
                    Program.CurrentOnlineGameName = game.Name;
                    Program.GameEngine            = new GameEngine(engine, game, reader.Replay.User);
                } catch {
                    reader?.Dispose();
                    engine?.Dispose();

                    throw;
                }

                var dispatcher = Dispatcher.CurrentDispatcher;

                Window window = null;
                await dispatcher.InvokeAsync(() => {
                    window = WindowManager.PlayWindow = new PlayWindow();

                    window.Closed += PlayWindow_Closed;

                    window.Show();
                }, DispatcherPriority.Background);

                return(window);
            } catch (UserMessageException) {
                throw;
            } catch (Exception e) {
                var msg = $"Error launching replay from {_replayPath}: {e.Message}";

                Log.Warn(msg, e);

                throw new UserMessageException(UserMessageExceptionMode.Blocking, msg, e);
            }
        }
Пример #2
0
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            try {
                var fn = Path.GetFileName(DeckPath);
                loadingView.UpdateStatus($"Loading Deck '{fn}'...");

                await Task.Run(() => {
                    Deck = (DeckPath == null) ? null : new MetaDeck(DeckPath);
                });

                Window win = null;
                await Dispatcher.CurrentDispatcher.InvokeAsync(() => {
                    win = new DeckBuilderWindow(Deck, true);

                    win.WindowStartupLocation = WindowStartupLocation.CenterScreen;

                    win.Show();
                }, DispatcherPriority.Background);

                return(win);
            } catch (Exception e) {
                string msg;
                if (string.IsNullOrWhiteSpace(DeckPath))
                {
                    msg = $"Deck editor failed to launch: {e.Message}";
                }
                else
                {
                    msg = $"Deck editor failed to launch '{DeckPath}': {e.Message}";
                }

                Log.Warn(msg, e);

                throw new UserMessageException(
                          UserMessageExceptionMode.Blocking,
                          msg,
                          e
                          );
            }
        }
Пример #3
0
        public async Task Load(ILoadingView view)
        {
            foreach (var loader in Loaders)
            {
                Log.Info($"Loading {loader.Name}");

                view.UpdateStatus($"Loading {loader.Name}");

                try {
                    await loader.Load(view);
                } catch (Exception ex) {
                    var msg = $"Error loading {loader.Name}: {ex.Message}";

                    Log.Error(msg, ex);

                    throw new UserMessageException(
                              UserMessageExceptionMode.Blocking,
                              msg,
                              ex
                              );
                }
            }
        }
Пример #4
0
        public async Task <bool> Launch(ILoadingView view)
        {
            Dispatcher.CurrentDispatcher.VerifyAccess();

            view.UpdateStatus($"Launching {Name}...");

            var window = await Load(view);

            if (window == null)
            {
                Log.Warn("No window created");

                return(false);
            }

            // do async so can run in backround
            await Dispatcher.Yield(DispatcherPriority.Background);

            Application.Current.MainWindow = window;

            await Task.Delay(300);

            return(true);
        }
Пример #5
0
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            var hostedGame = _game;

            try {
                Program.CurrentHostedGame = hostedGame;
                var password = string.Empty;
                if (Program.IsHost = _isHost)
                {
                    password = hostedGame.Password;
                }
                else
                {
                    if (hostedGame.HasPassword)
                    {
                        var dlg = new InputDlg("Password", "Please enter this games password", "");

                        password = dlg.GetString();
                    }
                }

                if (hostedGame.Source == HostedGameSource.Online)
                {
                    Program.CurrentOnlineGameName = hostedGame.Name;
                }

                loadingView.UpdateStatus("Loading game");
                var gm = GameManager.Get();

                var game = GameManager.Get().GetById(hostedGame.GameId);

                if (game == null)
                {
                    var msg = $"Game {hostedGame.GameName}({hostedGame.Id}) could not be found.";
                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                loadingView.UpdateStatus("Building engine");
                Program.GameEngine = new GameEngine(game, _username, _spectate, password);

                loadingView.UpdateStatus($"Connecting to {hostedGame.HostAddress}");
                await Task.Delay(100);

                Program.Client = await Connect(hostedGame.Host, hostedGame.Port);

                if (Program.Client == null)
                {
                    var msg = $"Unable to connect to {hostedGame.Name} at {hostedGame.HostAddress}";

                    throw new UserMessageException(UserMessageExceptionMode.Blocking, msg);
                }

                Window window = null;
                await Dispatcher.CurrentDispatcher.InvokeAsync(() => {
                    window = WindowManager.PlayWindow = new PlayWindow();

                    window.Closed += PlayWindow_Closed;

                    window.Show();
                }, DispatcherPriority.Background);

                return(window);
            } catch (Exception e) {
                var msg = $"Error joining game {hostedGame.Name}: {e.Message}";

                Log.Warn(msg, e);

                throw new UserMessageException(UserMessageExceptionMode.Blocking, msg, e);
            }
        }