Skip to content

Commit

Permalink
Minor changes to not necessarily generate await overhead for Task met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
Arcidev committed Aug 17, 2024
1 parent 74ad294 commit 8909925
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Client.UI/Sql/DataHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void LoadData(IReadOnlyDictionary<UInt32, SelectableCard> cards)

public SpellData GetSpellData(UInt32 id) => spellsData.TryGetValue(id, out var spellData) ? spellData : new SpellData(id, string.Empty, string.Empty, string.Empty, string.Empty);

public AchievementInfo GetAchievementInfo(UInt32 id) => achievements.TryGetValue(id, out var name) ? name : null;
public AchievementInfo GetAchievementInfo(UInt32 id) => achievements.TryGetValue(id, out var name) ? name : new AchievementInfo(string.Empty, string.Empty);

public string GetCriteriaDescription(UInt32 id) => criteriaDescriptions.TryGetValue(id, out var description) ? description : string.Empty;

Expand Down
3 changes: 2 additions & 1 deletion Client.UI/ViewModels/Achievements/AchievementsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public class AchievementsViewModel
public AchievementsViewModel()
{
var game = App.GetGame() ?? throw new InvalidOperationException("Game must exist at this point");
Achievements = game.Achievements.OrderByDescending(x => x.IsCompleted).ThenByDescending(x => x.CompletionDate).Select(x => new AchievementViewModel(x, game.DataHolder)).ToList();
Achievements = game.Achievements.OrderByDescending(x => x.IsCompleted).ThenByDescending(x => x.CompletionDate)
.Select(x => new AchievementViewModel(x, game.DataHolder)).ToList();
}
}
}
2 changes: 1 addition & 1 deletion Client.UI/ViewModels/Cards/CardViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private set
public ICommand OnClickCmd
{
get => onClickCmd;
protected set
protected init
{
if (onClickCmd == value)
return;
Expand Down
2 changes: 1 addition & 1 deletion Client.UI/ViewModels/MainGame/PlayingGameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public PlayingGameViewModel()

AttackCmd = new (() => InvokeCardAction(CardAction.BasicAttack));
SpellAttackCmd = new (() => InvokeCardAction(CardAction.SpellUse));
DefendCmd = new (() => Game.DefendSelfAsync());
DefendCmd = new (Game.DefendSelfAsync);

Game.PacketProcessed += OnPacketProcessed;
}
Expand Down
4 changes: 2 additions & 2 deletions Client.UI/ViewModels/User/CreateAccountViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class CreateAccountViewModel : LoginViewModel
{
public string Username { get; set; }

public async Task<Game> CreateAccount(string password, Action<UInt16> callback)
public Task<Game> CreateAccount(string password, Action<UInt16> callback)
{
return await UserOperation(new Packet(CMSGPackets.UserCreate).Builder().Write(Username).Write(Email).Write(password).Build(), callback);
return UserOperation(new Packet(CMSGPackets.UserCreate).Builder().Write(Username).Write(Email).Write(password).Build(), callback);
}
}
}
4 changes: 2 additions & 2 deletions Client.UI/ViewModels/User/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public LoginViewModel()
Server = ServerList.FirstOrDefault();
}

public async Task<Game> Login(string password, Action<UInt16> callback)
public Task<Game> Login(string password, Action<UInt16> callback)
{
return await UserOperation(new Packet(CMSGPackets.UserLogIn).Builder().Write(Email).Write(password).Build(), callback);
return UserOperation(new Packet(CMSGPackets.UserLogIn).Builder().Write(Email).Write(password).Build(), callback);
}

protected async Task<Game> UserOperation(Packet packet, Action<UInt16> callback)
Expand Down
12 changes: 6 additions & 6 deletions Client.UI/ViewModels/User/UserViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ public UserViewModel(string name, Game game)
{
this.game = game;
Name = name;
AcceptFriend = new AsyncCommandHandler(async () => await HandleFriendRequest(UserRelationAction.AcceptFriend));
DenyFriend = new AsyncCommandHandler(async () => await HandleFriendRequest(UserRelationAction.DenyFriend));
BlockUser = new AsyncCommandHandler(async () => await HandleFriendRequest(UserRelationAction.BlockUser));
RemoveBlockedUser = new AsyncCommandHandler(async () => await HandleFriendRequest(UserRelationAction.RemoveBlockedUser));
AcceptFriend = new AsyncCommandHandler(() => HandleFriendRequest(UserRelationAction.AcceptFriend));
DenyFriend = new AsyncCommandHandler(() => HandleFriendRequest(UserRelationAction.DenyFriend));
BlockUser = new AsyncCommandHandler(() => HandleFriendRequest(UserRelationAction.BlockUser));
RemoveBlockedUser = new AsyncCommandHandler(() => HandleFriendRequest(UserRelationAction.RemoveBlockedUser));
}

protected async Task HandleFriendRequest(UserRelationAction action)
protected Task HandleFriendRequest(UserRelationAction action)
{
var packet = new Packet(CMSGPackets.UserRelation);
packet.Write(Name);
packet.Write((byte)action);

await game.SendPacketAsync(packet);
return game.SendPacketAsync(packet);
}
}
}

0 comments on commit 8909925

Please sign in to comment.