2021-12-19 04:10:43 +00:00
using System ;
using System.Collections ;
using System.Collections.Generic ;
using System.Linq ;
using UnityEngine ;
using Starpelly ;
2023-06-10 19:13:29 +00:00
using Jukebox ;
2023-06-12 21:18:37 +00:00
using HeavenStudio.Util ;
2022-03-14 14:21:05 +00:00
using HeavenStudio.Games ;
2023-03-11 04:51:22 +00:00
using HeavenStudio.Common ;
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")]
2023-06-10 19:13:29 +00:00
[NonSerialized] public RiqBeatmap Beatmap = new ( ) ;
2022-01-21 01:24:30 +00:00
private List < GameObject > preloadedGames = new List < GameObject > ( ) ;
2023-05-07 20:33:15 +00:00
[NonSerialized] 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-05-07 20:33:15 +00:00
[NonSerialized] public Camera GameCamera , CursorCam , OverlayCamera , StaticCamera ;
[NonSerialized] public CircleCursor CircleCursor ;
[NonSerialized] public GameObject GamesHolder ;
[NonSerialized] public Games . Global . Flash fade ;
[NonSerialized] public Games . Global . Filter filter ;
2022-01-21 01:24:30 +00:00
2021-12-24 03:36:16 +00:00
[Header("Games")]
2023-05-07 20:33:15 +00:00
[NonSerialized] 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")]
2023-05-07 20:33:15 +00:00
[NonSerialized] public string txt = null ;
[NonSerialized] public string ext = null ;
[NonSerialized] public int currentEvent , currentTempoEvent , currentVolumeEvent , currentSectionEvent ,
2023-01-05 04:04:31 +00:00
currentPreEvent , currentPreSwitch , currentPreSequence ;
2023-06-10 19:13:29 +00:00
[NonSerialized] public double endBeat ;
2023-05-07 20:33:15 +00:00
[NonSerialized] public float startOffset ;
[NonSerialized] public bool playOnStart ;
2023-06-10 19:13:29 +00:00
[NonSerialized] public double startBeat ;
2022-02-20 13:57:20 +00:00
[NonSerialized] public GameObject currentGameO ;
2023-05-07 20:33:15 +00:00
[NonSerialized] public bool autoplay ;
[NonSerialized] public bool canInput = true ;
2023-06-10 19:13:29 +00:00
[NonSerialized] public RiqEntity currentSection , nextSection ;
public double sectionProgress { get ; private set ; }
2022-02-08 01:07:03 +00:00
2023-06-13 20:55:02 +00:00
bool AudioLoadDone ;
bool ChartLoadError ;
2023-06-10 19:13:29 +00:00
public event Action < double > onBeatChanged ;
public event Action < RiqEntity > onSectionChange ;
2022-02-08 01:07:03 +00:00
2022-01-30 23:40:12 +00:00
public int BeatmapEntities ( )
{
2023-06-10 19:13:29 +00:00
return Beatmap . Entities . Count + Beatmap . TempoChanges . Count + Beatmap . VolumeChanges . Count + Beatmap . SectionMarkers . 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-25 03:54:19 +00:00
// average input accuracy (msec)
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 ( ) ;
}
}
2023-01-25 03:54:19 +00:00
// input accuracy (%)
double totalInputs = 0 ;
double totalPlayerAccuracy = 0 ;
public double PlayerAccuracy
{
get
{
if ( totalInputs = = 0 ) return 0 ;
return totalPlayerAccuracy / totalInputs ;
}
}
2023-03-11 04:51:22 +00:00
bool skillStarCollected = false ;
2023-01-25 03:54:19 +00:00
2023-05-07 20:33:15 +00:00
// cleared sections
List < bool > clearedSections = new List < bool > ( ) ;
public bool ClearedSection
{
set
{
clearedSections . Add ( value ) ;
}
}
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
2023-06-10 19:13:29 +00:00
public void Init ( bool preLoaded = false )
2021-12-21 01:10:49 +00:00
{
2023-06-13 20:55:02 +00:00
AudioLoadDone = false ;
ChartLoadError = false ;
2022-06-12 19:32:00 +00:00
currentPreEvent = 0 ;
currentPreSwitch = 0 ;
2023-01-05 04:04:31 +00:00
currentPreSequence = 0 ;
2023-05-07 20:33:15 +00:00
2023-01-27 03:42:16 +00:00
GameObject filter = new GameObject ( "filter" ) ;
this . filter = filter . AddComponent < Games . Global . Filter > ( ) ;
2021-12-19 04:10:43 +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 ( ) ;
2023-06-10 19:13:29 +00:00
Conductor . instance . SetBpm ( 120f ) ;
Conductor . instance . SetVolume ( 100f ) ;
Conductor . instance . firstBeatOffset = Beatmap . data . offset ;
2021-12-23 02:28:05 +00:00
2023-03-11 04:51:22 +00:00
// note: serialize this shit in the inspector //
2023-05-07 20:33:15 +00:00
GameObject textbox = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Common/Textbox" ) ) ;
textbox . name = "Textbox" ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
GameObject timingDisp = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Common/Overlays/TimingAccuracy" ) ) ;
timingDisp . name = "TimingDisplay" ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
GameObject skillStarDisp = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Common/Overlays/SkillStar" ) ) ;
skillStarDisp . name = "SkillStar" ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
GameObject overlays = Instantiate ( Resources . Load < GameObject > ( "Prefabs/Common/Overlays" ) ) ;
overlays . name = "Overlays" ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
GoForAPerfect . instance . Disable ( ) ;
2023-03-11 04:51:22 +00:00
/////
2023-06-10 19:13:29 +00:00
if ( preLoaded )
2022-01-15 22:52:53 +00:00
{
2023-06-10 19:13:29 +00:00
LoadRemix ( false ) ;
2023-01-12 01:42:12 +00:00
}
else
{
2023-06-13 20:55:02 +00:00
RiqFileHandler . ClearCache ( ) ;
2023-01-12 01:42:12 +00:00
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
2023-06-10 19:13:29 +00:00
if ( Beatmap . Entities . Count > = 1 )
2021-12-28 02:36:27 +00:00
{
2023-06-10 19:13: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 )
{
2023-05-07 20:33:15 +00:00
StartCoroutine ( WaitReadyAndPlayCo ( startBeat ) ) ;
2023-01-12 01:42:12 +00:00
}
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 ( )
2023-06-13 20:55:02 +00:00
{
AudioLoadDone = false ;
2023-06-10 19:13:29 +00:00
Beatmap = new ( "1" , "HeavenStudio" ) ;
Beatmap . data . properties = Minigames . propertiesModel ;
Beatmap . AddNewTempoChange ( 0 , 120f ) ;
Beatmap . AddNewVolumeChange ( 0 , 100f ) ;
Beatmap . data . offset = 0f ;
2022-02-26 19:06:52 +00:00
Conductor . instance . musicSource . clip = null ;
2023-06-10 19:13:29 +00:00
RiqFileHandler . WriteRiq ( Beatmap ) ;
2023-06-13 20:55:02 +00:00
AudioLoadDone = true ;
2022-02-26 03:41:32 +00:00
}
2023-06-10 19:13:29 +00:00
public IEnumerator LoadMusic ( )
2022-01-30 12:03:37 +00:00
{
2023-06-13 20:55:02 +00:00
ChartLoadError = false ;
2023-06-10 19:13:29 +00:00
IEnumerator load = RiqFileHandler . LoadSong ( ) ;
while ( true )
2022-02-26 03:41:32 +00:00
{
2023-06-10 19:13:29 +00:00
object current = load . Current ;
try
2022-08-21 23:46:45 +00:00
{
2023-06-10 19:13:29 +00:00
if ( load . MoveNext ( ) = = false )
{
2022-08-21 23:46:45 +00:00
break ;
2023-06-10 19:13:29 +00:00
}
current = load . Current ;
2022-08-21 23:46:45 +00:00
}
2023-06-11 16:12:25 +00:00
catch ( System . IO . FileNotFoundException f )
{
Debug . LogWarning ( "chart has no music: " + f . Message ) ;
Conductor . instance . musicSource . clip = null ;
2023-06-13 20:55:02 +00:00
AudioLoadDone = true ;
yield break ;
2023-06-11 16:12:25 +00:00
}
2023-06-10 19:13:29 +00:00
catch ( Exception e )
{
Debug . LogError ( $"Failed to load music: {e.Message}" ) ;
GlobalGameManager . ShowErrorMessage ( "Error Loading Music" , e . Message + "\n\n" + e . StackTrace ) ;
2023-06-13 20:55:02 +00:00
AudioLoadDone = true ;
ChartLoadError = true ;
2023-06-10 19:13:29 +00:00
yield break ;
}
yield return current ;
2022-02-26 03:41:32 +00:00
}
2023-06-10 19:13:29 +00:00
Conductor . instance . musicSource . clip = RiqFileHandler . StreamedAudioClip ;
2023-06-13 20:55:02 +00:00
AudioLoadDone = true ;
2023-06-10 19:13:29 +00:00
}
public void LoadRemix ( bool editor = false )
{
2023-06-13 20:55:02 +00:00
AudioLoadDone = false ;
ChartLoadError = false ;
2023-06-10 19:13:29 +00:00
try
2022-02-26 03:41:32 +00:00
{
2023-06-10 19:13:29 +00:00
Beatmap = RiqFileHandler . ReadRiq ( ) ;
}
catch ( Exception e )
{
Debug . LogError ( $"Failed to load remix: {e.Message}" ) ;
GlobalGameManager . ShowErrorMessage ( "Error Loading RIQ" , e . Message + "\n\n" + e . StackTrace ) ;
2023-06-13 20:55:02 +00:00
ChartLoadError = true ;
2023-06-10 19:13:29 +00:00
return ;
2022-02-26 03:41:32 +00:00
}
2023-06-10 19:13:29 +00:00
if ( ! editor )
StartCoroutine ( LoadMusic ( ) ) ;
2022-08-22 23:14:38 +00:00
SortEventsList ( ) ;
2023-06-10 19:13:29 +00:00
Conductor . instance . SetBpm ( Beatmap . TempoChanges [ 0 ] [ "tempo" ] ) ;
Conductor . instance . SetVolume ( Beatmap . VolumeChanges [ 0 ] [ "volume" ] ) ;
Conductor . instance . firstBeatOffset = Beatmap . data . offset ;
2023-05-07 20:33:15 +00:00
if ( ! playOnStart )
{
Stop ( 0 ) ;
}
2022-02-02 01:11:42 +00:00
SetCurrentEventToClosest ( 0 ) ;
2022-01-30 12:03:37 +00:00
2023-06-10 19:13:29 +00:00
if ( Beatmap . Entities . Count > = 1 )
2022-01-30 12:03:37 +00:00
{
2023-06-10 19:13:29 +00:00
SetCurrentGame ( Beatmap . Entities [ 0 ] . datamodel . Split ( 0 ) ) ;
SetGame ( Beatmap . Entities [ 0 ] . datamodel . Split ( 0 ) ) ;
2022-01-30 12:03:37 +00:00
}
else
{
SetGame ( "noGame" ) ;
}
2023-06-12 21:18:37 +00:00
if ( editor )
{
Debug . Log ( Beatmap . data . riqOrigin ) ;
if ( Beatmap . data . riqOrigin ! = "HeavenStudio" )
{
2023-07-29 02:23:07 +00:00
string origin = Beatmap . data . riqOrigin ? . DisplayName ( ) ? ? "Unknown Origin" ;
GlobalGameManager . ShowErrorMessage ( "Warning" ,
$"This chart came from\n<alpha=#AA>{origin}</color>\nand uses content not included in Heaven Studio.\n\n<color=\" yellow \ ">You may be able to edit this chart in Heaven Studio to be used in its original program.</color>" ) ;
2023-06-12 21:18:37 +00:00
}
}
2022-01-30 12:03:37 +00:00
}
2023-03-11 04:51:22 +00:00
public void ScoreInputAccuracy ( double accuracy , bool late , double time , double weight = 1 , bool doDisplay = true )
2023-01-25 03:54:19 +00:00
{
totalInputs + = weight ;
totalPlayerAccuracy + = accuracy * weight ;
2023-03-11 04:51:22 +00:00
if ( accuracy < Minigame . rankOkThreshold & & weight > 0 )
{
SkillStarManager . instance . KillStar ( ) ;
}
if ( SkillStarManager . instance . IsEligible & & ! skillStarCollected & & accuracy > = 1f )
{
if ( SkillStarManager . instance . DoStarJust ( ) )
skillStarCollected = true ;
}
2023-01-25 03:54:19 +00:00
// push the hit event to the timing display
2023-03-11 04:51:22 +00:00
if ( doDisplay )
TimingAccuracyDisplay . instance . MakeAccuracyVfx ( time , late ) ;
2023-01-25 03:54:19 +00:00
}
2023-01-19 02:31:08 +00:00
public void SeekAheadAndPreload ( double start , float seekTime = 8f )
2022-06-12 19:32:00 +00:00
{
//seek ahead to preload games that have assetbundles
//check game switches first
2023-06-10 19:13:29 +00:00
var gameSwitchs = Beatmap . Entities . FindAll ( c = > c . datamodel . Split ( 1 ) = = "switchGame" ) ;
2022-06-12 19:32:00 +00:00
if ( currentPreSwitch < gameSwitchs . Count & & currentPreSwitch > = 0 )
{
if ( start + seekTime > = gameSwitchs [ currentPreSwitch ] . beat )
{
string gameName = gameSwitchs [ currentPreSwitch ] . datamodel . Split ( 2 ) ;
var inf = GetGameInfo ( gameName ) ;
2023-06-10 19:13:29 +00:00
if ( inf ! = null & & inf . usesAssetBundle & & ! inf . AssetsLoaded )
2022-06-12 19:32:00 +00:00
{
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
2023-06-10 19:13:29 +00:00
List < double > entities = Beatmap . Entities . Select ( c = > c . beat ) . ToList ( ) ;
if ( currentPreEvent < Beatmap . Entities . Count & & currentPreEvent > = 0 )
2022-06-12 19:32:00 +00:00
{
if ( start + seekTime > = entities [ currentPreEvent ] )
{
2023-06-10 19:13:29 +00:00
var entitiesAtSameBeat = Beatmap . Entities . FindAll ( c = > c . beat = = Beatmap . Entities [ currentPreEvent ] . beat & & ! EventCaller . FXOnlyGames ( ) . Contains ( EventCaller . instance . GetMinigame ( c . datamodel . Split ( '/' ) [ 0 ] ) ) ) ;
2023-01-19 02:31:08 +00:00
SortEventsByPriority ( entitiesAtSameBeat ) ;
2023-06-10 19:13:29 +00:00
foreach ( RiqEntity 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 ) ;
2023-06-10 19:13:29 +00:00
if ( inf ! = null & & inf . usesAssetBundle & & ! inf . AssetsLoaded )
2022-06-12 19:32:00 +00:00
{
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-02-18 22:12:49 +00:00
public void SeekAheadAndDoPreEvent ( double start )
2023-01-05 04:04:31 +00:00
{
2023-06-10 19:13:29 +00:00
List < double > entities = Beatmap . Entities . Select ( c = > c . beat ) . ToList ( ) ;
if ( currentPreSequence < Beatmap . Entities . Count & & currentPreSequence > = 0 )
2023-01-05 04:04:31 +00:00
{
2023-06-10 19:13:29 +00:00
var seekEntity = Beatmap . Entities [ currentPreSequence ] ;
2023-02-18 22:12:49 +00:00
float seekTime = EventCaller . instance . GetGameAction (
EventCaller . instance . GetMinigame ( seekEntity . datamodel . Split ( 0 ) ) , seekEntity . datamodel . Split ( 1 ) ) . preFunctionLength ;
2023-01-05 04:04:31 +00:00
if ( start + seekTime > = entities [ currentPreSequence ] )
{
2023-06-10 19:13:29 +00:00
double beat = seekEntity . beat ;
var entitiesAtSameBeat = Beatmap . Entities . FindAll ( c = > c . beat = = seekEntity . beat ) ;
2023-01-19 02:31:08 +00:00
SortEventsByPriority ( entitiesAtSameBeat ) ;
2023-06-10 19:13:29 +00:00
foreach ( RiqEntity entity in entitiesAtSameBeat )
2023-01-05 04:04:31 +00:00
{
2023-01-19 02:31:08 +00:00
currentPreSequence + + ;
2023-01-12 01:42:12 +00:00
string gameName = entity . datamodel . Split ( '/' ) [ 0 ] ;
var inf = GetGameInfo ( gameName ) ;
2023-06-10 19:13:29 +00:00
if ( inf ! = null & & inf . usesAssetBundle & & inf . AssetsLoaded & & ! inf . SequencesPreloaded )
2023-01-12 01:42:12 +00:00
{
Debug . Log ( $"Preloading game {gameName}" ) ;
PreloadGameSequences ( gameName ) ;
}
2023-06-10 19:13:29 +00:00
eventCaller . CallPreEvent ( entity ) ;
2023-01-05 04:04:31 +00:00
}
}
}
}
2022-02-20 17:28:56 +00:00
private void Update ( )
2021-12-21 01:10:49 +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 ;
2023-03-11 04:51:22 +00:00
Conductor cond = Conductor . instance ;
2022-09-18 20:48:14 +00:00
2023-06-10 19:13:29 +00:00
List < double > entities = Beatmap . Entities . Select ( c = > c . beat ) . ToList ( ) ;
2021-12-19 04:10:43 +00:00
2023-06-10 19:13:29 +00:00
List < double > tempoChanges = Beatmap . TempoChanges . Select ( c = > c . beat ) . ToList ( ) ;
if ( currentTempoEvent < Beatmap . TempoChanges . Count & & currentTempoEvent > = 0 )
2022-06-09 03:35:15 +00:00
{
2023-03-11 04:51:22 +00:00
if ( cond . songPositionInBeatsAsDouble > = tempoChanges [ currentTempoEvent ] )
2022-06-09 03:35:15 +00:00
{
2023-06-10 19:13:29 +00:00
cond . SetBpm ( Beatmap . TempoChanges [ currentTempoEvent ] [ "tempo" ] ) ;
2022-06-09 03:35:15 +00:00
currentTempoEvent + + ;
}
}
2023-06-10 19:13:29 +00:00
List < double > volumeChanges = Beatmap . VolumeChanges . Select ( c = > c . beat ) . ToList ( ) ;
if ( currentVolumeEvent < Beatmap . VolumeChanges . Count & & currentVolumeEvent > = 0 )
2022-09-18 20:48:14 +00:00
{
2023-03-11 04:51:22 +00:00
if ( cond . songPositionInBeatsAsDouble > = volumeChanges [ currentVolumeEvent ] )
2022-09-18 20:48:14 +00:00
{
2023-06-10 19:13:29 +00:00
cond . SetVolume ( Beatmap . VolumeChanges [ currentVolumeEvent ] [ "volume" ] ) ;
2022-09-18 20:48:14 +00:00
currentVolumeEvent + + ;
}
}
2023-06-10 19:13:29 +00:00
List < double > chartSections = Beatmap . SectionMarkers . Select ( c = > c . beat ) . ToList ( ) ;
if ( currentSectionEvent < Beatmap . SectionMarkers . Count & & currentSectionEvent > = 0 )
2022-09-18 20:48:14 +00:00
{
2023-03-11 04:51:22 +00:00
if ( cond . songPositionInBeatsAsDouble > = chartSections [ currentSectionEvent ] )
2022-09-18 20:48:14 +00:00
{
2023-06-10 19:13:29 +00:00
Debug . Log ( "Section " + Beatmap . SectionMarkers [ currentSectionEvent ] [ "sectionName" ] + " started" ) ;
currentSection = Beatmap . SectionMarkers [ currentSectionEvent ] ;
2022-09-18 20:48:14 +00:00
currentSectionEvent + + ;
2023-06-10 19:13:29 +00:00
if ( currentSectionEvent < Beatmap . SectionMarkers . Count )
nextSection = Beatmap . SectionMarkers [ currentSectionEvent ] ;
2022-09-18 20:48:14 +00:00
else
2023-06-10 19:13:29 +00:00
nextSection = default ( RiqEntity ) ;
2022-09-18 20:48:14 +00:00
onSectionChange ? . Invoke ( currentSection ) ;
}
}
2022-06-12 19:32:00 +00:00
float seekTime = 8f ;
//seek ahead to preload games that have assetbundles
2023-03-11 04:51:22 +00:00
SeekAheadAndPreload ( cond . songPositionInBeatsAsDouble , seekTime ) ;
2022-06-12 19:32:00 +00:00
2023-02-18 22:12:49 +00:00
SeekAheadAndDoPreEvent ( Conductor . instance . songPositionInBeatsAsDouble ) ;
2023-01-05 04:04:31 +00:00
2023-06-10 19:13:29 +00:00
if ( currentEvent < Beatmap . Entities . Count & & currentEvent > = 0 )
2021-12-19 04:10:43 +00:00
{
2023-03-11 04:51:22 +00:00
if ( cond . songPositionInBeatsAsDouble > = entities [ currentEvent ] )
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-06-10 19:13:29 +00:00
var entitiesAtSameBeat = Beatmap . Entities . FindAll ( c = > c . beat = = Beatmap . Entities [ currentEvent ] . beat & & ! EventCaller . FXOnlyGames ( ) . Contains ( EventCaller . instance . GetMinigame ( c . datamodel . Split ( '/' ) [ 0 ] ) ) ) ;
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
2023-01-19 02:31:08 +00:00
SortEventsByPriority ( fxEntities ) ;
SortEventsByPriority ( entitiesAtSameBeat ) ;
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-06-10 19:13:29 +00:00
foreach ( RiqEntity 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
}
2021-12-19 04:10:43 +00:00
}
}
2023-03-11 04:51:22 +00:00
if ( currentSection = = null )
{
sectionProgress = 0 ;
}
else
{
2023-06-10 19:13:29 +00:00
double currectSectionStart = cond . GetSongPosFromBeat ( currentSection . beat ) ;
2023-03-11 04:51:22 +00:00
2023-06-10 19:13:29 +00:00
if ( nextSection = = null )
sectionProgress = ( cond . songPosition - currectSectionStart ) / ( cond . GetSongPosFromBeat ( endBeat ) - currectSectionStart ) ;
2023-03-11 04:51:22 +00:00
else
2023-06-10 19:13:29 +00:00
sectionProgress = ( cond . songPosition - currectSectionStart ) / ( cond . GetSongPosFromBeat ( nextSection . beat ) - currectSectionStart ) ;
2023-03-11 04:51:22 +00:00
}
}
private void LateUpdate ( ) {
OverlaysManager . instance . TogleOverlaysVisibility ( Editor . Editor . instance = = null | | Editor . Editor . instance . fullscreen | | ( ( PersistentDataManager . gameSettings . overlaysInEditor ) & & ( ! Editor . Editor . instance . fullscreen ) ) | | HeavenStudio . Editor . GameSettings . InPreview ) ;
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
2023-06-10 19:13:29 +00:00
public void Play ( double beat , float delay = 0f )
2022-01-14 00:35:41 +00:00
{
2023-05-07 20:33:15 +00:00
bool paused = Conductor . instance . isPaused ;
Debug . Log ( "Playing at " + beat ) ;
2022-03-01 07:27:49 +00:00
canInput = true ;
2023-05-07 20:33:15 +00:00
if ( ! paused )
{
inputOffsetSamples . Clear ( ) ;
averageInputOffset = 0 ;
2023-01-25 03:54:19 +00:00
2023-05-07 20:33:15 +00:00
totalInputs = 0 ;
totalPlayerAccuracy = 0 ;
2023-01-25 03:54:19 +00:00
2023-05-07 20:33:15 +00:00
TimingAccuracyDisplay . instance . ResetArrow ( ) ;
SkillStarManager . instance . Reset ( ) ;
skillStarCollected = false ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
GoForAPerfect . instance . perfect = true ;
GoForAPerfect . instance . Disable ( ) ;
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
SectionMedalsManager . instance . Reset ( ) ;
clearedSections . Clear ( ) ;
}
2023-03-11 04:51:22 +00:00
2023-05-07 20:33:15 +00:00
StartCoroutine ( PlayCo ( beat , delay ) ) ;
2022-02-08 01:07:03 +00:00
onBeatChanged ? . Invoke ( beat ) ;
2022-01-14 00:35:41 +00:00
}
2023-06-10 19:13:29 +00:00
private IEnumerator PlayCo ( double beat , float delay = 0f )
2022-01-14 00:35:41 +00:00
{
2023-05-07 20:33:15 +00:00
yield return new WaitForSeconds ( delay ) ;
2022-01-14 02:33:51 +00:00
bool paused = Conductor . instance . isPaused ;
2022-01-28 02:50:57 +00:00
2022-01-14 00:35:41 +00:00
Conductor . instance . Play ( beat ) ;
2023-05-07 20:33:15 +00:00
if ( paused )
2022-01-14 02:33:51 +00:00
{
2023-06-10 19:13:29 +00:00
Util . SoundByte . UnpauseOneShots ( ) ;
2023-05-07 20:33:15 +00:00
}
else
{
2023-06-10 19:13:29 +00:00
Conductor . instance . SetBpm ( Beatmap . TempoChanges [ 0 ] [ "tempo" ] ) ;
Conductor . instance . SetVolume ( Beatmap . VolumeChanges [ 0 ] [ "volume" ] ) ;
Conductor . instance . firstBeatOffset = Beatmap . data . offset ;
2022-01-14 02:33:51 +00:00
SetCurrentEventToClosest ( beat ) ;
2023-05-07 20:33:15 +00:00
KillAllSounds ( ) ;
2022-01-14 02:33:51 +00:00
}
2022-01-21 01:24:30 +00:00
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 ( ) ;
2023-06-10 19:13:29 +00:00
Util . SoundByte . PauseOneShots ( ) ;
2023-05-07 20:33:15 +00:00
canInput = false ;
2022-01-14 00:35:41 +00:00
}
2023-06-10 19:13:29 +00:00
public void Stop ( double beat , bool restart = false , float restartDelay = 0f )
2022-01-14 00:35:41 +00:00
{
2023-05-07 20:33:15 +00:00
Minigame miniGame = currentGameO . GetComponent < Minigame > ( ) ;
if ( miniGame ! = null )
miniGame . OnStop ( beat ) ;
2022-01-14 00:35:41 +00:00
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-03-11 04:51:22 +00:00
// I feel like I should standardize the names
SkillStarManager . instance . KillStar ( ) ;
TimingAccuracyDisplay . instance . StopStarFlash ( ) ;
GoForAPerfect . instance . Disable ( ) ;
SectionMedalsManager . instance . OnRemixEnd ( ) ;
2023-05-07 20:33:15 +00:00
// pass this data to rating screen + stats
Debug . Log ( $"== Playthrough statistics of {Beatmap[" remixtitle "]} (played at {System.DateTime.Now.ToString(" yyyy - MM - dd HH : mm : ss ")}) ==" ) ;
2023-01-14 04:53:25 +00:00
Debug . Log ( $"Average input offset for playthrough: {averageInputOffset}ms" ) ;
2023-01-25 03:54:19 +00:00
Debug . Log ( $"Accuracy for playthrough: {(PlayerAccuracy * 100) : 0.00}" ) ;
2023-06-10 19:13:29 +00:00
Debug . Log ( $"Cleared {clearedSections.FindAll(c => c).Count} sections out of {Beatmap.SectionMarkers.Count}" ) ;
2023-05-07 20:33:15 +00:00
if ( SkillStarManager . instance . IsCollected )
Debug . Log ( $"Skill Star collected" ) ;
else
Debug . Log ( $"Skill Star not collected" ) ;
if ( GoForAPerfect . instance . perfect )
Debug . Log ( $"Perfect Clear!" ) ;
if ( playOnStart | | restart )
2023-01-12 01:42:12 +00:00
{
2023-05-07 20:33:15 +00:00
Play ( 0 , restartDelay ) ;
2023-01-12 01:42:12 +00:00
}
2023-05-07 20:33:15 +00:00
// when rating screen gets added playOnStart will instead move to that scene
}
2023-06-10 19:13:29 +00:00
private IEnumerator WaitReadyAndPlayCo ( double beat )
2023-05-07 20:33:15 +00:00
{
// wait for overlays to be ready
yield return new WaitUntil ( ( ) = > OverlaysManager . OverlaysReady ) ;
// wait for first game to be loaded
2023-06-10 19:13:29 +00:00
yield return new WaitUntil ( ( ) = > Beatmap ! = null & & Beatmap . Entities . Count > 0 ) ;
//wait for audio clip to be loaded
2023-06-13 20:55:02 +00:00
yield return new WaitUntil ( ( ) = > AudioLoadDone | | ( ChartLoadError & & ! GlobalGameManager . IsShowingDialog ) ) ;
2023-05-07 20:33:15 +00:00
SkillStarManager . instance . KillStar ( ) ;
TimingAccuracyDisplay . instance . StopStarFlash ( ) ;
GoForAPerfect . instance . Disable ( ) ;
SectionMedalsManager . instance ? . OnRemixEnd ( ) ;
GlobalGameManager . UpdateDiscordStatus ( Beatmap [ "remixtitle" ] , false , true ) ;
Play ( beat , 1f ) ;
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 ( ) ;
2023-06-10 19:13:29 +00:00
Util . SoundByte . KillOneShots ( ) ;
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
{
2023-06-10 19:13:29 +00:00
Beatmap . Entities . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
Beatmap . TempoChanges . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
Beatmap . VolumeChanges . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
Beatmap . SectionMarkers . Sort ( ( x , y ) = > x . beat . CompareTo ( y . beat ) ) ;
2021-12-19 04:10:43 +00:00
}
2021-12-21 01:10:49 +00:00
2023-06-10 19:13:29 +00:00
void SortEventsByPriority ( List < RiqEntity > entities )
2023-01-19 02:31:08 +00:00
{
entities . Sort ( ( x , y ) = > {
Minigames . Minigame xGame = EventCaller . instance . GetMinigame ( x . datamodel . Split ( 0 ) ) ;
Minigames . GameAction xAction = EventCaller . instance . GetGameAction ( xGame , x . datamodel . Split ( 1 ) ) ;
Minigames . Minigame yGame = EventCaller . instance . GetMinigame ( y . datamodel . Split ( 0 ) ) ;
Minigames . GameAction yAction = EventCaller . instance . GetGameAction ( yGame , y . datamodel . Split ( 1 ) ) ;
return yAction . priority . CompareTo ( xAction . priority ) ;
} ) ;
}
2023-06-10 19:13:29 +00:00
public static double GetClosestInList ( List < double > list , double compareTo )
{
if ( list . Count > 0 )
return list . Aggregate ( ( x , y ) = > Math . Abs ( x - compareTo ) < Math . Abs ( y - compareTo ) ? x : y ) ;
else
return double . MinValue ;
}
public void SetCurrentEventToClosest ( double 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 ) ;
2023-06-10 19:13:29 +00:00
if ( Beatmap . Entities . Count > 0 )
2021-12-21 01:10:49 +00:00
{
2023-06-10 19:13:29 +00:00
List < double > entities = Beatmap . Entities . Select ( c = > c . beat ) . ToList ( ) ;
2021-12-31 14:46:11 +00:00
2023-06-10 19:13:29 +00:00
currentEvent = entities . IndexOf ( GetClosestInList ( entities , beat ) ) ;
currentPreEvent = entities . IndexOf ( GetClosestInList ( entities , beat ) ) ;
currentPreSequence = entities . IndexOf ( GetClosestInList ( entities , beat ) ) ;
2021-12-31 14:46:11 +00:00
2023-06-10 19:13:29 +00:00
var gameSwitchs = Beatmap . Entities . FindAll ( c = > c . datamodel . Split ( 1 ) = = "switchGame" ) ;
2022-01-15 17:45:08 +00:00
2023-06-10 19:13:29 +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
{
2023-06-10 19:13:29 +00:00
int index = gameSwitchs . FindIndex ( c = > c . beat = = 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
{
2023-06-10 19:13:29 +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
{
2023-06-10 19:13:29 +00:00
newGame = Beatmap . Entities [ Beatmap . Entities . IndexOf ( closestGameSwitch ) - 1 ] . datamodel . Split ( 0 ) ;
2022-01-30 01:26:53 +00:00
}
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
2023-06-10 19:13:29 +00:00
List < RiqEntity > allEnds = EventCaller . GetAllInGameManagerList ( "gameManager" , new string [ ] { "end" } ) ;
2022-09-18 20:48:14 +00:00
if ( allEnds . Count > 0 )
endBeat = allEnds . Select ( c = > c . beat ) . Min ( ) ;
else
2023-06-10 19:13:29 +00:00
endBeat = Conductor . instance . SongLengthInBeatsAsDouble ( ) ;
2021-12-21 01:10:49 +00:00
}
2022-01-30 09:09:26 +00:00
else
{
SetGame ( "noGame" ) ;
2023-06-10 19:13:29 +00:00
endBeat = Conductor . instance . SongLengthInBeatsAsDouble ( ) ;
2022-01-30 09:09:26 +00:00
}
2022-01-28 02:50:57 +00:00
2023-06-10 19:13:29 +00:00
if ( Beatmap . TempoChanges . Count > 0 )
2022-01-28 02:50:57 +00:00
{
2022-06-06 16:54:57 +00:00
currentTempoEvent = 0 ;
2023-06-10 19:13:29 +00:00
List < double > tempoChanges = Beatmap . TempoChanges . Select ( c = > c . beat ) . ToList ( ) ;
2022-01-28 02:50:57 +00:00
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
2023-06-10 19:13:29 +00:00
if ( Beatmap . VolumeChanges . Count > 0 )
2022-09-18 20:48:14 +00:00
{
currentVolumeEvent = 0 ;
2023-06-10 19:13:29 +00:00
List < double > volumeChanges = Beatmap . VolumeChanges . Select ( c = > c . beat ) . ToList ( ) ;
2022-09-18 20:48:14 +00:00
for ( int t = 0 ; t < volumeChanges . Count ; t + + )
{
if ( volumeChanges [ t ] > beat )
{
break ;
}
currentVolumeEvent = t ;
}
}
2023-06-10 19:13:29 +00:00
currentSection = default ( RiqEntity ) ;
nextSection = default ( RiqEntity ) ;
if ( Beatmap . SectionMarkers . Count > 0 )
2022-09-18 20:48:14 +00:00
{
currentSectionEvent = 0 ;
2023-06-10 19:13:29 +00:00
List < double > beatmapSections = Beatmap . SectionMarkers . Select ( c = > c . beat ) . ToList ( ) ;
2022-09-18 20:48:14 +00:00
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
2023-06-10 19:13:29 +00:00
public void SwitchGame ( string game , double beat , bool flash )
2021-12-24 03:36:16 +00:00
{
2022-01-15 17:45:08 +00:00
if ( game ! = currentGame )
{
if ( currentGameSwitchIE ! = null )
StopCoroutine ( currentGameSwitchIE ) ;
2023-04-07 15:15:19 +00:00
currentGameSwitchIE = StartCoroutine ( SwitchGameIE ( game , beat , flash ) ) ;
2022-01-15 17:45:08 +00:00
}
2021-12-24 03:36:16 +00:00
}
2023-06-10 19:13:29 +00:00
IEnumerator SwitchGameIE ( string game , double beat , bool flash )
2021-12-24 03:36:16 +00:00
{
2023-07-17 15:56:57 +00:00
if ( flash )
2023-04-07 15:15:19 +00:00
{
2023-05-07 20:33:15 +00:00
HeavenStudio . StaticCamera . instance . ToggleCanvasVisibility ( false ) ;
2023-04-07 15:15:19 +00:00
}
2021-12-24 03:36:16 +00:00
2023-07-17 15:56:57 +00:00
SetGame ( game , false ) ;
2021-12-29 06:52:48 +00:00
2022-03-08 04:46:49 +00:00
Minigame miniGame = currentGameO . GetComponent < Minigame > ( ) ;
if ( miniGame ! = null )
miniGame . OnGameSwitch ( beat ) ;
2023-07-17 15:56:57 +00:00
//before beat-based: yield return new WaitForSeconds(0.1f);
yield return new WaitForSeconds ( Conductor . instance . pitchedSecPerBeat / 4 ) ;
2021-12-29 06:52:48 +00:00
2023-05-07 20:33:15 +00:00
HeavenStudio . StaticCamera . instance . ToggleCanvasVisibility ( true ) ;
2023-07-17 15:56:57 +00:00
SetAmbientGlowToCurrentMinigameColor ( ) ;
2021-12-29 06:52:48 +00:00
}
2023-07-17 15:56:57 +00:00
private void SetGame ( string game , bool useMinigameColor = true )
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
2023-07-17 15:56:57 +00:00
SetCurrentGame ( game , useMinigameColor ) ;
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
2023-06-10 19:13:29 +00:00
// TODO: this blocks the main thread, and sound sequences sould be stored in a ScriptableObject
2023-01-12 01:42:12 +00:00
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-06-10 19:13:29 +00:00
var gameInfos = Beatmap . Entities
2023-04-02 17:15:19 +00:00
. Select ( x = > x . datamodel . Split ( 0 ) )
. Select ( x = > GetGameInfo ( x ) )
. Where ( x = > x ! = null )
. Where ( x = > ! x . fxOnly )
. Select ( x = > x . LoadableName ) ;
name = gameInfos . FirstOrDefault ( ) ? ? "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 ) ;
}
2023-04-02 17:15:19 +00:00
name = gameInfo . LoadableName ;
2022-06-12 19:32:00 +00:00
}
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
}
2023-07-17 15:56:57 +00:00
public void SetCurrentGame ( string game , bool useMinigameColor = true )
2021-12-26 01:04:23 +00:00
{
currentGame = game ;
2023-03-12 02:56:26 +00:00
if ( GetGameInfo ( currentGame ) ! = null )
{
CircleCursor . InnerCircle . GetComponent < SpriteRenderer > ( ) . color = Colors . Hex2RGB ( GetGameInfo ( currentGame ) . color ) ;
2023-07-17 15:56:57 +00:00
if ( useMinigameColor ) HeavenStudio . StaticCamera . instance . SetAmbientGlowColour ( Colors . Hex2RGB ( GetGameInfo ( currentGame ) . color ) , true ) ;
//else HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(HeavenStudio.GameCamera.currentColor, false);
else HeavenStudio . StaticCamera . instance . SetAmbientGlowColour ( Color . black , false ) ;
2023-03-12 02:56:26 +00:00
}
2022-01-30 09:09:26 +00:00
else
2023-03-12 02:56:26 +00:00
{
2022-01-30 09:09:26 +00:00
CircleCursor . InnerCircle . GetComponent < SpriteRenderer > ( ) . color = Color . white ;
2023-07-17 15:56:57 +00:00
//HeavenStudio.StaticCamera.instance.SetAmbientGlowColour(HeavenStudio.GameCamera.currentColor, false);
HeavenStudio . StaticCamera . instance . SetAmbientGlowColour ( Color . black , false ) ;
2023-03-12 02:56:26 +00:00
}
2021-12-21 01:10:49 +00:00
}
2022-01-09 23:35:55 +00:00
2023-07-17 15:56:57 +00:00
private void SetAmbientGlowToCurrentMinigameColor ( )
{
if ( GetGameInfo ( currentGame ) ! = null )
HeavenStudio . StaticCamera . instance . SetAmbientGlowColour ( Colors . Hex2RGB ( GetGameInfo ( currentGame ) . color ) , true ) ;
}
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
}