UNPKG

7.97 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.lazyMultiInject = exports.lazyInject = exports.container = void 0;
9
10require("reflect-metadata");
11
12var _inversify = require("inversify");
13
14var _inversifyInjectDecorators = _interopRequireDefault(require("inversify-inject-decorators"));
15
16var _ComponentManager = require("./ComponentManager");
17
18var _CameraComponent = require("./components/camera/CameraComponent");
19
20var _System = require("./components/camera/System");
21
22var _ComputeComponent = require("./components/compute/ComputeComponent");
23
24var _LayoutComputeStrategy = require("./components/compute/LayoutComputeStrategy");
25
26var _ParticleComputeStrategy = require("./components/compute/ParticleComputeStrategy");
27
28var _System2 = require("./components/compute/System");
29
30var _PassNodeComponent = require("./components/framegraph/PassNodeComponent");
31
32var _ResourceHandleComponent = require("./components/framegraph/ResourceHandleComponent");
33
34var _System3 = require("./components/framegraph/System");
35
36var _GeometryComponent = require("./components/geometry/GeometryComponent");
37
38var _System4 = require("./components/geometry/System");
39
40var _System5 = require("./components/interaction/System");
41
42var _MaterialComponent = require("./components/material/MaterialComponent");
43
44var _System6 = require("./components/material/System");
45
46var _CullableComponent = require("./components/mesh/CullableComponent");
47
48var _MeshComponent = require("./components/mesh/MeshComponent");
49
50var _System7 = require("./components/mesh/System");
51
52var _Forward = require("./components/renderpath/Forward");
53
54var _SceneComponent = require("./components/scene/SceneComponent");
55
56var _System8 = require("./components/scene/System");
57
58var _HierarchyComponent = require("./components/scenegraph/HierarchyComponent");
59
60var _NameComponent = require("./components/scenegraph/NameComponent");
61
62var _System9 = require("./components/scenegraph/System");
63
64var _TransformComponent = require("./components/scenegraph/TransformComponent");
65
66var _identifier = require("./identifier");
67
68/**
69 * Root Container
70 * @see /dev-docs/IoC 容器、依赖注入与服务说明.md
71 */
72// @see https://github.com/inversify/InversifyJS/blob/master/wiki/container_api.md#defaultscope
73var container = new _inversify.Container(); // 支持使用 new 而非容器实例化的场景,同时禁止 lazyInject cache
74// @see https://github.com/inversify/inversify-inject-decorators#caching-vs-non-caching-behaviour
75
76exports.container = container;
77var DECORATORS = (0, _inversifyInjectDecorators.default)(container, false);
78
79// Add babel legacy decorators support
80// @see https://github.com/inversify/InversifyJS/issues/1050
81// @see https://github.com/inversify/InversifyJS/issues/1026#issuecomment-504936034
82var lazyInject = function lazyInject(serviceIdentifier) {
83 var original = DECORATORS.lazyInject(serviceIdentifier); // the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC
84 // so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression"
85
86 return function (proto, key, descriptor) {
87 // make it work as usual
88 original.call(this, proto, key); // return link to proto, so own value wont be 'undefined' after component's creation
89
90 if (descriptor) {
91 descriptor.initializer = function () {
92 return proto[key];
93 };
94 }
95 };
96};
97
98exports.lazyInject = lazyInject;
99
100var lazyMultiInject = function lazyMultiInject(serviceIdentifier) {
101 var original = DECORATORS.lazyMultiInject(serviceIdentifier); // the 'descriptor' parameter is actually always defined for class fields for Babel, but is considered undefined for TSC
102 // so we just hack it with ?/! combination to avoid "TS1240: Unable to resolve signature of property decorator when called as an expression"
103
104 return function (proto, key, descriptor) {
105 // make it work as usual
106 original.call(this, proto, key);
107
108 if (descriptor) {
109 // return link to proto, so own value wont be 'undefined' after component's creation
110 descriptor.initializer = function () {
111 return proto[key];
112 };
113 }
114 };
115};
116/**
117 * bind global component managers in root container
118 */
119
120
121exports.lazyMultiInject = lazyMultiInject;
122container.bind(_identifier.IDENTIFIER.NameComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_NameComponent.NameComponent));
123container.bind(_identifier.IDENTIFIER.HierarchyComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_HierarchyComponent.HierarchyComponent));
124container.bind(_identifier.IDENTIFIER.TransformComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_TransformComponent.TransformComponent));
125container.bind(_identifier.IDENTIFIER.CameraComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_CameraComponent.CameraComponent));
126container.bind(_identifier.IDENTIFIER.ResourceHandleComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_ResourceHandleComponent.ResourceHandleComponent));
127container.bind(_identifier.IDENTIFIER.PassNodeComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_PassNodeComponent.PassNodeComponent));
128container.bind(_identifier.IDENTIFIER.MeshComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_MeshComponent.MeshComponent));
129container.bind(_identifier.IDENTIFIER.CullableComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_CullableComponent.CullableComponent));
130container.bind(_identifier.IDENTIFIER.GeometryComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_GeometryComponent.GeometryComponent));
131container.bind(_identifier.IDENTIFIER.MaterialComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_MaterialComponent.MaterialComponent));
132container.bind(_identifier.IDENTIFIER.SceneComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_SceneComponent.SceneComponent));
133container.bind(_identifier.IDENTIFIER.ComputeComponentManager).toConstantValue(new _ComponentManager.ComponentManager(_ComputeComponent.ComputeComponent));
134/**
135 * bind systems
136 */
137
138container.bind(_identifier.IDENTIFIER.Systems).to(_System9.SceneGraphSystem).whenTargetNamed(_identifier.IDENTIFIER.SceneGraphSystem);
139container.bind(_identifier.IDENTIFIER.Systems).to(_System8.SceneSystem).whenTargetNamed(_identifier.IDENTIFIER.SceneSystem);
140container.bind(_identifier.IDENTIFIER.Systems).to(_System.CameraSystem).whenTargetNamed(_identifier.IDENTIFIER.CameraSystem);
141container.bind(_identifier.IDENTIFIER.Systems).to(_System3.FrameGraphSystem).whenTargetNamed(_identifier.IDENTIFIER.FrameGraphSystem);
142container.bind(_identifier.IDENTIFIER.Systems).to(_System7.MeshSystem).whenTargetNamed(_identifier.IDENTIFIER.MeshSystem);
143container.bind(_identifier.IDENTIFIER.Systems).to(_System4.GeometrySystem).whenTargetNamed(_identifier.IDENTIFIER.GeometrySystem);
144container.bind(_identifier.IDENTIFIER.Systems).to(_System6.MaterialSystem).whenTargetNamed(_identifier.IDENTIFIER.MaterialSystem);
145container.bind(_identifier.IDENTIFIER.Systems).to(_System5.InteractionSystem).whenTargetNamed(_identifier.IDENTIFIER.InteractionSystem);
146container.bind(_identifier.IDENTIFIER.Systems).to(_System2.ComputeSystem).whenTargetNamed(_identifier.IDENTIFIER.ComputeSystem);
147container.bind(_identifier.IDENTIFIER.ForwardRenderPath).to(_Forward.ForwardRenderPath).inSingletonScope();
148/**
149 * bind compute strategy
150 */
151
152container.bind(_identifier.IDENTIFIER.ComputeStrategy).to(_ParticleComputeStrategy.ParticleComputeStrategy).whenTargetNamed('particle');
153container.bind(_identifier.IDENTIFIER.ComputeStrategy).to(_LayoutComputeStrategy.LayoutComputeStrategy).whenTargetNamed('layout');
154//# sourceMappingURL=inversify.config.js.map
\No newline at end of file