Unrecognized entity support (#191)

Due to some recent discoveries about a certain upcoming rhythm game, I have added support for unrecognized entities found in remix.json to be loaded and moved, and be able to save them.
This commit is contained in:
Zeo 2023-01-06 21:59:54 -06:00 committed by GitHub
parent 87d20b8c8f
commit ddc183acdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 15 deletions

View file

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Text.RegularExpressions;
using UnityEngine; using UnityEngine;
using Newtonsoft.Json; using Newtonsoft.Json;
@ -344,8 +345,33 @@ namespace HeavenStudio
System.Type type, pType; System.Type type, pType;
foreach (var e in entities) foreach (var e in entities)
{ {
game = EventCaller.instance.GetMinigame(e.datamodel.Split(0)); var gameName = e.datamodel.Split(0);
action = EventCaller.instance.GetGameAction(game, e.datamodel.Split(1)); var actionName = e.datamodel.Split(1);
game = EventCaller.instance.GetMinigame(gameName);
if (game == null)
{
Debug.LogWarning($"Unknown game {gameName} found in remix.json! Adding game...");
game = new Minigames.Minigame(gameName, DisplayName(gameName) + " \n<color=#eb5454>[inferred from remix.json]</color>", "", false, true, new List<Minigames.GameAction>());
EventCaller.instance.minigames.Add(game);
Editor.Editor.instance.AddIcon(game);
}
action = EventCaller.instance.GetGameAction(game, actionName);
if (action == null)
{
Debug.LogWarning($"Unknown action {gameName}/{actionName} found in remix.json! Adding action...");
var parameters = new List<Minigames.Param>();
foreach (var item in e.DynamicData)
{
var value = item.Value;
if (value.GetType() == typeof(long))
value = new EntityTypes.Integer(int.MinValue, int.MaxValue, (int)value);
else if (value.GetType() == typeof(double))
value = new EntityTypes.Float(float.NegativeInfinity, float.PositiveInfinity, (float)value);
parameters.Add(new Minigames.Param(item.Key, value, item.Key, "[inferred from remix.json]"));
}
action = new Minigames.GameAction(actionName, DisplayName(actionName), e.length, true, parameters);
game.actions.Add(action);
}
Dictionary<string, dynamic> dynamicData = new Dictionary<string, dynamic>(); Dictionary<string, dynamic> dynamicData = new Dictionary<string, dynamic>();
//check each param of the action //check each param of the action
if (action.parameters != null) if (action.parameters != null)
@ -361,9 +387,9 @@ namespace HeavenStudio
{ {
Debug.LogWarning($"Property {param.propertyName} does not exist in the entity's dynamic data! Adding..."); Debug.LogWarning($"Property {param.propertyName} does not exist in the entity's dynamic data! Adding...");
if (type == typeof(EntityTypes.Integer)) if (type == typeof(EntityTypes.Integer))
dynamicData.Add(param.propertyName, (int)param.parameter); dynamicData.Add(param.propertyName, ((EntityTypes.Integer)param.parameter).val);
else if (type == typeof(EntityTypes.Float)) else if (type == typeof(EntityTypes.Float))
dynamicData.Add(param.propertyName, (float)param.parameter); dynamicData.Add(param.propertyName, ((EntityTypes.Float)param.parameter).val);
else if (type.IsEnum && param.propertyName != "ease") else if (type.IsEnum && param.propertyName != "ease")
dynamicData.Add(param.propertyName, (int)param.parameter); dynamicData.Add(param.propertyName, (int)param.parameter);
else else
@ -408,5 +434,29 @@ namespace HeavenStudio
} }
} }
} }
private string DisplayName(string name)
{
// "gameName" -> "Game Name"
// "action name" -> "Action Name"
if (!name.Contains(" "))
name = SplitCamelCase(name);
System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("en-US", false).TextInfo;
return textInfo.ToTitleCase(name);
}
// https://stackoverflow.com/a/5796793
public static string SplitCamelCase(string str)
{
return Regex.Replace(
Regex.Replace(
str,
@"(\P{Ll})(\P{Ll}\p{Ll})",
"$1 $2"
),
@"(\p{Ll})(\P{Ll})",
"$1 $2"
);
}
} }
} }

View file

@ -599,14 +599,18 @@ namespace HeavenStudio
{ {
if (gameInfo.fxOnly) if (gameInfo.fxOnly)
{ {
name = Beatmap.entities.FindAll(c => { var gameEntities = Beatmap.entities.FindAll(c => {
var gameName = c.datamodel.Split(0); var gameName = c.datamodel.Split(0);
var newGameInfo = GetGameInfo(gameName); var newGameInfo = GetGameInfo(gameName);
if (newGameInfo == null) if (newGameInfo == null)
return false; return false;
else else
return !newGameInfo.fxOnly; return !newGameInfo.fxOnly;
}).ToList()[0].datamodel.Split(0); }).ToList();
if (gameEntities.Count != 0)
name = gameEntities[0].datamodel.Split(0);
else
name = "noGame";
} }
else else
{ {

View file

@ -100,15 +100,8 @@ namespace HeavenStudio.Editor
GameManager.instance.Init(); GameManager.instance.Init();
Timeline.Init(); Timeline.Init();
for (int i = 0; i < EventCaller.instance.minigames.Count; i++) foreach (var minigame in EventCaller.instance.minigames)
{ AddIcon(minigame);
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
GameIcon_.GetComponent<Image>().sprite = GameIcon(EventCaller.instance.minigames[i].name);
GameIcon_.GetComponent<GridGameSelectorGame>().MaskTex = GameIconMask(EventCaller.instance.minigames[i].name);
GameIcon_.GetComponent<GridGameSelectorGame>().UnClickIcon();
GameIcon_.gameObject.SetActive(true);
GameIcon_.name = EventCaller.instance.minigames[i].displayName;
}
Tooltip.AddTooltip(NewBTN.gameObject, "New <color=#adadad>[Ctrl+N]</color>"); Tooltip.AddTooltip(NewBTN.gameObject, "New <color=#adadad>[Ctrl+N]</color>");
Tooltip.AddTooltip(OpenBTN.gameObject, "Open <color=#adadad>[Ctrl+O]</color>"); Tooltip.AddTooltip(OpenBTN.gameObject, "Open <color=#adadad>[Ctrl+O]</color>");
@ -128,6 +121,16 @@ namespace HeavenStudio.Editor
BuildDateDisplay.text = GlobalGameManager.buildTime; BuildDateDisplay.text = GlobalGameManager.buildTime;
} }
public void AddIcon(Minigames.Minigame minigame)
{
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
GameIcon_.GetComponent<Image>().sprite = GameIcon(minigame.name);
GameIcon_.GetComponent<GridGameSelectorGame>().MaskTex = GameIconMask(minigame.name);
GameIcon_.GetComponent<GridGameSelectorGame>().UnClickIcon();
GameIcon_.gameObject.SetActive(true);
GameIcon_.name = minigame.displayName;
}
public void LateUpdate() public void LateUpdate()
{ {
#region Keyboard Shortcuts #region Keyboard Shortcuts