Skip to content

Commit

Permalink
Rename CeresAPI to CeresLogger
Browse files Browse the repository at this point in the history
  • Loading branch information
AkiKurisu committed Feb 15, 2025
1 parent 1d7dad8 commit b72d46e
Show file tree
Hide file tree
Showing 23 changed files with 204 additions and 84 deletions.
4 changes: 2 additions & 2 deletions Editor/Core/Editors/CeresSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ public override void OnGUI(string searchContext)
{
if (disableILPostProcessProp.boolValue && !ScriptingSymbol.ContainsScriptingSymbol(DisableILPostProcessSymbol))
{
CeresAPI.Log("Disable ILPP");
CeresLogger.Log("Disable ILPP");
ScriptingSymbol.AddScriptingSymbol(DisableILPostProcessSymbol);
}
else if (ScriptingSymbol.ContainsScriptingSymbol(DisableILPostProcessSymbol))
{
CeresAPI.Log("Enable ILPP");
CeresLogger.Log("Enable ILPP");
ScriptingSymbol.RemoveScriptingSymbol(DisableILPostProcessSymbol);
}
CeresSettings.SaveSettings();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/UIElements/Graph/CeresGraphEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ protected override void Reload()
{
if (!Identifier.IsValid()) return;

CeresAPI.Log($"Reload graph from identifier [{Identifier}]");
CeresLogger.Log($"Reload graph from identifier [{Identifier}]");
Container = GetContainer();
OnReloadGraphView();
Repaint();
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/UIElements/Graph/CeresGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public override List<Port> GetCompatiblePorts(Port startPort, NodeAdapter nodeAd
var compatiblePorts = new List<Port>();
if (startPort is not CeresPortElement startPortView)
{
CeresAPI.LogWarning($"{startPort.GetType()} is not supported in Ceres default graph view");
CeresLogger.LogWarning($"{startPort.GetType()} is not supported in Ceres default graph view");
return compatiblePorts;
}

Expand Down
4 changes: 2 additions & 2 deletions Editor/Core/UIElements/Graph/Nodes/CeresNodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ protected void FillDefaultNodeProperties()
}
catch(Exception e)
{
CeresAPI.LogWarning($"Can not draw property {NodeType.Name}.{p.Name}, {e}");
CeresLogger.LogWarning($"Can not draw property {NodeType.Name}.{p.Name}, {e}");
}
});
NodeElement.mainContainer.Add(fieldContainer);
Expand Down Expand Up @@ -281,7 +281,7 @@ protected void FillDefaultNodePorts()
}
catch (Exception e)
{
CeresAPI.LogWarning($"Can not draw port {NodeType.Name}.{p.Name}, {e}");
CeresLogger.LogWarning($"Can not draw port {NodeType.Name}.{p.Name}, {e}");
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/Core/UIElements/Graph/Ports/CeresPortView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ public void SetDisplayDataFromParameterInfo(ParameterInfo parameterInfo)
}
else
{
CeresAPI.LogWarning($"Port can only be remapped from {nameof(ParameterInfo)} in {CeresPortViewBinding.PortBindingType.Field} binding");
CeresLogger.LogWarning($"Port can only be remapped from {nameof(ParameterInfo)} in {CeresPortViewBinding.PortBindingType.Field} binding");
}
}

Expand Down
2 changes: 1 addition & 1 deletion Editor/Flow/ExecutableNodeSearchWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private void BuildDelegateEntries(CeresNodeSearchEntryBuilder builder, Type para
if (parametersLength > maxParameters)
{
/* Not support uber version */
CeresAPI.LogWarning($"Event delegate does not support arguments out range of {maxParameters}");
CeresLogger.LogWarning($"Event delegate does not support arguments out range of {maxParameters}");
return;
}
builder.AddGroupEntry("Select Events", 1);
Expand Down
10 changes: 5 additions & 5 deletions Editor/Flow/FlowGraphView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public FlowGraphData SerializeGraph(bool copyPaste = false)
}

/* Copy and paste may log warning for missing connect nodes which is expected. */
using (CeresAPI.LogScope(copyPaste ? LogType.Error : LogType.Log))
using (CeresLogger.LogScope(copyPaste ? LogType.Error : LogType.Log))
{
var flowGraphData = new FlowGraphData
{
Expand Down Expand Up @@ -305,7 +305,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false)
{
var nodeView = (CeresNodeView)NodeViewFactory.Get().CreateInstance(nodeInstance.GetType(), _graphView);
/* Missing node class should be handled before deserializing graph */
CeresAPI.Assert(nodeView != null, $"Can not construct node view for type {nodeInstance.GetType()}");
CeresLogger.Assert(nodeView != null, $"Can not construct node view for type {nodeInstance.GetType()}");
try
{
nodeView!.SetNodeInstance(nodeInstance);
Expand All @@ -314,7 +314,7 @@ public void DeserializeGraph(FlowGraph flowGraph, bool copyPaste = false)
}
catch (Exception e)
{
CeresAPI.LogError($"Failed to construct node view for type {nodeInstance} with exception thrown:\n{e}");
CeresLogger.LogError($"Failed to construct node view for type {nodeInstance} with exception thrown:\n{e}");
/* Replace with illegal property node */
nodeView = (CeresNodeView)NodeViewFactory.Get().CreateInstance(typeof(IllegalExecutableNode), _graphView);
nodeView!.SetNodeInstance(new IllegalExecutableNode
Expand Down Expand Up @@ -386,13 +386,13 @@ public override async UniTask EnterNode(ExecutableNode node)
}
if (!CanSkipFrame() && CanPauseOnCurrentNode())
{
CeresAPI.Log($"Enter node >>> [{node.GetTypeName()}]({node.Guid})");
CeresLogger.Log($"Enter node >>> [{node.GetTypeName()}]({node.Guid})");
/* Reset skip frame flag */
_breakOnNext = false;
Time.timeScale = 0;
EditorApplication.isPaused = true;
await UniTask.WaitUntil(CanSkipFrame);
CeresAPI.Log($"Exit node <<< [{node.GetTypeName()}]({node.Guid})");
CeresLogger.Log($"Exit node <<< [{node.GetTypeName()}]({node.Guid})");
}
_currentView?.NodeElement.RemoveFromClassList("status_execute");
}
Expand Down
2 changes: 1 addition & 1 deletion Editor/Flow/Nodes/ExecutableEventNodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override void SetNodeInstance(CeresNode ceresNode)
return;
}
/* Change to normal execution event and validate event name */
CeresAPI.LogWarning($"{eventNode.eventName} is not an implementable event of {GetContainerType().Name}");
CeresLogger.LogWarning($"{eventNode.eventName} is not an implementable event of {GetContainerType().Name}");
IsImplementable = false;
}
ValidateEventName();
Expand Down
4 changes: 2 additions & 2 deletions Editor/Flow/Nodes/ExecuteFunctionNodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ public sealed override void SetNodeInstance(CeresNode ceresNode)
if (parametersLength != argumentsLength)
{
methodInfo = null;
CeresAPI.LogWarning($"{functionNode.methodName} expect {parametersLength} arguments but get {argumentsLength}");
CeresLogger.LogWarning($"{functionNode.methodName} expect {parametersLength} arguments but get {argumentsLength}");
}
}
else
{
CeresAPI.LogWarning($"{functionNode.methodName} is not an executable function of {NodeType.GetGenericArguments()[0].Name}");
CeresLogger.LogWarning($"{functionNode.methodName} is not an executable function of {NodeType.GetGenericArguments()[0].Name}");
}

if (methodInfo == null)
Expand Down
4 changes: 2 additions & 2 deletions Editor/Flow/Nodes/PropertyNodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ private void OnVariableChange(VariableChangeEvent evt)
}
else if(evt.ChangeType == VariableChangeType.Type)
{
CeresAPI.LogWarning($"The variable type of {evt.Variable.Name} has changed, which will cause an error in the referenced PropertyNode during runtime. Please recreate the corresponding node.");
CeresLogger.LogWarning($"The variable type of {evt.Variable.Name} has changed, which may cause an error in the referenced PropertyNode during runtime. Please recreate the corresponding node.");
GraphView.ClearSelection();
GraphView.schedule.Execute(FrameNode).ExecuteLater(200);
}
else if(evt.ChangeType == VariableChangeType.Delete)
{
CeresAPI.LogWarning($"The variable {evt.Variable.Name} was deleted, which will cause an error in the referenced PropertyNode during runtime. Please remove the corresponding node.");
CeresLogger.LogWarning($"The variable {evt.Variable.Name} was deleted, which may cause an error in the referenced PropertyNode during runtime. Please remove the corresponding node.");
GraphView.ClearSelection();
GraphView.schedule.Execute(FrameNode).ExecuteLater(200);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace Ceres
{
/// <summary>
/// Main api of Ceres
/// Logger of Ceres
/// </summary>
public static class CeresAPI
public static class CeresLogger
{
public readonly struct LogLevelAutoScope: IDisposable
{
Expand Down
File renamed without changes.
143 changes: 118 additions & 25 deletions Runtime/Core/Models/Graph/APIUpdateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ namespace Ceres.Graph
public class APIUpdateConfig : ScriptableObject
{
[Serializable]
private class SerializedNodeType: IEquatable<SerializedNodeType>
internal class Redirector<T>
{
public T source;

public T target;
}

[Serializable]
internal class SerializedNodeType: IEquatable<SerializedNodeType>
{
public SerializedType<CeresNode> nodeType;

Expand Down Expand Up @@ -49,14 +57,6 @@ public bool Equals(SerializedNodeType other)
}
}

[Serializable]
private class SerializedNodeTypeRedirector
{
public SerializedNodeType sourceNodeType;

public SerializedNodeType targetNodeType;
}

[Serializable]
private class SerializedVariableType: IEquatable<SerializedVariableType>
{
Expand Down Expand Up @@ -97,35 +97,106 @@ public bool Equals(SerializedVariableType other)
}
}

[Serializable]
private class SerializedVariableTypeRedirector
{
public SerializedVariableType sourceVariableType;

public SerializedVariableType targetVariableType;
}
[Header("Node")]
[SerializeField]
internal Redirector<SerializedNodeType>[] nodeRedirectors;

[Header("Variable")]
[SerializeField]
private SerializedNodeTypeRedirector[] nodeRedirectors;
private Redirector<SerializedVariableType>[] variableRedirectors;

[Header("Global")]
[SerializeField]
private SerializedVariableTypeRedirector[] variableRedirectors;
private Redirector<string>[] assemblyRedirectors;

public Type RedirectNode(ManagedReferenceType nodeType)
[SerializeField]
private Redirector<string>[] namespaceRedirectors;

[Header("Settings")]
[SerializeField, Tooltip("Enable auto redirect serialized type which will observe all possible serialized type " +
"deserialization in editor. Note that this does not fix type missing, you still need to " +
"fix them manually.")]
private bool enableAutoRedirectSerializedType;

public Type RedirectNode(in ManagedReferenceType nodeType)
{
var serializeType = new SerializedNodeType(nodeType);
var redirector = nodeRedirectors.FirstOrDefault(x => x.sourceNodeType.Equals(serializeType));
return redirector?.targetNodeType.ToType();
var redirector = nodeRedirectors.FirstOrDefault(x => x.source.Equals(serializeType));
return redirector?.target.ToType() ?? RedirectManagedReference(nodeType);
}

public Type RedirectVariable(ManagedReferenceType variableType)
public Type RedirectVariable(in ManagedReferenceType variableType)
{
var serializeType = new SerializedVariableType(variableType);
var redirector = variableRedirectors.FirstOrDefault(x => x.sourceVariableType.Equals(serializeType));
return redirector?.targetVariableType.ToType();
var redirector = variableRedirectors.FirstOrDefault(x => x.source.Equals(serializeType));
return redirector?.target.ToType() ?? RedirectManagedReference(variableType);
}

public Type RedirectManagedReference(ManagedReferenceType managedReferenceType)
{
ManagedReferenceType redirectedReferenceType = managedReferenceType;
var assemblyRedirector = assemblyRedirectors.FirstOrDefault(r => managedReferenceType._asm.StartsWith(r.source));
if (assemblyRedirector != null)
{
redirectedReferenceType._asm = redirectedReferenceType._asm.Replace(assemblyRedirector.source, assemblyRedirector.target);
}

var namespaceRedirector = namespaceRedirectors.FirstOrDefault(r => managedReferenceType._ns.StartsWith(r.source));
if (namespaceRedirector != null)
{
redirectedReferenceType._ns = redirectedReferenceType._ns.Replace(namespaceRedirector.source, namespaceRedirector.target);
}

if (redirectedReferenceType.Equals(managedReferenceType))
{
return null;
}

return redirectedReferenceType.ToType();
}

public Type RedirectSerializedType(string serializedType)
{
string redirectedSerializedType = serializedType;
var assemblyRedirector = assemblyRedirectors.FirstOrDefault(r => serializedType.Contains(r.source));
if (assemblyRedirector != null)
{
redirectedSerializedType = redirectedSerializedType.Replace(assemblyRedirector.source, assemblyRedirector.target);
}

var namespaceRedirector = namespaceRedirectors.FirstOrDefault(r => serializedType.Contains(r.source));
if (namespaceRedirector != null)
{
redirectedSerializedType = redirectedSerializedType.Replace(namespaceRedirector.source, namespaceRedirector.target);
}

if (redirectedSerializedType.Equals(serializedType))
{
return null;
}

CeresLogger.Log($"Redirect serialized type {serializedType} to {redirectedSerializedType}");
return SerializedType.FromString(redirectedSerializedType);
}

public static APIUpdateConfig Get()
public static ConfigAutoScope AutoScope()
{
return new ConfigAutoScope(GetConfig_Internal());
}

private static APIUpdateConfig _activeConfig;

/// <summary>
/// Internal config survive until the next config is activated
/// </summary>
private static APIUpdateConfig _internalActiveConfig;

/// <summary>
/// Current active config, can be null if no valid config
/// </summary>
public static APIUpdateConfig Current => _activeConfig;

private static APIUpdateConfig GetConfig_Internal()
{
#if UNITY_EDITOR
var guids = UnityEditor.AssetDatabase.FindAssets($"t:{nameof(APIUpdateConfig)}");
Expand All @@ -138,5 +209,27 @@ public static APIUpdateConfig Get()
return null;
#endif
}

public readonly struct ConfigAutoScope: IDisposable
{
public ConfigAutoScope(APIUpdateConfig updateConfig)
{
_activeConfig = updateConfig;
if (_internalActiveConfig)
{
SerializedTypeRedirector.RedirectSerializedType -= _internalActiveConfig.RedirectSerializedType;
}
_internalActiveConfig = updateConfig;
if (_internalActiveConfig&& _internalActiveConfig.enableAutoRedirectSerializedType)
{
SerializedTypeRedirector.RedirectSerializedType += _internalActiveConfig.RedirectSerializedType;
}
}

public void Dispose()
{
_activeConfig = null;
}
}
}
}
Loading

0 comments on commit b72d46e

Please sign in to comment.