Skip to content

Commit

Permalink
Move adding default text to chat out of domain and into controller
Browse files Browse the repository at this point in the history
This is a client concern and not a domain concern
  • Loading branch information
ethanmoffat committed May 9, 2021
1 parent 6b25235 commit 61c12ec
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
19 changes: 0 additions & 19 deletions EOLib/Domain/Login/LoginActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ public class LoginActions : ILoginActions
private readonly IPacketTranslator<IAccountLoginData> _loginPacketTranslator;
private readonly IPacketTranslator<ILoginRequestGrantedData> _loginRequestGrantedPacketTranslator;
private readonly IPacketTranslator<ILoginRequestCompletedData> _loginRequestCompletedPacketTranslator;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly ICharacterSelectorRepository _characterSelectorRepository;
private readonly IPlayerInfoRepository _playerInfoRepository;
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly ILoginFileChecksumRepository _loginFileChecksumRepository;
private readonly INewsRepository _newsRepository;
private readonly IChatRepository _chatRepository;
private readonly ICharacterInventoryRepository _characterInventoryRepository;
private readonly IPaperdollRepository _paperdollRepository;

Expand All @@ -52,14 +50,12 @@ public class LoginActions : ILoginActions
_loginPacketTranslator = loginPacketTranslator;
_loginRequestGrantedPacketTranslator = loginRequestGrantedPacketTranslator;
_loginRequestCompletedPacketTranslator = loginRequestCompletedPacketTranslator;
_localizedStringFinder = localizedStringFinder;
_characterSelectorRepository = characterSelectorRepository;
_playerInfoRepository = playerInfoRepository;
_characterRepository = characterRepository;
_currentMapStateRepository = currentMapStateRepository;
_loginFileChecksumRepository = loginFileChecksumRepository;
_newsRepository = newsRepository;
_chatRepository = chatRepository;
_characterInventoryRepository = characterInventoryRepository;
_paperdollRepository = paperdollRepository;
}
Expand Down Expand Up @@ -150,7 +146,6 @@ public async Task CompleteCharacterLogin()

_newsRepository.NewsHeader = data.News.First();
_newsRepository.NewsText = data.News.Except(new[] { data.News.First() }).ToList();
AddDefaultTextToChat();

var mainCharacter = data.MapCharacters.Single(
x => x.Name.ToLower() == _characterRepository.MainCharacter.Name.ToLower());
Expand Down Expand Up @@ -192,20 +187,6 @@ private bool IsInvalidWelcome(IPacket response)
{
return response.Family != PacketFamily.Welcome || response.Action != PacketAction.Reply;
}

private void AddDefaultTextToChat()
{
var server = _localizedStringFinder.GetString(EOResourceID.STRING_SERVER);
var serverMessage1 = _localizedStringFinder.GetString(EOResourceID.GLOBAL_CHAT_SERVER_MESSAGE_1);
var serverMessage2 = _localizedStringFinder.GetString(EOResourceID.GLOBAL_CHAT_SERVER_MESSAGE_2);

_chatRepository.AllChat[ChatTab.Local].Add(
new ChatData(server, _newsRepository.NewsHeader, ChatIcon.Note, ChatColor.Server));
_chatRepository.AllChat[ChatTab.Global].Add(
new ChatData(server, serverMessage1, ChatIcon.Note, ChatColor.Server));
_chatRepository.AllChat[ChatTab.Global].Add(
new ChatData(server, serverMessage2, ChatIcon.Note, ChatColor.Server));
}
}

public interface ILoginActions
Expand Down
28 changes: 27 additions & 1 deletion EndlessClient/Controllers/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using EndlessClient.HUD.Chat;
using EndlessClient.Rendering.Map;
using EOLib.Domain.Character;
using EOLib.Domain.Chat;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Protocol;
Expand All @@ -30,6 +31,9 @@ public class LoginController : ILoginController
private readonly IGameStateActions _gameStateActions;
private readonly IChatTextBoxActions _chatTextBoxActions;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly ILocalizedStringFinder _localizedStringFinder;
private readonly IChatRepository _chatRepository;
private readonly INewsProvider _newsProvider;
private readonly IErrorDialogDisplayAction _errorDisplayAction;
private readonly ISafeNetworkOperationFactory _networkOperationFactory;
private readonly IGameLoadingDialogFactory _gameLoadingDialogFactory;
Expand All @@ -48,7 +52,10 @@ public class LoginController : ILoginController
ISafeNetworkOperationFactory networkOperationFactory,
IGameLoadingDialogFactory gameLoadingDialogFactory,
ICurrentMapStateProvider currentMapStateProvider,
IStatusLabelSetter statusLabelSetter)
IStatusLabelSetter statusLabelSetter,
ILocalizedStringFinder localizedStringFinder,
IChatRepository chatRepository,
INewsProvider newsProvider)
{
_loginActions = loginActions;
_mapFileLoadActions = mapFileLoadActions;
Expand All @@ -62,6 +69,9 @@ public class LoginController : ILoginController
_gameLoadingDialogFactory = gameLoadingDialogFactory;
_currentMapStateProvider = currentMapStateProvider;
_statusLabelSetter = statusLabelSetter;
_localizedStringFinder = localizedStringFinder;
_chatRepository = chatRepository;
_newsProvider = newsProvider;
}

public async Task LoginToAccount(ILoginParameters loginParameters)
Expand Down Expand Up @@ -163,6 +173,8 @@ public async Task LoginToCharacter(ICharacter character)
if (!await completeCharacterLoginOperation.Invoke())
return;

AddDefaultTextToChat();

await Task.Delay(1000); //always wait 1 second
}
finally
Expand Down Expand Up @@ -208,6 +220,20 @@ private async Task<bool> SafeGetFile(Func<Task> operation)
SetInitialStateAndShowError);
return await op.Invoke();
}

private void AddDefaultTextToChat()
{
var server = _localizedStringFinder.GetString(EOResourceID.STRING_SERVER);
var serverMessage1 = _localizedStringFinder.GetString(EOResourceID.GLOBAL_CHAT_SERVER_MESSAGE_1);
var serverMessage2 = _localizedStringFinder.GetString(EOResourceID.GLOBAL_CHAT_SERVER_MESSAGE_2);

_chatRepository.AllChat[ChatTab.Local].Add(
new ChatData(server, _newsProvider.NewsHeader, ChatIcon.Note, ChatColor.Server));
_chatRepository.AllChat[ChatTab.Global].Add(
new ChatData(server, serverMessage1, ChatIcon.Note, ChatColor.Server));
_chatRepository.AllChat[ChatTab.Global].Add(
new ChatData(server, serverMessage2, ChatIcon.Note, ChatColor.Server));
}
}

public interface ILoginController
Expand Down

0 comments on commit 61c12ec

Please sign in to comment.