mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-22 17:45:16 +00:00
correct param typings on load now
This commit is contained in:
parent
4b83724079
commit
3697021976
4 changed files with 92 additions and 66 deletions
|
@ -67,7 +67,7 @@ namespace HeavenStudio
|
||||||
return JsonConvert.DeserializeObject<Entity>(JsonConvert.SerializeObject(this));
|
return JsonConvert.DeserializeObject<Entity>(JsonConvert.SerializeObject(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public object this[string propertyName]
|
public dynamic this[string propertyName]
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
|
|
|
@ -110,37 +110,12 @@ namespace HeavenStudio
|
||||||
case "datamodel":
|
case "datamodel":
|
||||||
return datamodel;
|
return datamodel;
|
||||||
default:
|
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))
|
if (DynamicData.ContainsKey(propertyName))
|
||||||
{
|
|
||||||
var pType = DynamicData[propertyName].GetType();
|
|
||||||
if (pType == type)
|
|
||||||
{
|
|
||||||
return DynamicData[propertyName];
|
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
|
else
|
||||||
{
|
{
|
||||||
|
Minigames.Minigame game = EventCaller.instance.GetMinigame(datamodel.Split(0));
|
||||||
|
Minigames.Param param = EventCaller.instance.GetGameParam(game, datamodel.Split(1), propertyName);
|
||||||
return param.parameter;
|
return param.parameter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -222,44 +197,49 @@ namespace HeavenStudio
|
||||||
dynamicBeatmap.musicVolume = beatmap.musicVolume;
|
dynamicBeatmap.musicVolume = beatmap.musicVolume;
|
||||||
dynamicBeatmap.firstBeatOffset = beatmap.firstBeatOffset;
|
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<string, dynamic> dynamicData = new Dictionary<string, dynamic>();
|
||||||
|
//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()
|
dynamicBeatmap.entities.Add(new DynamicEntity()
|
||||||
{
|
{
|
||||||
beat = entity.beat,
|
beat = e.beat,
|
||||||
track = entity.track,
|
track = e.track,
|
||||||
length = entity.length,
|
length = e.length,
|
||||||
swing = entity.swing,
|
swing = e.swing,
|
||||||
datamodel = entity.datamodel,
|
datamodel = e.datamodel,
|
||||||
//TODO: only convert properties that actually exist in each GameAction
|
DynamicData = dynamicData
|
||||||
DynamicData = new Dictionary<string, dynamic>()
|
|
||||||
{
|
|
||||||
{ "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 },
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
foreach (var tempoChange in beatmap.tempoChanges)
|
foreach (var tempoChange in beatmap.tempoChanges)
|
||||||
|
@ -306,5 +286,49 @@ namespace HeavenStudio
|
||||||
return beatmap;
|
return beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// processes an riq beatmap after it is loaded
|
||||||
|
/// </summary>
|
||||||
|
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<string, dynamic> dynamicData = new Dictionary<string, dynamic>();
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -125,7 +125,6 @@ namespace HeavenStudio
|
||||||
|
|
||||||
public void LoadRemix(string json = "", string type = "riq", int version = 0)
|
public void LoadRemix(string json = "", string type = "riq", int version = 0)
|
||||||
{
|
{
|
||||||
SortEventsList();
|
|
||||||
|
|
||||||
if (json != "")
|
if (json != "")
|
||||||
{
|
{
|
||||||
|
@ -138,6 +137,7 @@ namespace HeavenStudio
|
||||||
break;
|
break;
|
||||||
case "riq":
|
case "riq":
|
||||||
Beatmap = JsonConvert.DeserializeObject<DynamicBeatmap>(json);
|
Beatmap = JsonConvert.DeserializeObject<DynamicBeatmap>(json);
|
||||||
|
Beatmap.PostProcess();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
NewRemix();
|
NewRemix();
|
||||||
|
@ -148,6 +148,7 @@ namespace HeavenStudio
|
||||||
{
|
{
|
||||||
NewRemix();
|
NewRemix();
|
||||||
}
|
}
|
||||||
|
SortEventsList();
|
||||||
Conductor.instance.SetBpm(Beatmap.bpm);
|
Conductor.instance.SetBpm(Beatmap.bpm);
|
||||||
Conductor.instance.SetVolume(Beatmap.musicVolume);
|
Conductor.instance.SetVolume(Beatmap.musicVolume);
|
||||||
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
Conductor.instance.firstBeatOffset = Beatmap.firstBeatOffset;
|
||||||
|
@ -336,6 +337,7 @@ namespace HeavenStudio
|
||||||
{
|
{
|
||||||
Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat));
|
Beatmap.entities.Sort((x, y) => x.beat.CompareTo(y.beat));
|
||||||
Beatmap.tempoChanges.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)
|
public void SetCurrentEventToClosest(float beat)
|
||||||
|
|
|
@ -78,7 +78,7 @@ namespace HeavenStudio.Editor
|
||||||
eventSelector.SetActive(false);
|
eventSelector.SetActive(false);
|
||||||
this.entity = entity;
|
this.entity = entity;
|
||||||
|
|
||||||
Editor.instance.SetGameEventTitle($"Properties for {entity.datamodel} at beat {entity.beat}");
|
Editor.instance.SetGameEventTitle($"Properties for {entity.datamodel}");
|
||||||
|
|
||||||
DestroyParams();
|
DestroyParams();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue