Skip to content

Commit

Permalink
feat: display online interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
LingFeng-bbben committed Oct 22, 2024
1 parent 1c86a9f commit 46f4737
Show file tree
Hide file tree
Showing 20 changed files with 23,354 additions and 12,183 deletions.
6,490 changes: 5,341 additions & 1,149 deletions Assets/Font/GenJyuuGothicScore.asset

Large diffs are not rendered by default.

16,109 changes: 9,683 additions & 6,426 deletions Assets/Font/GenJyuuGothicX-Medium SDF.asset

Large diffs are not rendered by default.

5,667 changes: 3,954 additions & 1,713 deletions Assets/Font/GenJyuuGothicXGold.asset

Large diffs are not rendered by default.

116 changes: 110 additions & 6 deletions Assets/Font/Minimoon SDF.asset

Large diffs are not rendered by default.

1,382 changes: 929 additions & 453 deletions Assets/Font/SourceHanSans-Medium SDF.asset

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions Assets/Prefab/List/Danmaku.prefab
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &8689199224619827205
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 336921771382832073}
- component: {fileID: 3270854224572761495}
- component: {fileID: 294420130874679028}
- component: {fileID: 3265452433697327105}
m_Layer: 5
m_Name: Danmaku
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &336921771382832073
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8689199224619827205}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 159.41, y: -55}
m_SizeDelta: {x: 428.12, y: 163.7}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &3270854224572761495
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8689199224619827205}
m_CullTransparentMesh: 1
--- !u!114 &294420130874679028
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8689199224619827205}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 8cb6273d740045b4aa08f9875bbd7601, type: 3}
m_FontSize: 18
m_FontStyle: 0
m_BestFit: 1
m_MinSize: 5
m_MaxSize: 20
m_Alignment: 0
m_AlignByGeometry: 0
m_RichText: 1
m_HorizontalOverflow: 0
m_VerticalOverflow: 0
m_LineSpacing: 1
m_Text: 'asdjasdjhaskjdhaksjdh
aksjdhaksjdhaksjdh
kajshdsakjdhaksjd
kajshdkajsdhkasjdh
akjsdhkajdhadakjsdhkajhdakjsdhakjhdak'
--- !u!114 &3265452433697327105
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8689199224619827205}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 44c17983a4705464aaadf6e9d5190d0e, type: 3}
m_Name:
m_EditorClassIdentifier:
7 changes: 7 additions & 0 deletions Assets/Prefab/List/Danmaku.prefab.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5,207 changes: 2,808 additions & 2,399 deletions Assets/Scenes/List.unity

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Assets/Script/List/CoverListDisplayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class CoverListDisplayer : MonoBehaviour
public GameObject CoverSmallPrefab;
public GameObject DirSmallPrefab;
public CoverBigDisplayer CoverBigDisplayer;
public SubInfoDisplayer SubInfoDisplayer;

public int desiredListPos = 0;
public float listPosReal;
Expand Down Expand Up @@ -168,6 +169,7 @@ public void SlideToList(int pos)
CoverBigDisplayer.SetCover(songinfo);
CoverBigDisplayer.SetMeta(songinfo.Title, songinfo.Artist, songinfo.Designers[selectedDifficulty], songinfo.Levels[selectedDifficulty]);
CoverBigDisplayer.SetScore(songScore);
SubInfoDisplayer.RefreshContent(songinfo);
SongStorage.WorkingCollection.Index = desiredListPos;
break;
}
Expand Down
22 changes: 22 additions & 0 deletions Assets/Script/List/DanmakuDisplayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class DanmakuDisplayer : MonoBehaviour
{
RectTransform rt;
// Start is called before the first frame update
void Start()
{
rt = GetComponent<RectTransform>();
rt.anchoredPosition = new Vector2(770f, -55f);
}

// Update is called once per frame
void Update()
{
rt.anchoredPosition -= new Vector2(300f * Time.deltaTime,0f);
if (rt.anchoredPosition.x < -1000f) Destroy(gameObject);
}
}
11 changes: 11 additions & 0 deletions Assets/Script/List/DanmakuDisplayer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions Assets/Script/List/SubInfoDisplayer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
using MajdataPlay.Types;
using Cysharp.Threading.Tasks;
using MajdataPlay.Net;
using System.Text.Json;

public class SubInfoDisplayer : MonoBehaviour
{
public TMP_Text id_text;
public TMP_Text good_text;
public GameObject commentPrefab;
List<GameObject> comments = new List<GameObject>();
// Start is called before the first frame update
public void RefreshContent(SongDetail song)
{
if (song.isOnline)
{
id_text.text = "ID: " + song.OnlineId;
StopAllCoroutines();
foreach(var obj in comments)
{
Destroy(obj);
}
comments.Clear();
StartCoroutine( GetOnlineInteraction(song));
}
else
{
id_text.text = "";
good_text.text = "";
}
}

IEnumerator GetOnlineInteraction(SongDetail song)
{
var client = HttpTransporter.ShareClient;
var interactUrl = song.ApiEndpoint.Url + "/Interact/" + song.OnlineId;
var task = client.GetStringAsync(interactUrl);
while(!task.IsCompleted)
{
yield return new WaitForEndOfFrame();
}
var intjson = task.Result;

var list = JsonSerializer.Deserialize<MajNetSongInteract>(intjson);
good_text.text = "ÔÞ: " + list.LikeList.Length +" ÆÀ: " +list.CommentsList.Count;

foreach ( var comment in list.CommentsList )
{
var text = comment.Key + "\n" + comment.Value + "\n";
var obj = Instantiate(commentPrefab,gameObject.transform);
comments.Add(obj);
obj.GetComponent<Text>().text = text;
yield return new WaitForSeconds(2f);
}

}
}
11 changes: 11 additions & 0 deletions Assets/Script/List/SubInfoDisplayer.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions Assets/Script/Misc/Types/DataFormats/GameSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,20 @@ public class SFXVolume
public class OnlineOptions
{
public bool Enable { get; set; } = false;
public Dictionary<string,string> ApiEndpoints { get; set; } = new Dictionary<string, string> {
{ "Majnet","https://majdata.net/api3/api" },
{ "Contest","https://majdata.net/api1/api"}
public List<ApiEndpoint> ApiEndpoints { get; set; } = new List<ApiEndpoint> {
{ new ApiEndpoint(){ Name = "Majnet",Url = "https://majdata.net/api3/api" } },
{ new ApiEndpoint(){ Name = "Contest", Url = "https://majdata.net/api1/api"} }
};
}

public class ApiEndpoint
{
public string Name { get; set; }
public string Url { get; set; }
public string? Username { get; set; }
public string? Password { get; set; }
}

public class DebugOptions
{
public bool DisplaySensor { get; set; } = false;
Expand Down
6 changes: 6 additions & 0 deletions Assets/Script/Misc/Types/DataFormats/MajnetSongDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ public partial class MajnetSongDetail
[JsonPropertyName("Timestamp")]
public long Timestamp { get; set; }
}

public partial class MajNetSongInteract
{
public string[] LikeList { get; set; }
public Dictionary<string,string> CommentsList { get; set; }
}
}
32 changes: 32 additions & 0 deletions Assets/Script/Misc/Types/DataFormats/SongDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class SongDetail
private Sprite? SongCover;
public double First { get; set; }
public string Hash { get; set; } = string.Empty;
public string OnlineId { get; set; } = "";
public ApiEndpoint? ApiEndpoint { get; set; }
public DateTime AddTime { get; set; }
public bool isOnline { get; set; } = false;

Expand Down Expand Up @@ -110,6 +112,36 @@ await Task.Run(() =>
AddTime = maidataFile.LastWriteTime
};
}

public static SongDetail ParseOnline(ApiEndpoint api, MajnetSongDetail song)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(song.Timestamp).ToLocalTime();
var apiroot = api.Url;
var songDetail = new SongDetail()
{
Title = song.Title,
Artist = song.Artist,
Levels = song.Levels.ToArray(),
isOnline = true,
MaidataPath = apiroot + "/Maidata/" + song.Id,
TrackPath = apiroot + "/Track/" + song.Id,
BGPath = apiroot + "/ImageFull/" + song.Id,
VideoPath = apiroot + "/Video/" + song.Id,
CoverPath = apiroot + "/Image/" + song.Id,
Hash = song.Id.ToString() + "-" + song.Timestamp,
ApiEndpoint = api,
OnlineId = song.Id,
AddTime = dateTime
};
for (int i = 0; i < songDetail.Designers.Count(); i++)
{
songDetail.Designers[i] = song.Uploader + "@" + song.Designer;
}

return songDetail;
}

private static string GetValue(string varline)
{
try
Expand Down
30 changes: 8 additions & 22 deletions Assets/Script/Utils/SongStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static async ValueTask<SongCollection[]> GetCollections(string rootPath)
{
foreach(var item in MajInstances.Setting.Online.ApiEndpoints)
{
tasks.Add(GetOnlineCollection(item.Key,item.Value));
tasks.Add(GetOnlineCollection(item));
}
}

Expand Down Expand Up @@ -134,9 +134,11 @@ static async Task<SongCollection> GetCollection(string rootPath)
charts.Add(task.Result);
return new SongCollection(thisDir.Name, charts.ToArray());
}
static async Task<SongCollection> GetOnlineCollection(string name, string apiroot)
static async Task<SongCollection> GetOnlineCollection(ApiEndpoint api)
{
var name = api.Name;
var collection = SongCollection.Empty(name);
var apiroot = api.Url;
if (string.IsNullOrEmpty(apiroot))
return collection;

Expand All @@ -153,26 +155,7 @@ static async Task<SongCollection> GetOnlineCollection(string name, string apiroo
var gameList = new List<SongDetail>();
foreach (var song in list)
{
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
dateTime = dateTime.AddSeconds(song.Timestamp).ToLocalTime();
var songDetail = new SongDetail()
{
Title = song.Title,
Artist = song.Artist,
Levels = song.Levels.ToArray(),
isOnline = true,
MaidataPath = apiroot + "/Maidata/" + song.Id,
TrackPath = apiroot + "/Track/" + song.Id,
BGPath = apiroot + "/ImageFull/" + song.Id,
VideoPath = apiroot + "/Video/" + song.Id,
CoverPath = apiroot + "/Image/" + song.Id,
Hash = song.Id.ToString()+"-" + song.Timestamp,
AddTime = dateTime
};
for (int i = 0; i < songDetail.Designers.Count(); i++)
{
songDetail.Designers[i] = song.Uploader + "@" + song.Designer;
}
SongDetail songDetail = SongDetail.ParseOnline(api, song);
gameList.Add(songDetail);
}
Debug.Log("Loaded Online Charts List:" + gameList.Count);
Expand All @@ -184,6 +167,9 @@ static async Task<SongCollection> GetOnlineCollection(string name, string apiroo
return collection;
}
}



public static void SortAndFind(string searchKey, SortType sortType)
{
OrderBy.Keyword = searchKey;
Expand Down
Binary file added Assets/Sprites/xxlb_good.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 46f4737

Please sign in to comment.