ordinary_component_binding.bend

bendvy-ecs-core@0.1.0.1 · 26 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.1/ordinary_declaration.bend as Identity
3import bendvy-ecs-core@0.1.0.1/component.bend as C
4import bendvy-ecs-core@0.1.0.1/column.bend as Col
5
6# Static trusted schema lenses; this Data binding owns no payload or closure.
7type Binding<-S:Data,-Store:Type,-Rest:Type,-P:Type,-V:Data,-Token:Data,-take:Store -> Rest & Col.Column<S,P>,-put:Rest -> Col.Column<S,P> -> Store,-view:P -> P & V> is Data:
8  Binding{identity:Identity.Declaration<S,P>,family:C.Family<S,Store,Rest,P,V,Token,take,put,view>}
9# Trusted schema setup: connect a component identity to its column take/put
10# lenses and owner-preserving Data projection. The resulting Data binding owns
11# no payload. Callers must supply mutually consistent lenses; this constructor
12# does not prove their laws or establish runtime world identity.
13# Example: examples/scheduled-health/registration.bend component bindings.
14def bind(~S:Data,~Store:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:Store -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> Store,~view:P -> P & V,+identity:Identity.Declaration<S,P>) -> Binding<S,Store,Rest,P,V,Token,take,put,view>:
15  Binding{identity,C.Family{Identity.key(~S,~P,identity)}}
16# Return the schema-scoped component identity from a trusted binding.
17# This detached declaration does not identify an entity or grant world access.
18def identity(~S:Data,~Store:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:Store -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> Store,~view:P -> P & V,binding:Binding<S,Store,Rest,P,V,Token,take,put,view>) -> Identity.Declaration<S,P>:
19  match binding:
20    case Binding{identity,_}:identity
21# Return the typed component family used by lower-level component operations.
22# Retains the binding's schema, storage and projection indices; does not access
23# a world. Raw family construction is trusted provisioning, not gameplay access.
24def family(~S:Data,~Store:Type,~Rest:Type,~P:Type,~V:Data,~Token:Data,~take:Store -> Rest & Col.Column<S,P>,~put:Rest -> Col.Column<S,P> -> Store,~view:P -> P & V,binding:Binding<S,Store,Rest,P,V,Token,take,put,view>) -> C.Family<S,Store,Rest,P,V,Token,take,put,view>:
25  match binding:
26    case Binding{_,family}:family