mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-15 06:05:10 +00:00
Put Minigame Definitions in a Dictionary (#614)
* put minigame definitions in a dictionary why haven't we done this two years ago * paranoia
This commit is contained in:
parent
5cc31c32d8
commit
254e725b6f
7 changed files with 72 additions and 46 deletions
|
@ -2,9 +2,7 @@ using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
|
||||||
using Jukebox;
|
using Jukebox;
|
||||||
using Jukebox.Legacy;
|
|
||||||
|
|
||||||
namespace HeavenStudio
|
namespace HeavenStudio
|
||||||
{
|
{
|
||||||
|
@ -18,11 +16,15 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public static EventCaller instance { get; private set; }
|
public static EventCaller instance { get; private set; }
|
||||||
|
|
||||||
public List<Minigames.Minigame> minigames = new List<Minigames.Minigame>();
|
public Dictionary<string, Minigames.Minigame> minigames = new();
|
||||||
|
|
||||||
public Minigames.Minigame GetMinigame(string gameName)
|
public Minigames.Minigame GetMinigame(string gameName)
|
||||||
{
|
{
|
||||||
return minigames.Find(c => c.name == gameName);
|
if (!minigames.ContainsKey(gameName))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return minigames[gameName];
|
||||||
}
|
}
|
||||||
|
|
||||||
public Minigames.GameAction GetGameAction(Minigames.Minigame game, string action)
|
public Minigames.GameAction GetGameAction(Minigames.Minigame game, string action)
|
||||||
|
@ -30,11 +32,29 @@ namespace HeavenStudio
|
||||||
return game.actions.Find(c => c.actionName == action);
|
return game.actions.Find(c => c.actionName == action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Minigames.Param GetGameParam(Minigames.Minigame game, string action, string param)
|
public Minigames.Param GetGameParam(Minigames.Minigame game, string action, string param)
|
||||||
{
|
{
|
||||||
return GetGameAction(game, action).parameters.Find(c => c.propertyName == param);
|
return GetGameAction(game, action).parameters.Find(c => c.propertyName == param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Minigames.Param GetGameParam(string gameName, string action, string param)
|
||||||
|
{
|
||||||
|
return GetGameAction(gameName, action).parameters.Find(c => c.propertyName == param);
|
||||||
|
}
|
||||||
|
|
||||||
public void Init()
|
public void Init()
|
||||||
{
|
{
|
||||||
instance = this;
|
instance = this;
|
||||||
|
@ -68,7 +88,7 @@ namespace HeavenStudio
|
||||||
public void CallEvent(RiqEntity entity, bool gameActive)
|
public void CallEvent(RiqEntity entity, bool gameActive)
|
||||||
{
|
{
|
||||||
string[] details = entity.datamodel.Split('/');
|
string[] details = entity.datamodel.Split('/');
|
||||||
Minigames.Minigame game = minigames.Find(c => c.name == details[0]);
|
Minigames.Minigame game = minigames[details[0]];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
currentEntity = entity;
|
currentEntity = entity;
|
||||||
|
@ -94,7 +114,7 @@ namespace HeavenStudio
|
||||||
public void CallPreEvent(RiqEntity entity)
|
public void CallPreEvent(RiqEntity entity)
|
||||||
{
|
{
|
||||||
string[] details = entity.datamodel.Split('/');
|
string[] details = entity.datamodel.Split('/');
|
||||||
Minigames.Minigame game = minigames.Find(c => c.name == details[0]);
|
Minigames.Minigame game = minigames[details[0]];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
currentEntity = entity;
|
currentEntity = entity;
|
||||||
|
@ -153,7 +173,7 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public static List<Minigames.Minigame> FXOnlyGames()
|
public static List<Minigames.Minigame> FXOnlyGames()
|
||||||
{
|
{
|
||||||
return instance.minigames.FindAll(c => c.fxOnly == true).ToList();
|
return instance.minigames.Values.ToList().FindAll(c => c.fxOnly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -469,8 +469,7 @@ namespace HeavenStudio
|
||||||
|
|
||||||
string[] seekEntityDatamodel = seekEntity.datamodel.Split('/');
|
string[] seekEntityDatamodel = seekEntity.datamodel.Split('/');
|
||||||
|
|
||||||
float seekTime = eventCaller.GetGameAction(
|
float seekTime = eventCaller.GetGameAction(seekEntityDatamodel[0], seekEntityDatamodel[1]).preFunctionLength;
|
||||||
eventCaller.GetMinigame(seekEntityDatamodel[0]), seekEntityDatamodel[1]).preFunctionLength;
|
|
||||||
|
|
||||||
if (start + seekTime >= eventBeats[currentPreSequence])
|
if (start + seekTime >= eventBeats[currentPreSequence])
|
||||||
{
|
{
|
||||||
|
@ -904,10 +903,8 @@ namespace HeavenStudio
|
||||||
xDatamodel = x.datamodel.Split('/');
|
xDatamodel = x.datamodel.Split('/');
|
||||||
yDatamodel = y.datamodel.Split('/');
|
yDatamodel = y.datamodel.Split('/');
|
||||||
|
|
||||||
Minigames.Minigame xGame = eventCaller.GetMinigame(xDatamodel[0]);
|
Minigames.GameAction xAction = eventCaller.GetGameAction(xDatamodel[0], xDatamodel[1]);
|
||||||
Minigames.GameAction xAction = eventCaller.GetGameAction(xGame, xDatamodel[1]);
|
Minigames.GameAction yAction = eventCaller.GetGameAction(yDatamodel[0], yDatamodel[1]);
|
||||||
Minigames.Minigame yGame = eventCaller.GetMinigame(yDatamodel[0]);
|
|
||||||
Minigames.GameAction yAction = eventCaller.GetGameAction(yGame, yDatamodel[1]);
|
|
||||||
|
|
||||||
return yAction.priority.CompareTo(xAction.priority);
|
return yAction.priority.CompareTo(xAction.priority);
|
||||||
});
|
});
|
||||||
|
@ -1196,7 +1193,7 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public Minigames.Minigame GetGameInfo(string name)
|
public Minigames.Minigame GetGameInfo(string name)
|
||||||
{
|
{
|
||||||
return eventCaller.minigames.Find(c => c.name == name);
|
return eventCaller.GetMinigame(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Color colMain;
|
Color colMain;
|
||||||
|
|
|
@ -104,7 +104,7 @@ namespace HeavenStudio.Editor
|
||||||
GameManager.instance.Init();
|
GameManager.instance.Init();
|
||||||
Timeline.Init();
|
Timeline.Init();
|
||||||
|
|
||||||
foreach (var minigame in EventCaller.instance.minigames)
|
foreach (var minigame in EventCaller.instance.minigames.Values)
|
||||||
AddIcon(minigame);
|
AddIcon(minigame);
|
||||||
|
|
||||||
UpdateEditorStatus(true);
|
UpdateEditorStatus(true);
|
||||||
|
|
|
@ -81,8 +81,9 @@ namespace HeavenStudio.Editor
|
||||||
|
|
||||||
private void AddParams(RiqEntity entity)
|
private void AddParams(RiqEntity entity)
|
||||||
{
|
{
|
||||||
var minigame = EventCaller.instance.GetMinigame(entity.datamodel.Split(0));
|
string[] split = entity.datamodel.Split('/');
|
||||||
int actionIndex = minigame.actions.IndexOf(minigame.actions.Find(c => c.actionName == entity.datamodel.Split(1)));
|
var minigame = EventCaller.instance.GetMinigame(split[0]);
|
||||||
|
int actionIndex = minigame.actions.IndexOf(minigame.actions.Find(c => c.actionName == split[1]));
|
||||||
Minigames.GameAction action = minigame.actions[actionIndex];
|
Minigames.GameAction action = minigame.actions[actionIndex];
|
||||||
|
|
||||||
if (action.parameters != null)
|
if (action.parameters != null)
|
||||||
|
|
|
@ -873,10 +873,8 @@ namespace HeavenStudio.Editor.Track
|
||||||
|
|
||||||
public TimelineEventObj AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), RiqEntity entity = null, bool addEvent = false)
|
public TimelineEventObj AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), RiqEntity entity = null, bool addEvent = false)
|
||||||
{
|
{
|
||||||
var game = EventCaller.instance.GetMinigame(eventName.Split(0));
|
string[] split = eventName.Split('/');
|
||||||
var action = EventCaller.instance.GetGameAction(game, eventName.Split(1));
|
var action = EventCaller.instance.GetGameAction(split[0], split[1]);
|
||||||
|
|
||||||
var gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
|
||||||
|
|
||||||
if (addEvent)
|
if (addEvent)
|
||||||
{
|
{
|
||||||
|
@ -884,7 +882,7 @@ namespace HeavenStudio.Editor.Track
|
||||||
|
|
||||||
if (entity == null)
|
if (entity == null)
|
||||||
{
|
{
|
||||||
RiqEntity en = GameManager.instance.Beatmap.AddNewEntity(eventName, 0, gameAction.defaultLength);
|
RiqEntity en = GameManager.instance.Beatmap.AddNewEntity(eventName, 0, action.defaultLength);
|
||||||
|
|
||||||
tempEntity = en;
|
tempEntity = en;
|
||||||
|
|
||||||
|
|
|
@ -87,32 +87,31 @@ namespace HeavenStudio.Editor.Track
|
||||||
|
|
||||||
var eventName = entity.datamodel;
|
var eventName = entity.datamodel;
|
||||||
|
|
||||||
var game = EventCaller.instance.GetMinigame(eventName.Split(0));
|
string[] split = eventName.Split('/');
|
||||||
var action = EventCaller.instance.GetGameAction(game, eventName.Split(1));
|
var action = EventCaller.instance.GetGameAction(split[0], split[1]);
|
||||||
var gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
|
||||||
|
|
||||||
if (eventName.Split(1) == "switchGame")
|
if (split[1] == "switchGame")
|
||||||
Icon.sprite = Editor.GameIcon(eventName.Split(2));
|
Icon.sprite = Editor.GameIcon(split[2]);
|
||||||
else
|
else
|
||||||
Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
Icon.sprite = Editor.GameIcon(split[0]);
|
||||||
|
|
||||||
if (gameAction != null)
|
if (action != null)
|
||||||
{
|
{
|
||||||
this.resizable = gameAction.resizable;
|
this.resizable = action.resizable;
|
||||||
if (gameAction.resizable == false)
|
if (action.resizable == false)
|
||||||
{
|
{
|
||||||
rectTransform.sizeDelta = new Vector2(gameAction.defaultLength * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
rectTransform.sizeDelta = new Vector2(action.defaultLength * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
||||||
this.length = gameAction.defaultLength;
|
this.length = action.defaultLength;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (entity != null && gameAction.defaultLength != entity.length)
|
if (entity != null && action.defaultLength != entity.length)
|
||||||
{
|
{
|
||||||
rectTransform.sizeDelta = new Vector2(entity.length * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
rectTransform.sizeDelta = new Vector2(entity.length * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
rectTransform.sizeDelta = new Vector2(gameAction.defaultLength * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
rectTransform.sizeDelta = new Vector2(action.defaultLength * Timeline.instance.PixelsPerBeat, Timeline.instance.LayerHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -383,13 +382,13 @@ namespace HeavenStudio.Editor.Track
|
||||||
}
|
}
|
||||||
else if (Input.GetMouseButton(2))
|
else if (Input.GetMouseButton(2))
|
||||||
{
|
{
|
||||||
var mgs = EventCaller.instance.minigames;
|
// var mgs = EventCaller.instance.minigames;
|
||||||
string[] datamodels = entity.datamodel.Split('/');
|
string[] datamodels = entity.datamodel.Split('/');
|
||||||
Debug.Log("Selected entity's datamodel : " + entity.datamodel);
|
Debug.Log("Selected entity's datamodel : " + entity.datamodel);
|
||||||
|
|
||||||
bool isSwitchGame = datamodels[1] == "switchGame";
|
bool isSwitchGame = datamodels[1] == "switchGame";
|
||||||
int gameIndex = mgs.FindIndex(c => c.name == datamodels[isSwitchGame ? 2 : 0]);
|
// int gameIndex = mgs.FindIndex(c => c.name == datamodels[isSwitchGame ? 2 : 0]);
|
||||||
int block = isSwitchGame ? 0 : mgs[gameIndex].actions.FindIndex(c => c.actionName == datamodels[1]) + 1;
|
int block = isSwitchGame ? 0 : EventCaller.instance.minigames[datamodels[isSwitchGame ? 2 : 0]].actions.FindIndex(c => c.actionName == datamodels[1]) + 1;
|
||||||
|
|
||||||
if (!isSwitchGame)
|
if (!isSwitchGame)
|
||||||
{
|
{
|
||||||
|
|
|
@ -192,16 +192,18 @@ namespace HeavenStudio
|
||||||
System.Type type, pType;
|
System.Type type, pType;
|
||||||
if (EventCaller.instance != null)
|
if (EventCaller.instance != null)
|
||||||
{
|
{
|
||||||
|
string[] split;
|
||||||
foreach (var e in data.entities)
|
foreach (var e in data.entities)
|
||||||
{
|
{
|
||||||
var gameName = e.datamodel.Split(0);
|
split = e.datamodel.Split('/');
|
||||||
var actionName = e.datamodel.Split(1);
|
var gameName = split[0];
|
||||||
|
var actionName = split[1];
|
||||||
game = EventCaller.instance.GetMinigame(gameName);
|
game = EventCaller.instance.GetMinigame(gameName);
|
||||||
if (game == null)
|
if (game == null)
|
||||||
{
|
{
|
||||||
Debug.LogWarning($"Unknown game {gameName} found in remix.json! Adding game...");
|
Debug.LogWarning($"Unknown game {gameName} found in remix.json! Adding game...");
|
||||||
game = new Minigames.Minigame(gameName, gameName.DisplayName() + " \n<color=#eb5454>[inferred from remix.json]</color>", "", false, false, new List<Minigames.GameAction>(), inferred: true);
|
game = new Minigames.Minigame(gameName, gameName.DisplayName() + " \n<color=#eb5454>[inferred from remix.json]</color>", "", false, false, new List<Minigames.GameAction>(), inferred: true);
|
||||||
EventCaller.instance.minigames.Add(game);
|
EventCaller.instance.minigames.Add(gameName, game);
|
||||||
if (Editor.Editor.instance != null)
|
if (Editor.Editor.instance != null)
|
||||||
Editor.Editor.instance.AddIcon(game);
|
Editor.Editor.instance.AddIcon(game);
|
||||||
}
|
}
|
||||||
|
@ -646,9 +648,6 @@ namespace HeavenStudio
|
||||||
this.preFunction = prescheduleFunction ?? delegate { };
|
this.preFunction = prescheduleFunction ?? delegate { };
|
||||||
this.priority = priority;
|
this.priority = priority;
|
||||||
this.preFunctionLength = preFunctionLength;
|
this.preFunctionLength = preFunctionLength;
|
||||||
|
|
||||||
|
|
||||||
//todo: converting to new versions of GameActions
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -728,7 +727,7 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public static void Init(EventCaller eventCaller)
|
public static void Init(EventCaller eventCaller)
|
||||||
{
|
{
|
||||||
eventCaller.minigames = new List<Minigame>()
|
List<Minigame> defaultGames = new()
|
||||||
{
|
{
|
||||||
new Minigame("gameManager", "Game Manager", "", false, true, new List<GameAction>()
|
new Minigame("gameManager", "Game Manager", "", false, true, new List<GameAction>()
|
||||||
{
|
{
|
||||||
|
@ -1175,11 +1174,23 @@ namespace HeavenStudio
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
foreach (var game in defaultGames)
|
||||||
|
{
|
||||||
|
eventCaller.minigames.Add(game.name, game);
|
||||||
|
}
|
||||||
|
|
||||||
BuildLoadRunnerList();
|
BuildLoadRunnerList();
|
||||||
|
Debug.Log($"Running {loadRunners.Count} game loaders...");
|
||||||
foreach (var load in loadRunners)
|
foreach (var load in loadRunners)
|
||||||
{
|
{
|
||||||
Debug.Log("Running game loader " + RuntimeReflectionExtensions.GetMethodInfo(load).DeclaringType.Name);
|
Debug.Log("Running game loader " + RuntimeReflectionExtensions.GetMethodInfo(load).DeclaringType.Name);
|
||||||
eventCaller.minigames.Add(load(eventCaller));
|
Minigame game = load(eventCaller);
|
||||||
|
if (game == null)
|
||||||
|
{
|
||||||
|
Debug.LogError("Game loader " + RuntimeReflectionExtensions.GetMethodInfo(load).DeclaringType.Name + " failed!");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
eventCaller.minigames.Add(game.name, game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue