static void ModifyProperty(PersistentEffectEventArgs ea, string propertyPath, string prefix = null, string propertyKey = null, bool logDetails = false) { if (logDetails) { Talespire.Log.Debug($"ModifyProperty({propertyPath})"); } if (propertyKey == null) { propertyKey = propertyPath; } GameObject childNodeToModify = ea.AttachedNode.GetChildNodeStartingWith(prefix); if (childNodeToModify == null) { Talespire.Log.Error($"childNodeToModify == null"); childNodeToModify = ea.AttachedNode; } PropertyModDetails propertyModDetails = BasePropertyChanger.GetPropertyModDetails(childNodeToModify, propertyPath, logDetails); if (propertyModDetails == null) { Talespire.Log.Error($"propertyModDetails == null for property {propertyPath}"); return; } if (logDetails) { Talespire.Log.Debug($"propertyModDetails.GetPropertyType() = {propertyModDetails.GetPropertyType()}"); } BasePropertyChanger propertyChanger = PropertyChangerManager.GetPropertyChanger(propertyModDetails.GetPropertyType()); if (propertyChanger != null) { propertyChanger.FullPropertyPath = propertyPath; if (ea.PersistentEffect is SuperPersistentEffect superPersistentEffect && prefix != null) { if (logDetails) { Talespire.Log.Warning($"prefix = \"{prefix}\""); } string numberStr; if (prefix.StartsWith("0") && prefix.Length > 1) { numberStr = prefix.Remove(0, 1); } else { numberStr = prefix; } if (!int.TryParse(numberStr, out int index)) { Talespire.Log.Error($"Unable to parse \"{numberStr}\" into a number."); index = 0; } if (index >= 0 && index < superPersistentEffect.EffectProperties.Count) { EffectProperties effectProperties = superPersistentEffect.EffectProperties[index]; ChangeProperty(effectProperties.Properties, propertyKey, propertyPath, propertyModDetails, propertyChanger, logDetails); } else { Talespire.Log.Error($"index ({index}) out of range. Unable to modify property."); } } else { ChangeProperty(ea.PersistentEffect.Properties, propertyKey, propertyPath, propertyModDetails, propertyChanger, logDetails); } }
private void lstProperties_SelectedIndexChanged(object sender, EventArgs e) { try { EffectProperty effectProperty = lstProperties.SelectedItem as EffectProperty; if (effectProperty != null) { Talespire.Log.Warning($"{effectProperty.Name} selected!"); WindowHelper.FocusTaleSpire(); } frmPersistentEffectPropertyEditor.Controls.Clear(); UserControl valueEditor = ValueEditors.Get(STR_PersistentEffectsEditorKey, effectProperty.Type) as UserControl; if (valueEditor != null) { // TODO: Set the control's state based on the actual value. frmPersistentEffectPropertyEditor.Controls.Add(valueEditor); frmPersistentEffectPropertyEditor.Height = valueEditor.Height + 8; if (valueEditor is IScriptEditor scriptEditor) { //Talespire.Log.Warning($"Instance = \"{Instance}\""); if (effectProperty.Paths.StartsWith("<") && effectProperty.Paths.EndsWith(">")) { // Could be a script! //Talespire.Log.Debug($"Could be a script!"); Type scriptType = KnownScripts.GetType(effectProperty.Paths.Substring(1, effectProperty.Paths.Length - 2)); if (scriptType != null) { //Talespire.Log.Debug($"scriptType found {scriptType.FullName}"); UnityEngine.Component script = Instance.GetComponent(scriptType.FullName); scriptEditor.InitializeInstance(script as MonoBehaviour); } else { //Talespire.Log.Debug($"{effectProperty.Paths} is not a Script!"); } } } if (valueEditor is IValueEditor iValueEditor) { iValueEditor.EditingProperty(effectProperty.Name, effectProperty.Paths); //Talespire.Log.Warning($"effectProperty.Paths = \"{effectProperty.Paths}\""); PropertyModDetails propertyModDetails = BasePropertyChanger.GetPropertyModDetails(Instance, effectProperty.Paths); //Talespire.Log.Warning($"iValueEditor.SetValue(\"{propertyModDetails.GetValue()}\");"); object newValue = propertyModDetails.GetValue(); if (newValue == null) { BasePropertyChanger propertyChanger = iValueEditor.GetPropertyChanger(); newValue = propertyChanger.TryGetValue(Instance, effectProperty.Paths); } iValueEditor.SetValue(newValue); } else { Talespire.Log.Error($"valueEditor is NOT an IValueEditor!!!"); } } else { Talespire.Log.Error($"value editor NOT found!!!"); } frmPersistentEffectPropertyEditor.Show(); } catch (Exception ex) { Talespire.Log.Exception(ex, nameof(lstProperties_SelectedIndexChanged)); } }