diff --git a/Assets/Scripts/BeatmapFormats/Beatmap.cs b/Assets/Scripts/BeatmapFormats/Beatmap.cs index 82e6885a..8d944af2 100644 --- a/Assets/Scripts/BeatmapFormats/Beatmap.cs +++ b/Assets/Scripts/BeatmapFormats/Beatmap.cs @@ -67,7 +67,7 @@ namespace HeavenStudio return JsonConvert.DeserializeObject(JsonConvert.SerializeObject(this)); } - public object this[string propertyName] + public dynamic this[string propertyName] { get { diff --git a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs index 02401c54..ddad957c 100644 --- a/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs +++ b/Assets/Scripts/BeatmapFormats/DynamicBeatmap.cs @@ -110,37 +110,12 @@ namespace HeavenStudio case "datamodel": return datamodel; default: - //TODO: do this checking and conversion on load instead of at runtime - 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); - } - } + return DynamicData[propertyName]; else { + Minigames.Minigame game = EventCaller.instance.GetMinigame(datamodel.Split(0)); + Minigames.Param param = EventCaller.instance.GetGameParam(game, datamodel.Split(1), propertyName); return param.parameter; } } @@ -222,44 +197,49 @@ namespace HeavenStudio dynamicBeatmap.musicVolume = beatmap.musicVolume; dynamicBeatmap.firstBeatOffset = beatmap.firstBeatOffset; - foreach (var entity in beatmap.entities) + Minigames.Minigame game; + Minigames.GameAction action; + System.Type type, pType; + foreach (var e in beatmap.entities) { + game = EventCaller.instance.GetMinigame(e.datamodel.Split(0)); + action = EventCaller.instance.GetGameAction(game, e.datamodel.Split(1)); + + Dictionary dynamicData = new Dictionary(); + //check each param of the action + if (action.parameters != null) + { + foreach (var param in action.parameters) + { + type = param.parameter.GetType(); + pType = e[param.propertyName].GetType(); + if (pType == type) + { + dynamicData.Add(param.propertyName, e[param.propertyName]); + } + else + { + if (type == typeof(EntityTypes.Integer)) + dynamicData.Add(param.propertyName, (int) e[param.propertyName]); + else if (type == typeof(EntityTypes.Float)) + dynamicData.Add(param.propertyName, (float) e[param.propertyName]); + else if (type.IsEnum && param.propertyName != "ease") + dynamicData.Add(param.propertyName, (int) e[param.propertyName]); + else if (pType == typeof(Newtonsoft.Json.Linq.JObject)) + dynamicData.Add(param.propertyName, e[param.propertyName].ToObject(type)); + else + dynamicData.Add(param.propertyName, Convert.ChangeType(e[param.propertyName], type)); + } + } + } dynamicBeatmap.entities.Add(new DynamicEntity() { - beat = entity.beat, - track = entity.track, - length = entity.length, - swing = entity.swing, - datamodel = entity.datamodel, - //TODO: only convert properties that actually exist in each GameAction - DynamicData = new Dictionary() - { - { "valA", entity.valA }, - { "valB", entity.valB }, - { "valC", entity.valC }, - - { "toggle", entity.toggle }, - - { "type", entity.type }, - { "type2", entity.type2 }, - { "type3", entity.type3 }, - { "type4", entity.type4 }, - { "type5", entity.type5 }, - { "type6", entity.type6 }, - - { "ease", (int) entity.ease }, - - { "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 }, - { "text3", entity.text3 }, - } + beat = e.beat, + track = e.track, + length = e.length, + swing = e.swing, + datamodel = e.datamodel, + DynamicData = dynamicData }); } foreach (var tempoChange in beatmap.tempoChanges) @@ -306,5 +286,49 @@ namespace HeavenStudio return beatmap; } + /// + /// processes an riq beatmap after it is loaded + /// + public void PostProcess() + { + Minigames.Minigame game; + Minigames.GameAction action; + System.Type type, pType; + foreach (var e in entities) + { + game = EventCaller.instance.GetMinigame(e.datamodel.Split(0)); + action = EventCaller.instance.GetGameAction(game, e.datamodel.Split(1)); + Dictionary dynamicData = new Dictionary(); + //check each param of the action + if (action.parameters != null) + { + foreach (var param in action.parameters) + { + type = param.parameter.GetType(); + pType = e[param.propertyName].GetType(); + if (pType == type) + { + dynamicData.Add(param.propertyName, e[param.propertyName]); + } + else + { + if (type == typeof(EntityTypes.Integer)) + dynamicData.Add(param.propertyName, (int) e[param.propertyName]); + else if (type == typeof(EntityTypes.Float)) + dynamicData.Add(param.propertyName, (float) e[param.propertyName]); + else if (type == typeof(EasingFunction.Ease) && pType == typeof(string)) + dynamicData.Add(param.propertyName, Enum.Parse(typeof(EasingFunction.Ease), (string) e[param.propertyName])); + else if (type.IsEnum) + dynamicData.Add(param.propertyName, (int) e[param.propertyName]); + else if (pType == typeof(Newtonsoft.Json.Linq.JObject)) + dynamicData.Add(param.propertyName, e[param.propertyName].ToObject(type)); + else + dynamicData.Add(param.propertyName, Convert.ChangeType(e[param.propertyName], type)); + } + } + } + e.DynamicData = dynamicData; + } + } } } \ No newline at end of file diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index 0b86e52a..61a1515a 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -125,7 +125,6 @@ namespace HeavenStudio public void LoadRemix(string json = "", string type = "riq", int version = 0) { - SortEventsList(); if (json != "") { @@ -138,6 +137,7 @@ namespace HeavenStudio break; case "riq": Beatmap = JsonConvert.DeserializeObject(json); + Beatmap.PostProcess(); break; default: NewRemix(); @@ -148,6 +148,7 @@ namespace HeavenStudio { NewRemix(); } + SortEventsList(); Conductor.instance.SetBpm(Beatmap.bpm); Conductor.instance.SetVolume(Beatmap.musicVolume); Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset; @@ -336,6 +337,7 @@ namespace HeavenStudio { Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat)); Beatmap.tempoChanges.Sort((x, y) => x.beat.CompareTo(y.beat)); + Beatmap.volumeChanges.Sort((x, y) => x.beat.CompareTo(y.beat)); } public void SetCurrentEventToClosest(float beat) diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs index a918ad68..3ebd306b 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs @@ -78,7 +78,7 @@ namespace HeavenStudio.Editor eventSelector.SetActive(false); this.entity = entity; - Editor.instance.SetGameEventTitle($"Properties for {entity.datamodel} at beat {entity.beat}"); + Editor.instance.SetGameEventTitle($"Properties for {entity.datamodel}"); DestroyParams();