|
@@ -2,7 +2,7 @@
|
|
|
* 3D position
|
|
|
*/
|
|
|
|
|
|
-import { addComponent, defineComponent, hasComponent, Types, type IWorld, defineQuery, type Entity } from './ecs';
|
|
|
+import { addComponent, defineComponent, hasComponent, Types, type IWorld, defineQuery, type Entity, removeComponent, type Component } from './ecs';
|
|
|
import { isLandscape } from './landscape';
|
|
|
import { describe } from '$lib';
|
|
|
|
|
@@ -41,12 +41,19 @@ export const placeOnMap = (world: IWorld, e: Entity, x, y, z) => {
|
|
|
processLevelTriggers(world, e, undefined, z);
|
|
|
};
|
|
|
|
|
|
+export const removeFromMap = (world, e) => {
|
|
|
+ // const {x, y, z} = getPos3(e);
|
|
|
+ // removeFrom(world, e, x, y);
|
|
|
+ removeComponent(world, Pos3, e);
|
|
|
+ /// TODO
|
|
|
+};
|
|
|
+
|
|
|
export const moveTo = (world, e, x, y, z) => {
|
|
|
Pos3.x[e] = x;
|
|
|
Pos3.y[e] = y;
|
|
|
Pos3.z[e] = z;
|
|
|
registerOnGrid(world, e, x, y, z);
|
|
|
-// processFeatureTriggers(world, e, x, y, z);
|
|
|
+ processLocationTriggers(world, e, x, y, z);
|
|
|
};
|
|
|
|
|
|
const levelTriggers = [];
|
|
@@ -171,3 +178,27 @@ export const getGrid = (world, z, x0, y0, x1, y1) => {
|
|
|
export const landscapeAt = (world, x: number, y: number, z: number) => {
|
|
|
return getTile(x, y, z).landscape;
|
|
|
};
|
|
|
+
|
|
|
+type LocationTrigger = {
|
|
|
+ target: Component,
|
|
|
+ trigger: (world: IWorld, feature: Entity, e: Entity) => void,
|
|
|
+};
|
|
|
+
|
|
|
+const locationTriggers: LocationTrigger[] = [];
|
|
|
+
|
|
|
+export const registerLocationTrigger = (trigger: LocationTrigger) => {
|
|
|
+ locationTriggers.push(trigger);
|
|
|
+};
|
|
|
+
|
|
|
+const processLocationTriggers = (world: IWorld, e: Entity, x: number, y: number, z: number) => {
|
|
|
+ const stack = getStack(x, y, z);
|
|
|
+ for (let other of stack) {
|
|
|
+ if (e === other)
|
|
|
+ continue;
|
|
|
+ for (let {target, trigger} of locationTriggers) {
|
|
|
+ if (hasComponent(world, target, other)) {
|
|
|
+ trigger(world, other, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|