ordinary_schema_dump.bend
bendvy-ecs-core@0.1.0.1 · 87 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/column.bend as Col
4import bendvy-ecs-core@0.1.0.1/ordinary_schema.bend as Schema
5import bendvy-ecs-core@0.1.0.1/ordinary_declaration.bend as Identity
6import bendvy-ecs-core@0.1.0.1/owner_product.bend as Product
7import bendvy-ecs-core@0.1.0.1/ordinary_schema_provision.bend as Ordinary
8import bendvy-ecs-core@0.1.0.1/ordinary_dump_builtin.bend as Builtin
9# One retained ordinary Provision/Schema. Read indices contain no keys or owners.
10# Trusted ordinary schema provision plus matching component/resource
11# display routes. Contains no live owners. Display indices carry no independent
12# keys; raw construction must preserve schema/slot/owner consistency.
13type Provision<-S:Data,-C:Type,-R:Type,-empty:Unit -> C,-count:C -> List<&2,W.Handle<S>> -> C & List<&2,Maybe<&2,U32>>,-components:C -> U32 -> C & List<&2,Maybe<&2,String>>,-resources:R -> R & List<&2,Maybe<&2,String>>> is Data:
14 Provision{ordinary:Ordinary.Provision<S,C,R,empty,count>}
15def component_returned(~S:Data,~P:Type,result:Col.Column<S,P> & Maybe<&2,String>) -> Col.Column<S,P> & List<&2,Maybe<&2,String>>:
16 match result:
17 case (column,value):(column,[value])
18def component_read(~S:Data,~P:Type,~show:P -> P & String,column:Col.Column<S,P>,id:U32) -> Col.Column<S,P> & List<&2,Maybe<&2,String>>:
19 component_returned(~S,~P,Col.view(~S,~P,~String,~show,column,id))
20def component_resources(value:Unit) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}])
21def resource_components(value:Unit,id:U32) -> Unit & List<&2,Maybe<&2,String>>:(value,[None{}])
22def resource_returned(~P:Type,result:P & String) -> P & List<&2,Maybe<&2,String>>:
23 match result:
24 case (value,text):(value,[Some{text}])
25def resource_read(~P:Type,~show:P -> P & String,value:P) -> P & List<&2,Maybe<&2,String>>:
26 resource_returned(~P,show(value))
27# Opaque payload display is an explicit allowed extension; built-ins below need none.
28# Declare a component dump leaf with explicit owner-preserving presentation.
29# show must return P with text; opaque user values may supply this formatter.
30# Does not read a column or grant gameplay access during setup.
31def component(~S:Data,~P:Type,~show:P -> P & String,declaration:Identity.Declaration<S,P>) -> Provision<S,Col.Column<S,P>,Unit,Ordinary.component_empty(~S,~P),Ordinary.component_count(~S,~P),component_read(~S,~P,~show),component_resources>:
32 Provision{Ordinary.component(~S,~P,declaration)}
33# Declare a resource dump leaf with owner-preserving presentation.
34# show returns the same owner type with text, without copying affine payloads.
35# Arbitrary caller callbacks remain trusted; no rollback is added.
36def resource(~S:Data,~P:Type,~show:P -> P & String,declaration:Schema.Resource<S,P>) -> Provision<S,Unit,P,Ordinary.resource_empty,Ordinary.resource_count(~S),resource_components,resource_read(~P,~show)>:
37 Provision{Ordinary.resource(~S,~P,declaration)}
38# Component dump provision with built-in Array<U32> presentation.
39# Retains the array owner; no manual display adapter is required.
40def array_component(~S:Data,declaration:Identity.Declaration<S,Array<U32>>) -> Provision<S,Col.Column<S,Array<U32>>,Unit,Ordinary.component_empty(~S,~Array<U32>),Ordinary.component_count(~S,~Array<U32>),component_read(~S,~Array<U32>,~Builtin.array),component_resources>:
41 component(~S,~Array<U32>,~Builtin.array,declaration)
42# Resource dump provision with built-in Array<U32> presentation.
43# Retains the array owner; does not inspect it until dump evaluation.
44def array_resource(~S:Data,declaration:Schema.Resource<S,Array<U32>>) -> Provision<S,Unit,Array<U32>,Ordinary.resource_empty,Ordinary.resource_count(~S),resource_components,resource_read(~Array<U32>,~Builtin.array)>:
45 resource(~S,~Array<U32>,~Builtin.array,declaration)
46# Component provision with built-in U32 display and matching population
47# callbacks. Does not create a component instance or scan entities.
48def u32_component(~S:Data,declaration:Identity.Declaration<S,U32>) -> Provision<S,Col.Column<S,U32>,Unit,Ordinary.component_empty(~S,~U32),Ordinary.component_count(~S,~U32),component_read(~S,~U32,~Builtin.u32),component_resources>:
49 component(~S,~U32,~Builtin.u32,declaration)
50# Component provision with built-in Bool display and matching population
51# callbacks. Metadata comes from the ordinary declaration, not a second key.
52def bool_component(~S:Data,declaration:Identity.Declaration<S,Bool>) -> Provision<S,Col.Column<S,Bool>,Unit,Ordinary.component_empty(~S,~Bool),Ordinary.component_count(~S,~Bool),component_read(~S,~Bool,~Builtin.bool),component_resources>:
53 component(~S,~Bool,~Builtin.bool,declaration)
54def joined(~L:Type,~R:Type,left:L,before:List<&2,Maybe<&2,String>>,result:R & List<&2,Maybe<&2,String>>) -> Product.Owner<L,R> & List<&2,Maybe<&2,String>>:
55 match result:
56 case (right,after):(Product.Owner{left,right},List.append(&2,Maybe<&2,String>,before,after))
57def components_left(~L:Type,~R:Type,~rightRead:R -> U32 -> R & List<&2,Maybe<&2,String>>,right:R,id:U32,result:L & List<&2,Maybe<&2,String>>) -> Product.Owner<L,R> & List<&2,Maybe<&2,String>>:
58 match result:
59 case (left,before):joined(~L,~R,left,before,rightRead(right,id))
60def product_components(~L:Type,~R:Type,~leftRead:L -> U32 -> L & List<&2,Maybe<&2,String>>,~rightRead:R -> U32 -> R & List<&2,Maybe<&2,String>>,store:Product.Owner<L,R>,id:U32) -> Product.Owner<L,R> & List<&2,Maybe<&2,String>>:
61 match store:
62 case Product.Owner{left,right}:
63 +id=id
64 components_left(~L,~R,~rightRead,right,id,leftRead(left,id))
65def resources_left(~L:Type,~R:Type,~rightRead:R -> R & List<&2,Maybe<&2,String>>,right:R,result:L & List<&2,Maybe<&2,String>>) -> Product.Owner<L,R> & List<&2,Maybe<&2,String>>:
66 match result:
67 case (left,before):joined(~L,~R,left,before,rightRead(right))
68def product_resources(~L:Type,~R:Type,~leftRead:L -> L & List<&2,Maybe<&2,String>>,~rightRead:R -> R & List<&2,Maybe<&2,String>>,value:Product.Owner<L,R>) -> Product.Owner<L,R> & List<&2,Maybe<&2,String>>:
69 match value:
70 case Product.Owner{left,right}:resources_left(~L,~R,~rightRead,right,leftRead(left))
71# Compose dump provisions with matching left/right owner products and
72# entry/count/value order. Does not duplicate affine payloads or validate
73# arbitrary forged callback relationships; ordinary constructors keep them aligned.
74def product(~S:Data,~LC:Type,~LR:Type,~RC:Type,~RR:Type,~leftEmpty:Unit -> LC,~leftCount:LC -> List<&2,W.Handle<S>> -> LC & List<&2,Maybe<&2,U32>>,~leftComponents:LC -> U32 -> LC & List<&2,Maybe<&2,String>>,~leftResources:LR -> LR & List<&2,Maybe<&2,String>>,~rightEmpty:Unit -> RC,~rightCount:RC -> List<&2,W.Handle<S>> -> RC & List<&2,Maybe<&2,U32>>,~rightComponents:RC -> U32 -> RC & List<&2,Maybe<&2,String>>,~rightResources:RR -> RR & List<&2,Maybe<&2,String>>,left:Provision<S,LC,LR,leftEmpty,leftCount,leftComponents,leftResources>,right:Provision<S,RC,RR,rightEmpty,rightCount,rightComponents,rightResources>) -> Provision<S,Product.Owner<LC,RC>,Product.Owner<LR,RR>,Ordinary.product_empty(~LC,~RC,~leftEmpty,~rightEmpty),Ordinary.product_count(~S,~LC,~RC,~leftCount,~rightCount),product_components(~LC,~RC,~leftComponents,~rightComponents),product_resources(~LR,~RR,~leftResources,~rightResources)>:
75 match left right:
76 case Provision{left} Provision{right}:Provision{Ordinary.product(~S,~LC,~LR,~RC,~RR,~leftEmpty,~leftCount,~rightEmpty,~rightCount,left,right)}
77
78# Metadata-free token generated by the same operational provisioning constructor.
79# Detached advanced token indexing the schema-matched counting/display
80# routes. It carries no live World, payload or duplicated metadata list.
81type Recipe<-S:Data,-C:Type,-R:Type,-count:C -> List<&2,W.Handle<S>> -> C & List<&2,Maybe<&2,U32>>,-components:C -> U32 -> C & List<&2,Maybe<&2,String>>,-resources:R -> R & List<&2,Maybe<&2,String>>> is Data:
82 Recipe{}
83# Consume dump provision and return its retained ordinary schema plus the
84# matching Recipe token. Performs no observation, counting or system execution.
85def prepared(~S:Data,~C:Type,~R:Type,~empty:Unit -> C,~count:C -> List<&2,W.Handle<S>> -> C & List<&2,Maybe<&2,U32>>,~components:C -> U32 -> C & List<&2,Maybe<&2,String>>,~resources:R -> R & List<&2,Maybe<&2,String>>,value:Provision<S,C,R,empty,count,components,resources>) -> Schema.Schema<S,C,R> & Recipe<S,C,R,count,components,resources>:
86 match value:
87 case Provision{Ordinary.Provision{schema}}:(schema,Recipe{})