dacha 0.15.2 → 0.15.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,7 +9,9 @@ export declare class BehaviorSystem extends SceneSystem {
|
|
|
9
9
|
private scene;
|
|
10
10
|
private activeBehaviors;
|
|
11
11
|
constructor(options: SceneSystemOptions);
|
|
12
|
+
onSceneEnter(): void;
|
|
12
13
|
onSceneDestroy(): void;
|
|
14
|
+
private handleActorAdd;
|
|
13
15
|
private handleActorRemove;
|
|
14
16
|
private setUpBehavior;
|
|
15
17
|
update(options: UpdateOptions): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SceneSystem } from '../../../engine/system';
|
|
2
2
|
import { ActorCollection } from '../../../engine/actor';
|
|
3
3
|
import { Behaviors } from '../../components';
|
|
4
|
-
import { RemoveActor } from '../../../engine/events';
|
|
4
|
+
import { AddActor, RemoveActor } from '../../../engine/events';
|
|
5
5
|
export class BehaviorSystem extends SceneSystem {
|
|
6
6
|
behaviorCollection;
|
|
7
7
|
actorSpawner;
|
|
@@ -28,15 +28,24 @@ export class BehaviorSystem extends SceneSystem {
|
|
|
28
28
|
return acc;
|
|
29
29
|
}, {});
|
|
30
30
|
this.activeBehaviors = {};
|
|
31
|
+
}
|
|
32
|
+
onSceneEnter() {
|
|
33
|
+
this.behaviorCollection.forEach((actor) => this.setUpBehavior(actor));
|
|
34
|
+
this.behaviorCollection.addEventListener(AddActor, this.handleActorAdd);
|
|
31
35
|
this.behaviorCollection.addEventListener(RemoveActor, this.handleActorRemove);
|
|
32
36
|
}
|
|
33
37
|
onSceneDestroy() {
|
|
38
|
+
this.behaviorCollection.removeEventListener(AddActor, this.handleActorAdd);
|
|
34
39
|
this.behaviorCollection.removeEventListener(RemoveActor, this.handleActorRemove);
|
|
35
40
|
this.behaviorCollection.forEach((actor) => {
|
|
36
41
|
this.activeBehaviors[actor.id].forEach((behavior) => behavior.destroy?.());
|
|
37
42
|
delete this.activeBehaviors[actor.id];
|
|
38
43
|
});
|
|
39
44
|
}
|
|
45
|
+
handleActorAdd = (event) => {
|
|
46
|
+
const { actor } = event;
|
|
47
|
+
this.setUpBehavior(actor);
|
|
48
|
+
};
|
|
40
49
|
handleActorRemove = (event) => {
|
|
41
50
|
const { actor } = event;
|
|
42
51
|
this.activeBehaviors[actor.id].forEach((behavior) => behavior.destroy?.());
|
|
@@ -44,7 +53,14 @@ export class BehaviorSystem extends SceneSystem {
|
|
|
44
53
|
};
|
|
45
54
|
setUpBehavior(actor) {
|
|
46
55
|
const { list } = actor.getComponent(Behaviors);
|
|
47
|
-
this.activeBehaviors[actor.id] = list
|
|
56
|
+
this.activeBehaviors[actor.id] = list
|
|
57
|
+
.filter((config) => {
|
|
58
|
+
if (!this.behaviors[config.name]) {
|
|
59
|
+
console.warn(`Behavior not found: ${config.name}`);
|
|
60
|
+
}
|
|
61
|
+
return this.behaviors[config.name];
|
|
62
|
+
})
|
|
63
|
+
.map((config) => {
|
|
48
64
|
const options = {
|
|
49
65
|
...config.options,
|
|
50
66
|
actor,
|
|
@@ -59,9 +75,6 @@ export class BehaviorSystem extends SceneSystem {
|
|
|
59
75
|
}
|
|
60
76
|
update(options) {
|
|
61
77
|
this.behaviorCollection.forEach((actor) => {
|
|
62
|
-
if (!this.activeBehaviors[actor.id]) {
|
|
63
|
-
this.setUpBehavior(actor);
|
|
64
|
-
}
|
|
65
78
|
this.activeBehaviors[actor.id].forEach((behavior) => behavior.update?.(options));
|
|
66
79
|
});
|
|
67
80
|
}
|
|
@@ -27,7 +27,12 @@ export class SceneManager {
|
|
|
27
27
|
acc[scene.id] = scene;
|
|
28
28
|
return acc;
|
|
29
29
|
}, {});
|
|
30
|
-
this.systemConfigs = systemConfigs.filter((config) =>
|
|
30
|
+
this.systemConfigs = systemConfigs.filter((config) => {
|
|
31
|
+
if (!this.availableSystems[config.name]) {
|
|
32
|
+
console.warn(`System not found: ${config.name}`);
|
|
33
|
+
}
|
|
34
|
+
return this.availableSystems[config.name];
|
|
35
|
+
});
|
|
31
36
|
this.templateCollection = templateCollection;
|
|
32
37
|
this.globalOptions = globalOptions;
|
|
33
38
|
this.resources = resources;
|