Add a node that names the collision layer of an object (#211)
The issue asked for three nodes: Set layer, Set collides with and Layer of. A probe showed that the finding behind the first two is outdated. The Properties node of type Collider already writes both settings while the game runs, and both collision systems see the change at once. As agreed, only Layer of is built, and writing stays with Properties. - Layer of is a data node with the input object and the outputs name and number. The name is what the project calls the layer. - NodeContext.collisionLayerOf answers the number, and the new field collisionLayers on GraphLookup brings the names to the node. - layerHolderOf in solids.ts says whose layer counts. An object stands for its first collider child, a collider or tilemap for itself. - Decided here: a collider that is switched off counts too, because its layer is set either way. - Decided here: without a collider the name is empty and the number is -1. - The node is a read, not a run, so it answers at the moment it is asked. Right after a Set in the same flow it names the new layer. - The output number was not asked for. It fits the layer port of Properties as it is. Changing the layer during a run had no test at all so far. Five tests now hold it in both systems. Tests: - Gate: 198 files, 2929 tests (2914 + 15), exit 0 - e2e 1-6: 285 checks passed (06: +2 for block 6z-x) - Five unit tests for the change during a run: a mover is blocked, passes and is blocked again, a ray with a layer filter follows the change, and a dynamic body falls through the ground in Play - Six unit tests for Layer of, three against each system, and four cases in the node catalog - 6z-x finds the node in the palette, checks its ports and logs "Ghost" and "1" for the owner's collider in a Play run - Two counter-probes for the change during a run fail 1 and 4 tests, and only new ones, so those places were unguarded before - Six counter-probes for Layer of fail 2 to 3 tests each. All eight ran on stein2, not in the container. - The browser counter-probe fails 6z-x with "Layer 1" and "1" - The e2e sum of 1619 is calculated (1617 measured in CI run 276, plus 2). Neither the full suite nor the smokes ran for this state. - Not looked at in the browser: that the layer port of Properties shows the same picker as the inspector. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d39bf83ea9
commit
3e8c88c66d
12 files changed
+329
-7
No files matched your search
@@ -4,6 +4,7 @@
|
||||
* Handles arriving from a graph are resolved to the world's entities here, so no node holds one.
|
||||
*/
|
||||
import type { EntityHandle, NodeContext, PhysicsControl, SharedState } from '../../core/graph';
|
||||
import { collisionFilterOf } from '../../core/model/collisionLayers';
|
||||
import type { Vec2 } from '../../core/model/Properties';
|
||||
import { findAssetOf, findScene, type Project } from '../../core/model/Project';
|
||||
import { soundFileOf } from '../../core/model/sound';
|
||||
@@ -15,7 +16,7 @@ import type { World } from '../World';
|
||||
import type { AudioSink } from './Audio';
|
||||
import type { Instance } from './behaviorPulses';
|
||||
import type { Input } from './Input';
|
||||
import { bodyOf, type CollisionSource, NOT_BLOCKED } from './solids';
|
||||
import { bodyOf, type CollisionSource, layerHolderOf, NOT_BLOCKED } from './solids';
|
||||
|
||||
export interface TimeScaled {
|
||||
scale: number;
|
||||
@@ -112,6 +113,11 @@ export function behaviorContext(
|
||||
world.noteRay(from, end, hits.length > 0);
|
||||
return hits.map((hit) => ({ ...hit, object: bodyOf(hit.collider) }));
|
||||
},
|
||||
collisionLayerOf: (target) => {
|
||||
const found = resolve(target);
|
||||
const holder = found && layerHolderOf(world, found);
|
||||
return holder ? collisionFilterOf(holder.props).layer : null;
|
||||
},
|
||||
ignoreOneWay: (target, seconds) => {
|
||||
const found = resolve(target);
|
||||
if (found) world.ignoreOneWay(found, seconds);
|
||||
|
||||
@@ -646,6 +646,14 @@ export function isCollisionBody(entity: Entity): boolean {
|
||||
return entity.type === 'collider' || entity.type === 'tilemap';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whose layer an object is on (#211): a collider or tilemap its own, anything else that of its first
|
||||
* collider child, switched on or not – the layer is set either way.
|
||||
*/
|
||||
export function layerHolderOf(world: World, entity: Entity): Entity | undefined {
|
||||
return isCollisionBody(entity) ? entity : world.childrenOf(entity).find((e) => e.type === 'collider');
|
||||
}
|
||||
|
||||
/**
|
||||
* The object a collider belongs to: its parent, or the collider itself when top-level. A tilemap
|
||||
* is its own body wherever it is placed – its cells are the thing, not a shape stuck on one.
|
||||
|
||||
Reference in new issue
Block a user