1 /++
2 Component module. Components extend the functionality of instances, but
3 independently of a specific one (at least so. Or only one group of instances).
4 
5 Macros:
6     LREF = <a href="#$1">$1</a>
7     HREF = <a href="$1">$2</a>
8     PHOBREF = <a href="https://dlang.org/phobos/$1.html#$2">$2</a>
9 
10 Authors: $(HREF https://github.com/TodNaz,TodNaz)
11 Copyright: Copyright (c) 2020 - 2021, TodNaz.
12 License: $(HREF https://github.com/TodNaz/Tida/blob/master/LICENSE,MIT)
13 +/
14 module tida.component;
15 
16 /++
17 Checks if an object is a component for an instance.
18 +/
19 template isComponent(T)
20 {
21     enum isComponent = is(T : Component);
22 }
23 
24 struct ComponentEvents
25 {
26     import tida.event;
27     import tida.render;
28     import tida.localevent;
29     import tida.instance;
30 
31     struct FEInit
32     {
33         Instance instance;
34         void delegate(Instance) @safe fun;
35     }
36 
37     struct SRTrigger
38     {
39         Trigger ev;
40         FETrigger fun;
41     }
42 
43     alias FEStep = void delegate() @safe;
44     alias FERestart = void delegate() @safe;
45     alias FEEntry = void delegate() @safe;
46     alias FELeave = void delegate() @safe;
47     alias FEGameStart = void delegate() @safe;
48     alias FEGameExit = void delegate() @safe;
49     alias FEGameRestart = void delegate() @safe;
50     alias FEEventHandle = void delegate(EventHandler) @safe;
51     alias FEDraw = void delegate(IRenderer) @safe;
52     alias FEOnError = void delegate() @safe;
53     alias FECollision = void delegate(Instance) @safe;
54     alias FETrigger = void delegate() @safe;
55     alias FEDestroy = void delegate(Instance) @safe;
56     alias FEATrigger = void delegate(string) @safe;
57 
58     FEInit[] CInitFunctions;
59     FEStep[] CStepFunctions;
60     FEStep[][size_t] CStepThreadFunctions;
61     FELeave[] CLeaveFunctions;
62     FEEventHandle[] CEventHandleFunctions;
63     FEDraw[] CDrawFunctions;
64     FEOnError[] COnErrorFunctions;
65     SRTrigger[] COnTriggerFunctions;
66     FEATrigger[] COnAnyTriggerFunctions;
67     FECollision[] COnAnyCollisionFunctions;
68 }
69 
70 /++
71 A component object that extends some functionality to an entire
72 or group of instances.
73 +/
74 class Component
75 {
76 public:
77     string name; /// Component
78     string[] tags; /// Component tags.
79 
80     ComponentEvents events;
81 }