HeavenStudio/Assets/Scripts/EventCaller.cs

158 lines
5.9 KiB
C#
Raw Normal View History

2021-12-23 00:08:35 +00:00
using System;
using System.Linq;
2021-12-23 00:08:35 +00:00
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
2022-03-14 14:21:05 +00:00
namespace HeavenStudio
2021-12-23 00:08:35 +00:00
{
public class EventCaller : MonoBehaviour
{
public Transform GamesHolder;
public DynamicBeatmap.DynamicEntity currentEntity = new DynamicBeatmap.DynamicEntity();
2022-01-17 19:23:18 +00:00
public string currentSwitchGame;
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; }
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);
}
public Minigames.Param GetGameParam(Minigames.Minigame game, string action, string param)
{
return GetGameAction(game, action).parameters.Find(c => c.propertyName == param);
}
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
currentEntity = new DynamicBeatmap.DynamicEntity();
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++)
{
//go through every entity in the timeline and add the game that they're from to the minigamesInBeatmap list (ignore entities from FX only categories, i.e. Game Manager and Count-Ins)
Minigames.Minigame game = GetMinigame(GameManager.instance.Beatmap.entities[i].datamodel.Split('/')[0]);
if (!minigamesInBeatmap.Contains(game) && !FXOnlyGames().Contains(game))
2021-12-31 14:46:11 +00:00
{
minigamesInBeatmap.Add(game);
2021-12-31 14:46:11 +00:00
}
}
for (int i = 0; i < minigamesInBeatmap.Count; i++)
2021-12-23 00:08:35 +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 00:08:35 +00:00
}
public void CallEvent(DynamicBeatmap.DynamicEntity entity, bool gameActive)
2021-12-23 00:08:35 +00:00
{
string[] details = entity.datamodel.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
{
currentEntity = entity;
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]);
if (gameActive)
{
action.function.Invoke();
}
else
{
action.inactiveFunction.Invoke();
}
2021-12-23 00:08:35 +00:00
}
catch (Exception ex)
{
2022-03-07 02:37:27 +00:00
Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented.\n" + ex);
2021-12-23 00:08:35 +00:00
}
}
public void CallPreEvent(DynamicBeatmap.DynamicEntity entity)
{
string[] details = entity.datamodel.Split('/');
Minigames.Minigame game = minigames.Find(c => c.name == details[0]);
try
{
currentEntity = entity;
Minigames.GameAction action = game.actions.Find(c => c.actionName == details[1]);
action.preFunction.Invoke();
}
catch (Exception ex)
{
Debug.LogWarning("Event not found! May be spelled wrong or it is not implemented.\n" + ex);
}
}
public static List<DynamicBeatmap.DynamicEntity> GetAllInGameManagerList(string gameName, string[] include)
{
List<DynamicBeatmap.DynamicEntity> temp1 = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
List<DynamicBeatmap.DynamicEntity> temp2 = new List<DynamicBeatmap.DynamicEntity>();
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<DynamicBeatmap.DynamicEntity> GetAllInGameManagerListExclude(string gameName, string[] exclude)
{
List<DynamicBeatmap.DynamicEntity> temp1 = GameManager.instance.Beatmap.entities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
List<DynamicBeatmap.DynamicEntity> temp2 = new List<DynamicBeatmap.DynamicEntity>();
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<DynamicBeatmap.DynamicEntity> GetAllPlayerEntities(string gameName)
2021-12-24 03:36:16 +00:00
{
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] == gameName);
}
public static List<DynamicBeatmap.DynamicEntity> GetAllPlayerEntitiesExcept(string gameName)
2021-12-24 03:36:16 +00:00
{
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] != gameName);
}
// elaborate as fuck, boy
public static List<DynamicBeatmap.DynamicEntity> GetAllPlayerEntitiesExceptBeforeBeat(string gameName, float beat)
2021-12-24 03:36:16 +00:00
{
return GameManager.instance.playerEntities.FindAll(c => c.datamodel.Split('/')[0] != gameName && c.beat < beat);
}
2022-02-03 03:58:08 +00:00
public static List<Minigames.Minigame> FXOnlyGames()
{
return instance.minigames.FindAll(c => c.fxOnly == true).ToList();
}
2021-12-23 00:08:35 +00:00
}
}