Files
ichni_Official/Assets/Scripts/Manager/ProjectLoader.cs

145 lines
6.3 KiB
C#
Raw Normal View History

2025-07-08 14:28:40 -04:00
using System;
2025-06-03 02:42:28 -04:00
using System.Collections;
using System.Collections.Generic;
2026-03-14 03:13:10 -04:00
using System.Linq;
2025-07-21 05:42:20 -04:00
using DG.Tweening;
2026-03-14 03:13:10 -04:00
using Ichni.RhythmGame;
2025-06-03 02:42:28 -04:00
using Ichni.RhythmGame.Beatmap;
using Sirenix.OdinInspector;
using UniRx;
using UnityEngine;
namespace Ichni
{
public class ProjectLoader
{
2025-08-22 14:54:40 -04:00
public float fakeLoadPercent;
public float realLoadPercent;
public float displayLoadPercent => Mathf.Min(realLoadPercent, fakeLoadPercent);
2025-07-08 14:28:40 -04:00
2025-06-03 02:42:28 -04:00
public static readonly ES3Settings SaveSettings = new ES3Settings
{
compressionType = ES3.CompressionType.None,
encryptionType = ES3.EncryptionType.None,
format = ES3.Format.JSON,
location = ES3.Location.Resources
};
private static readonly ES3Settings LoadSettings = new ES3Settings
{
compressionType = ES3.CompressionType.Gzip,
encryptionType = ES3.EncryptionType.AES,
encryptionPassword = "Soullies515",
format = ES3.Format.JSON,
location = ES3.Location.Resources
};
2025-07-21 05:42:20 -04:00
2025-06-03 02:42:28 -04:00
public void TestLoad()
{
2025-07-21 05:42:20 -04:00
string beatMapFolderPath = "Beatmaps/" + InformationTransistor.instance.chapter.chapterIndex +
"/" + InformationTransistor.instance.song.songName +
"/" + InformationTransistor.instance.difficulty.difficultyName;
2025-07-10 08:42:30 -04:00
LoadProjectInfo(beatMapFolderPath);
LoadSongInfo(beatMapFolderPath);
LoadCommandScripts(beatMapFolderPath);
2025-08-22 14:54:40 -04:00
2026-03-14 03:13:10 -04:00
GameManager.Instance.gameLoadingCanvas.MoveParts();
2025-07-10 08:42:30 -04:00
2026-03-14 03:13:10 -04:00
ThemeBundleManager.instance.LoadThemeBundles(GameManager.Instance.projectInformation.selectedThemeBundleList);
2025-08-22 14:54:40 -04:00
realLoadPercent = 0f;
fakeLoadPercent = 0f;
2025-07-08 14:28:40 -04:00
Observable.EveryUpdate()
2025-08-22 14:54:40 -04:00
.Where(_ => ThemeBundleManager.instance.waitingBundleAmount.Value == 0 &&
2026-03-14 03:13:10 -04:00
GameManager.Instance.gameLoadingCanvas.allPartsSet)
2025-07-08 14:28:40 -04:00
.First()
.Subscribe(_ =>
{
2025-07-10 08:42:30 -04:00
LoadBeatMap(beatMapFolderPath);
2025-07-21 05:42:20 -04:00
2025-08-22 14:54:40 -04:00
IDisposable fakeLoadObserver = Observable.EveryUpdate().Subscribe(_ =>
{
fakeLoadPercent += Time.deltaTime * 0.2f;
2026-03-14 03:13:10 -04:00
GameManager.Instance.gameLoadingCanvas.SetProgress(displayLoadPercent * 100f);
2025-08-22 14:54:40 -04:00
});
2025-07-21 05:42:20 -04:00
Observable.EveryUpdate()
2026-03-14 03:13:10 -04:00
.Where(_ => ((BeatmapContainer_BM)GameManager.Instance.beatmapContainer.matchedBM).remainingElementAmount.Value == 0 &&
2025-08-22 14:54:40 -04:00
fakeLoadPercent >= 1f)
2025-07-21 05:42:20 -04:00
.First()
.Subscribe(_ =>
{
2025-08-22 14:54:40 -04:00
fakeLoadObserver.Dispose();
Observable.Timer(TimeSpan.FromSeconds(1f)).First().Subscribe(_ =>
2025-07-21 05:42:20 -04:00
{
2026-03-14 03:13:10 -04:00
GameManager.Instance.gameLoadingCanvas.FadeOut();
GameManager.Instance.songPlayer.isLoading = false;
2025-08-22 14:54:40 -04:00
2026-03-14 03:13:10 -04:00
GameManager.Instance.beatmapContainer.gameElementList.ForEach(element => element.BeforeStart());
2025-08-22 14:54:40 -04:00
2026-03-14 03:13:10 -04:00
GameManager.Instance.gameUICanvas.readyText.DOFade(1, 0.5f)
2025-08-22 14:54:40 -04:00
.SetLoops(4, LoopType.Yoyo).SetEase(Ease.InOutFlash).Play();
Observable.Timer(TimeSpan.FromSeconds(2)).First().Subscribe(_ =>
2025-08-11 14:04:06 -04:00
{
2026-03-14 03:13:10 -04:00
GameManager.Instance.songPlayer.isDelaying = true;
GameManager.Instance.songPlayer.isStarting = false;
2025-08-22 14:54:40 -04:00
Observable.NextFrame().Subscribe(_ =>
{
2026-03-14 03:13:10 -04:00
GameManager.Instance.timeDurations = GameManager.Instance.beatmapContainer.gameElementList
.Select(x=> (x as IHaveTimeDurationSubmodule)?.timeDurationSubmodule)
.Where(x => x != null && x.startTime > 0 && x.endTime < GameManager.Instance.songInformation.songLength).ToList();
GameManager.Instance.beatmapContainer.gameElementList.ForEach(element => element.WhenStart());
2025-08-22 14:54:40 -04:00
});
2025-08-11 14:04:06 -04:00
});
2025-07-21 05:42:20 -04:00
});
});
2025-07-08 14:28:40 -04:00
});
2025-07-21 05:42:20 -04:00
/*Observable.EveryUpdate()
2026-03-14 03:13:10 -04:00
.Where(_ => !GameManager.Instance.audioManager.isStarting)
2025-07-08 14:28:40 -04:00
.First()
.Subscribe(_ =>
2025-06-03 02:42:28 -04:00
{
2025-07-21 05:42:20 -04:00
});*/
2025-06-03 02:42:28 -04:00
}
public void Load(string chapterName, string musicName, string difficultyName)
{
string beatMapFolderPath = "Beatmaps/" + chapterName + "/" + musicName + "/" + difficultyName;
LoadProjectInfo(beatMapFolderPath);
LoadSongInfo(beatMapFolderPath);
LoadCommandScripts(beatMapFolderPath);
LoadBeatMap(beatMapFolderPath);
}
private void LoadProjectInfo(string beatMapFolderPath)
{
string projectInfoPath = beatMapFolderPath + "/ProjectInfo.bytes";
ES3.Load<ProjectInformation_BM>("ProjectInformation", projectInfoPath, LoadSettings).ExecuteBM();
}
private void LoadSongInfo(string beatMapFolderPath)
{
string songInfoPath = beatMapFolderPath + "/SongInfo.bytes";
ES3.Load<SongInformation_BM>("SongInformation",songInfoPath, LoadSettings).ExecuteBM();
}
private void LoadBeatMap(string beatMapFolderPath)
{
2025-07-08 14:28:40 -04:00
string beatmapPath = beatMapFolderPath + "/Beatmap.bytes";
ES3.Load<BeatmapContainer_BM>("Beatmap", beatmapPath, LoadSettings).ExecuteBM();
2025-06-03 02:42:28 -04:00
}
private void LoadCommandScripts(string beatMapFolderPath)
{
string commandScriptsPath = beatMapFolderPath + "/CommandScripts.bytes";
ES3.Load<CommandScripts_BM>("CommandScripts", commandScriptsPath, LoadSettings).ExecuteBM();
}
}
}