void HandleLoadPreset(string aPath) { if (String.IsNullOrEmpty(aPath)) { return; } _lastBrowseDir = aPath.Substring(0, aPath.LastIndexOfAny(new char[] { '/', '\\' })) + @"\"; JSONNode json = this.LoadJSON(aPath); HairStyle style = HairStyle.CreateFromSavedJson(json); style?.ApplyToPerson(containingAtom, _loadColor.val, _loadStyle.val, _loadPhysics.val); }
public void ApplyToPerson(Atom aPerson, bool aColor = true, bool aStyle = true, bool aPhysics = true) { DAZCharacterSelector character = aPerson.GetStorableByID("geometry") as DAZCharacterSelector; List <string> hairSettingsRestoreList = new List <string>(); List <string> restoreStorablesList = new List <string>(); HairStyle origStyle = null; // Colors are stored per-style. If we change styles, but not color, the color will change. // So, if we are changing style but not color, we need to store off the current color and // restore it after the style change to ensure the color doesn't actually change. if (aStyle && !aColor) { origStyle = HairStyle.CreateFromPerson(aPerson); } JSONStorable scalps = FindStorableByName(aPerson, "Scalps"); JSONStorable styles = FindStorableByName(aPerson, "Styles"); // Apply any style changes so we are sure to apply modifications to the correct style if (aStyle) { RestoreStorable(scalps, _savedJson["Scalps"]); RestoreStorable(styles, _savedJson["Styles"]); } // Now that any style change is done, let's get the rest of the storables JSONStorable moveContainer = FindStorableByName(aPerson, "ScalpContainer"); JSONStorable hairSettings = FindStorableByName(aPerson, "HairSettings"); // Get Style and Scalp choices string scalpName = scalps.GetStringChooserParamValue("choiceName"); JSONStorable scalpStorable = null; if (scalpName != "NoScalp") { scalpStorable = FindStorableByName(aPerson, scalpName.Replace("Scalp", "HairScalp")); } // HairSettings contains color, style and physics, so has a special-case filter list if (aColor) { restoreStorablesList.AddRange(colorLoadList); hairSettingsRestoreList.AddRange(simColorList); } if (aStyle) { restoreStorablesList.AddRange(styleLoadList); hairSettingsRestoreList.AddRange(simStyleList); // Scalp style has already been restored, if applicable. } if (aPhysics) { restoreStorablesList.AddRange(physicsLoadList); hairSettingsRestoreList.AddRange(simPhysicsList); } foreach (var saveGroup in _savedJson) { List <string> restoreList = null; string groupName = saveGroup.Key; if (!restoreStorablesList.Contains(groupName)) { continue; } // Hair Settings contains all parameters for sim hair so must be filtered if (groupName == "HairSettings") { restoreList = hairSettingsRestoreList; } // Scalp params are stored per-style, but saved as scalpParams. Adjust the name to the current style. if (groupName == "scalpParams") { if (null != scalpStorable) { groupName = scalpStorable.name; } else { continue; // Can't save scalp parameters when there is no scalp } } // Restore the setting! var storable = FindStorableByName(aPerson, groupName); RestoreStorable(storable, saveGroup.Value, restoreList); } // If we switched styles without loading color, then copy over the color from the last style origStyle?.ApplyToPerson(aPerson, true, false, false); }