Example #1
0
    public MainMenuState(ITyperPool typerPool)
    {
        _typerPool = typerPool;

        Exit            = _typerPool.MakeUniqueTyper("exit");
        CreateCharacter = _typerPool.MakeUniqueTyper("create-character");
    }
 public CharacterCreationState(
     ITyperPool typerPool,
     ComponentPool componentPool)
 {
     CharacterNameInput = componentPool.MakeInputComponent();
     BackToMainMenu     = typerPool.MakeUniqueTyper();
     CreateCharacter    = typerPool.MakeUniqueTyper();
 }
    public WorldScreenState(
        ITyperPool typerPool)
    {
        _typerPool      = typerPool;
        CurrentLocation = null;

        Disconnect = _typerPool.MakeUniqueTyper("disconnect");
    }
    private void UpdateState(TypingRealm.World.WorldState state)
    {
        lock (_updateStateLock)
        {
            if (state.LocationId != _currentState.CurrentLocation?.LocationId)
            {
                // Very crude implementation, goes to API all the time and blocks the thread.
                var locationData = _locationsClient.GetLocationAsync(state.LocationId, default)
                                   .GetAwaiter().GetResult();

                // Update current location details only when moving to another location.
                _currentState.CurrentLocation = new LocationInfo(
                    state.LocationId,
                    locationData.Name,
                    locationData.Description);

                /*"TODO: get location name from cache",
                 * "TODO: get location description from cache");*/
            }

            if (state.AllowedActivityTypes.Contains(ActivityType.RopeWar) &&
                _currentState.CreateRopeWarTyper == null)
            {
                _currentState.CreateRopeWarTyper = _typerPool.MakeUniqueTyper(Guid.NewGuid().ToString());
            }

            if (!state.AllowedActivityTypes.Contains(ActivityType.RopeWar) &&
                _currentState.CreateRopeWarTyper != null)
            {
                _typerPool.RemoveTyper(_currentState.CreateRopeWarTyper);
                _currentState.CreateRopeWarTyper = null;
            }

            // TODO: Dispose all previous location entrances - sync up like at character selection screen.
            _currentState.LocationEntrances = new HashSet <LocationEntrance>(state.Locations.Select(
                                                                                 x => new LocationEntrance(x, GetLocationName(x), _typerPool.MakeUniqueTyper(Guid.NewGuid().ToString()))));

            // TODO: Dispose all previous things - sync up like at character selection screen.
            _currentState.RopeWars = new HashSet <RopeWarInfo>(state.RopeWarActivities.Select(
                                                                   x => new RopeWarInfo(x.ActivityId, x.ActivityId, x.Bet, _typerPool.MakeUniqueTyper(Guid.NewGuid().ToString()))));

            var characterId    = _characterId;
            var currentRopeWar = state.RopeWarActivities.FirstOrDefault(rw => rw.LeftSideParticipants.Contains(characterId) || rw.RightSideParticipants.Contains(characterId));

            if (currentRopeWar != null)
            {
                _currentState.CurrentRopeWar = new JoinedRopeWar(
                    _currentState.RopeWars.First(x => x.RopeWarId == currentRopeWar.ActivityId), _typerPool.MakeUniqueTyper(Guid.NewGuid().ToString()), _typerPool.MakeUniqueTyper(Guid.NewGuid().ToString()));
            }
            // TODO: Clean up these typers. When current rope war becomes null - we need to delete them from the typer pool.
            else
            {
                _currentState.CurrentRopeWar = null;
            }

            _stateSubject.OnNext(_currentState);
        }
    }
    public static Typer MakeUniqueTyper(this ITyperPool typerPool)
    {
        var id    = Guid.NewGuid().ToString();
        var typer = typerPool.MakeUniqueTyper(id);

        typer.Id = id;

        return(typer);
    }
Example #6
0
    public InputComponent MakeInputComponent()
    {
        var typer = _focusTyperPool.MakeUniqueTyper();

        var component = new InputComponent(typer);

        _components.Add(typer, component);

        return(component);
    }
Example #7
0
    public void SyncSelectCharacterTyper(string characterId, string name)
    {
        if (Characters.Any(c => c.CharacterId == characterId))
        {
            return;
        }

        var typer = _typerPool.MakeUniqueTyper($"select-character-{characterId}");

        _characters.Add(new SelectCharacter(characterId, name, typer));
    }