Skip to content

Commit

Permalink
Switched from SongDataCore to SongDetailsCache
Browse files Browse the repository at this point in the history
  • Loading branch information
ReadieFur committed Dec 29, 2021
1 parent 555b233 commit d21d89a
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 63 deletions.
6 changes: 3 additions & 3 deletions beatmods.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
DataPuller

## Mod Version
2.0.9
2.0.10

## Game Version
1.18.0
1.19.0

## Dependencies
BSIPA@4.2.0,BeatSaverSharp@3.0.2,websocket-sharp@1.0.4,SongCore@3.8.0,SongDataCore@1.4.5,SiraUtil@2.5.8
BSIPA@4.2.1,BeatSaverSharp@3.1.1,websocket-sharp@1.0.4,SongCore@3.9.0,SongDetailsCache@1.1.11,SiraUtil@3.0.2

## Category
Tweaks/Tools
Expand Down
4 changes: 2 additions & 2 deletions src/Client/MapData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ public static void Reset()
SongSubName = default;
SongAuthor = default;
Mapper = default;
BSRKey = default;
coverImage = default;
BSRKey = null;
coverImage = null;
CustomDifficultyLabel = default;
Length = default;
TimeScale = default;
Expand Down
92 changes: 40 additions & 52 deletions src/Client/MapEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
using UnityEngine;
using System.Timers;
using System.IO;
using SongDataCore.BeatStar;
using SongDetailsCache;
using SongDetailsCache.Structs;
using System.Collections.Generic;
using Zenject;
using HarmonyLib;
Expand Down Expand Up @@ -38,7 +39,7 @@ class MapEvents : IInitializable, IDisposable
[InjectOptional] private PauseController pauseController;
[InjectOptional] private StandardLevelGameplayManager standardLevelGameplayManager;

public MapEvents() { } //Injects made above now
public MapEvents() {} //Injects made above now

public void Initialize()
{
Expand Down Expand Up @@ -97,12 +98,13 @@ public void Initialize()

private bool MainRequiredObjectsExist()
{
if (!(scoreController is ScoreController)) { Plugin.Logger.Error("ScoreController not found"); return false; }
if (!(beatmapObjectManager is BeatmapObjectManager)) { Plugin.Logger.Error("BeatmapObjectManager not found"); return false; }
if (!(gameplayCoreSceneSetupData is GameplayCoreSceneSetupData)) { Plugin.Logger.Error("GameplayCoreSceneSetupData not found"); return false; }
if (!(audioTimeSyncController is AudioTimeSyncController)) { Plugin.Logger.Error("AudioTimeSyncController not found"); return false; }
if (!(gameEnergyCounter is GameEnergyCounter)) { Plugin.Logger.Error("GameEnergyCounter not found"); return false; }
return true;
bool objectsExist = true;
if (!(beatmapObjectManager is BeatmapObjectManager)) { Plugin.Logger.Error("BeatmapObjectManager not found"); objectsExist = false; }
if (!(gameplayCoreSceneSetupData is GameplayCoreSceneSetupData)) { Plugin.Logger.Error("GameplayCoreSceneSetupData not found"); objectsExist = false; }
if (!(audioTimeSyncController is AudioTimeSyncController)) { Plugin.Logger.Error("AudioTimeSyncController not found"); objectsExist = false; }
if (!(relativeScoreAndImmediateRankCounter is RelativeScoreAndImmediateRankCounter)) { Plugin.Logger.Error("RelativeScoreAndImmediateRankCounter not found"); objectsExist = false; }
if (!(gameEnergyCounter is GameEnergyCounter)) { Plugin.Logger.Error("GameEnergyCounter not found"); objectsExist = false; }
return objectsExist;
}

private bool IsLegacyReplay()
Expand Down Expand Up @@ -190,48 +192,41 @@ public void LevelLoaded()
MapData.CustomDifficultyLabel = difficultyData?._difficultyLabel ?? null;


SongDataCoreCurrent sdc = new SongDataCoreCurrent { available = isCustomLevel ? SongDataCore.Plugin.Songs.IsDataAvailable() : false };
if (sdc.available)
if (isCustomLevel)
{
BeatStarSong map;
SongDataCore.Plugin.Songs.Data.Songs.TryGetValue(mapHash, out map);
sdc.map = map;
if (sdc.map != null)
Task.Run(async () =>
{
BeatStarCharacteristics mapType;
switch (gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
SongDetails songDetails = await SongDetails.Init();
if (songDetails.songs.FindByHash(mapHash, out Song song))
{
case "Degree360":
mapType = BeatStarCharacteristics.Degree360;
break;
case "Degree90":
mapType = BeatStarCharacteristics.Degree90;
break;
default:
mapType = (BeatStarCharacteristics)Enum.Parse(typeof(BeatStarCharacteristics),
gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName);
break;
MapCharacteristic mapType;
switch (gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName)
{
case "Degree360":
mapType = MapCharacteristic.ThreeSixtyDegree;
break;
case "Degree90":
mapType = MapCharacteristic.NinetyDegree;
break;
default:
mapType = (MapCharacteristic)Enum.Parse(typeof(MapCharacteristic),

This comment has been minimized.

Copy link
@kinsi55

kinsi55 Dec 29, 2021

Should probably TryParse here instead and not move on if it fails because the Characteristic that mappers enter can be arbitrary

This comment has been minimized.

Copy link
@kinsi55

kinsi55 Dec 29, 2021

I'll probably add an overload next version that accepts a String characteristic and automatically handles the 90 / 360 degree chars

This comment has been minimized.

Copy link
@ReadieFur

ReadieFur Dec 29, 2021

Author Owner

alright thanks

gameplayCoreSceneSetupData.difficultyBeatmap.parentDifficultyBeatmapSet.beatmapCharacteristic.serializedName);
break;
}

if (song.GetDifficulty(
out SongDifficulty difficulty,
(MapDifficulty)gameplayCoreSceneSetupData.difficultyBeatmap.difficulty,
mapType
))
{
MapData.PP = difficulty.approximatePpValue;
MapData.Star = difficulty.stars;
MapData.Send();
}
}
Dictionary<string, BeatStarSongDifficultyStats> diffs = sdc.map.characteristics[mapType];

sdc.stats = diffs[MapData.Difficulty == "ExpertPlus" ? "Expert+" : MapData.Difficulty];
MapData.PP = sdc.stats.pp;
MapData.Star = sdc.stats.star;
}
else { sdc.available = false; }
}

/*if (sdc.available)
{
MapData.BSRKey = sdc.map.key;
if (levelData is CustomPreviewBeatmapLevel customLevel) { MapData.coverImage = GetBase64CoverImage(customLevel); }
else { getBeatsaverMap(); }
}
else { getBeatsaverMap(); }*/
getBeatsaverMap();
});

void getBeatsaverMap()
{
Task.Run(async () =>
{
BeatSaverSharp.Models.Beatmap beatmap = await beatSaver.BeatmapByHash(mapHash);
Expand Down Expand Up @@ -426,13 +421,6 @@ private static string GetBase64CoverImage(CustomPreviewBeatmapLevel level) //Tha
return string.Concat("data:image/", prefix, ";base64,", base64String);
}

private class SongDataCoreCurrent
{
public bool available { get; set; }
public BeatStarSong map { get; set; }
public BeatStarSongDifficultyStats stats { get; set; }
}

enum Modifiers
{
//noFail = -50,
Expand Down
9 changes: 4 additions & 5 deletions src/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public void Init(IPALogger _logger, Zenjector zenjector)
Logger.Debug("Logger initialized.");

#if DEBUG
zenjector.OnApp<TestInstaller>();
//zenjector.OnGame<TestInstaller>().Expose<ScoreController>();
zenjector.Install<TestInstaller>(Location.App);
#endif
webSocketServer = new Server.Server();
zenjector.OnGame<ClientInstaller>(false);
zenjector.On<GameCoreSceneSetup>().Pseudo((_) => {}).Expose<ScoreUIController>();
zenjector.Install<ClientInstaller>(Location.Player);
zenjector.Expose<ScoreUIController>("BSDP_ScoreUIController");
}

[OnStart]
Expand All @@ -38,7 +37,7 @@ public void OnApplicationStart()
[OnExit]
public void OnApplicationQuit()
{
webSocketServer?.Dispose(); //Do I need to do this even though the application is closing?
webSocketServer?.Dispose();
Logger.Debug("OnApplicationQuit");
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"BeatSaverSharp": "^3.1.1",
"websocket-sharp": "^1.0.4",
"SongCore": "^3.9.0",
"SongDataCore": "^1.4.6",
"SongDetailsCache": "^1.1.11",
"SiraUtil": "^3.0.2"
},
"links": {
Expand Down

0 comments on commit d21d89a

Please sign in to comment.