ordinary_app_relation_system.bend
bendvy-ecs-core@0.1.0.1 · 43 lines · 0 definitions
1import Base
2import bendvy-ecs-core@0.1.0.1/world.bend as W
3import bendvy-ecs-core@0.1.0.1/ordinary_app_relation.bend as Relation
4import bendvy-ecs-core@0.1.0.1/relation_failure_reader.bend as Ord
5import bendvy-ecs-core@0.1.0.1/relation_commands.bend as A
6import bendvy-ecs-core@0.1.0.1/relation_providers.bend as P
7import bendvy-ecs-core@0.1.0.1/transaction.bend as T
8import bendvy-ecs-core@0.1.0.1/commands.bend as Cmd
9import bendvy-ecs-core@0.1.0.1/system.bend as Sys
10import bendvy-ecs-core@0.1.0.1/ordinary_app_observation_data.bend as DTO
11import bendvy-ecs-core@0.1.0.1/ordinary_app_registration_fields.bend as Fields
12import bendvy-ecs-core@0.1.0.1/schedule.bend as Sch
13
14def finished(~S:Data,~C:Type,~R:Type,~E:Data,result:T.Returned<Relation.World(~S,~C,~R,~E),Unit>) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),Unit,Unit>:
15 match result:
16 case T.Returned{world,T.Success{}}:Sys.Succeeded{world,Unit{}}
17 case T.Returned{world,T.Failure{error}}:Sys.Failed{world,error}
18def read_done(~S:Data,~C:Type,~R:Type,~E:Data,result:T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>> & Maybe<&2,List<&2,W.Handle<S>>>) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),Unit,Unit>:
19 match result:
20 case (frame,_):finished(~S,~C,~R,~E,Cmd.tx_finish(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Unit,frame,T.Success{}))
21def reader(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,world:Relation.World(~S,~C,~R,~E),args:Unit) -> Sys.Outcome<Relation.World(~S,~C,~R,~E),Unit,Unit>:
22 read_done(~S,~C,~R,~E,P.read(~T.Tx<Relation.World(~S,~C,~R,~E),A.Notice<S,E>>,~S,~P.provide_read(~S,~C,~R,~E,~Relation.descriptor(~S,declaration)),T.begin(~Relation.World(~S,~C,~R,~E),~A.Notice<S,E>,world),target))
23def Owner(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>) -> Type:
24 Sys.Registry<S,A.Store<S,C>,R,A.Notice<S,E>,Unit,Unit,Unit,reader(~S,~C,~R,~E,~declaration,~target)>
25def register(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,world:Relation.World(~S,~C,~R,~E),name:String) -> Sys.RegistrationResult<S,A.Store<S,C>,R,A.Notice<S,E>,Unit,Unit,Unit,reader(~S,~C,~R,~E,~declaration,~target)>:
26 Sys.register(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Unit,~Unit,~Unit,~reader(~S,~C,~R,~E,~declaration,~target),world,name,Ord.accesses(~S,[declaration]))
27def empty_fold(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,owner:Owner(~S,~C,~R,~E,~declaration,~target)) -> Owner(~S,~C,~R,~E,~declaration,~target) & List<&2,Fields.Fields<S>>:
28 (owner,[])
29def binding(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,owner:Owner(~S,~C,~R,~E,~declaration,~target),slot:String) -> Owner(~S,~C,~R,~E,~declaration,~target) & DTO.Binding<S>:
30 match owner:
31 case Sys.Registry{+namespace,+id,+name,+access,+cursor}:(Sys.Registry{namespace,id,name,access,cursor},DTO.Binding{namespace,id,name,access,cursor,slot,[]})
32def dispatched(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,result:Sys.RunResult<S,A.Store<S,C>,R,A.Notice<S,E>,Unit,Unit,Unit,reader(~S,~C,~R,~E,~declaration,~target)>) -> Owner(~S,~C,~R,~E,~declaration,~target) & Sys.Outcome<Relation.World(~S,~C,~R,~E),Maybe<&2,Unit>,Unit>:
33 match result:
34 case Sys.Completed{registry,Sys.Succeeded{world,output}}:(registry,Sys.Succeeded{world,output})
35 case Sys.Completed{registry,Sys.Failed{world,error}}:(registry,Sys.Failed{world,Some{error}})
36 case Sys.RegistrationRejected{registry,world,args}:(registry,Sys.Failed{world,None{}})
37def dispatch_checked(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,allowed:Bool,owner:Owner(~S,~C,~R,~E,~declaration,~target),world:Relation.World(~S,~C,~R,~E)) -> Owner(~S,~C,~R,~E,~declaration,~target) & Sys.Outcome<Relation.World(~S,~C,~R,~E),Maybe<&2,Unit>,Unit>:
38 match allowed:
39 case False{}:(owner,Sys.Failed{world,None{}})
40 case True{}:dispatched(~S,~C,~R,~E,~declaration,~target,Sys.run(~S,~A.Store<S,C>,~R,~A.Notice<S,E>,~Unit,~Unit,~Unit,~reader(~S,~C,~R,~E,~declaration,~target),owner,world,Unit{}))
41def dispatch(~S:Data,~C:Type,~R:Type,~E:Data,~declaration:Ord.Declaration<S>,~target:W.Handle<S>,owner:Owner(~S,~C,~R,~E,~declaration,~target),world:Relation.World(~S,~C,~R,~E),id:U32) -> Owner(~S,~C,~R,~E,~declaration,~target) & Sys.Outcome<Relation.World(~S,~C,~R,~E),Maybe<&2,Unit>,Unit>:
42 match owner:
43 case Sys.Registry{namespace,+actual,name,access,cursor}:dispatch_checked(~S,~C,~R,~E,~declaration,~target,U32.is_eq(actual,id),Sys.Registry{namespace,actual,name,access,cursor},world)