private void SaveStorable(JSONStorable aStorable, out JsonDict aDict) { aDict = new JsonDict(); foreach (var param in aStorable.GetAllFloatAndColorParamNames()) { var type = aStorable.GetParamOrActionType(param); JSONClass json = new JSONClass(); json["type"] = type.ToString(); json["id"] = param; JSONClass storableParams = new JSONClass(); switch (type) { case JSONStorable.Type.Color: aStorable.GetColorJSONParam(param)?.StoreJSON(storableParams); break; case JSONStorable.Type.Float: aStorable.GetFloatJSONParam(param)?.StoreJSON(storableParams); break; case JSONStorable.Type.Bool: aStorable.GetBoolJSONParam(param)?.StoreJSON(storableParams); break; case JSONStorable.Type.String: aStorable.GetStringJSONParam(param)?.StoreJSON(storableParams); break; case JSONStorable.Type.StringChooser: aStorable.GetStringChooserJSONParam(param)?.StoreJSON(storableParams); break; default: SuperController.LogError("Unhandled type: " + type.ToString()); break; } json["params"] = storableParams; aDict[param] = json; } }
private void RestoreStorable(JSONStorable aStorable, JsonDict aDict, List <string> aRestoreList = null) { foreach (var kp in aDict) { JSONClass json = kp.Value; string param = kp.Key; if (aRestoreList != null && !aRestoreList.Contains(param)) { continue; } JSONStorable.Type type = (JSONStorable.Type)Enum.Parse(typeof(JSONStorable.Type), json["type"].Value); JSONClass paramJson = json["params"].AsObject; switch (type) { case JSONStorable.Type.Color: aStorable.GetColorJSONParam(param)?.RestoreFromJSON(paramJson); break; case JSONStorable.Type.Float: aStorable.GetFloatJSONParam(param)?.RestoreFromJSON(paramJson); break; case JSONStorable.Type.Bool: aStorable.GetBoolJSONParam(param)?.RestoreFromJSON(paramJson); break; case JSONStorable.Type.String: aStorable.GetStringJSONParam(param)?.RestoreFromJSON(paramJson); break; case JSONStorable.Type.StringChooser: aStorable.GetStringChooserJSONParam(param)?.RestoreFromJSON(paramJson); break; default: SuperController.LogError("Unhandled type: " + type.ToString()); break; } } }