diff --git a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs index 36b3c004..ad7c4a00 100644 --- a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs +++ b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using UnityEngine; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using HeavenStudio.Util; @@ -95,7 +96,38 @@ namespace HeavenStudio { get { - return DynamicData[propertyName]; + Minigames.Minigame game = EventCaller.instance.GetMinigame(datamodel.Split(0)); + Minigames.GameAction action = EventCaller.instance.GetGameAction(game, datamodel.Split(1)); + Minigames.Param param = EventCaller.instance.GetGameParam(game, datamodel.Split(1), propertyName); + var type = param.parameter.GetType(); + if (DynamicData.ContainsKey(propertyName)) + { + var pType = DynamicData[propertyName].GetType(); + if (pType == type) + { + return DynamicData[propertyName]; + } + else + { + if (type == typeof(EntityTypes.Integer)) + return (int) DynamicData[propertyName]; + else if (type == typeof(EntityTypes.Float)) + return (float) DynamicData[propertyName]; + else if (type.IsEnum) + return (int) DynamicData[propertyName]; + else if (pType == typeof(Newtonsoft.Json.Linq.JObject)) + { + DynamicData[propertyName] = DynamicData[propertyName].ToObject(type); + return DynamicData[propertyName]; + } + else + return Convert.ChangeType(DynamicData[propertyName], type); + } + } + else + { + return param.parameter; + } } set { @@ -200,12 +232,12 @@ namespace HeavenStudio { "ease", (int) entity.ease }, - { "colorA", (EntityTypes.SerializableColor) entity.colorA }, - { "colorB", (EntityTypes.SerializableColor) entity.colorB }, - { "colorC", (EntityTypes.SerializableColor) entity.colorC }, - { "colorD", (EntityTypes.SerializableColor) entity.colorD }, - { "colorE", (EntityTypes.SerializableColor) entity.colorE }, - { "colorF", (EntityTypes.SerializableColor) entity.colorF }, + { "colorA", (Color) entity.colorA }, + { "colorB", (Color) entity.colorB }, + { "colorC", (Color) entity.colorC }, + { "colorD", (Color) entity.colorD }, + { "colorE", (Color) entity.colorE }, + { "colorF", (Color) entity.colorF }, { "text1", entity.text1 }, { "text2", entity.text2 }, diff --git a/Assets/Scripts/EventCaller.cs b/Assets/Scripts/EventCaller.cs index 27aab25a..7d687e1d 100644 --- a/Assets/Scripts/EventCaller.cs +++ b/Assets/Scripts/EventCaller.cs @@ -28,6 +28,11 @@ namespace HeavenStudio 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); + } + public void Init() { instance = this; diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs index e531980e..a918ad68 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs @@ -118,7 +118,7 @@ namespace HeavenStudio.Editor { prefab = DropdownP; } - else if (objType == typeof(Color) || objType == typeof(EntityTypes.SerializableColor)) + else if (objType == typeof(Color)) { prefab = ColorP; } diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs index 5713b0aa..5bfdf155 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs @@ -120,10 +120,10 @@ namespace HeavenStudio.Editor ); break; - case EntityTypes.SerializableColor _: + // case EntityTypes.SerializableColor _: case Color _: colorPreview.colorPicker.onColorChanged += _ => - parameterManager.entity[propertyName] = new EntityTypes.SerializableColor { Color = colorPreview.colorPicker.color }; + parameterManager.entity[propertyName] = colorPreview.colorPicker.color; Color paramCol = parameterManager.entity[propertyName]; diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index e3a7eba9..fd04b965 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -592,10 +592,6 @@ namespace HeavenStudio.Editor.Track { returnVal = ((EntityTypes.Float)ep[i].parameter).val; } - else if (propertyType == typeof(Color)) - { - returnVal = new EntityTypes.SerializableColor { Color = (UnityEngine.Color) ep[i].parameter }; - } else if (propertyType.IsEnum) { returnVal = (int) ep[i].parameter; diff --git a/Assets/Scripts/Util/EntityTypes.cs b/Assets/Scripts/Util/EntityTypes.cs index 5dd37692..8db25e71 100644 --- a/Assets/Scripts/Util/EntityTypes.cs +++ b/Assets/Scripts/Util/EntityTypes.cs @@ -36,30 +36,5 @@ namespace HeavenStudio this.max = max; } } - - // https://answers.unity.com/questions/772235/cannot-serialize-color.html - // i am crying - [System.Serializable] - public class SerializableColor - { - public float[] colorStore = new float[4] { 1F, 1F, 1F, 1F }; - public UnityEngine.Color Color - { - get { return new Color(colorStore[0], colorStore[1], colorStore[2], colorStore[3]); } - set { colorStore = new float[4] { value.r, value.g, value.b, value.a }; } - } - - //makes this class usable as Color, Color normalColor = mySerializableColor; - public static implicit operator UnityEngine.Color(SerializableColor instance) - { - return instance.Color; - } - - //makes this class assignable by Color, SerializableColor myColor = Color.white; - public static implicit operator SerializableColor(UnityEngine.Color color) - { - return new SerializableColor { Color = color }; - } - } } } \ No newline at end of file