ordinary_schema_dump.bend
bendvy-ecs-core@0.1.0.4 · 87 lines · 21 definitions
1import Base
2import bendvy-ecs-core@0.1.0.4/world.bend as W
3import bendvy-ecs-core@0.1.0.4/column.bend as Col
4import bendvy-ecs-core@0.1.0.4/ordinary_schema.bend as Schema
5import bendvy-ecs-core@0.1.0.4/ordinary_declaration.bend as Identity
6import bendvy-ecs-core@0.1.0.4/owner_product.bend as Product
7import bendvy-ecs-core@0.1.0.4/ordinary_schema_provision.bend as Ordinary
8import bendvy-ecs-core@0.1.0.4/ordinary_dump_builtin.bend as Builtin
9
10
11
12
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
28
29
30
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
34
35
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
39
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
43
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
47
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
51
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
72
73
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
79
80
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
84
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{})