finally fix deserialization of the new format

This commit is contained in:
minenice55 2022-08-21 21:57:32 -04:00
parent 9de0e1734e
commit 22335a7df7
6 changed files with 47 additions and 39 deletions

View file

@ -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 },

View file

@ -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;

View file

@ -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;
}

View file

@ -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];

View file

@ -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;

View file

@ -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 };
}
}
}
}