Compare commits

...

2 Commits

Author SHA1 Message Date
afe095286b fix: the unity serializer is well regarded 2024-05-22 06:33:16 +09:00
e7c0dad0d7 fix: epic trailing slash fail 2024-05-20 21:54:06 +00:00
8 changed files with 147 additions and 108 deletions

47
Inohara.DT/BatchManual.cs Normal file
View File

@ -0,0 +1,47 @@
using System;
namespace Inohara.DT;
[Serializable]
public struct BatchManual {
public BatchManualMeta meta;
public BatchManualScore[] scores;
}
[Serializable]
public struct BatchManualMeta {
public string game;
public string playtype;
public string service;
}
[Serializable]
public struct BatchManualScore {
public int score;
public string difficulty;
public UInt64 timeAchieved;
public string noteLamp;
public string bellLamp;
public string matchType;
public string identifier;
public BatchManualJudgements judgements;
public BatchManualOptional optional;
}
[Serializable]
public struct BatchManualJudgements {
public int cbreak;
public int breakMyBonesIWill;
public int hit;
public int miss;
}
[Serializable]
public struct BatchManualOptional {
public int fast;
public int slow;
public int bellCount;
public int totalBellCount;
public int damage;
public int platScore;
}

View File

@ -0,0 +1,34 @@
using System;
namespace Inohara.DT;
[Serializable]
public struct BatchManualPB {
public BatchManualPBMeta meta;
public BatchManualPBScore[] scores;
}
[Serializable]
public struct BatchManualPBMeta {
public string game;
public string playtype;
public string service;
}
[Serializable]
public struct BatchManualPBScore {
public int score;
public string difficulty;
public string noteLamp;
public string bellLamp;
public string matchType;
public string identifier;
public BatchManualPBJudgements judgements;
public BatchManualPBOptional optional;
}
[Serializable]
public struct BatchManualPBJudgements {}
[Serializable]
public struct BatchManualPBOptional {}

View File

@ -0,0 +1,19 @@
using System;
namespace Inohara.DT;
[Serializable]
public struct BatchResponse {
public bool success;
public BatchResponseBody body;
}
[Serializable]
public struct BatchResponseBody {
public string url;
}
[Serializable]
public struct BatchResponse2 {
public bool success;
}

View File

@ -0,0 +1,16 @@
using System;
namespace Inohara.DT;
[Serializable]
public struct StatusResponse {
public bool success;
public StatusBody body;
}
[Serializable]
public struct StatusBody {
public string version;
public string whoami;
public string[] permissions;
}

View File

@ -1,92 +0,0 @@
using System;
namespace Inohara;
/**
* Batch manual
*/
[Serializable]
public struct BatchManual {
public BatchMeta meta;
public BatchScore[] scores;
}
[Serializable]
public struct BatchMeta {
public string game;
public string playtype;
public string service;
}
[Serializable]
public struct BatchScore {
public int score;
public string difficulty;
public UInt64? timeAchieved;
public string noteLamp;
public string bellLamp;
public string matchType;
public string identifier;
public BatchJudgements judgements;
public BatchOptional optional;
}
[Serializable]
public struct BatchJudgements {
public int? cbreak;
public int? breakMyBonesIWill;
public int? hit;
public int? miss;
}
[Serializable]
public struct BatchOptional {
public int? fast;
public int? slow;
public int? bellCount;
public int? totalBellCount;
public int? damage;
public int? platScore;
}
/**
* BM response 1
*/
[Serializable]
public struct BatchResponse {
public bool success;
public BatchResponseBody body;
}
[Serializable]
public struct BatchResponseBody {
public string url;
}
/**
* BM response 2
*/
[Serializable]
public struct BatchResponse2 {
public bool success;
}
/**
* API status response
*/
[Serializable]
public struct StatusResponse {
public bool success;
public StatusBody body;
}
[Serializable]
public struct StatusBody {
public string version;
public string whoami;
public string[] permissions;
}

View File

@ -11,6 +11,7 @@ using MU3.Util;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using Inohara.DT;
namespace Inohara;
@ -31,7 +32,7 @@ public class Exporter: SingletonMonoBehaviour<Exporter> {
private readonly Dictionary<string, string> _tokens = new();
private string _currToken = "";
private readonly Font _arial = Resources.GetBuiltinResource<Font>("Arial.ttf");
private List<BatchScore> _scores = new();
private List<BatchManualScore> _scores = new();
private void Log(object o, bool drawText) {
Debug.Log("[Inohara] " + o.ToString());
@ -180,7 +181,7 @@ public class Exporter: SingletonMonoBehaviour<Exporter> {
req.SetRequestHeader("Content-Type", "application/json");
_scores.Add(Util.CreateScore(result, info));
var batch = Util.CreateBatch(_scores, "inohara");
var batch = Util.CreateBatch(_scores);
byte[] jsonToSend = new UTF8Encoding().GetBytes(batch);
req.uploadHandler = new UploadHandlerRaw(jsonToSend);
@ -233,7 +234,7 @@ public class Exporter: SingletonMonoBehaviour<Exporter> {
}
var userMusic = Singleton<UserManager>.instance.userMusic;
var scores = new List<BatchScore>();
var scores = new List<BatchManualPBScore>();
foreach(var x in userMusic.Values) {
foreach(var y in x.UserFumen) {
if(y != null) {
@ -241,7 +242,7 @@ public class Exporter: SingletonMonoBehaviour<Exporter> {
}
}
}
var batch = Util.CreateBatch(scores, "inohara-pb");
var batch = Util.CreatePBBatch(scores);
using StreamWriter writer = new(Path.Combine(Application.dataPath, "../batch-manual.json"));
writer.Write(batch);

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using Inohara.DT;
using MU3.Battle;
using MU3.DataStudio;
using MU3.Game;
@ -36,9 +37,9 @@ class Util {
};
}
public static BatchScore CreateScore(BattleResult result, SessionInfo info) {
public static BatchManualScore CreateScore(BattleResult result, SessionInfo info) {
var timestampSec = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
return new BatchScore {
return new BatchManualScore {
score = result.technicalScore,
difficulty = GetStringDiff(info.musicLevel),
timeAchieved = (ulong)timestampSec * 1000,
@ -46,7 +47,7 @@ class Util {
identifier = info.musicData.id.ToString(),
bellLamp = result.bellComboResult == BellComboResult.None ? "NONE" : "FULL BELL",
noteLamp = GetLamp(result),
optional = new BatchOptional() {
optional = new BatchManualOptional() {
fast = result.numNotesFast,
slow = result.numNotesLate,
bellCount = result.numBellCatch,
@ -54,7 +55,7 @@ class Util {
damage = result.countDamage,
platScore = result.platinumScore
},
judgements = new BatchJudgements() {
judgements = new BatchManualJudgements() {
cbreak = result.numNotesCBreak,
breakMyBonesIWill = result.numNotesBreak,
hit = result.numNotesHit,
@ -63,8 +64,8 @@ class Util {
};
}
public static BatchScore CreatePB(UserFumen fumen) {
return new BatchScore {
public static BatchManualPBScore CreatePB(UserFumen fumen) {
return new BatchManualPBScore {
score = fumen.TechScoreMax,
difficulty = GetStringDiff(fumen.Level),
matchType = "inGameID",
@ -77,21 +78,34 @@ class Util {
// basing this on score is ass but for the most part it will be accurate.
fumen.TechScoreMax >= 940000 ? "CLEAR" :
"LOSS",
optional = new BatchOptional() {},
judgements = new BatchJudgements() {}
optional = new BatchManualPBOptional() {},
judgements = new BatchManualPBJudgements() {}
};
}
public static string CreateBatch(List<BatchScore> scores, string name) {
public static string CreateBatch(List<BatchManualScore> scores) {
var bm = new BatchManual {
meta = new BatchMeta {
meta = new BatchManualMeta {
game = "ongeki",
playtype = "Single",
service = name
service = "inohara"
},
scores = scores.ToArray()
};
return JsonUtility.ToJson(bm).Replace("breakMyBonesIWill", "break");
}
public static string CreatePBBatch(List<BatchManualPBScore> scores) {
var bm = new BatchManualPB {
meta = new BatchManualPBMeta {
game = "ongeki",
playtype = "Single",
service = "inohara-pb"
},
scores = scores.ToArray()
};
return JsonUtility.ToJson(bm);
}
}

View File

@ -7,7 +7,7 @@ Enable = true
Timeout = 3
# Tachi instance base URL
BaseUrl = https://kamai.tachi.ac/
BaseUrl = https://kamai.tachi.ac
# Tachi status endpoint
Status = /api/v1/status