2021-12-19 04:10:43 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using Starpelly;
|
|
|
|
using Newtonsoft.Json;
|
2022-03-14 14:21:05 +00:00
|
|
|
using HeavenStudio.Games;
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
|
|
|
public class GameManager : MonoBehaviour
|
|
|
|
{
|
2022-01-21 01:24:30 +00:00
|
|
|
[Header("Lists")]
|
2022-08-21 23:46:45 +00:00
|
|
|
public DynamicBeatmap Beatmap = new DynamicBeatmap();
|
|
|
|
[HideInInspector] public List<DynamicBeatmap.DynamicEntity> playerEntities = new List<DynamicBeatmap.DynamicEntity>();
|
2022-01-21 01:24:30 +00:00
|
|
|
private List<GameObject> preloadedGames = new List<GameObject>();
|
|
|
|
public List<GameObject> SoundObjects = new List<GameObject>();
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-01-21 01:24:30 +00:00
|
|
|
[Header("Components")]
|
2023-01-12 01:42:12 +00:00
|
|
|
public string txt;
|
|
|
|
public string ext;
|
2022-06-04 03:15:05 +00:00
|
|
|
public Camera GameCamera, CursorCam, OverlayCamera;
|
2022-09-23 02:05:04 +00:00
|
|
|
public GameObject GameLetterbox;
|
2021-12-26 01:04:23 +00:00
|
|
|
public CircleCursor CircleCursor;
|
2022-01-21 01:24:30 +00:00
|
|
|
[HideInInspector] public GameObject GamesHolder;
|
2022-02-08 01:07:03 +00:00
|
|
|
public Games.Global.Flash fade;
|
2022-06-04 03:15:05 +00:00
|
|
|
public GameObject textbox;
|
2022-01-21 01:24:30 +00:00
|
|
|
|
2021-12-24 03:36:16 +00:00
|
|
|
[Header("Games")]
|
2022-03-07 02:37:27 +00:00
|
|
|
public string currentGame;
|
2022-01-21 01:24:30 +00:00
|
|
|
Coroutine currentGameSwitchIE;
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-01-21 01:24:30 +00:00
|
|
|
[Header("Properties")]
|
2022-09-18 20:48:14 +00:00
|
|
|
public int currentEvent, currentTempoEvent, currentVolumeEvent, currentSectionEvent,
|
2023-01-05 04:04:31 +00:00
|
|
|
currentPreEvent, currentPreSwitch, currentPreSequence;
|
2022-09-18 20:48:14 +00:00
|
|
|
public float endBeat;
|
2022-01-21 01:24:30 +00:00
|
|
|
public float startOffset;
|
|
|
|
public bool playOnStart;
|
|
|
|
public float startBeat;
|
2022-02-20 13:57:20 +00:00
|
|
|
[NonSerialized] public GameObject currentGameO;
|
2022-01-23 03:40:53 +00:00
|
|
|
public bool autoplay;
|
2022-03-01 07:27:49 +00:00
|
|
|
public bool canInput = true;
|
2022-09-18 20:48:14 +00:00
|
|
|
public DynamicBeatmap.ChartSection currentSection, nextSection;
|
|
|
|
public float sectionProgress { get {
|
|
|
|
if (currentSection == null) return 0;
|
|
|
|
if (nextSection == null) return (Conductor.instance.songPositionInBeats - currentSection.beat) / (endBeat - currentSection.beat);
|
|
|
|
return (Conductor.instance.songPositionInBeats - currentSection.beat) / (nextSection.beat - currentSection.beat);
|
|
|
|
}}
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2023-01-05 04:04:31 +00:00
|
|
|
public event Action<float> onBeatChanged;
|
2022-09-18 20:48:14 +00:00
|
|
|
public event Action<DynamicBeatmap.ChartSection> onSectionChange;
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-01-30 23:40:12 +00:00
|
|
|
public int BeatmapEntities()
|
|
|
|
{
|
2022-09-18 20:48:14 +00:00
|
|
|
return Beatmap.entities.Count + Beatmap.tempoChanges.Count + Beatmap.volumeChanges.Count + Beatmap.beatmapSections.Count;
|
2022-01-30 23:40:12 +00:00
|
|
|
}
|
2021-12-31 14:46:11 +00:00
|
|
|
|
2022-01-21 01:24:30 +00:00
|
|
|
public static GameManager instance { get; private set; }
|
|
|
|
private EventCaller eventCaller;
|
2022-01-06 00:11:33 +00:00
|
|
|
|
2023-01-14 04:53:25 +00:00
|
|
|
List<int> inputOffsetSamples = new List<int>();
|
|
|
|
float averageInputOffset = 0;
|
|
|
|
public float AvgInputOffset
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return averageInputOffset;
|
|
|
|
}
|
|
|
|
set
|
|
|
|
{
|
|
|
|
inputOffsetSamples.Add((int)value);
|
|
|
|
averageInputOffset = (float)inputOffsetSamples.Average();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
2022-02-05 03:48:35 +00:00
|
|
|
// autoplay = true;
|
2021-12-21 01:10:49 +00:00
|
|
|
instance = this;
|
|
|
|
}
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
public void Init()
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2022-06-12 19:32:00 +00:00
|
|
|
currentPreEvent= 0;
|
|
|
|
currentPreSwitch = 0;
|
2023-01-05 04:04:31 +00:00
|
|
|
currentPreSequence = 0;
|
2022-06-12 19:32:00 +00:00
|
|
|
|
2022-02-02 08:36:20 +00:00
|
|
|
this.transform.localScale = new Vector3(30000000, 30000000);
|
2022-06-12 19:32:00 +00:00
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
SpriteRenderer sp = this.gameObject.AddComponent<SpriteRenderer>();
|
|
|
|
sp.enabled = false;
|
|
|
|
sp.color = Color.black;
|
|
|
|
sp.sprite = Resources.Load<Sprite>("Sprites/GeneralPurpose/Square");
|
|
|
|
sp.sortingOrder = 30000;
|
2022-03-08 00:21:27 +00:00
|
|
|
gameObject.layer = LayerMask.NameToLayer("Flash");
|
2022-02-08 01:07:03 +00:00
|
|
|
|
|
|
|
GameObject fade = new GameObject();
|
|
|
|
this.fade = fade.AddComponent<Games.Global.Flash>();
|
2021-12-19 04:10:43 +00:00
|
|
|
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
GlobalGameManager.Init();
|
2021-12-23 00:08:35 +00:00
|
|
|
|
2022-01-03 22:42:43 +00:00
|
|
|
eventCaller = this.gameObject.AddComponent<EventCaller>();
|
|
|
|
eventCaller.GamesHolder = GamesHolder.transform;
|
2021-12-23 00:08:35 +00:00
|
|
|
eventCaller.Init();
|
2021-12-23 02:28:05 +00:00
|
|
|
Conductor.instance.SetBpm(Beatmap.bpm);
|
2022-03-19 12:46:38 +00:00
|
|
|
Conductor.instance.SetVolume(Beatmap.musicVolume);
|
2022-02-24 14:02:21 +00:00
|
|
|
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
2021-12-23 02:28:05 +00:00
|
|
|
|
2022-06-04 03:15:05 +00:00
|
|
|
GameObject textbox = Instantiate(Resources.Load<GameObject>("Prefabs/Common/Textbox"));
|
|
|
|
textbox.name = "Textbox";
|
2023-01-12 01:42:12 +00:00
|
|
|
if (txt != null && ext != null)
|
2022-01-15 22:52:53 +00:00
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
LoadRemix(txt, ext);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NewRemix();
|
2022-01-15 22:52:53 +00:00
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
SortEventsList();
|
2021-12-28 02:36:27 +00:00
|
|
|
|
|
|
|
if (Beatmap.entities.Count >= 1)
|
|
|
|
{
|
2022-01-29 23:30:29 +00:00
|
|
|
SetCurrentGame(Beatmap.entities[0].datamodel.Split(0));
|
|
|
|
SetGame(Beatmap.entities[0].datamodel.Split(0));
|
2021-12-28 02:36:27 +00:00
|
|
|
}
|
2022-01-30 09:09:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetGame("noGame");
|
|
|
|
}
|
2023-01-12 01:42:12 +00:00
|
|
|
|
|
|
|
if (playOnStart)
|
|
|
|
{
|
|
|
|
Play(startBeat);
|
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-02-26 03:41:32 +00:00
|
|
|
public void NewRemix()
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
Beatmap = new DynamicBeatmap();
|
2022-02-26 03:41:32 +00:00
|
|
|
Beatmap.bpm = 120f;
|
2022-03-19 12:46:38 +00:00
|
|
|
Beatmap.musicVolume = 100;
|
2022-02-26 03:41:32 +00:00
|
|
|
Beatmap.firstBeatOffset = 0f;
|
2022-02-26 19:06:52 +00:00
|
|
|
Conductor.instance.musicSource.clip = null;
|
2022-02-26 03:41:32 +00:00
|
|
|
}
|
|
|
|
|
2022-08-21 23:46:45 +00:00
|
|
|
public void LoadRemix(string json = "", string type = "riq", int version = 0)
|
2022-01-30 12:03:37 +00:00
|
|
|
{
|
|
|
|
|
2022-02-26 03:41:32 +00:00
|
|
|
if (json != "")
|
|
|
|
{
|
2022-08-21 23:46:45 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case "tengoku":
|
|
|
|
case "rhmania":
|
|
|
|
Beatmap toConvert = JsonConvert.DeserializeObject<Beatmap>(json);
|
|
|
|
Beatmap = DynamicBeatmap.BeatmapConverter(toConvert);
|
|
|
|
break;
|
|
|
|
case "riq":
|
|
|
|
Beatmap = JsonConvert.DeserializeObject<DynamicBeatmap>(json);
|
2022-08-22 23:14:38 +00:00
|
|
|
Beatmap.PostProcess();
|
2022-08-21 23:46:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NewRemix();
|
|
|
|
break;
|
|
|
|
}
|
2022-02-26 03:41:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NewRemix();
|
|
|
|
}
|
2022-08-22 23:14:38 +00:00
|
|
|
SortEventsList();
|
2022-01-30 12:03:37 +00:00
|
|
|
Conductor.instance.SetBpm(Beatmap.bpm);
|
2022-03-19 12:46:38 +00:00
|
|
|
Conductor.instance.SetVolume(Beatmap.musicVolume);
|
2022-02-24 14:02:21 +00:00
|
|
|
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
2022-02-02 01:11:42 +00:00
|
|
|
Stop(0);
|
|
|
|
SetCurrentEventToClosest(0);
|
2022-01-30 12:03:37 +00:00
|
|
|
|
|
|
|
if (Beatmap.entities.Count >= 1)
|
|
|
|
{
|
|
|
|
SetCurrentGame(Beatmap.entities[0].datamodel.Split(0));
|
|
|
|
SetGame(Beatmap.entities[0].datamodel.Split(0));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetGame("noGame");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 19:32:00 +00:00
|
|
|
public void SeekAheadAndPreload(float start, float seekTime = 8f)
|
|
|
|
{
|
|
|
|
//seek ahead to preload games that have assetbundles
|
|
|
|
//check game switches first
|
|
|
|
var gameSwitchs = Beatmap.entities.FindAll(c => c.datamodel.Split(1) == "switchGame");
|
|
|
|
if (currentPreSwitch < gameSwitchs.Count && currentPreSwitch >= 0)
|
|
|
|
{
|
|
|
|
if (start + seekTime >= gameSwitchs[currentPreSwitch].beat)
|
|
|
|
{
|
|
|
|
string gameName = gameSwitchs[currentPreSwitch].datamodel.Split(2);
|
|
|
|
var inf = GetGameInfo(gameName);
|
|
|
|
if (inf.usesAssetBundle && !inf.AssetsLoaded)
|
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
2022-06-12 19:32:00 +00:00
|
|
|
StartCoroutine(inf.LoadCommonAssetBundleAsync());
|
|
|
|
StartCoroutine(inf.LoadLocalizedAssetBundleAsync());
|
|
|
|
}
|
|
|
|
currentPreSwitch++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//then check game entities
|
|
|
|
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
|
|
|
|
if (currentPreEvent < Beatmap.entities.Count && currentPreEvent >= 0)
|
|
|
|
{
|
|
|
|
if (start + seekTime >= entities[currentPreEvent])
|
|
|
|
{
|
|
|
|
var entitiesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentPreEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0])));
|
2023-01-12 01:42:12 +00:00
|
|
|
foreach (DynamicBeatmap.DynamicEntity entity in entitiesAtSameBeat)
|
2022-06-12 19:32:00 +00:00
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
string gameName = entity.datamodel.Split('/')[0];
|
2022-06-12 19:32:00 +00:00
|
|
|
var inf = GetGameInfo(gameName);
|
|
|
|
if (inf.usesAssetBundle && !inf.AssetsLoaded)
|
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
Debug.Log($"ASYNC loading assetbundles for game {gameName}");
|
2022-06-12 19:32:00 +00:00
|
|
|
StartCoroutine(inf.LoadCommonAssetBundleAsync());
|
|
|
|
StartCoroutine(inf.LoadLocalizedAssetBundleAsync());
|
|
|
|
}
|
2023-01-12 01:42:12 +00:00
|
|
|
currentPreEvent++;
|
2022-06-12 19:32:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
public void SeekAheadAndDoPreEvent(float start, float seekTime = 2f)
|
2023-01-05 04:04:31 +00:00
|
|
|
{
|
|
|
|
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
|
|
|
|
if (currentPreSequence < Beatmap.entities.Count && currentPreSequence >= 0)
|
|
|
|
{
|
|
|
|
if (start + seekTime >= entities[currentPreSequence])
|
|
|
|
{
|
|
|
|
float beat = Beatmap.entities[currentPreSequence].beat;
|
|
|
|
var entitiesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentPreSequence].beat);
|
|
|
|
foreach (DynamicBeatmap.DynamicEntity entity in entitiesAtSameBeat)
|
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
string gameName = entity.datamodel.Split('/')[0];
|
|
|
|
var inf = GetGameInfo(gameName);
|
|
|
|
if (inf.usesAssetBundle && inf.AssetsLoaded && !inf.SequencesPreloaded)
|
|
|
|
{
|
|
|
|
Debug.Log($"Preloading game {gameName}");
|
|
|
|
PreloadGameSequences(gameName);
|
|
|
|
}
|
2023-01-05 04:04:31 +00:00
|
|
|
eventCaller.CallPreEvent(entity);
|
2023-01-12 01:42:12 +00:00
|
|
|
currentPreSequence++;
|
2023-01-05 04:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:28:56 +00:00
|
|
|
// LateUpdate works a bit better(?) but causes some bugs (like issues with bop animations).
|
|
|
|
private void Update()
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2022-07-24 00:36:10 +00:00
|
|
|
PlayerInput.UpdateInputControllers();
|
2022-07-19 22:50:35 +00:00
|
|
|
|
2022-06-06 16:54:57 +00:00
|
|
|
if (BeatmapEntities() < 1) //bruh really you forgot to ckeck tempo changes
|
2021-12-21 01:10:49 +00:00
|
|
|
return;
|
2022-01-07 11:36:23 +00:00
|
|
|
if (!Conductor.instance.isPlaying)
|
2021-12-30 12:17:22 +00:00
|
|
|
return;
|
2022-09-18 20:48:14 +00:00
|
|
|
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2021-12-23 00:08:35 +00:00
|
|
|
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
List<float> tempoChanges = Beatmap.tempoChanges.Select(c => c.beat).ToList();
|
2022-06-09 03:35:15 +00:00
|
|
|
if (currentTempoEvent < Beatmap.tempoChanges.Count && currentTempoEvent >= 0)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.songPositionInBeats >= tempoChanges[currentTempoEvent])
|
|
|
|
{
|
|
|
|
Conductor.instance.SetBpm(Beatmap.tempoChanges[currentTempoEvent].tempo);
|
|
|
|
currentTempoEvent++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
List<float> volumeChanges = Beatmap.volumeChanges.Select(c => c.beat).ToList();
|
|
|
|
if (currentVolumeEvent < Beatmap.volumeChanges.Count && currentVolumeEvent >= 0)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.songPositionInBeats >= volumeChanges[currentVolumeEvent])
|
|
|
|
{
|
|
|
|
Conductor.instance.SetVolume(Beatmap.volumeChanges[currentVolumeEvent].volume);
|
|
|
|
currentVolumeEvent++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
List<float> chartSections = Beatmap.beatmapSections.Select(c => c.beat).ToList();
|
|
|
|
if (currentSectionEvent < Beatmap.beatmapSections.Count && currentSectionEvent >= 0)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.songPositionInBeats >= chartSections[currentSectionEvent])
|
|
|
|
{
|
|
|
|
Debug.Log("Section " + Beatmap.beatmapSections[currentSectionEvent].sectionName + " started");
|
|
|
|
currentSection = Beatmap.beatmapSections[currentSectionEvent];
|
|
|
|
currentSectionEvent++;
|
|
|
|
if (currentSectionEvent < Beatmap.beatmapSections.Count)
|
|
|
|
nextSection = Beatmap.beatmapSections[currentSectionEvent];
|
|
|
|
else
|
|
|
|
nextSection = null;
|
|
|
|
onSectionChange?.Invoke(currentSection);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-12 19:32:00 +00:00
|
|
|
float seekTime = 8f;
|
|
|
|
//seek ahead to preload games that have assetbundles
|
|
|
|
SeekAheadAndPreload(Conductor.instance.songPositionInBeats, seekTime);
|
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
SeekAheadAndDoPreEvent(Conductor.instance.songPositionInBeats, 2f);
|
2023-01-05 04:04:31 +00:00
|
|
|
|
2021-12-23 00:08:35 +00:00
|
|
|
if (currentEvent < Beatmap.entities.Count && currentEvent >= 0)
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2022-01-16 19:23:46 +00:00
|
|
|
if (Conductor.instance.songPositionInBeats >= entities[currentEvent] /*&& SongPosLessThanClipLength(Conductor.instance.songPositionInBeats)*/)
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2021-12-26 05:11:54 +00:00
|
|
|
// allows for multiple events on the same beat to be executed on the same frame, so no more 1-frame delay
|
2023-01-12 01:42:12 +00:00
|
|
|
var entitiesAtSameBeat = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && !EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0])));
|
2022-02-03 03:58:08 +00:00
|
|
|
var fxEntities = Beatmap.entities.FindAll(c => c.beat == Beatmap.entities[currentEvent].beat && EventCaller.FXOnlyGames().Contains(EventCaller.instance.GetMinigame(c.datamodel.Split('/')[0])));
|
2021-12-31 14:46:11 +00:00
|
|
|
|
2022-02-03 03:58:08 +00:00
|
|
|
// FX entities should ALWAYS execute before gameplay entities
|
|
|
|
for (int i = 0; i < fxEntities.Count; i++)
|
2021-12-31 14:46:11 +00:00
|
|
|
{
|
2022-03-02 21:59:35 +00:00
|
|
|
eventCaller.CallEvent(fxEntities[i], true);
|
2022-01-31 05:02:36 +00:00
|
|
|
currentEvent++;
|
2021-12-31 14:46:11 +00:00
|
|
|
}
|
2021-12-23 00:08:35 +00:00
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
foreach (DynamicBeatmap.DynamicEntity entity in entitiesAtSameBeat)
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
2022-01-15 17:45:08 +00:00
|
|
|
// if game isn't loaded, preload game so whatever event that would be called will still run outside if needed
|
2023-01-12 01:42:12 +00:00
|
|
|
if (entity.datamodel.Split('/')[0] != currentGame)
|
2021-12-31 14:46:11 +00:00
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
eventCaller.CallEvent(entity, false);
|
2022-03-02 21:59:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
eventCaller.CallEvent(entity, true);
|
2021-12-31 14:46:11 +00:00
|
|
|
}
|
2022-01-31 04:59:15 +00:00
|
|
|
|
|
|
|
// Thank you to @shshwdr for bring this to my attention
|
|
|
|
currentEvent++;
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
2022-01-31 05:02:36 +00:00
|
|
|
// currentEvent += gameManagerEntities.Count;
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-01 07:27:49 +00:00
|
|
|
public void ToggleInputs(bool inputs)
|
|
|
|
{
|
|
|
|
canInput = inputs;
|
|
|
|
}
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
#region Play Events
|
|
|
|
|
|
|
|
public void Play(float beat)
|
|
|
|
{
|
2022-03-01 07:27:49 +00:00
|
|
|
canInput = true;
|
2023-01-14 04:53:25 +00:00
|
|
|
inputOffsetSamples.Clear();
|
|
|
|
averageInputOffset = 0;
|
2022-01-14 00:35:41 +00:00
|
|
|
StartCoroutine(PlayCo(beat));
|
2022-02-08 01:07:03 +00:00
|
|
|
onBeatChanged?.Invoke(beat);
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerator PlayCo(float beat)
|
|
|
|
{
|
|
|
|
yield return null;
|
2022-01-14 02:33:51 +00:00
|
|
|
bool paused = Conductor.instance.isPaused;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
|
|
|
Conductor.instance.SetBpm(Beatmap.bpm);
|
2022-03-19 12:46:38 +00:00
|
|
|
Conductor.instance.SetVolume(Beatmap.musicVolume);
|
2022-02-24 14:02:21 +00:00
|
|
|
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
2022-01-28 02:50:57 +00:00
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
Conductor.instance.Play(beat);
|
2022-01-14 02:33:51 +00:00
|
|
|
if (!paused)
|
|
|
|
{
|
|
|
|
SetCurrentEventToClosest(beat);
|
|
|
|
}
|
2022-01-21 01:24:30 +00:00
|
|
|
|
2022-03-07 09:16:31 +00:00
|
|
|
KillAllSounds();
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
Minigame miniGame = currentGameO.GetComponent<Minigame>();
|
|
|
|
if (miniGame != null)
|
|
|
|
miniGame.OnPlay(beat);
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Pause()
|
|
|
|
{
|
|
|
|
Conductor.instance.Pause();
|
2022-03-07 09:41:07 +00:00
|
|
|
KillAllSounds();
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Stop(float beat)
|
|
|
|
{
|
|
|
|
Conductor.instance.Stop(beat);
|
|
|
|
SetCurrentEventToClosest(beat);
|
2022-02-08 01:07:03 +00:00
|
|
|
onBeatChanged?.Invoke(beat);
|
2022-03-07 09:16:31 +00:00
|
|
|
KillAllSounds();
|
2023-01-12 01:42:12 +00:00
|
|
|
|
2023-01-14 04:53:25 +00:00
|
|
|
Debug.Log($"Average input offset for playthrough: {averageInputOffset}ms");
|
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
if (playOnStart)
|
|
|
|
{
|
|
|
|
Play(0);
|
|
|
|
}
|
2022-03-07 09:16:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void KillAllSounds()
|
|
|
|
{
|
|
|
|
for (int i = 0; i < SoundObjects.Count; i++)
|
|
|
|
Destroy(SoundObjects[i].gameObject);
|
2022-03-07 09:41:07 +00:00
|
|
|
|
|
|
|
SoundObjects.Clear();
|
2022-01-14 00:35:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region List Functions
|
|
|
|
|
2021-12-21 01:10:49 +00:00
|
|
|
public void SortEventsList()
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2021-12-23 00:08:35 +00:00
|
|
|
Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat));
|
2022-01-28 02:50:57 +00:00
|
|
|
Beatmap.tempoChanges.Sort((x, y) => x.beat.CompareTo(y.beat));
|
2022-08-22 23:14:38 +00:00
|
|
|
Beatmap.volumeChanges.Sort((x, y) => x.beat.CompareTo(y.beat));
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
|
2021-12-31 14:46:11 +00:00
|
|
|
public void SetCurrentEventToClosest(float beat)
|
2021-12-19 04:10:43 +00:00
|
|
|
{
|
2022-01-09 23:35:55 +00:00
|
|
|
SortEventsList();
|
2022-02-08 01:07:03 +00:00
|
|
|
onBeatChanged?.Invoke(beat);
|
2021-12-23 00:08:35 +00:00
|
|
|
if (Beatmap.entities.Count > 0)
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2021-12-23 00:08:35 +00:00
|
|
|
List<float> entities = Beatmap.entities.Select(c => c.beat).ToList();
|
2021-12-31 14:46:11 +00:00
|
|
|
|
2022-01-07 23:51:08 +00:00
|
|
|
currentEvent = entities.IndexOf(Mathp.GetClosestInList(entities, beat));
|
2022-06-12 19:32:00 +00:00
|
|
|
currentPreEvent = entities.IndexOf(Mathp.GetClosestInList(entities, beat));
|
2023-01-05 04:04:31 +00:00
|
|
|
currentPreSequence = entities.IndexOf(Mathp.GetClosestInList(entities, beat));
|
2021-12-31 14:46:11 +00:00
|
|
|
|
2022-01-15 18:46:50 +00:00
|
|
|
var gameSwitchs = Beatmap.entities.FindAll(c => c.datamodel.Split(1) == "switchGame");
|
2022-01-15 17:45:08 +00:00
|
|
|
|
|
|
|
string newGame = Beatmap.entities[currentEvent].datamodel.Split(0);
|
2022-01-07 23:51:08 +00:00
|
|
|
|
2022-01-15 17:45:08 +00:00
|
|
|
if (gameSwitchs.Count > 0)
|
2021-12-31 14:46:11 +00:00
|
|
|
{
|
2022-01-15 18:46:50 +00:00
|
|
|
int index = gameSwitchs.FindIndex(c => c.beat == Mathp.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat));
|
2022-06-12 19:32:00 +00:00
|
|
|
currentPreSwitch = index;
|
2022-01-15 18:46:50 +00:00
|
|
|
var closestGameSwitch = gameSwitchs[index];
|
|
|
|
if (closestGameSwitch.beat <= beat)
|
|
|
|
{
|
|
|
|
newGame = closestGameSwitch.datamodel.Split(2);
|
|
|
|
}
|
|
|
|
else if (closestGameSwitch.beat > beat)
|
|
|
|
{
|
2022-01-30 01:26:53 +00:00
|
|
|
if (index == 0)
|
2022-01-15 18:46:50 +00:00
|
|
|
{
|
2022-01-30 01:26:53 +00:00
|
|
|
newGame = Beatmap.entities[0].datamodel.Split(0);
|
2022-01-15 18:46:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-01-30 01:26:53 +00:00
|
|
|
if (index - 1 >= 0)
|
|
|
|
{
|
|
|
|
newGame = gameSwitchs[index - 1].datamodel.Split(2);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newGame = Beatmap.entities[Beatmap.entities.IndexOf(closestGameSwitch) - 1].datamodel.Split(0);
|
|
|
|
}
|
2022-01-15 18:46:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// newGame = gameSwitchs[gameSwitchs.IndexOf(gameSwitchs.Find(c => c.beat == Mathp.GetClosestInList(gameSwitchs.Select(c => c.beat).ToList(), beat)))].datamodel.Split(2);
|
2022-01-15 17:45:08 +00:00
|
|
|
}
|
2022-01-07 23:51:08 +00:00
|
|
|
|
2022-02-03 03:58:08 +00:00
|
|
|
if (!GetGameInfo(newGame).fxOnly)
|
|
|
|
{
|
|
|
|
SetGame(newGame);
|
|
|
|
}
|
2022-09-18 20:48:14 +00:00
|
|
|
|
|
|
|
List<DynamicBeatmap.DynamicEntity> allEnds = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "end" });
|
|
|
|
if (allEnds.Count > 0)
|
|
|
|
endBeat = allEnds.Select(c => c.beat).Min();
|
|
|
|
else
|
|
|
|
endBeat = Conductor.instance.SongLengthInBeats();
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
2022-01-30 09:09:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
SetGame("noGame");
|
2022-09-18 20:48:14 +00:00
|
|
|
endBeat = Conductor.instance.SongLengthInBeats();
|
2022-01-30 09:09:26 +00:00
|
|
|
}
|
2022-01-28 02:50:57 +00:00
|
|
|
|
|
|
|
if (Beatmap.tempoChanges.Count > 0)
|
|
|
|
{
|
2022-06-06 16:54:57 +00:00
|
|
|
currentTempoEvent = 0;
|
2022-01-28 02:50:57 +00:00
|
|
|
List<float> tempoChanges = Beatmap.tempoChanges.Select(c => c.beat).ToList();
|
|
|
|
|
2022-06-06 16:54:57 +00:00
|
|
|
//for tempo changes, just go over all of em until the last one we pass
|
|
|
|
for (int t = 0; t < tempoChanges.Count; t++)
|
|
|
|
{
|
|
|
|
// Debug.Log("checking tempo event " + t + " against beat " + beat + "( tc beat " + tempoChanges[t] + ")");
|
|
|
|
if (tempoChanges[t] > beat)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentTempoEvent = t;
|
|
|
|
}
|
|
|
|
// Debug.Log("currentTempoEvent is now " + currentTempoEvent);
|
2022-01-28 02:50:57 +00:00
|
|
|
}
|
2022-06-12 19:32:00 +00:00
|
|
|
|
2022-09-18 20:48:14 +00:00
|
|
|
if (Beatmap.volumeChanges.Count > 0)
|
|
|
|
{
|
|
|
|
currentVolumeEvent = 0;
|
|
|
|
List<float> volumeChanges = Beatmap.volumeChanges.Select(c => c.beat).ToList();
|
|
|
|
|
|
|
|
for (int t = 0; t < volumeChanges.Count; t++)
|
|
|
|
{
|
|
|
|
if (volumeChanges[t] > beat)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentVolumeEvent = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
currentSection = null;
|
|
|
|
nextSection = null;
|
|
|
|
if (Beatmap.beatmapSections.Count > 0)
|
|
|
|
{
|
|
|
|
currentSectionEvent = 0;
|
|
|
|
List<float> beatmapSections = Beatmap.beatmapSections.Select(c => c.beat).ToList();
|
|
|
|
|
|
|
|
for (int t = 0; t < beatmapSections.Count; t++)
|
|
|
|
{
|
|
|
|
if (beatmapSections[t] > beat)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
currentSectionEvent = t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
onSectionChange?.Invoke(currentSection);
|
|
|
|
|
2022-06-12 19:32:00 +00:00
|
|
|
SeekAheadAndPreload(beat);
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 00:35:41 +00:00
|
|
|
#endregion
|
|
|
|
|
2022-03-08 04:46:49 +00:00
|
|
|
public void SwitchGame(string game, float beat)
|
2021-12-24 03:36:16 +00:00
|
|
|
{
|
2022-01-15 17:45:08 +00:00
|
|
|
if (game != currentGame)
|
|
|
|
{
|
|
|
|
if (currentGameSwitchIE != null)
|
|
|
|
StopCoroutine(currentGameSwitchIE);
|
2022-03-08 04:46:49 +00:00
|
|
|
currentGameSwitchIE = StartCoroutine(SwitchGameIE(game, beat));
|
2022-01-15 17:45:08 +00:00
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-08 04:46:49 +00:00
|
|
|
IEnumerator SwitchGameIE(string game, float beat)
|
2021-12-24 03:36:16 +00:00
|
|
|
{
|
|
|
|
this.GetComponent<SpriteRenderer>().enabled = true;
|
|
|
|
|
2021-12-29 06:52:48 +00:00
|
|
|
SetGame(game);
|
|
|
|
|
2022-03-08 04:46:49 +00:00
|
|
|
Minigame miniGame = currentGameO.GetComponent<Minigame>();
|
|
|
|
if (miniGame != null)
|
|
|
|
miniGame.OnGameSwitch(beat);
|
|
|
|
|
2022-01-15 17:45:08 +00:00
|
|
|
yield return new WaitForSeconds(0.1f);
|
2021-12-29 06:52:48 +00:00
|
|
|
|
|
|
|
this.GetComponent<SpriteRenderer>().enabled = false;
|
|
|
|
}
|
|
|
|
|
2022-03-27 18:13:13 +00:00
|
|
|
private void SetGame(string game)
|
2021-12-29 06:52:48 +00:00
|
|
|
{
|
2021-12-31 14:46:11 +00:00
|
|
|
Destroy(currentGameO);
|
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
currentGameO = Instantiate(GetGame(game));
|
|
|
|
currentGameO.transform.parent = eventCaller.GamesHolder.transform;
|
|
|
|
currentGameO.name = game;
|
2021-12-24 03:36:16 +00:00
|
|
|
|
2022-03-07 02:37:27 +00:00
|
|
|
SetCurrentGame(game);
|
2022-02-24 03:17:53 +00:00
|
|
|
|
|
|
|
ResetCamera();
|
2021-12-24 03:36:16 +00:00
|
|
|
}
|
2021-12-19 04:10:43 +00:00
|
|
|
|
2023-01-12 01:42:12 +00:00
|
|
|
public void PreloadGameSequences(string game)
|
2021-12-31 14:46:11 +00:00
|
|
|
{
|
2023-01-12 01:42:12 +00:00
|
|
|
var gameInfo = GetGameInfo(game);
|
|
|
|
//load the games' sound sequences
|
|
|
|
if (gameInfo != null && gameInfo.LoadedSoundSequences == null)
|
|
|
|
gameInfo.LoadedSoundSequences = GetGame(game).GetComponent<Minigame>().SoundSequences;
|
2021-12-31 14:46:11 +00:00
|
|
|
}
|
|
|
|
|
2022-01-23 07:01:59 +00:00
|
|
|
public GameObject GetGame(string name)
|
2021-12-21 01:10:49 +00:00
|
|
|
{
|
2022-02-03 07:47:38 +00:00
|
|
|
var gameInfo = GetGameInfo(name);
|
|
|
|
if (gameInfo != null)
|
2022-01-29 23:30:29 +00:00
|
|
|
{
|
2022-02-03 07:47:38 +00:00
|
|
|
if (gameInfo.fxOnly)
|
|
|
|
{
|
2023-01-07 03:59:54 +00:00
|
|
|
var gameEntities = Beatmap.entities.FindAll(c => {
|
2022-02-03 07:47:38 +00:00
|
|
|
var gameName = c.datamodel.Split(0);
|
|
|
|
var newGameInfo = GetGameInfo(gameName);
|
|
|
|
if (newGameInfo == null)
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
return !newGameInfo.fxOnly;
|
2023-01-07 03:59:54 +00:00
|
|
|
}).ToList();
|
|
|
|
if (gameEntities.Count != 0)
|
|
|
|
name = gameEntities[0].datamodel.Split(0);
|
|
|
|
else
|
|
|
|
name = "noGame";
|
2022-02-03 07:47:38 +00:00
|
|
|
}
|
2022-06-12 19:32:00 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gameInfo.usesAssetBundle)
|
|
|
|
{
|
|
|
|
//game is packed in an assetbundle, load from that instead
|
|
|
|
return gameInfo.GetCommonAssetBundle().LoadAsset<GameObject>(name);
|
|
|
|
}
|
|
|
|
}
|
2022-01-29 23:30:29 +00:00
|
|
|
}
|
2022-01-23 07:01:59 +00:00
|
|
|
return Resources.Load<GameObject>($"Games/{name}");
|
|
|
|
}
|
|
|
|
|
|
|
|
public Minigames.Minigame GetGameInfo(string name)
|
|
|
|
{
|
|
|
|
return EventCaller.instance.minigames.Find(c => c.name == name);
|
2021-12-26 01:04:23 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 02:37:27 +00:00
|
|
|
public void SetCurrentGame(string game)
|
2021-12-26 01:04:23 +00:00
|
|
|
{
|
|
|
|
currentGame = game;
|
2022-01-30 09:09:26 +00:00
|
|
|
if (GetGameInfo(currentGame) != null) CircleCursor.InnerCircle.GetComponent<SpriteRenderer>().color = Colors.Hex2RGB(GetGameInfo(currentGame).color);
|
|
|
|
else
|
|
|
|
CircleCursor.InnerCircle.GetComponent<SpriteRenderer>().color = Color.white;
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|
2022-01-09 23:35:55 +00:00
|
|
|
|
|
|
|
private bool SongPosLessThanClipLength(float t)
|
|
|
|
{
|
|
|
|
if (Conductor.instance.musicSource.clip != null)
|
|
|
|
return Conductor.instance.GetSongPosFromBeat(t) < Conductor.instance.musicSource.clip.length;
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
2022-02-24 03:17:53 +00:00
|
|
|
|
|
|
|
public void ResetCamera()
|
|
|
|
{
|
2022-05-16 05:29:39 +00:00
|
|
|
HeavenStudio.GameCamera.ResetAdditionalTransforms();
|
2022-02-24 03:17:53 +00:00
|
|
|
}
|
2021-12-19 04:10:43 +00:00
|
|
|
}
|
2021-12-21 01:10:49 +00:00
|
|
|
}
|