Skip to content
This repository has been archived by the owner on Jan 18, 2022. It is now read-only.

Commit

Permalink
simplify gameobject creation generator methods
Browse files Browse the repository at this point in the history
Signed-off-by: Paul Balaji <[email protected]>
  • Loading branch information
Paul Balaji committed Feb 11, 2020
1 parent 236d6eb commit c45e2cd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class UnityCommandSenderReceiverGenerator

public static CodeWriter Generate(UnityComponentDetails details)
{
var Namespace = $"global::{details.Namespace}.{details.Name}";
var fullyQualifiedNamespace = $"global::{details.Namespace}.{details.Name}";

return CodeWriter.Populate(cgw =>
{
Expand All @@ -26,17 +26,17 @@ public static CodeWriter Generate(UnityComponentDetails details)

cgw.Namespace(details.Namespace, ns =>
{
ns.Type(GenerateCommandSenderSubscriptionManager(details, details.Namespace));
ns.Type(GenerateCommandReceiverSubscriptionManager(details, details.Namespace));
ns.Type(GenerateCommandSender(details, details.Namespace, Namespace));
ns.Type(GenerateCommandReceiver(details, details.Namespace, Namespace));
ns.Type(GenerateCommandSenderSubscriptionManager(details));
ns.Type(GenerateCommandReceiverSubscriptionManager(details));
ns.Type(GenerateCommandSender(details, fullyQualifiedNamespace));
ns.Type(GenerateCommandReceiver(details, fullyQualifiedNamespace));
});
});
}

private static TypeBlock GenerateCommandSenderSubscriptionManager(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateCommandSenderSubscriptionManager(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}CommandSenderSubscriptionManager class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}CommandSenderSubscriptionManager class.");

var commandSenderType = $"{componentDetails.Name}CommandSender";

Expand All @@ -57,9 +57,9 @@ private static TypeBlock GenerateCommandSenderSubscriptionManager(UnityComponent
});
}

private static TypeBlock GenerateCommandReceiverSubscriptionManager(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateCommandReceiverSubscriptionManager(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}CommandReceiverSubscriptionManager class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}CommandReceiverSubscriptionManager class.");

var commandReceiverType = $"{componentDetails.Name}CommandReceiver";

Expand All @@ -80,9 +80,9 @@ private static TypeBlock GenerateCommandReceiverSubscriptionManager(UnityCompone
});
}

private static TypeBlock GenerateCommandSender(UnityComponentDetails componentDetails, string qualifiedNamespace, string Namespace)
private static TypeBlock GenerateCommandSender(UnityComponentDetails componentDetails, string fullyQualifiedNamespace)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}CommandSender class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}CommandSender class.");

var commandSenderType = $"{componentDetails.Name}CommandSender";

Expand All @@ -109,7 +109,7 @@ private static TypeBlock GenerateCommandSender(UnityComponentDetails componentDe
");
foreach (var commandDetails in componentDetails.CommandDetails)
{
var receivedCommandResponseType = $"{Namespace}.{commandDetails.Name}.ReceivedResponse";
var receivedCommandResponseType = $"{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedResponse";
var commandRequest = $"{componentDetails.Name}.{commandDetails.Name}.Request";

c.Line($@"
Expand All @@ -119,13 +119,13 @@ private static TypeBlock GenerateCommandSender(UnityComponentDetails componentDe
Send{commandDetails.Name}Command(commandRequest, callback);
}}
public void Send{commandDetails.Name}Command({Namespace}.{commandDetails.Name}.Request request, Action<{Namespace}.{commandDetails.Name}.ReceivedResponse> callback = null)
public void Send{commandDetails.Name}Command({fullyQualifiedNamespace}.{commandDetails.Name}.Request request, Action<{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedResponse> callback = null)
{{
int validCallbackEpoch = callbackEpoch;
var requestId = commandSender.SendCommand(request, entity);
if (callback != null)
{{
Action<{Namespace}.{commandDetails.Name}.ReceivedResponse> wrappedCallback = response =>
Action<{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedResponse> wrappedCallback = response =>
{{
if (!this.IsValid || validCallbackEpoch != this.callbackEpoch)
{{
Expand All @@ -149,9 +149,9 @@ public void RemoveAllCallbacks()
});
}

private static TypeBlock GenerateCommandReceiver(UnityComponentDetails componentDetails, string qualifiedNamespace, string Namespace)
private static TypeBlock GenerateCommandReceiver(UnityComponentDetails componentDetails, string fullyQualifiedNamespace)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}CommandReceiver class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}CommandReceiver class.");

var commandReceiverType = $"{componentDetails.Name}CommandReceiver";

Expand All @@ -168,15 +168,15 @@ private static TypeBlock GenerateCommandReceiver(UnityComponentDetails component
foreach (var commandDetails in componentDetails.CommandDetails)
{
c.Line($@"
private Dictionary<Action<{Namespace}.{commandDetails.Name}.ReceivedRequest>, ulong> {commandDetails.CamelCaseName}CallbackToCallbackKey;
private Dictionary<Action<{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedRequest>, ulong> {commandDetails.CamelCaseName}CallbackToCallbackKey;
public event Action<{Namespace}.{commandDetails.Name}.ReceivedRequest> On{commandDetails.Name}RequestReceived
public event Action<{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedRequest> On{commandDetails.Name}RequestReceived
{{
add
{{
if ({commandDetails.CamelCaseName}CallbackToCallbackKey == null)
{{
{commandDetails.CamelCaseName}CallbackToCallbackKey = new Dictionary<Action<{Namespace}.{commandDetails.Name}.ReceivedRequest>, ulong>();
{commandDetails.CamelCaseName}CallbackToCallbackKey = new Dictionary<Action<{fullyQualifiedNamespace}.{commandDetails.Name}.ReceivedRequest>, ulong>();
}}
var key = callbackSystem.RegisterCommandRequestCallback(entityId, value);
Expand Down Expand Up @@ -211,19 +211,19 @@ public event Action<{Namespace}.{commandDetails.Name}.ReceivedRequest> On{comman
foreach (var commandDetails in componentDetails.CommandDetails)
{
c.Line($@"
public void Send{commandDetails.Name}Response({Namespace}.{commandDetails.Name}.Response response)
public void Send{commandDetails.Name}Response({fullyQualifiedNamespace}.{commandDetails.Name}.Response response)
{{
commandSystem.SendResponse(response);
}}
public void Send{commandDetails.Name}Response(long requestId, {commandDetails.FqnResponseType} response)
{{
commandSystem.SendResponse(new {Namespace}.{commandDetails.Name}.Response(requestId, response));
commandSystem.SendResponse(new {fullyQualifiedNamespace}.{commandDetails.Name}.Response(requestId, response));
}}
public void Send{commandDetails.Name}Failure(long requestId, string failureMessage)
{{
commandSystem.SendResponse(new {Namespace}.{commandDetails.Name}.Response(requestId, failureMessage));
commandSystem.SendResponse(new {fullyQualifiedNamespace}.{commandDetails.Name}.Response(requestId, failureMessage));
}}
");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ public static CodeWriter Generate(UnityComponentDetails details)

cgw.Namespace(details.Namespace, ns =>
{
ns.Type(GenerateComponentReaderSubscriptionManager(details, details.Namespace));
ns.Type(GenerateComponentWriterSubscriptionManager(details, details.Namespace));
ns.Type(GenerateComponentReader(details, details.Namespace));
ns.Type(GenerateComponentWriter(details, details.Namespace));
ns.Type(GenerateComponentReaderSubscriptionManager(details));
ns.Type(GenerateComponentWriterSubscriptionManager(details));
ns.Type(GenerateComponentReader(details));
ns.Type(GenerateComponentWriter(details));
});
});
}

private static TypeBlock GenerateComponentReaderSubscriptionManager(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateComponentReaderSubscriptionManager(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}ReaderSubscriptionManager class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}ReaderSubscriptionManager class.");

return Scope.AnnotatedType("AutoRegisterSubscriptionManager",
$"public class {componentDetails.Name}ReaderSubscriptionManager : SubscriptionManager<{componentDetails.Name}Reader>",
Expand Down Expand Up @@ -166,9 +166,9 @@ private void OnComponentRemoved(EntityId entityId)
});
}

private static TypeBlock GenerateComponentWriterSubscriptionManager(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateComponentWriterSubscriptionManager(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}WriterSubscriptionManager class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}WriterSubscriptionManager class.");

return Scope.AnnotatedType("AutoRegisterSubscriptionManager",
$"public class {componentDetails.Name}WriterSubscriptionManager : SubscriptionManager<{componentDetails.Name}Writer>",
Expand Down Expand Up @@ -291,9 +291,9 @@ public override void ResetValue(ISubscription subscription)
});
}

private static TypeBlock GenerateComponentReader(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateComponentReader(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}Reader class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}Reader class.");

return Scope.Type($"public class {componentDetails.Name}Reader",
reader =>
Expand Down Expand Up @@ -522,9 +522,9 @@ public event Action<{eventDetails.FqnPayloadType}> On{eventDetails.Name}Event
});
}

private static TypeBlock GenerateComponentWriter(UnityComponentDetails componentDetails, string qualifiedNamespace)
private static TypeBlock GenerateComponentWriter(UnityComponentDetails componentDetails)
{
Logger.Trace($"Generating {qualifiedNamespace}.{componentDetails.Name}Writer class.");
Logger.Trace($"Generating {componentDetails.Namespace}.{componentDetails.Name}Writer class.");

return Scope.Type($"public class {componentDetails.Name}Writer : {componentDetails.Name}Reader",
writer =>
Expand Down

0 comments on commit c45e2cd

Please sign in to comment.