restore_clear.bend

bendvy-ecs-core@0.1.0.0 · 40 lines · 0 definitions

1import Base
2import bendvy-ecs-core@0.1.0.0/restore_data.bend as R
3import bendvy-ecs-core@0.1.0.0/snapshot_leaf.bend as Leaf
4import bendvy-ecs-core@0.1.0.0/ordinary_declaration.bend as Identity
5import bendvy-ecs-core@0.1.0.0/persistence_declaration.bend as Decl
6import bendvy-ecs-core@0.1.0.0/decode_data.bend as D
7import bendvy-ecs-core@0.1.0.0/column.bend as Col
8import bendvy-ecs-core@0.1.0.0/world.bend as W
9import bendvy-ecs-core@0.1.0.0/owner_product.bend as Product
10
11# Called only after complete staging and capacity admission. Old payloads leave
12# scope here; no inverse, destructor or finalizer callback is executed.
13def component_cleared(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,declaration:Decl.Constructed<S,P,identity,project>,+handle:W.Handle<S>,observed:Col.SwapOutcome<S,P>) -> Leaf.Component<S,P,identity,project> & List<&2,R.Change<S>>:
14  match observed:
15    case Col.Accepted{column,Some{owner}}:(Leaf.Component{column,declaration},[R.Removed{handle,Identity.key(~S,~P,identity)}])
16    case Col.Accepted{column,None{}}:(Leaf.Component{column,declaration},[])
17    case Col.Rejected{column,_}:(Leaf.Component{column,declaration},[])
18def component(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,~project:P -> P & D.Raw,owner:Leaf.Component<S,P,identity,project>,+handle:W.Handle<S>) -> Leaf.Component<S,P,identity,project> & List<&2,R.Change<S>>:
19  match owner:
20    case Leaf.Component{column,declaration}:component_cleared(~S,~P,~identity,~project,declaration,handle,Col.clear(~S,~P,column,W.handle_index(~S,handle)))
21def transient_cleared(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,declaration:Decl.Transient<S,P,identity>,+handle:W.Handle<S>,observed:Col.SwapOutcome<S,P>) -> Leaf.TransientComponent<S,P,identity> & List<&2,R.Change<S>>:
22  match observed:
23    case Col.Accepted{column,Some{owner}}:(Leaf.TransientComponent{column,declaration},[R.Removed{handle,Identity.key(~S,~P,identity)}])
24    case Col.Accepted{column,None{}}:(Leaf.TransientComponent{column,declaration},[])
25    case Col.Rejected{column,_}:(Leaf.TransientComponent{column,declaration},[])
26def transient_component_owned(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,owner:Leaf.TransientComponent<S,P,identity>,+handle:W.Handle<S>) -> Leaf.TransientComponent<S,P,identity> & List<&2,R.Change<S>>:
27  match owner:
28    case Leaf.TransientComponent{column,declaration}:transient_cleared(~S,~P,~identity,declaration,handle,Col.clear(~S,~P,column,W.handle_index(~S,handle)))
29def transient_component(~S:Data,~P:Type,~identity:Identity.Declaration<S,P>,owner:Leaf.TransientComponent<S,P,identity>,handle:W.Handle<S>) -> Leaf.TransientComponent<S,P,identity> & List<&2,R.Change<S>>:
30  transient_component_owned(~S,~P,~identity,owner,handle)
31def unit(~S:Data,owner:Unit,handle:W.Handle<S>) -> Unit & List<&2,R.Change<S>>:(owner,[])
32def product_join(~S:Data,~LC:Type,~RC:Type,left:LC,events:List<&2,R.Change<S>>,observed:RC & List<&2,R.Change<S>>) -> Product.Owner<LC,RC> & List<&2,R.Change<S>>:
33  match observed:
34    case (right,more):(Product.Owner{left,right},List.append(&2,R.Change<S>,events,more))
35def product_left(~S:Data,~LC:Type,~RC:Type,~right:RC -> W.Handle<S> -> RC & List<&2,R.Change<S>>,owner:RC,handle:W.Handle<S>,observed:LC & List<&2,R.Change<S>>) -> Product.Owner<LC,RC> & List<&2,R.Change<S>>:
36  match observed:
37    case (left,events):product_join(~S,~LC,~RC,left,events,right(owner,handle))
38def product(~S:Data,~LC:Type,~RC:Type,~left:LC -> W.Handle<S> -> LC & List<&2,R.Change<S>>,~right:RC -> W.Handle<S> -> RC & List<&2,R.Change<S>>,owner:Product.Owner<LC,RC>,+handle:W.Handle<S>) -> Product.Owner<LC,RC> & List<&2,R.Change<S>>:
39  match owner:
40    case Product.Owner{a,b}:product_left(~S,~LC,~RC,~right,b,handle,left(a,handle))