bundle_insert_adapter.bend

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

1import Base
2import bundle_batch.bend as BT
3import bundle_construction.bend as CS
4import world.bend as W
5import schema_fragments.bend as SF
6
7type Input<S:Data,Raw:Type> is Type:
8  Input{target:W.Handle<S>,raw:Raw}
9type Refusal<Error:Data> is Data:
10  ConstructionRefused{positions:List<&2,Maybe<&2,Error>>}
11  EntityRefused{error:W.WorldError}
12  DeclarationRefused{error:SF.Error}
13type Output<Raw:Type,Error:Data> is Type:
14  Accepted{}
15  Refused{raw:Raw,error:Refusal<Error>}
16type Owner<S:Data,Store:Type,R:Type,E:Data,Packet:Type,Context:Type> is Type:
17  Owner{batch:BT.Batch<S,Store,R,E,Packet>,context:Context}
18def inserted(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Error:Data,~unpack:Packet -> Raw,context:Context,result:BT.Inserted<S,Store,R,E,Packet>) -> Owner<S,Store,R,E,Packet,Context> & Output<Raw,Error>:
19  match result:
20    case BT.Inserted{batch}: (Owner{batch,context},Accepted{})
21    case BT.Refused{batch,packet,error}: (Owner{batch,context},Refused{unpack(packet),EntityRefused{error}})
22def constructed(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,batch:BT.Batch<S,Store,R,E,Packet>,target:W.Handle<S>,result:CS.Staged<Context,Raw,Cooked,Error>) -> Owner<S,Store,R,E,Packet,Context> & Output<Raw,Error>:
23  match result:
24    case CS.Failed{context,raw,positions}: (Owner{batch,context},Refused{raw,ConstructionRefused{positions}})
25    case CS.Valid{context,cooked,undo,positions}: inserted(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Error,~unpack,context,BT.insert(~S,~Store,~R,~E,~Packet,batch,target,pack(cooked,undo)))
26def request(~S:Data,~Store:Type,~R:Type,~E:Data,~Packet:Type,~Context:Type,~Raw:Type,~Cooked:Type,~Error:Data,~construct:Context -> Raw -> CS.Staged<Context,Raw,Cooked,Error>,~pack:Cooked -> (Cooked -> Raw) -> Packet,~unpack:Packet -> Raw,owner:Owner<S,Store,R,E,Packet,Context>,input:Input<S,Raw>) -> Owner<S,Store,R,E,Packet,Context> & Output<Raw,Error>:
27  match owner input:
28    case Owner{batch,context} Input{target,raw}: constructed(~S,~Store,~R,~E,~Packet,~Context,~Raw,~Cooked,~Error,~pack,~unpack,batch,target,construct(context,raw))