feature_provision.bend
bendvy-ecs-core@0.1.0.1 · 33 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/feature.bend as F
3import bendvy-ecs-core@0.1.0.1/component.bend as C
4import bendvy-ecs-core@0.1.0.1/schema_fragments.bend as SF
5import bendvy-ecs-core@0.1.0.1/capabilities.bend as Cap
6# Trusted schema author closes the getter; universal gameplay receives only H.
7def read(-H:Type,-V:Data,cap:Cap.Read<H,V>,ctx:H) -> H & C.Access<V>:
8 match cap:
9 case Cap.Read{get}: get(ctx)
10def provide(~Ctx:Type,~V:Data,~get:Ctx -> Ctx & C.Access<V>,~body:@-H:Type -> Cap.Read<H,V> -> H -> H & C.Access<V>,ctx:Ctx) -> Ctx & C.Access<V>:
11 body(Ctx,Cap.Read{get},ctx)
12# Exact repeated descriptors collapse in access scope; conflicts remain validation errors.
13def scope_keep(~S:Data,present:Bool,item:SF.Entry<S>,rest:List<&2,SF.Entry<S>>) -> List<&2,SF.Entry<S>>:
14 match present:
15 case True{}: rest
16 case False{}: Con{item,rest}
17def scope_seen(~S:Data,items:List<&2,SF.Entry<S>>,+seen:List<&2,SF.Entry<S>>) -> List<&2,SF.Entry<S>>:
18 match items:
19 case Nil{}: Nil{}
20 case +item <> rest: scope_keep(~S,SF.descriptor_present(~S,seen,item),item,scope_seen(~S,rest,Con{item,seen}))
21def scope_unique(~S:Data,items:List<&2,SF.Entry<S>>) -> List<&2,SF.Entry<S>>:
22 scope_seen(~S,items,Nil{})
23# Authoring boundary: actual declared scope checked before closed construction.
24def bind_feature(~S:Data,~Owners:Type,~Output:Type,~build:Owners -> Output,definition:F.Definition<S>,required:List<&2,SF.Entry<S>>,owners:Owners) -> SF.Bound<S,Owners,Output>:
25 SF.bind_declared(~S,~Owners,~Output,~build,SF.Fragment{scope_unique(~S,F.visibility(~S,F.definition_tree(~S,definition))),owners},required)
26def write(-H:Type,-C:Type,-V:Data,cap:Cap.Write<H,C,V>,ctx:H,value:C) -> H:
27 match cap:
28 case Cap.Write{_,set}: set(ctx,value)
29def action(-H:Type,cap:Cap.Action<H>,ctx:H) -> H:
30 match cap:
31 case Cap.Action{run}: run(ctx)
32def provide_action(~Ctx:Type,~run:Ctx -> Ctx,~body:@-H:Type -> Cap.Action<H> -> H -> H,ctx:Ctx) -> Ctx:
33 body(Ctx,Cap.Action{run},ctx)