Skip to content

Commit a3ce16d

Browse files
committed
Update Code
1 parent 8104ef1 commit a3ce16d

File tree

88 files changed

+1616
-1525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+1616
-1525
lines changed

AndrealImageGenerator.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
12+
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
13+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.1" />
14+
</ItemGroup>
15+
16+
</Project>

AndrealImageGenerator.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndrealImageGenerator", "AndrealImageGenerator.csproj", "{505FA106-482E-44D6-92E0-FB2304B3140F}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{505FA106-482E-44D6-92E0-FB2304B3140F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{505FA106-482E-44D6-92E0-FB2304B3140F}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{505FA106-482E-44D6-92E0-FB2304B3140F}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{505FA106-482E-44D6-92E0-FB2304B3140F}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ALA/@EntryIndexedValue">ALA</s:String></wpf:ResourceDictionary>

Beans/ArcaeaChart.cs

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
using System.Collections.Concurrent;
2+
using AndrealImageGenerator.Graphics;
3+
using Newtonsoft.Json;
4+
using Path = AndrealImageGenerator.Common.Path;
5+
6+
#pragma warning disable CS8618
7+
8+
namespace AndrealImageGenerator.Beans;
9+
10+
public class ArcaeaChart
11+
{
12+
private static readonly ConcurrentDictionary<string, Stream> SongImage = new();
13+
14+
[JsonProperty("name_en")]
15+
public string NameEn { get; set; }
16+
17+
[JsonProperty("name_jp")]
18+
public string NameJp { get; set; }
19+
20+
[JsonProperty("artist")]
21+
public string Artist { get; set; }
22+
23+
[JsonProperty("bpm")]
24+
public string Bpm { get; set; }
25+
26+
[JsonProperty("bpm_base")]
27+
public double BpmBase { get; set; }
28+
29+
[JsonProperty("set")]
30+
public string Set { get; set; }
31+
32+
[JsonProperty("set_friendly")]
33+
public string SetFriendly { get; set; }
34+
35+
[JsonProperty("time")]
36+
public int Time { get; set; }
37+
38+
[JsonProperty("side")]
39+
public Side Side { get; set; }
40+
41+
[JsonProperty("world_unlock")]
42+
public bool WorldUnlock { get; set; }
43+
44+
[JsonProperty("remote_download")]
45+
public bool RemoteDownload { get; set; }
46+
47+
[JsonProperty("bg")]
48+
public string Bg { get; set; }
49+
50+
[JsonProperty("date")]
51+
public int Date { get; set; }
52+
53+
[JsonProperty("version")]
54+
public string Version { get; set; }
55+
56+
[JsonProperty("difficulty")]
57+
public int Difficulty { get; set; }
58+
59+
[JsonProperty("rating")]
60+
public int Rating { get; set; }
61+
62+
[JsonProperty("note")]
63+
public int Note { get; set; }
64+
65+
[JsonProperty("chart_designer")]
66+
public string ChartDesigner { get; set; }
67+
68+
[JsonProperty("jacket_designer")]
69+
public string JacketDesigner { get; set; }
70+
71+
[JsonProperty("jacket_override")]
72+
public bool JacketOverride { get; set; }
73+
74+
[JsonProperty("audio_override")]
75+
public bool AudioOverride { get; set; }
76+
77+
internal string SongID { get; set; }
78+
79+
internal double Const => (double)Rating / 10;
80+
81+
internal int RatingClass { get; set; }
82+
83+
internal DifficultyInfo DifficultyInfo => DifficultyInfo.GetByIndex(RatingClass);
84+
85+
internal string GetSongName(byte length) => NameEn.Length < length + 3 ? NameEn : $"{NameEn[..length]}...";
86+
87+
internal async Task<Image> GetSongImage()
88+
{
89+
var path = await Path.ArcaeaSong(this);
90+
91+
try
92+
{
93+
if (!SongImage.TryGetValue(path, out var stream))
94+
{
95+
await using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
96+
97+
using var reader = new BinaryReader(fileStream);
98+
var bytes = reader.ReadBytes((int)fileStream.Length);
99+
stream = new MemoryStream(bytes);
100+
reader.Close();
101+
fileStream.Close();
102+
103+
SongImage.TryAdd(path, stream);
104+
}
105+
106+
var img = new Image(stream);
107+
if (img.Width == 512) return img;
108+
var newimg = new Image(img, 512, 512);
109+
newimg.SaveAsPng(path);
110+
img.Dispose();
111+
return newimg;
112+
}
113+
catch (Exception e)
114+
{
115+
SongImage.TryRemove(path, out var s);
116+
s?.DisposeAsync();
117+
throw new ArgumentException("GetSongImage Failed.", NameEn, e);
118+
}
119+
}
120+
}

Model/ArcaeaCharts.cs renamed to Beans/ArcaeaCharts.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
using System.Collections.Concurrent;
2-
using ImageGenerator.Json.ArcaeaUnlimited;
2+
using AndrealImageGenerator.Beans.Json;
3+
using AndrealImageGenerator.Common;
34
using Newtonsoft.Json;
5+
using Path = AndrealImageGenerator.Common.Path;
46

5-
namespace ImageGenerator.Model;
7+
namespace AndrealImageGenerator.Beans;
68

79
internal static class ArcaeaCharts
810
{
@@ -12,7 +14,20 @@ static ArcaeaCharts()
1214
{
1315
Songs.Clear();
1416

15-
List<SongsItem> slst = JsonConvert.DeserializeObject<SongListContent>(File.ReadAllText(Path.ArcaeaSongs))!.Songs;
17+
List<SongsItem>? slst;
18+
19+
try
20+
{
21+
slst = ArcaeaUnlimitedAPI.SongList().Result?.Content.Songs;
22+
if (slst != null) File.WriteAllText(Path.TmpSongList, JsonConvert.SerializeObject(slst));
23+
}
24+
catch
25+
{
26+
if (!File.Exists(Path.TmpSongList)) throw;
27+
slst = JsonConvert.DeserializeObject<List<SongsItem>>(File.ReadAllText(Path.TmpSongList));
28+
}
29+
30+
if (slst == null) return;
1631

1732
foreach (var songitem in slst)
1833
{

Model/ArcaeaSong.cs renamed to Beans/ArcaeaSong.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace ImageGenerator.Model;
1+
namespace AndrealImageGenerator.Beans;
22

33
public class ArcaeaSong : List<ArcaeaChart>, IEquatable<ArcaeaSong>
44
{

Beans/Best30Data.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using AndrealImageGenerator.Beans.Json;
2+
3+
namespace AndrealImageGenerator.Beans;
4+
5+
internal class Best30Data
6+
{
7+
internal Best30Data(UserBestsContent b30data)
8+
{
9+
B30data = b30data;
10+
}
11+
12+
private UserBestsContent B30data { get; }
13+
14+
internal string Best30Avg => B30data.Best30Avg.ToString("0.0000");
15+
16+
internal string Recent10Avg => B30data.Recent10Avg > 0 ? B30data.Recent10Avg.ToString("0.0000") : "--";
17+
18+
internal List<RecordInfo> Best30List => B30data.Best30List.Select(i => new RecordInfo(i)).ToList();
19+
}

Beans/Best40Data.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using AndrealImageGenerator.Beans.Json;
2+
3+
namespace AndrealImageGenerator.Beans;
4+
5+
internal class Best40Data
6+
{
7+
internal Best40Data(UserBestsContent b40data)
8+
{
9+
B40data = b40data;
10+
}
11+
12+
private UserBestsContent B40data { get; }
13+
14+
internal string Best30Avg => B40data.Best30Avg.ToString("0.0000");
15+
16+
internal string Recent10Avg => B40data.Recent10Avg > 0 ? B40data.Recent10Avg.ToString("0.0000") : "--";
17+
18+
internal List<RecordInfo> Best30List => B40data.Best30List.Select(i => new RecordInfo(i)).ToList();
19+
20+
internal List<RecordInfo>? OverflowList => B40data.OverflowList?.Select(i => new RecordInfo(i)).ToList();
21+
}

Beans/DifficultyInfo.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using System.Collections.Concurrent;
2+
using System.Drawing;
3+
4+
#pragma warning disable CS8618
5+
6+
namespace AndrealImageGenerator.Beans;
7+
8+
[Serializable]
9+
internal class DifficultyInfo
10+
{
11+
private static readonly ConcurrentDictionary<int, DifficultyInfo> List = new();
12+
13+
static DifficultyInfo()
14+
{
15+
List.TryAdd(3, new() { LongStr = "Beyond", ShortStr = "BYD", Alias = new[] { "byn", "byd", "beyond" }, Color = Color.FromArgb(165, 20, 49) });
16+
17+
List.TryAdd(2, new() { LongStr = "Future", ShortStr = "FTR", Alias = new[] { "ftr", "future" }, Color = Color.FromArgb(115, 35, 100) });
18+
19+
List.TryAdd(1, new() { LongStr = "Present", ShortStr = "PRS", Alias = new[] { "prs", "present" }, Color = Color.FromArgb(120, 155, 80) });
20+
21+
List.TryAdd(0, new() { LongStr = "Past", ShortStr = "PST", Alias = new[] { "pst", "past" }, Color = Color.FromArgb(20, 165, 215) });
22+
}
23+
24+
private string[] Alias { get; set; }
25+
internal string LongStr { get; private set; }
26+
internal string ShortStr { get; private set; }
27+
internal Color Color { get; private set; }
28+
29+
internal static DifficultyInfo GetByIndex(int index) => List[index];
30+
31+
internal static (string, int) DifficultyConverter(string dif)
32+
{
33+
foreach (var (key, value) in List)
34+
{
35+
foreach (var alias in value.Alias.Where(dif.EndsWith)) return (dif[..^alias.Length], key);
36+
}
37+
38+
return (dif, -1);
39+
}
40+
41+
public static implicit operator string(DifficultyInfo info) => info.ShortStr;
42+
}

Beans/ImgVersion.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace AndrealImageGenerator.Beans;
2+
3+
public enum ImgVersion
4+
{
5+
ImgV1 = 1,
6+
ImgV2,
7+
ImgV3,
8+
ImgV4
9+
}

Beans/Json/AccountInfo.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Newtonsoft.Json;
2+
3+
#pragma warning disable CS8618
4+
5+
namespace AndrealImageGenerator.Beans.Json;
6+
7+
public class AccountInfo
8+
{
9+
[JsonProperty("code")]
10+
public int Code { get; set; }
11+
12+
[JsonProperty("name")]
13+
public string Name { get; set; }
14+
15+
[JsonProperty("user_id")]
16+
public int UserID { get; set; }
17+
18+
[JsonProperty("is_mutual")]
19+
public bool IsMutual { get; set; }
20+
21+
[JsonProperty("is_char_uncapped_override")]
22+
public bool IsCharUncappedOverride { get; set; }
23+
24+
[JsonProperty("is_char_uncapped")]
25+
public bool IsCharUncapped { get; set; }
26+
27+
[JsonProperty("is_skill_sealed")]
28+
public bool IsSkillSealed { get; set; }
29+
30+
[JsonProperty("rating")]
31+
public short Rating { get; set; }
32+
33+
[JsonProperty("character")]
34+
public int Character { get; set; }
35+
}

Beans/Json/ArcSongdata.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using Newtonsoft.Json;
2+
3+
#pragma warning disable CS8618
4+
5+
namespace AndrealImageGenerator.Beans.Json;
6+
7+
public class ArcSongdata
8+
{
9+
[JsonProperty("song_id")]
10+
public string SongID { get; set; }
11+
12+
[JsonProperty("difficulty")]
13+
public sbyte Difficulty { get; set; }
14+
15+
[JsonProperty("score")]
16+
public int Score { get; set; }
17+
18+
[JsonProperty("shiny_perfect_count")]
19+
public string MaxPure { get; set; }
20+
21+
[JsonProperty("perfect_count")]
22+
public string Pure { get; set; }
23+
24+
[JsonProperty("near_count")]
25+
public string Far { get; set; }
26+
27+
[JsonProperty("miss_count")]
28+
public string Lost { get; set; }
29+
30+
[JsonProperty("time_played")]
31+
public long TimePlayed { get; set; }
32+
33+
[JsonProperty("clear_type")]
34+
public sbyte ClearType { get; set; }
35+
36+
[JsonProperty("rating")]
37+
public double Rating { get; set; }
38+
}

Beans/Json/ResponseRoot.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Newtonsoft.Json;
2+
3+
#pragma warning disable CS8618
4+
5+
namespace AndrealImageGenerator.Beans.Json;
6+
7+
public class ResponseRoot<T>
8+
{
9+
[JsonProperty("status")]
10+
public int Status { get; set; }
11+
12+
[JsonProperty("message")]
13+
public string Message { get; set; }
14+
15+
[JsonProperty("content")]
16+
public T Content { get; set; }
17+
}

0 commit comments

Comments
 (0)