Skip to content

Commit

Permalink
feat: add two pages
Browse files Browse the repository at this point in the history
  • Loading branch information
bsdayo committed Dec 29, 2022
1 parent 5a9bd76 commit e061ead
Show file tree
Hide file tree
Showing 23 changed files with 928 additions and 300 deletions.
File renamed without changes
Binary file added assets/screenshot-v1.1.0.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/SlstGen/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CommunityToolkit.Mvvm.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using NekoSpace.SlstGen.Services;
using NekoSpace.SlstGen.ViewModels;

namespace NekoSpace.SlstGen;

Expand All @@ -15,10 +16,11 @@ public App()
Ioc.Default.ConfigureServices(GetServiceProvider());
}

private IServiceProvider GetServiceProvider()
private static IServiceProvider GetServiceProvider()
{
return new ServiceCollection()
.AddSingleton<SlstService>()
.AddSingleton<SharedViewModel>()
.BuildServiceProvider();
}
}
3 changes: 0 additions & 3 deletions src/SlstGen/Models/SlstDifficultyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class SlstDifficultyInfo
[JsonPropertyName("ratingPlus")]
public bool? RatingPlus { get; set; } = null;

[JsonPropertyName("plusFingers")]
public bool? PlusFingers { get; set; } = null;

[JsonPropertyName("jacket_night")]
public string? JacketNight { get; set; } = null;

Expand Down
24 changes: 9 additions & 15 deletions src/SlstGen/Models/SlstItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ public class SlstItem
[JsonPropertyName("artist")]
public string Artist { get; set; } = string.Empty;

[JsonPropertyName("artist_localized")]
public SlstLocalizationInfo? ArtistLocalized { get; set; } = null;

[JsonPropertyName("bpm")]
public string Bpm { get; set; } = string.Empty;

Expand All @@ -46,10 +43,10 @@ public class SlstItem
public string Bg { get; set; } = string.Empty;

[JsonPropertyName("bg_inverse")]
public string? BgInverse { get; set; } = null;
public string? BgInverse { get; set; }

[JsonPropertyName("bg_daynight")]
public SlstBgDayNightInfo? BgDayNight { get; set; } = null;
public SlstBgDayNightInfo? BgDayNight { get; set; }

[JsonPropertyName("date")]
public long Date { get; set; }
Expand All @@ -58,31 +55,28 @@ public class SlstItem
public string Version { get; set; } = string.Empty;

[JsonPropertyName("world_unlock")]
public bool? WorldUnlock { get; set; } = null;
public bool? WorldUnlock { get; set; }

[JsonPropertyName("remote_dl")]
public bool? RemoteDl { get; set; } = null;
public bool? RemoteDl { get; set; }

[JsonPropertyName("byd_local_unlock")]
public bool? BydLocalUnlock { get; set; } = null;
public bool? BydLocalUnlock { get; set; }

[JsonPropertyName("songlist_hidden")]
public bool? SonglistHidden { get; set; } = null;

[JsonPropertyName("no_pp")]
public bool? NoPp { get; set; } = null;
public bool? SonglistHidden { get; set; }

[JsonPropertyName("source_localized")]
public SlstLocalizationInfo? SourceLocalized { get; set; } = null;

[JsonPropertyName("source_copyright")]
public string? SourceCopyright { get; set; } = null;
public string? SourceCopyright { get; set; }

[JsonPropertyName("no_stream")]
public bool? NoStream { get; set; } = null;
public bool? NoStream { get; set; }

[JsonPropertyName("jacket_localized")]
public SlstLocalizationInfo? JacketLocalized { get; set; } = null;
public SlstJacketLocalizationInfo? JacketLocalized { get; set; }

[JsonPropertyName("difficulties")]
public List<SlstDifficultyInfo> Difficulties { get; set; } = Enumerable.Range(0, 3)
Expand Down
23 changes: 23 additions & 0 deletions src/SlstGen/Models/SlstJacketLocalizationInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Text.Json.Serialization;

namespace NekoSpace.SlstGen.Models;

public class SlstJacketLocalizationInfo
{
[JsonPropertyName("ja")]
public bool? Ja { get; set; } = null;

[JsonPropertyName("ko")]
public bool? Ko { get; set; } = null;

[JsonPropertyName("zh-Hans")]
public bool? ZhHans { get; set; } = null;

[JsonPropertyName("zh-Hant")]
public bool? ZhHant { get; set; } = null;

public bool IsAllNull()
{
return (Ja, Ko, ZhHans, ZhHant) is (null, null, null, null);
}
}
33 changes: 28 additions & 5 deletions src/SlstGen/SlstGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,36 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0-preview2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="WPF-UI" Version="2.0.3" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.1.0-preview2"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0"/>
<PackageReference Include="WPF-UI" Version="2.0.3"/>
</ItemGroup>


<ItemGroup>
<Content Include="../../LICENSE" CopyToPublishDirectory="Always"/>
</ItemGroup>

<ItemGroup>
<Content Include="../../LICENSE" CopyToPublishDirectory="Always" />
<Page Update="Views\Pages\BasicPage.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Pages\LocalizationPage.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Pages\MiscPage.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
<Page Update="Views\Pages\AboutPage.xaml">
<Generator>MSBuild:Compile</Generator>
<XamlRuntime>Wpf</XamlRuntime>
<SubType>Designer</SubType>
</Page>
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions src/SlstGen/Utils/Extensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace NekoSpace.SlstGen.Utils;

public static class Extensions
{
public static string? NullOrNotEmpty(this string str)
{
return string.IsNullOrEmpty(str) ? null : str;
}

public static bool? NullOrTrue(this bool? val)
{
return val.GetValueOrDefault(false) ? true : null;
}

public static bool? NullOrTrue(this bool val)
{
return val ? true : null;
}
}
37 changes: 3 additions & 34 deletions src/SlstGen/ViewModels/BasicPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using NekoSpace.SlstGen.Models;
using CommunityToolkit.Mvvm.DependencyInjection;

namespace NekoSpace.SlstGen.ViewModels;

public class BasicPageViewModel : SlstViewModel
{
public SharedViewModel Shared { get; } = Ioc.Default.GetRequiredService<SharedViewModel>();

public string Id
{
get => Service.Slst.Id;
Expand All @@ -21,13 +21,6 @@ public int Idx
(s, v) => s.Idx = v);
}

public string NameEn
{
get => Service.Slst.TitleLocalized.En;
set => Update(Service.Slst.TitleLocalized.En, value, Service.Slst,
(s, v) => s.TitleLocalized.En = v ?? string.Empty);
}

public string Artist
{
get => Service.Slst.Artist;
Expand Down Expand Up @@ -130,28 +123,4 @@ private void UpdateDate()
Update(Service.Slst.Date, timestamp, Service.Slst,
(s, v) => s.Date = v);
}

public ObservableCollection<SlstDifficultyInfoViewModel> Difficulties { get; }

public BasicPageViewModel()
{
Difficulties =
new ObservableCollection<SlstDifficultyInfoViewModel>(
Service.Slst.Difficulties.Select(d => new SlstDifficultyInfoViewModel(d)));
}

public void AddBeyondDifficulty()
{
var diffInfo = new SlstDifficultyInfo { RatingClass = ArcaeaRatingClass.Beyond };
Service.Slst.Difficulties.Add(diffInfo);
Difficulties.Add(new SlstDifficultyInfoViewModel(diffInfo));
Service.InvokeSlstUpdatedEvent();
}

public void RemoveBeyondDifficulty()
{
Service.Slst.Difficulties.RemoveAt(3);
Difficulties.RemoveAt(3);
Service.InvokeSlstUpdatedEvent();
}
}
64 changes: 64 additions & 0 deletions src/SlstGen/ViewModels/LocalizationPageViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System;
using System.Runtime.CompilerServices;
using CommunityToolkit.Mvvm.DependencyInjection;
using NekoSpace.SlstGen.Models;
using NekoSpace.SlstGen.Utils;

namespace NekoSpace.SlstGen.ViewModels;

public class LocalizationPageViewModel : SlstViewModel
{
public SharedViewModel Shared { get; } = Ioc.Default.GetRequiredService<SharedViewModel>();

public SlstLocalizationInfoViewModel TitleLocalized { get; }

public SlstLocalizationInfoViewModel SourceLocalized { get; }

private readonly SlstJacketLocalizationInfo _jacketInfo;

public bool JacketLocalizedJa
{
get => _jacketInfo.Ja ?? false;
set => UpdateJacketLocalized(_jacketInfo.Ja, value,
(i, v) => i.Ja = v);
}

public bool JacketLocalizedKo
{
get => _jacketInfo.Ko ?? false;
set => UpdateJacketLocalized(_jacketInfo.Ko, value,
(i, v) => i.Ko = v);
}

public bool JacketLocalizedZhHans
{
get => _jacketInfo.ZhHans ?? false;
set => UpdateJacketLocalized(_jacketInfo.ZhHans, value,
(i, v) => i.ZhHans = v);
}

public bool JacketLocalizedZhHant
{
get => _jacketInfo.ZhHant ?? false;
set => UpdateJacketLocalized(_jacketInfo.ZhHant, value,
(i, v) => i.ZhHant = v);
}

public LocalizationPageViewModel()
{
TitleLocalized = new SlstLocalizationInfoViewModel(
"曲目名称", nameof(Service.Slst.TitleLocalized));
SourceLocalized = new SlstLocalizationInfoViewModel(
"曲目来源", nameof(Service.Slst.SourceLocalized));

_jacketInfo = Service.Slst.JacketLocalized ?? new SlstJacketLocalizationInfo();
}

private void UpdateJacketLocalized(bool? oldValue, bool newValue, Action<SlstJacketLocalizationInfo, bool?> action,
[CallerMemberName] string? propertyName = null)
{
SetProperty(oldValue, newValue.NullOrTrue(), _jacketInfo, action, propertyName);
Service.Slst.JacketLocalized = _jacketInfo.IsAllNull() ? null : _jacketInfo;
Service.InvokeSlstUpdatedEvent();
}
}
Loading

0 comments on commit e061ead

Please sign in to comment.