2021-12-23 00:08:35 +00:00
|
|
|
using System;
|
2021-12-23 01:49:16 +00:00
|
|
|
using System.Linq;
|
2024-04-07 04:54:06 +00:00
|
|
|
using BurstLinq;
|
2021-12-23 00:08:35 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
2023-06-10 19:13:29 +00:00
|
|
|
using Jukebox;
|
2021-12-23 00:08:35 +00:00
|
|
|
|
2022-03-14 14:21:05 +00:00
|
|
|
namespace HeavenStudio
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
|
|
|
public class EventCaller : MonoBehaviour
|
|
|
|
{
|
2024-01-25 17:29:05 +00:00
|
|
|
public GameManager gameManager { get; private set; }
|
2021-12-23 00:08:35 +00:00
|
|
|
public Transform GamesHolder;
|
2023-06-10 19:13:29 +00:00
|
|
|
public RiqEntity currentEntity = new RiqEntity();
|
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; }
|
|
|
|
|
2024-01-08 06:38:05 +00:00
|
|
|
public Dictionary<string, Minigames.Minigame> minigames = new();
|
2021-12-23 00:08:35 +00:00
|
|
|
|
2024-01-25 17:29:05 +00:00
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
public Minigames.Minigame GetMinigame(string gameName)
|
2022-01-08 16:42:48 +00:00
|
|
|
{
|
2024-01-08 06:38:05 +00:00
|
|
|
if (!minigames.ContainsKey(gameName))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return minigames[gameName];
|
2022-01-08 16:42:48 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-01-08 06:38:05 +00:00
|
|
|
public Minigames.GameAction GetGameAction(string gameName, string action)
|
|
|
|
{
|
|
|
|
if (minigames.ContainsKey(gameName))
|
|
|
|
{
|
|
|
|
return minigames[gameName].actions.Find(c => c.actionName == action);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Debug.LogWarning($"Game {gameName} not found!");
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-22 01:57:32 +00:00
|
|
|
public Minigames.Param GetGameParam(Minigames.Minigame game, string action, string param)
|
|
|
|
{
|
|
|
|
return GetGameAction(game, action).parameters.Find(c => c.propertyName == param);
|
|
|
|
}
|
|
|
|
|
2024-01-08 06:38:05 +00:00
|
|
|
public Minigames.Param GetGameParam(string gameName, string action, string param)
|
|
|
|
{
|
|
|
|
return GetGameAction(gameName, action).parameters.Find(c => c.propertyName == param);
|
|
|
|
}
|
|
|
|
|
2024-01-25 17:29:05 +00:00
|
|
|
public void Init(GameManager mgr)
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
2024-01-25 17:29:05 +00:00
|
|
|
gameManager = mgr;
|
2022-01-08 16:42:48 +00:00
|
|
|
instance = this;
|
2022-01-17 19:23:18 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
currentEntity = new RiqEntity();
|
2022-02-08 01:07:03 +00:00
|
|
|
|
2022-01-17 19:23:18 +00:00
|
|
|
Minigames.Init(this);
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void CallEvent(RiqEntity entity, bool gameActive)
|
2021-12-23 00:08:35 +00:00
|
|
|
{
|
2022-02-27 18:49:06 +00:00
|
|
|
string[] details = entity.datamodel.Split('/');
|
2024-01-08 06:38:05 +00:00
|
|
|
Minigames.Minigame game = minigames[details[0]];
|
2021-12-23 00:08:35 +00:00
|
|
|
try
|
|
|
|
{
|
2022-02-27 18:49:06 +00:00
|
|
|
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]);
|
2022-03-02 21:59:35 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2021-12-23 01:49:16 +00:00
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public void CallPreEvent(RiqEntity entity)
|
2023-01-05 04:04:31 +00:00
|
|
|
{
|
|
|
|
string[] details = entity.datamodel.Split('/');
|
2024-01-08 06:38:05 +00:00
|
|
|
Minigames.Minigame game = minigames[details[0]];
|
2023-01-05 04:04:31 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public static List<RiqEntity> GetAllInGameManagerList(string gameName, string[] include)
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
2024-04-09 02:01:18 +00:00
|
|
|
Predicate<RiqEntity> match = c =>
|
2021-12-26 05:11:54 +00:00
|
|
|
{
|
2024-04-09 02:01:18 +00:00
|
|
|
string[] details = c.datamodel.Split('/');
|
|
|
|
return details[0] == gameName && include.Contains(details[1]);
|
|
|
|
};
|
|
|
|
return instance.gameManager.Beatmap.Entities.FindAll(match);
|
2021-12-26 05:11:54 +00:00
|
|
|
}
|
|
|
|
|
2023-06-10 19:13:29 +00:00
|
|
|
public static List<RiqEntity> GetAllInGameManagerListExclude(string gameName, string[] exclude)
|
2021-12-23 01:49:16 +00:00
|
|
|
{
|
2024-04-09 02:01:18 +00:00
|
|
|
Predicate<RiqEntity> match = c =>
|
2021-12-23 01:49:16 +00:00
|
|
|
{
|
2024-04-09 02:01:18 +00:00
|
|
|
string[] details = c.datamodel.Split('/');
|
|
|
|
return details[0] == gameName && !exclude.Contains(details[1]);
|
|
|
|
};
|
|
|
|
return instance.gameManager.Beatmap.Entities.FindAll(match);
|
2021-12-23 01:49:16 +00:00
|
|
|
}
|
2021-12-24 03:36:16 +00:00
|
|
|
|
2022-02-03 03:58:08 +00:00
|
|
|
public static List<Minigames.Minigame> FXOnlyGames()
|
|
|
|
{
|
2024-01-08 06:38:05 +00:00
|
|
|
return instance.minigames.Values.ToList().FindAll(c => c.fxOnly);
|
2022-02-03 03:58:08 +00:00
|
|
|
}
|
2021-12-23 00:08:35 +00:00
|
|
|
}
|
|
|
|
}
|