Skip to content

Commit

Permalink
chore: Added Weapons as its own character
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorixon committed Sep 16, 2023
1 parent 5edb477 commit 3c906cd
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 6 deletions.
29 changes: 29 additions & 0 deletions src/GIMI-ModManager.Core/Services/GenshinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public async Task InitializeAsync(string assetsUriPath)
_characters.AddRange(characters);
_characters.Add(getGlidersCharacter(assetsUriPath));
_characters.Add(getOthersCharacter(assetsUriPath));
_characters.Add(getWeaponsCharacter(assetsUriPath));
}

private static void SetImageUriForCharacter(string assetsUriPath, GenshinCharacter character)
Expand Down Expand Up @@ -184,8 +185,32 @@ private static GenshinCharacter getGlidersCharacter(string assetsUriPath)
return character;
}

private const int _weaponsCharacterId = -1236;
public int WeaponsCharacterId => _weaponsCharacterId;

private static GenshinCharacter getWeaponsCharacter(string assetsUriPath)
{
var character = new GenshinCharacter
{
Id = _weaponsCharacterId,
DisplayName = "Weapons",
ReleaseDate = DateTime.MinValue,
Rarity = -1,
Keys = new[] { "weapon", "claymore", "sword", "polearm", "catalyst", "bow" },
ImageUri = "Character_Weapons_Thumb.webp"
};
SetImageUriForCharacter(assetsUriPath, character);
return character;
}

public GenshinCharacter? GetCharacter(int id)
=> _characters.FirstOrDefault(c => c.Id == id);

public bool IsMultiModCharacter(GenshinCharacter character)
=> IsMultiModCharacter(character.Id);

public bool IsMultiModCharacter(int characterId)
=> characterId == OtherCharacterId || characterId == GlidersCharacterId || characterId == WeaponsCharacterId;
}

public interface IGenshinService
Expand All @@ -202,6 +227,10 @@ public Dictionary<GenshinCharacter, int> GetCharacters(string searchQuery,
public GenshinCharacter? GetCharacter(int id);
public int OtherCharacterId { get; }
public int GlidersCharacterId { get; }
public int WeaponsCharacterId { get; }

public bool IsMultiModCharacter(GenshinCharacter character);
public bool IsMultiModCharacter(int characterId);
}

internal static class GenshinCharacters
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public interface ILocalSettingsService
public string SettingsLocation { get; }
Task<T?> ReadSettingAsync<T>(string key);

Task<T> ReadOrCreateSettingAsync<T>(string key) where T : new();

Task SaveSettingAsync<T>(string key, T value);

T? ReadSetting<T>(string key);
}
}
4 changes: 4 additions & 0 deletions src/GIMI-ModManager.WinUI/GIMI-ModManager.WinUI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<Content Remove="Assets\Images\Character_Traveler_Thumb.png" />
<Content Remove="Assets\Images\Character_Venti_Thumb.png" />
<Content Remove="Assets\Images\Character_Wanderer_Thumb.png" />
<Content Remove="Assets\Images\Character_Weapons_Thumb.webp" />
<Content Remove="Assets\Images\Character_Xiangling_Thumb.png" />
<Content Remove="Assets\Images\Character_Xiao_Thumb.png" />
<Content Remove="Assets\Images\Character_Xingqiu_Thumb.png" />
Expand Down Expand Up @@ -374,6 +375,9 @@
<None Update="Assets\Images\Character_Wanderer_Thumb.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\Images\Character_Weapons_Thumb.webp">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Assets\Images\Character_Xiangling_Thumb.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
4 changes: 4 additions & 0 deletions src/GIMI-ModManager.WinUI/Models/CharacterGridItemModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommunityToolkit.Mvvm.ComponentModel;
using GIMI_ModManager.Core.Entities;
using GIMI_ModManager.WinUI.Models.Options;

namespace GIMI_ModManager.WinUI.Models;

Expand All @@ -13,6 +14,9 @@ public partial class CharacterGridItemModel : ObservableObject, IEquatable<Chara
[ObservableProperty] private bool _warning;
[ObservableProperty] private bool _isHidden;

[ObservableProperty] private bool _notification;
[ObservableProperty] private AttentionType _notificationType;

public CharacterGridItemModel(GenshinCharacter character)
{
Character = character;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class ModAttentionSettings

public sealed class ModNotification
{
public int CharacterId { get; set; }
public string ModCustomName { get; set; }
public string ModFolderName { get; set; }
public bool ShowOnOverview { get; set; }
Expand All @@ -20,8 +21,9 @@ public sealed class ModNotification

public enum AttentionType
{
None,
Added,
Modified,
UpdateAvailable,
Error
UpdateAvailable, // Also show in character overview
Error // Also show in character overview
}
6 changes: 6 additions & 0 deletions src/GIMI-ModManager.WinUI/Services/LocalSettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ private async Task InitializeAsync()
return default;
}

public async Task<T> ReadOrCreateSettingAsync<T>(string key) where T : new()
{
var setting = await ReadSettingAsync<T>(key);
return setting ?? new T();
}

public async Task SaveSettingAsync<T>(string key, T value)
{
if (RuntimeHelper.IsMSIX)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public async void OnNavigatedTo(object parameter)
ShownCharacter = character;
MoveModsFlyoutVM.SetShownCharacter(ShownCharacter);
_modList = _skinManagerService.GetCharacterModList(character);
if (ShownCharacter.Id == _genshinService.OtherCharacterId)
if (_genshinService.IsMultiModCharacter(ShownCharacter))
ModListVM.DisableInfoBar = true;

try
Expand Down
10 changes: 8 additions & 2 deletions src/GIMI-ModManager.WinUI/ViewModels/CharactersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ public async void OnNavigatedTo(object parameter)
characters.Add(gliders);
}

var weapons = characters.FirstOrDefault(ch => ch.Id == _genshinService.WeaponsCharacterId);
if (weapons is not null) // Add to end
{
characters.Remove(weapons);
characters.Add(weapons);
}

_characters = characters.ToArray();

var pinnedCharactersOptions = await ReadCharacterSettings();
Expand Down Expand Up @@ -320,8 +327,7 @@ public async void OnNavigatedTo(object parameter)
foreach (var characterGridItemModel in Characters.Where(x =>
charactersWithMultipleActiveSkins.Contains(x.Character.Id)))
{
if (characterGridItemModel.Character.Id == _genshinService.OtherCharacterId ||
characterGridItemModel.Character.Id == _genshinService.GlidersCharacterId)
if (_genshinService.IsMultiModCharacter(characterGridItemModel.Character))
continue;

characterGridItemModel.Warning = true;
Expand Down
3 changes: 3 additions & 0 deletions src/GIMI-ModManager.WinUI/Views/ShellPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public ShellPage(ShellViewModel viewModel)
App.MainWindow.SetTitleBar(AppTitleBar);
App.MainWindow.Activated += MainWindow_Activated;
AppTitleBarText.Text = "AppDisplayName".GetLocalized();
#if DEBUG
AppTitleBarText.Text += " - DEBUG";
#endif
this.KeyDown += GlobalKeyHandler_Invoked;

Loaded += (sender, args) =>
Expand Down

0 comments on commit 3c906cd

Please sign in to comment.