Codestyle formatting #1522

This commit is contained in:
Wojtek Figat
2023-10-04 22:25:27 +02:00
parent 2e6fa8fc25
commit 92f677f238
11 changed files with 74 additions and 72 deletions

View File

@@ -1393,7 +1393,7 @@ namespace FlaxEditor.Scripting
return _custom.GetMembers(name, MemberTypes.Method, bindingAttr).FirstOrDefault();
return ScriptMemberInfo.Null;
}
/// <summary>
/// Basic check to see if a type could be casted to another type
/// </summary>

View File

@@ -744,12 +744,12 @@ namespace FlaxEditor.Surface.Archetypes
base.OnDestroy();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
return inputType.IsVoid;
@@ -1161,48 +1161,48 @@ namespace FlaxEditor.Surface.Archetypes
base.OnDestroy();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
if (nodeArch.Tag is not ScriptMemberInfo memberInfo)
return false;
if (!memberInfo.IsStatic)
{
if (VisjectSurface.FullCastCheck(memberInfo.DeclaringType, outputType, hint))
return true;
}
var parameters = memberInfo.GetParameters();
bool isPure = (parameters.Length == 0 && !memberInfo.ValueType.IsVoid);
if (outputType.IsVoid)
return !isPure;
foreach (var param in parameters)
{
if(param.IsOut)
if (param.IsOut)
continue;
if (VisjectSurface.FullCastCheck(param.Type, outputType, hint))
return true;
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
if (nodeArch.Tag is not ScriptMemberInfo memberInfo)
return false;
if (VisjectSurface.FullCastCheck(memberInfo.ValueType, inputType, hint))
return true;
var parameters = memberInfo.GetParameters();
bool isPure = (parameters.Length == 0 && !memberInfo.ValueType.IsVoid);
if (inputType.IsVoid)
return !isPure;
foreach (var param in memberInfo.GetParameters())
{
if(!param.IsOut)
if (!param.IsOut)
continue;
if (VisjectSurface.FullCastCheck(param.Type, inputType, hint))
return true;
@@ -1835,12 +1835,12 @@ namespace FlaxEditor.Surface.Archetypes
base.OnDestroy();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
return inputType.IsVoid;
@@ -1981,19 +1981,19 @@ namespace FlaxEditor.Surface.Archetypes
Title = "Get " + SurfaceUtils.GetMethodDisplayName((string)Values[1]);
UpdateSignature();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
var scriptType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
if (scriptType == ScriptType.Null)
return false;
var members = scriptType.GetMembers((string)nodeArch.DefaultValues[1], MemberTypes.Field, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var member in members)
{
if (!SurfaceUtils.IsValidVisualScriptField(member))
continue;
if (member)
{
if (!member.IsStatic && VisjectSurface.FullCastCheck(scriptType, outputType, hint))
@@ -2007,22 +2007,22 @@ namespace FlaxEditor.Surface.Archetypes
}
break;
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
var scriptType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
if (scriptType == ScriptType.Null)
return false;
var members = scriptType.GetMembers((string)nodeArch.DefaultValues[1], MemberTypes.Field, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var member in members)
{
if (!SurfaceUtils.IsValidVisualScriptField(member))
continue;
if (member)
{
if (VisjectSurface.FullCastCheck(member.ValueType, inputType, hint))
@@ -2092,22 +2092,22 @@ namespace FlaxEditor.Surface.Archetypes
Title = "Set " + SurfaceUtils.GetMethodDisplayName((string)Values[1]);
UpdateSignature();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
if(outputType.IsVoid)
if (outputType.IsVoid)
return true;
var scriptType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
if (scriptType == ScriptType.Null)
return false;
var members = scriptType.GetMembers((string)nodeArch.DefaultValues[1], MemberTypes.Field, BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly);
foreach (var member in members)
{
if (!SurfaceUtils.IsValidVisualScriptField(member))
continue;
if (member)
{
if (VisjectSurface.FullCastCheck(member.ValueType, outputType, hint))
@@ -2126,10 +2126,10 @@ namespace FlaxEditor.Surface.Archetypes
}
break;
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
return inputType.IsVoid;
@@ -2352,13 +2352,13 @@ namespace FlaxEditor.Surface.Archetypes
base.OnDestroy();
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
// Event based nodes always have a pulse input, so it's always compatible with void
if (outputType.IsVoid)
return true;
var eventName = (string)nodeArch.DefaultValues[1];
var eventType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
var member = eventType.GetMember(eventName, MemberTypes.Event, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
@@ -2372,13 +2372,13 @@ namespace FlaxEditor.Surface.Archetypes
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
// Event based nodes always have a pulse output, so it's always compatible with void
if (inputType.IsVoid)
return true;
var eventName = (string)nodeArch.DefaultValues[1];
var eventType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
var member = eventType.GetMember(eventName, MemberTypes.Event, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);

View File

@@ -207,13 +207,13 @@ namespace FlaxEditor.Surface.Archetypes
AddElement(box);
}
}
protected static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
// Event based nodes always have a pulse input, so it's always compatible with void
if (outputType.IsVoid)
return true;
var eventName = (string)nodeArch.DefaultValues[1];
var eventType = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
var member = eventType.GetMember(eventName, MemberTypes.Event, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
@@ -236,7 +236,7 @@ namespace FlaxEditor.Surface.Archetypes
: base(id, context, nodeArch, groupArch, false)
{
}
internal static bool IsInputCompatible(NodeArchetype nodeArch, ScriptType outputType, ConnectionsHint hint)
{
var typeName = (string)nodeArch.DefaultValues[0];
@@ -253,7 +253,7 @@ namespace FlaxEditor.Surface.Archetypes
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
var typeName = (string)nodeArch.DefaultValues[0];
@@ -286,7 +286,7 @@ namespace FlaxEditor.Surface.Archetypes
}
return false;
}
internal static bool IsOutputCompatible(NodeArchetype nodeArch, ScriptType inputType, ConnectionsHint hint)
{
var typeName = (string)nodeArch.DefaultValues[0];

View File

@@ -164,7 +164,7 @@ namespace FlaxEditor.Surface.ContextMenu
HorizontalAlignment = TextAlignment.Far,
Font = titleFontReference,
};
_contextSensitiveToggle = new CheckBox
{
Width = 20,
@@ -174,7 +174,7 @@ namespace FlaxEditor.Surface.ContextMenu
Checked = _contextSensitiveSearchEnabled,
};
_contextSensitiveToggle.StateChanged += OnContextSensitiveToggleStateChanged;
// Search box
_searchBox = new SearchBox(false, 2, 22)
{
@@ -313,7 +313,7 @@ namespace FlaxEditor.Surface.ContextMenu
OnSearchFilterChanged();
}
}
else if(_contextSensitiveSearchEnabled)
else if (_contextSensitiveSearchEnabled)
{
group.EvaluateVisibilityWithBox(_selectedBox);
}
@@ -350,8 +350,8 @@ namespace FlaxEditor.Surface.ContextMenu
Parent = group
};
}
if(_contextSensitiveSearchEnabled)
group.EvaluateVisibilityWithBox(_selectedBox);
if (_contextSensitiveSearchEnabled)
group.EvaluateVisibilityWithBox(_selectedBox);
group.SortChildren();
group.Parent = _groupsPanel;
_groups.Add(group);
@@ -459,7 +459,7 @@ namespace FlaxEditor.Surface.ContextMenu
// Skip events during setup or init stuff
if (IsLayoutLocked)
return;
Profiler.BeginEvent("VisjectCM.OnContextSensitiveToggleStateChanged");
_contextSensitiveSearchEnabled = checkBox.Checked;
UpdateFilters();
@@ -551,7 +551,7 @@ namespace FlaxEditor.Surface.ContextMenu
for (int i = 0; i < _groups.Count; i++)
{
_groups[i].ResetView();
if(_contextSensitiveSearchEnabled)
if (_contextSensitiveSearchEnabled)
_groups[i].EvaluateVisibilityWithBox(_selectedBox);
}
UnlockChildrenRecursive();

View File

@@ -132,7 +132,7 @@ namespace FlaxEditor.Surface.ContextMenu
}
Profiler.BeginEvent("VisjectCMGroup.EvaluateVisibilityWithBox");
bool isAnyVisible = false;
for (int i = 0; i < _children.Count; i++)
{
@@ -142,7 +142,7 @@ namespace FlaxEditor.Surface.ContextMenu
isAnyVisible |= item.Visible;
}
}
// Update itself
if (isAnyVisible)
{

View File

@@ -103,7 +103,7 @@ namespace FlaxEditor.Surface.ContextMenu
{
// Is compatible if box is null for reset reasons
if (startBox == null)
return true;
return true;
if (_archetype == null)
return false;
@@ -112,7 +112,7 @@ namespace FlaxEditor.Surface.ContextMenu
if (startBox.IsOutput && _archetype.IsInputCompatible != null)
{
isCompatible |= _archetype.IsInputCompatible.Invoke(_archetype, startBox.CurrentType, _archetype.ConnectionsHints);
}
}
else if (!startBox.IsOutput && _archetype.IsOutputCompatible != null)
{
isCompatible |= _archetype.IsOutputCompatible.Invoke(_archetype, startBox.CurrentType, startBox.ParentNode.Archetype.ConnectionsHints);
@@ -122,23 +122,23 @@ namespace FlaxEditor.Surface.ContextMenu
// Check compatibility based on the defined elements in the archetype. This handles all the default groups and items
isCompatible = CheckElementsCompatibility(startBox);
}
return isCompatible;
}
private bool CheckElementsCompatibility(Box startBox)
{
bool isCompatible = false;
foreach (NodeElementArchetype element in _archetype.Elements)
{
// Ignore all elements that aren't inputs or outputs (e.g. input fields)
if(element.Type != NodeElementType.Output && element.Type != NodeElementType.Input)
if (element.Type != NodeElementType.Output && element.Type != NodeElementType.Input)
continue;
// Ignore elements with the same direction as the box
if ((startBox.IsOutput && element.Type == NodeElementType.Output) || (!startBox.IsOutput && element.Type == NodeElementType.Input))
continue;
ScriptType fromType;
ScriptType toType;
ConnectionsHint hint;
@@ -154,13 +154,13 @@ namespace FlaxEditor.Surface.ContextMenu
toType = element.ConnectionsType;
hint = startBox.ParentNode.Archetype.ConnectionsHints;
}
isCompatible |= VisjectSurface.FullCastCheck(fromType, toType, hint);
}
return isCompatible;
}
/// <summary>
/// Updates the filter.
/// </summary>
@@ -176,7 +176,7 @@ namespace FlaxEditor.Surface.ContextMenu
return;
}
}
_isStartsWithMatch = _isFullMatch = false;
if (string.IsNullOrEmpty(filterText))
{
@@ -242,7 +242,7 @@ namespace FlaxEditor.Surface.ContextMenu
Data = data;
}
else if(!groupHeaderMatches)
else if (!groupHeaderMatches)
{
// Hide
_highlights?.Clear();

View File

@@ -231,7 +231,7 @@ namespace FlaxEditor.Surface.Elements
}
// Check using connection hints
if(VisjectSurface.IsTypeCompatible(Archetype.ConnectionsType, type, ParentNode.Archetype.ConnectionsHints))
if (VisjectSurface.IsTypeCompatible(Archetype.ConnectionsType, type, ParentNode.Archetype.ConnectionsHints))
return true;
// Check independent and if there is box with bigger potential because it may block current one from changing type

View File

@@ -35,7 +35,7 @@ namespace FlaxEditor.Surface.Elements
{
// Calculate control points
CalculateBezierControlPoints(start, end, out var control1, out var control2);
// Draw line
Render2D.DrawBezier(start, control1, control2, end, color, thickness);
@@ -54,16 +54,16 @@ namespace FlaxEditor.Surface.Elements
const float maxControlLength = 150f;
var dst = (end - start).Length;
var yDst = Mathf.Abs(start.Y - end.Y);
// Calculate control points
var minControlDst = dst * 0.5f;
var maxControlDst = Mathf.Max(Mathf.Min(maxControlLength, dst), minControlLength);
var controlDst = Mathf.Lerp(minControlDst, maxControlDst, Mathf.Clamp(yDst / minControlLength, 0f, 1f));
control1 = new Float2(start.X + controlDst, start.Y);
control2 = new Float2(end.X - controlDst, end.Y);
}
/// <summary>
/// Checks if a point intersects a connection
/// </summary>
@@ -86,11 +86,13 @@ namespace FlaxEditor.Surface.Elements
public static bool IntersectsConnection(ref Float2 start, ref Float2 end, ref Float2 point, float distance)
{
// Pretty much a point in rectangle check
if ((point.X - start.X) * (end.X - point.X) < 0) return false;
if ((point.X - start.X) * (end.X - point.X) < 0)
return false;
float offset = Mathf.Sign(end.Y - start.Y) * distance;
if ((point.Y - (start.Y - offset)) * ((end.Y + offset) - point.Y) < 0) return false;
if ((point.Y - (start.Y - offset)) * ((end.Y + offset) - point.Y) < 0)
return false;
float squaredDistance = distance;
CalculateBezierControlPoints(start, end, out var control1, out var control2);

View File

@@ -93,7 +93,7 @@ namespace FlaxEditor.Surface
/// Checks if the given type is compatible with the given node archetype. Used for custom nodes
/// </summary>
public delegate bool IsCompatible(NodeArchetype nodeArch, ScriptType portType, ConnectionsHint hint);
/// <summary>
/// Unique node type ID within a single group.
/// </summary>
@@ -108,12 +108,12 @@ namespace FlaxEditor.Surface
/// Function for asynchronously loaded nodes to check if input ports are compatible, for filtering.
/// </summary>
public IsCompatible IsInputCompatible;
/// <summary>
/// Function for asynchronously loaded nodes to check if output ports are compatible, for filtering.
/// </summary>
public IsCompatible IsOutputCompatible;
/// <summary>
/// Default initial size of the node.
/// </summary>

View File

@@ -406,8 +406,8 @@ namespace FlaxEditor.Surface
internal static bool IsValidVisualScriptType(ScriptType scriptType)
{
if (!scriptType.IsPublic ||
scriptType.HasAttribute(typeof(HideInEditorAttribute), true) ||
if (!scriptType.IsPublic ||
scriptType.HasAttribute(typeof(HideInEditorAttribute), true) ||
scriptType.HasAttribute(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false))
return false;
if (scriptType.IsGenericType)

View File

@@ -212,12 +212,12 @@ namespace FlaxEditor.Surface
// Yes, from and to are switched on purpose
if (CanUseDirectCastStatic(to, from, false))
return true;
if(IsTypeCompatible(from, to, hint))
if (IsTypeCompatible(from, to, hint))
return true;
// Same here
return to.CanCastTo(from);
}
/// <summary>
/// Checks if can use direct conversion from one type to another.
/// </summary>