ordinary_app_composer.bend

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

1import bendvy-ecs-core@0.1.0.0/ordinary_app_records.bend as Leaf
2import Base
3import bendvy-ecs-core@0.1.0.0/ordinary_app_registration_fields.bend as Records
4import bendvy-ecs-core@0.1.0.0/ordinary_app_description.bend as Description
5import bendvy-ecs-core@0.1.0.0/ordinary_app_recipe.bend as Tree
6import bendvy-ecs-core@0.1.0.0/ordinary_app_observation_data.bend as DTO
7# Affine App carrier retaining actual World, heterogeneous registration owners,
8# observation recipe and debug flag. observe/fold are trusted closed setup adapters;
9# metadata and detached observations do not themselves grant gameplay operations.
10type Registered<S:Data,World:Type,Owners:Type,Rows:Data,-observe:World -> World & DTO.Observation<Rows>,-fold:Owners -> Owners & List<&2,Records.Fields<S>>> is Type:
11  Registered{world:World,owners:Owners,recipe:Tree.Recipe<World,Rows,observe>,debug:Bool}
12# Advanced empty observer returning the actual World with Unit rows and no text.
13# It does not enumerate entities, register readers or apply pending commands.
14def empty_observe(~World:Type,world:World) -> World & DTO.Observation<Unit>:
15  (world,DTO.Observation{Unit{},[]})
16# Start an App with the actual World, Unit registration owner and empty observer.
17# Debug is disabled; this performs no registration or gameplay execution.
18def empty(~S:Data,~World:Type,world:World) -> Registered<S,World,Unit,Unit,empty_observe(~World),Leaf.empty(~S)>:
19  Registered{world,Unit{},Tree.Recipe{},False{}}
20# Replace only the observation-enable flag, returning actual World/owners/recipe.
21# Enabling observation does not add gameplay access or execute a system.
22def enabled(~S:Data,~World:Type,~Owners:Type,~Rows:Data,~observe:World -> World & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,app:Registered<S,World,Owners,Rows,observe,fold>,flag:Bool) -> Registered<S,World,Owners,Rows,observe,fold>:
23  match app:
24    case Registered{world,owners,recipe,_}:Registered{world,owners,recipe,flag}
25def observed(~S:Data,~World:Type,~Owners:Type,~Rows:Data,~observe:World -> World & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,owners:Owners,fields:List<&2,Records.Fields<S>>,result:World & DTO.Observation<Rows>) -> Registered<S,World,Owners,Rows,observe,fold> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>:
26  match result:
27    case (world,view):(Registered{world,owners,Tree.Recipe{},True{}},Some{DTO.Product{Description.bindings(~S,fields),view}})
28def folded(~S:Data,~World:Type,~Owners:Type,~Rows:Data,~observe:World -> World & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,world:World,result:Owners & List<&2,Records.Fields<S>>) -> Registered<S,World,Owners,Rows,observe,fold> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>:
29  match result:
30    case (owners,fields):observed(~S,~World,~Owners,~Rows,~observe,~fold,owners,fields,observe(world))
31# Return App and optional detached bindings/observation. Disabled returns None
32# before calling fold or observe. Enabled folds registration owners first, then
33# observes World, retaining both returned owners. The callbacks remain trusted;
34# this wrapper is not a universal noninterference proof or a restorable save.
35# See ordinary-app-component.bend and examples/scheduled-health/application.bend.
36def snapshot(~S:Data,~World:Type,~Owners:Type,~Rows:Data,~observe:World -> World & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,app:Registered<S,World,Owners,Rows,observe,fold>) -> Registered<S,World,Owners,Rows,observe,fold> & Maybe<&2,DTO.Product<List<&2,DTO.Binding<S>>,DTO.Observation<Rows>>>:
37  match app:
38    case Registered{world,owners,recipe,False{}}:(Registered{world,owners,recipe,False{}},None{})
39    case Registered{world,owners,_,True{}}:folded(~S,~World,~Owners,~Rows,~observe,~fold,world,fold(owners))
40# Advanced registration-composition adapter pairing existing and leaf owners.
41# Combine observations and field folds in left-before-right order, preserving the
42# supplied World and debug flag. This does not itself register or run the leaf.
43def appended(~S:Data,~World:Type,~Owners:Type,~Rows:Data,~observe:World -> World & DTO.Observation<Rows>,~fold:Owners -> Owners & List<&2,Records.Fields<S>>,~Leaf:Type,~Value:Data,~leafObserve:World -> World & DTO.Observation<Value>,~leafFold:Leaf -> Leaf & List<&2,Records.Fields<S>>,world:World,owners:Owners,leaf:Leaf,debug:Bool) -> Registered<S,World,Owners & Leaf,DTO.Product<Rows,Value>,Tree.observe_pair(~World,~Rows,~Value,~observe,~leafObserve),Leaf.fold_pair(~S,~Owners,~Leaf,~fold,~leafFold)>:
44  Registered{world,(owners,leaf),Tree.Recipe{},debug}