2021-12-23 00:08:35 +00:00
|
|
|
using System;
|
2021-12-23 01:49:16 +00:00
|
|
|
using System.Linq;
|
2021-12-23 00:08:35 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
namespace RhythmHeavenMania
|
|
|
|
{
|
|
|
|
public class EventCaller : MonoBehaviour
|
|
|
|
{
|
|
|
|
public Transform GamesHolder;
|
2022-01-17 19:23:18 +00:00
|
|
|
public float currentBeat;
|
|
|
|
public float currentLength;
|
|
|
|
public float currentValA;
|
|
|
|
public string currentSwitchGame;
|
|
|
|
public int currentType;
|
2021-12-23 00:08:35 +00:00
|
|
|
|
|
|
|
public delegate void EventCallback();
|
|
|
|
|
2022-01-08 16:42:48 +00:00
|
|
|
public static EventCaller instance { get; private set; }
|
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
public List<Minigames.Minigame> minigames = new List<Minigames.Minigame>()
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
|
|
|
};
|
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
public Minigames.Minigame GetMinigame(string gameName)
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
|
|
|
return minigames.Find(c => c.name == gameName);
|
|
|
|
}
|
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
public Minigames.GameAction GetGameAction(Minigames.Minigame game, string action)
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
|
|
|
return game.actions.Find(c => c.actionName == action);
|
|
|
|
}
|
|
|
|
|
2021-12-23 00:08:35 +00:00
|
|
|
public void Init()
|
|
|
|
{
|
2022-01-08 16:42:48 +00:00
|
|
|
instance = this;
|
2022-01-17 19:23:18 +00:00
|
|
|
|
|
|
|
Minigames.Init(this);
|
|
|
|
|
|
|
|
List<Minigames.Minigame> minigamesInBeatmap = new List<Minigames.Minigame>();
|
2021-12-31 14:46:11 +00:00
|
|
|
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
|
|
|
{
|
|
|
|
if (!minigamesInBeatmap.Contains(minigames.Find(c => c.name == GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0])) && GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0] != "gameManager")
|
|
|
|
{
|
|
|
|
minigamesInBeatmap.Add(minigames.Find(c => c.name == GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < minigamesInBeatmap.Count; i++)
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
2021-12-31 14:46:11 +00:00
|
|
|
minigames[minigames.FindIndex(c => c.name == minigamesInBeatmap[i].name)].holder = Resources.Load<GameObject>($"Games/{minigamesInBeatmap[i].name}");
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2021-12-23 02:28:05 +00:00
|
|
|
if (GameManager.instance.currentEvent >= 0 && GameManager.instance.currentEvent < GameManager.instance.Beatmap.entities.Count)
|
2021-12-23 00:08:35 +00:00
|
|
|
currentBeat = GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent].beat;
|
|
|
|
}
|
|
|
|
|
2021-12-23 01:49:16 +00:00
|
|
|
public void CallEvent(string event_)
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
|
|
|
string[] details = event_.Split('/');
|
2022-01-17 19:23:18 +00:00
|
|
|
Minigames.Minigame game = minigames.Find(c => c.name == details[0]);
|
2021-12-23 00:08:35 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2021-12-23 22:39:03 +00:00
|
|
|
currentLength = GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent].length;
|
2021-12-25 13:32:52 +00:00
|
|
|
currentType = GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent].type;
|
2021-12-26 01:04:23 +00:00
|
|
|
currentValA = GameManager.instance.Beatmap.entities[GameManager.instance.currentEvent].valA;
|
2021-12-23 22:39:03 +00:00
|
|
|
|
2021-12-24 03:36:16 +00:00
|
|
|
if (details.Length > 2) currentSwitchGame = details[2];
|
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
Minigames.GameAction action = game.actions.Find(c => c.actionName == details[1]);
|
2021-12-23 00:08:35 +00:00
|
|
|
action.function.Invoke();
|
2021-12-23 01:49:16 +00:00
|
|
|
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
2021-12-25 02:37:03 +00:00
|
|
|
Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented." + ex);
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-12-23 01:49:16 +00:00
|
|
|
|
2021-12-26 05:11:54 +00:00
|
|
|
public static List<Beatmap.Entity> GetAllInGameManagerList(string gameName, string[] include)
|
|
|
|
{
|
|
|
|
List<Beatmap.Entity> temp1 = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
|
|
|
|
List<Beatmap.Entity> temp2 = new List<Beatmap.Entity>();
|
|
|
|
for (int i = 0; i < temp1.Count; i++)
|
|
|
|
{
|
|
|
|
if (include.Any(temp1[i].datamodel.Split('/')[1].Contains))
|
|
|
|
{
|
|
|
|
temp2.Add(temp1[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return temp2;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<Beatmap.Entity> GetAllInGameManagerListExclude(string gameName, string[] exclude)
|
2021-12-23 01:49:16 +00:00
|
|
|
{
|
|
|
|
List<Beatmap.Entity> temp1 = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
|
|
|
|
List<Beatmap.Entity> temp2 = new List<Beatmap.Entity>();
|
|
|
|
for (int i = 0; i < temp1.Count; i++)
|
|
|
|
{
|
|
|
|
if (!exclude.Any(temp1[i].datamodel.Split('/')[1].Contains))
|
|
|
|
{
|
|
|
|
temp2.Add(temp1[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return temp2;
|
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
|
|
|
|
public static List<Beatmap.Entity> GetAllPlayerEntities(string gameName)
|
|
|
|
{
|
|
|
|
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static List<Beatmap.Entity> GetAllPlayerEntitiesExcept(string gameName)
|
|
|
|
{
|
|
|
|
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] != gameName);
|
|
|
|
}
|
|
|
|
|
|
|
|
// elaborate as fuck, boy
|
|
|
|
public static List<Beatmap.Entity> GetAllPlayerEntitiesExceptBeforeBeat(string gameName, float beat)
|
|
|
|
{
|
|
|
|
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] != gameName && c.beat < beat);
|
|
|
|
}
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
}
|