// Preparation stage..
        // another option would be that each request, even single content, should have a name included, so that we don't need the Game to generate the name for the request..
        // TODO: Or should we show 'Preparing' here, and no abort or ?
        private Task <IContentAction <IContent> > PrepareAction(object request, INotifyAction act) =>
        act.PerformAction(async() => {
            var shouldSave = await HandleGameContents(request, act.GameId).ConfigureAwait(false);
            var gc         = _locator.GetGameContext();
            var game       = await gc.FindGameOrThrowAsync(act).ConfigureAwait(false);
            if (!game.InstalledState.IsInstalled)
            {
                throw new GameNotInstalledException("The requested game appears not installed: " +
                                                    game.Metadata.Name);
            }
            var syncer = request as INeedSynchronization;
            if (syncer != null)
            {
                await syncer.Synchronize(game, _networkSyncer).ConfigureAwait(false);
                shouldSave = true;
            }

            var action = act.GetAction(game);
            // We do this here because it's a pre-action that must be saved before starting the main action.
            // Abstracting it in a separate command, either ran manually or auto, could work
            // however we would not be able to optimize the save dedup between this and handlegamecontents.
            if (request is IUseContent)
            {
                game.UseContent(action);
                shouldSave = true;
            }
            // intermediary save..
            if (shouldSave)
            {
                await gc.SaveChanges().ConfigureAwait(false);
            }
            return(action);
        }, (request as IHaveRequestName)?.Name ?? "One moment...");
Esempio n. 2
0
        public async Task UpdateGameState(Guid gameId, ContentQuery query = null)
        {
            _stateHandler.SelectedGameId = gameId;

            var gameContext = _locator.GetGameContext();
            var game        = await gameContext.FindGameOrThrowAsync(gameId).ConfigureAwait(false);

            if (query == null)
            {
                game.CleanupContent();
            }

            await _setup.HandleGameContentsWhenNeeded(query, game.Id).ConfigureAwait(false);
        }
Esempio n. 3
0
        async Task ImportPwsSettingsInternal(IAbsoluteFilePath filePath)
        {
            var pwsSettings = filePath.LoadXml <UserSettings>();
            var db          = _locator.GetGameContext();
            await db.LoadAll().ConfigureAwait(false);

            foreach (var g in db.Games)
            {
                var ss = pwsSettings.GameOptions.GameSettingsController.Profiles.FirstOrDefault()?.GameSettings;
                if (ss != null && ss.ContainsKey(g.Id))
                {
                    HandleGameSettings(pwsSettings, g);
                }
                HandleGameContent(pwsSettings, g);
            }

            // TODO
            var ctx      = _locator.GetSettingsContext();
            var settings = await ctx.GetSettings().ConfigureAwait(false);

            settings.Local.PlayWithSixImportVersion = ImportVersion;
        }
        public IDomainEventHandler Get()
        {
            var context = _contextFactory.GetGameContext();

            return(context.DomainEventHandler);
        }
Esempio n. 5
0
 public async Task <T> GetGame <T>(Guid id) where T : Game
 => (T)await _contextLocator.GetGameContext().FindGameOrThrowAsync(id).ConfigureAwait(false);
 public Task <Game> GetGame(Guid gameId) => _locator.GetGameContext().Games.FindOrThrowAsync(gameId);