execution_relation_command.bend

bendvy-ecs-core@0.1.0.3 · 27 lines · 8 definitions

1import Base
2import bendvy-ecs-core@0.1.0.3/world.bend as W
3import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as Layout
4import bendvy-ecs-core@0.1.0.3/execution_relation_operation.bend as O
5
6# The closed command declaration binds route and enqueue to the existing Buffer.
7# These adapters do not allocate a queue or accept a World callback.
8type Commands<-Q:Type,-S:Data> is Type:
9  Commands{relate:Q -> W.Handle<S> -> W.Handle<S> -> Q,unrelate:Q -> W.Handle<S> -> Q}
10type HierarchyCommands<-Q:Type,-S:Data> is Type:
11  HierarchyCommands{relations:Commands<Q,S>,reorder:Q -> W.Handle<S> -> List<&2,W.Handle<S>> -> Q}
12def commands(~S:Data,~Q:Type,~route:Layout.Route,~enqueue:Q -> Layout.Route -> O.Operation<S> -> Q) -> Commands<Q,S>:
13  Commands{queue => source => target => enqueue(queue,route,O.Relate{source,target}),queue => source => enqueue(queue,route,O.Unrelate{source})}
14def hierarchy(~S:Data,~Q:Type,~route:Layout.Route,~enqueue:Q -> Layout.Route -> O.Operation<S> -> Q) -> HierarchyCommands<Q,S>:
15  HierarchyCommands{commands(~S,~Q,~route,~enqueue),queue => parent => children => enqueue(queue,route,O.Reorder{parent,children})}
16def relate_field(~S:Data,~Q:Type,cap:Commands<Q,S>) -> Q -> W.Handle<S> -> W.Handle<S> -> Q:
17  match cap:
18    case Commands{relate,_}:relate
19def unrelate_field(~S:Data,~Q:Type,cap:Commands<Q,S>) -> Q -> W.Handle<S> -> Q:
20  match cap:
21    case Commands{_,unrelate}:unrelate
22def relations_field(~S:Data,~Q:Type,cap:HierarchyCommands<Q,S>) -> Commands<Q,S>:
23  match cap:
24    case HierarchyCommands{relations,_}:relations
25def reorder_field(~S:Data,~Q:Type,cap:HierarchyCommands<Q,S>) -> Q -> W.Handle<S> -> List<&2,W.Handle<S>> -> Q:
26  match cap:
27    case HierarchyCommands{_,reorder}:reorder