execution_relation_resource_publication.bend
bendvy-ecs-core@0.1.0.3 · 31 lines · 5 definitions
1import Base
2import bendvy-ecs-core@0.1.0.3/execution_composer_layout.bend as Layout
3import bendvy-ecs-core@0.1.0.3/execution_relation_store.bend as Store
4import bendvy-ecs-core@0.1.0.3/execution_relation_operation.bend as O
5import bendvy-ecs-core@0.1.0.3/execution_relation_publication.bend as Publication
6import bendvy-ecs-core@0.1.0.3/execution_relation_context.bend as Context
7import bendvy-ecs-core@0.1.0.3/relation_types.bend as T
8import bendvy-ecs-core@0.1.0.3/entity_allocator.bend as Allocator
9import bendvy-ecs-core@0.1.0.3/change_tick.bend as Tick
10
11
12
13def slot(~S:Data,~key:String,~origin:Layout.Layout,~FromP:Type,~ToP:Type,~FromV:Data,~ToV:Data,payload:{FromP == ToP : Type},view:{FromV == ToV : Data},value:Layout.ResourceSlot<S,Layout.Viewed<FromP,FromV>,key,origin>) -> Layout.ResourceSlot<S,Layout.Viewed<ToP,ToV>,key,origin>:
14 %payload : Layout.ResourceSlot<S,Layout.Viewed<_,ToV>,key,origin>
15 %view : Layout.ResourceSlot<S,Layout.Viewed<FromP,_>,key,origin>
16 value
17def restored(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},rest:Layout.resource_rest(~S,resources,route),result:Allocator.Allocator & (Layout.ResourceSlot<S,Layout.Viewed<Store.Store<S,descriptor>,Store.View<S,descriptor>>,Layout.key(resources,route),Layout.origin(resources,route)> & Store.Receipt<S>)) -> Allocator.Allocator & (WR & Store.Receipt<S>):
18 match result:
19 case (allocator,(selected,receipt)):(allocator,(Layout.checked_owner(Layout.resources(~S,resources),WR,Equal.sym(Type,WR,Layout.resources(~S,resources),same),Layout.resource_put(~S,resources,route,rest,slot(~S,~Layout.key(resources,route),~Layout.origin(resources,route),~Store.Store<S,descriptor>,~Layout.payload(resources,route),~Store.View<S,descriptor>,~Layout.view(resources,route),Equal.sym(Type,Layout.payload(resources,route),Store.Store<S,descriptor>,payload),Equal.sym(Data,Layout.view(resources,route),Store.View<S,descriptor>,view),selected))),receipt))
20def taken(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},namespace:U32,allocator:Allocator.Allocator,operation:O.Operation<S>,tick:Tick.Tick,result:Layout.resource_rest(~S,resources,route) & Layout.ResourceSlot<S,Layout.stored(resources,route),Layout.key(resources,route),Layout.origin(resources,route)>) -> Allocator.Allocator & (WR & Store.Receipt<S>):
21 match result:
22 case (rest,selected):restored(~S,~WR,~resources,~same,~route,~descriptor,~payload,~view,rest,Publication.apply(~S,~descriptor,~Layout.key(resources,route),~Layout.origin(resources,route),namespace,allocator,slot(~S,~Layout.key(resources,route),~Layout.origin(resources,route),~Layout.payload(resources,route),~Store.Store<S,descriptor>,~Layout.view(resources,route),~Store.View<S,descriptor>,payload,view,selected),operation,tick))
23def checked(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},allowed:Bool,namespace:U32,allocator:Allocator.Allocator,owners:WR,operation:O.Operation<S>,tick:Tick.Tick) -> Allocator.Allocator & (WR & Store.Receipt<S>):
24 match allowed:
25 case False{}:(allocator,(owners,Store.Refused{operation,Store.NamespaceMismatch{}}))
26 case True{}:taken(~S,~WR,~resources,~same,~route,~descriptor,~payload,~view,namespace,allocator,operation,tick,Layout.resource_take(~S,resources,route,Layout.checked_owner(WR,Layout.resources(~S,resources),same,owners)))
27
28
29def apply(~S:Data,~WR:Type,~resources:Layout.Layout,~same:{WR == Layout.resources(~S,resources) : Type},~route:Layout.Route,~valid:{Layout.grant_valid(~resources,~route) == True{} : Bool},~descriptor:T.Descriptor<S>,~payload:{Layout.payload(resources,route) == Store.Store<S,descriptor> : Type},~view:{Layout.view(resources,route) == Store.View<S,descriptor> : Data},context:Context.Context<S,WR,resources,same>,+namespace:U32,allocator:Allocator.Allocator,owners:WR,operation:O.Operation<S>,tick:Tick.Tick) -> Allocator.Allocator & (WR & Store.Receipt<S>):
30 match context:
31 case Context.Context{expected}:checked(~S,~WR,~resources,~same,~route,~valid,~descriptor,~payload,~view,U32.is_eq(expected,namespace),namespace,allocator,owners,operation,tick)