Skip to content

Commit

Permalink
Update Code
Browse files Browse the repository at this point in the history
  • Loading branch information
Awbugl committed Apr 20, 2023
1 parent 8104ef1 commit a3ce16d
Show file tree
Hide file tree
Showing 88 changed files with 1,616 additions and 1,525 deletions.
16 changes: 16 additions & 0 deletions AndrealImageGenerator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="System.Drawing.Common" Version="5.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.1" />
</ItemGroup>

</Project>
16 changes: 16 additions & 0 deletions AndrealImageGenerator.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndrealImageGenerator", "AndrealImageGenerator.csproj", "{505FA106-482E-44D6-92E0-FB2304B3140F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{505FA106-482E-44D6-92E0-FB2304B3140F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{505FA106-482E-44D6-92E0-FB2304B3140F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{505FA106-482E-44D6-92E0-FB2304B3140F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{505FA106-482E-44D6-92E0-FB2304B3140F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
2 changes: 2 additions & 0 deletions AndrealImageGenerator.sln.DotSettings.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<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">
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=ALA/@EntryIndexedValue">ALA</s:String></wpf:ResourceDictionary>
120 changes: 120 additions & 0 deletions Beans/ArcaeaChart.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System.Collections.Concurrent;
using AndrealImageGenerator.Graphics;
using Newtonsoft.Json;
using Path = AndrealImageGenerator.Common.Path;

#pragma warning disable CS8618

namespace AndrealImageGenerator.Beans;

public class ArcaeaChart
{
private static readonly ConcurrentDictionary<string, Stream> SongImage = new();

[JsonProperty("name_en")]
public string NameEn { get; set; }

[JsonProperty("name_jp")]
public string NameJp { get; set; }

[JsonProperty("artist")]
public string Artist { get; set; }

[JsonProperty("bpm")]
public string Bpm { get; set; }

[JsonProperty("bpm_base")]
public double BpmBase { get; set; }

[JsonProperty("set")]
public string Set { get; set; }

[JsonProperty("set_friendly")]
public string SetFriendly { get; set; }

[JsonProperty("time")]
public int Time { get; set; }

[JsonProperty("side")]
public Side Side { get; set; }

[JsonProperty("world_unlock")]
public bool WorldUnlock { get; set; }

[JsonProperty("remote_download")]
public bool RemoteDownload { get; set; }

[JsonProperty("bg")]
public string Bg { get; set; }

[JsonProperty("date")]
public int Date { get; set; }

[JsonProperty("version")]
public string Version { get; set; }

[JsonProperty("difficulty")]
public int Difficulty { get; set; }

[JsonProperty("rating")]
public int Rating { get; set; }

[JsonProperty("note")]
public int Note { get; set; }

[JsonProperty("chart_designer")]
public string ChartDesigner { get; set; }

[JsonProperty("jacket_designer")]
public string JacketDesigner { get; set; }

[JsonProperty("jacket_override")]
public bool JacketOverride { get; set; }

[JsonProperty("audio_override")]
public bool AudioOverride { get; set; }

internal string SongID { get; set; }

internal double Const => (double)Rating / 10;

internal int RatingClass { get; set; }

internal DifficultyInfo DifficultyInfo => DifficultyInfo.GetByIndex(RatingClass);

internal string GetSongName(byte length) => NameEn.Length < length + 3 ? NameEn : $"{NameEn[..length]}...";

internal async Task<Image> GetSongImage()
{
var path = await Path.ArcaeaSong(this);

try
{
if (!SongImage.TryGetValue(path, out var stream))
{
await using var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

using var reader = new BinaryReader(fileStream);
var bytes = reader.ReadBytes((int)fileStream.Length);
stream = new MemoryStream(bytes);
reader.Close();
fileStream.Close();

SongImage.TryAdd(path, stream);
}

var img = new Image(stream);
if (img.Width == 512) return img;
var newimg = new Image(img, 512, 512);
newimg.SaveAsPng(path);
img.Dispose();
return newimg;
}
catch (Exception e)
{
SongImage.TryRemove(path, out var s);
s?.DisposeAsync();
throw new ArgumentException("GetSongImage Failed.", NameEn, e);
}
}
}
21 changes: 18 additions & 3 deletions Model/ArcaeaCharts.cs → Beans/ArcaeaCharts.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections.Concurrent;
using ImageGenerator.Json.ArcaeaUnlimited;
using AndrealImageGenerator.Beans.Json;
using AndrealImageGenerator.Common;
using Newtonsoft.Json;
using Path = AndrealImageGenerator.Common.Path;

namespace ImageGenerator.Model;
namespace AndrealImageGenerator.Beans;

internal static class ArcaeaCharts
{
Expand All @@ -12,7 +14,20 @@ static ArcaeaCharts()
{
Songs.Clear();

List<SongsItem> slst = JsonConvert.DeserializeObject<SongListContent>(File.ReadAllText(Path.ArcaeaSongs))!.Songs;
List<SongsItem>? slst;

try
{
slst = ArcaeaUnlimitedAPI.SongList().Result?.Content.Songs;
if (slst != null) File.WriteAllText(Path.TmpSongList, JsonConvert.SerializeObject(slst));
}
catch
{
if (!File.Exists(Path.TmpSongList)) throw;
slst = JsonConvert.DeserializeObject<List<SongsItem>>(File.ReadAllText(Path.TmpSongList));
}

if (slst == null) return;

foreach (var songitem in slst)
{
Expand Down
2 changes: 1 addition & 1 deletion Model/ArcaeaSong.cs → Beans/ArcaeaSong.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ImageGenerator.Model;
namespace AndrealImageGenerator.Beans;

public class ArcaeaSong : List<ArcaeaChart>, IEquatable<ArcaeaSong>
{
Expand Down
19 changes: 19 additions & 0 deletions Beans/Best30Data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using AndrealImageGenerator.Beans.Json;

namespace AndrealImageGenerator.Beans;

internal class Best30Data
{
internal Best30Data(UserBestsContent b30data)
{
B30data = b30data;
}

private UserBestsContent B30data { get; }

internal string Best30Avg => B30data.Best30Avg.ToString("0.0000");

internal string Recent10Avg => B30data.Recent10Avg > 0 ? B30data.Recent10Avg.ToString("0.0000") : "--";

internal List<RecordInfo> Best30List => B30data.Best30List.Select(i => new RecordInfo(i)).ToList();
}
21 changes: 21 additions & 0 deletions Beans/Best40Data.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using AndrealImageGenerator.Beans.Json;

namespace AndrealImageGenerator.Beans;

internal class Best40Data
{
internal Best40Data(UserBestsContent b40data)
{
B40data = b40data;
}

private UserBestsContent B40data { get; }

internal string Best30Avg => B40data.Best30Avg.ToString("0.0000");

internal string Recent10Avg => B40data.Recent10Avg > 0 ? B40data.Recent10Avg.ToString("0.0000") : "--";

internal List<RecordInfo> Best30List => B40data.Best30List.Select(i => new RecordInfo(i)).ToList();

internal List<RecordInfo>? OverflowList => B40data.OverflowList?.Select(i => new RecordInfo(i)).ToList();
}
42 changes: 42 additions & 0 deletions Beans/DifficultyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System.Collections.Concurrent;
using System.Drawing;

#pragma warning disable CS8618

namespace AndrealImageGenerator.Beans;

[Serializable]
internal class DifficultyInfo
{
private static readonly ConcurrentDictionary<int, DifficultyInfo> List = new();

static DifficultyInfo()
{
List.TryAdd(3, new() { LongStr = "Beyond", ShortStr = "BYD", Alias = new[] { "byn", "byd", "beyond" }, Color = Color.FromArgb(165, 20, 49) });

List.TryAdd(2, new() { LongStr = "Future", ShortStr = "FTR", Alias = new[] { "ftr", "future" }, Color = Color.FromArgb(115, 35, 100) });

List.TryAdd(1, new() { LongStr = "Present", ShortStr = "PRS", Alias = new[] { "prs", "present" }, Color = Color.FromArgb(120, 155, 80) });

List.TryAdd(0, new() { LongStr = "Past", ShortStr = "PST", Alias = new[] { "pst", "past" }, Color = Color.FromArgb(20, 165, 215) });
}

private string[] Alias { get; set; }
internal string LongStr { get; private set; }
internal string ShortStr { get; private set; }
internal Color Color { get; private set; }

internal static DifficultyInfo GetByIndex(int index) => List[index];

internal static (string, int) DifficultyConverter(string dif)
{
foreach (var (key, value) in List)
{
foreach (var alias in value.Alias.Where(dif.EndsWith)) return (dif[..^alias.Length], key);
}

return (dif, -1);
}

public static implicit operator string(DifficultyInfo info) => info.ShortStr;
}
9 changes: 9 additions & 0 deletions Beans/ImgVersion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace AndrealImageGenerator.Beans;

public enum ImgVersion
{
ImgV1 = 1,
ImgV2,
ImgV3,
ImgV4
}
35 changes: 35 additions & 0 deletions Beans/Json/AccountInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Newtonsoft.Json;

#pragma warning disable CS8618

namespace AndrealImageGenerator.Beans.Json;

public class AccountInfo
{
[JsonProperty("code")]
public int Code { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("user_id")]
public int UserID { get; set; }

[JsonProperty("is_mutual")]
public bool IsMutual { get; set; }

[JsonProperty("is_char_uncapped_override")]
public bool IsCharUncappedOverride { get; set; }

[JsonProperty("is_char_uncapped")]
public bool IsCharUncapped { get; set; }

[JsonProperty("is_skill_sealed")]
public bool IsSkillSealed { get; set; }

[JsonProperty("rating")]
public short Rating { get; set; }

[JsonProperty("character")]
public int Character { get; set; }
}
38 changes: 38 additions & 0 deletions Beans/Json/ArcSongdata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Newtonsoft.Json;

#pragma warning disable CS8618

namespace AndrealImageGenerator.Beans.Json;

public class ArcSongdata
{
[JsonProperty("song_id")]
public string SongID { get; set; }

[JsonProperty("difficulty")]
public sbyte Difficulty { get; set; }

[JsonProperty("score")]
public int Score { get; set; }

[JsonProperty("shiny_perfect_count")]
public string MaxPure { get; set; }

[JsonProperty("perfect_count")]
public string Pure { get; set; }

[JsonProperty("near_count")]
public string Far { get; set; }

[JsonProperty("miss_count")]
public string Lost { get; set; }

[JsonProperty("time_played")]
public long TimePlayed { get; set; }

[JsonProperty("clear_type")]
public sbyte ClearType { get; set; }

[JsonProperty("rating")]
public double Rating { get; set; }
}
17 changes: 17 additions & 0 deletions Beans/Json/ResponseRoot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;

#pragma warning disable CS8618

namespace AndrealImageGenerator.Beans.Json;

public class ResponseRoot<T>
{
[JsonProperty("status")]
public int Status { get; set; }

[JsonProperty("message")]
public string Message { get; set; }

[JsonProperty("content")]
public T Content { get; set; }
}
Loading

0 comments on commit a3ce16d

Please sign in to comment.