-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathComponentCreatedWriter.cs
More file actions
47 lines (43 loc) · 2.1 KB
/
Copy pathComponentCreatedWriter.cs
File metadata and controls
47 lines (43 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.CodeDom;
using Invert.Core.GraphDesigner;
using uFrame.ECS;
namespace Invert.uFrame.ECS
{
public class ComponentCreatedWriter : HandlerCodeWriter<ComponentCreatedEvent>
{
public override void WriteFilterMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerFilterMethod,
CodeMethodInvokeExpression invoker)
{
var component = handlerNode.InputFrom<IMappingsConnectable>();
invoker.Parameters.Add(new CodeSnippetExpression(string.Format("data.Component as {0}", component.Name)));
handlerFilterMethod.Statements.Add(invoker);
}
public override void WriteSetupMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerMethod)
{
var component = handlerNode.InputFrom<IMappingsConnectable>();
ctx._("this.OnEvent<ComponentCreatedEvent>().Where(x=>x.Component is {0}).Subscribe(_=>{{ {1}(_); }}).DisposeWith(this)",
component.Name,
handlerNode.HandlerFilterMethodName
);
}
}
public class ComponentDestroyedWriter : HandlerCodeWriter<ComponentDestroyedEvent>
{
public override void WriteFilterMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerFilterMethod,
CodeMethodInvokeExpression invoker)
{
var component = handlerNode.InputFrom<IMappingsConnectable>();
invoker.Parameters.Add(new CodeSnippetExpression(string.Format("data.Component as {0}", component.Name)));
handlerFilterMethod.Statements.Add(invoker);
}
public override void WriteSetupMethod(HandlerNode handlerNode, TemplateContext ctx, CodeMemberMethod handlerMethod)
{
var component = handlerNode.InputFrom<IMappingsConnectable>();
ctx._("this.OnEvent<ComponentDestroyedEvent>().Where(x=>x.Component is {0}).Subscribe(_=>{{ {1}(_); }}).DisposeWith(this)",
component.Name,
handlerNode.HandlerFilterMethodName
);
}
}
}