Need help saving jsonstorablefloats to a file. How do I create a prefs variable and dump that to be loaded later. This is to store slider data for my plugin
public override void Init()
{
SetupSliderFloat("MySlider", 0.3f, 0.0f, 1.0f, false);
}
private JSONStorableFloat SetupSliderFloat(string label, float defaultValue, float minValue, float maxValue, bool rightSide)
{
JSONStorableFloat storable = new JSONStorableFloat(label, defaultValue, minValue, maxValue, true, true);
storable.storeType = JSONStorableParam.StoreType.Full;
CreateSlider(storable, rightSide);
RegisterFloat(storable);
return storable;
}
public override JSONClass GetJSON(bool includePhysical = true, bool includeAppearance = true, bool forceStore = false)
{
JSONClass jc = base.GetJSON(includePhysical, includeAppearance, forceStore);
if (includePhysical || forceStore)
{
needsStore = true;
// save your custom data in JSON here
jc["MyData"].AsInt = 42;
}
return jc;
}
public override void LateRestoreFromJSON(JSONClass jc, bool restorePhysical = true, bool restoreAppearance = true, bool setMissingToDefault = true)
{
base.LateRestoreFromJSON(jc, restorePhysical, restoreAppearance, setMissingToDefault);
if (!base.physicalLocked && restorePhysical)
{
// load your custom data from JSON here
myData = jc["MyData"].AsInt;
}
}
public void SaveJSON(JSONClass jc, string saveName)
public void SaveJSON(JSONClass jc, string saveName, UserActionCallback confirmCallback, UserActionCallback denyCallback, ExceptionCallback exceptionCallback)
public JSONNode LoadJSON(string saveName)
protected Dictionary<string, JSONStorableParam> allParams;
public void SaveToStore1()
{
copyStore1 = GetJSON(includePhysical: true, includeAppearance: true, forceStore: true);
}
public void RestoreAllFromStore1()
{
RestoreFromStore1();
}
JSONClass jc = new JSONClass();
JSONClass info = new JSONClass();
info["Format"] = "AWWalker.MultiPass";
info["Version"].AsInt = GMP_VERSION;
string creatorName = UserPreferences.singleton.creatorName;
if (string.IsNullOrEmpty(creatorName))
creatorName = "Unknown";
info["Author"] = creatorName;
jc["Info"] = info;
jc["OverallIntensity"].AsFloat = OverallIntensity.val;
...
...
jc["LabMinLLowMorphChangeMax"].AsFloat = LabMinLLowMorphChangeMax.val;
SaveJSON(jc, path);
JSONClass jc = LoadJSON(path).AsObject;
try { OverallIntensity.val = jc["OverallIntensity"].AsFloat; } catch { SuperController.LogError("Couldn't apply settings to :OverallIntensity"); }
...
...
try { LabMinLLowMorphChangeMax.val = jc["LabMinLLowMorphChangeMax"].AsFloat; } catch { SuperController.LogError("Couldn't apply settings to :LabMinLLowMorphChangeMax"); }
I would recommend to make your code stable enough that you can rely on having your storables (OverallIntensity, ...) initialized at the point your code could reach the loading/saving code?Also made it sturdy, so that bad values, or missing morphs don't jack it up on the load. Should i do the same to the save?
IdlePoser and LogicBricks have both various examples of custom UI elements. MacGruber_Utils.cs will help you. E.g. there are some labels with checkboxes plus an X button used for the morph captures in IdlePoser.Now if i can make a slider with a toggle all in one...
Nope, I'm busy with other things......working on LogicBricks.14Have you checked it out at all?