Skip to content

Commit

Permalink
added suppressing setting points to < 4 count on polygon
Browse files Browse the repository at this point in the history
  • Loading branch information
vchelaru committed Dec 22, 2024
1 parent cd59e25 commit c5d76ca
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 37 deletions.
71 changes: 38 additions & 33 deletions Gum/DataTypes/StateSaveExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -514,39 +514,7 @@ public static void SetValue(this StateSave stateSave, string variableName, objec
{
exposedVariableSourceName = coreVariableDefinition.Name;
}
bool isFile = false;

// Why might instanceSave be null?
// The reason is because StateSaves
// are used both for actual game data
// as well as temporary variable containers.
// If a StateSave is a temporary container then
// instanceSave may (probably will be) null.
if (instanceSave != null)
{
VariableSave temp = variableSave;
if (variableSave == null)
{
temp = new VariableSave();
temp.Name = variableName;
}
isFile = temp.GetIsFileFromRoot(instanceSave);
}
else
{
VariableSave temp = variableSave;
if (variableSave == null)
{
temp = new VariableSave();
temp.Name = variableName;
}
if (stateSave.ParentContainer != null)
{
isFile = temp.GetIsFileFromRoot(stateSave.ParentContainer);
}
}


bool isFile = DetermineIfIsFile(stateSave, variableName, instanceSave, variableSave);

if (value != null && value is IList)
{
Expand Down Expand Up @@ -594,6 +562,43 @@ value is string asString &&

}

private static bool DetermineIfIsFile(StateSave stateSave, string variableName, InstanceSave instanceSave, VariableSave variableSave)
{
bool isFile = false;

// Why might instanceSave be null?
// The reason is because StateSaves
// are used both for actual game data
// as well as temporary variable containers.
// If a StateSave is a temporary container then
// instanceSave may (probably will be) null.
if (instanceSave != null)
{
VariableSave temp = variableSave;
if (variableSave == null)
{
temp = new VariableSave();
temp.Name = variableName;
}
isFile = temp.GetIsFileFromRoot(instanceSave);
}
else
{
VariableSave temp = variableSave;
if (variableSave == null)
{
temp = new VariableSave();
temp.Name = variableName;
}
if (stateSave.ParentContainer != null)
{
isFile = temp.GetIsFileFromRoot(stateSave.ParentContainer);
}
}

return isFile;
}

private static bool TrySetReservedValues(StateSave stateSave, string variableName, object value, InstanceSave instanceSave)
{
bool isReservedName = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CommonFormsAndControls;
using ExCSS;
using Gum.DataTypes;
using Gum.DataTypes.ComponentModel;
using Gum.DataTypes.Variables;
Expand Down Expand Up @@ -561,6 +562,15 @@ private object HandleCustomGet(object instance)

private void HandleCustomSet(object gumElementOrInstanceSaveAsObject, SetPropertyArgs setPropertyArgs)
{
////////////////////Early Out/////////////////////////
if (!CanSetValue(gumElementOrInstanceSaveAsObject, setPropertyArgs))
{
setPropertyArgs.IsAssignmentCancelled = true;
return;
}
/////////////////End Early Out////////////////////////


object newValue = setPropertyArgs.Value;
if (mPropertyDescriptor != null)
{
Expand Down Expand Up @@ -678,6 +688,21 @@ private void HandleCustomSet(object gumElementOrInstanceSaveAsObject, SetPropert
// set the value
}

private bool CanSetValue(object gumElementOrInstanceSaveAsObject, SetPropertyArgs setPropertyArgs)
{
if(this.RootVariableName == "Points")
{
var value = setPropertyArgs.Value as List<System.Numerics.Vector2>;

if(value?.Count < 4)
{
return false;
}
}

return true;
}

private void HandleSetToDefault(string obj)
{
string variableName = Name;
Expand Down
11 changes: 10 additions & 1 deletion WpfDataUi/DataTypes/InstanceMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class SetPropertyArgs
{
public SetPropertyCommitType CommitType { get; set; }
public object Value { get; set; }
public bool IsAssignmentCancelled { get; set; }
}

public class InstanceMember : DependencyObject
Expand Down Expand Up @@ -137,8 +138,10 @@ public object Value

}

public void SetValue(object value, SetPropertyCommitType commitType)
public ApplyValueResult SetValue(object value, SetPropertyCommitType commitType)
{
ApplyValueResult result = ApplyValueResult.Success;

if (CustomSetPropertyEvent != null)
{
var args = new SetPropertyArgs
Expand All @@ -147,6 +150,11 @@ public void SetValue(object value, SetPropertyCommitType commitType)
Value = value
};
CustomSetPropertyEvent(Instance, args);

if(args.IsAssignmentCancelled)
{
result = ApplyValueResult.UnknownError;
}
}
else if (CustomSetEvent != null)
{
Expand All @@ -157,6 +165,7 @@ public void SetValue(object value, SetPropertyCommitType commitType)
LateBinder.GetInstance(Instance.GetType()).SetValue(Instance, Name, value);
}
OnPropertyChanged("Value");
return result;
}

public bool IsDefined
Expand Down
8 changes: 5 additions & 3 deletions WpfDataUi/IDataUiExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ public static ApplyValueResult TrySetValueOnInstance(this IDataUi dataUi)
if(dataUi.InstanceMember.Value != valueOnUi)
{
//dataUi.InstanceMember.Value = valueOnUi;
dataUi.InstanceMember.SetValue(valueOnUi, SetPropertyCommitType.Full);
result = ApplyValueResult.Success;
dataUi.InstanceMember.CallAfterSetByUi();
result = dataUi.InstanceMember.SetValue(valueOnUi, SetPropertyCommitType.Full);
if(result == ApplyValueResult.Success)
{
dataUi.InstanceMember.CallAfterSetByUi();
}
}
else
{
Expand Down

0 comments on commit c5d76ca

Please sign in to comment.