1 import Base 2 import ./change_tick.bend as Tick 3 import ./restore_schema.bend as Basic 4 import ./snapshot_schema.bend as Save 5 import ./restore_data.bend as R 6 import ./relation_commands.bend as Relation 7 import ./relation_types.bend as G 8 import ./owner_product.bend as Product 9 import ./ordinary_schema.bend as Ordinary 10 import ./world.bend as W 11 import ./decode_data.bend as D 12 def cleared(~S:Data,~C:Type,graph:G.Graph,result:C & List<&2,R.Change>) -> Relation.Store & List<&2,R.Change>: 13 match result: 14 case (components,changes):(Relation.Store{components,graph},changes) 15 def clear(~S:Data,~C:Type,~clearBase:C -> W.Handle -> C & List<&2,R.Change>,store:Relation.Store,handle:W.Handle) -> Relation.Store & List<&2,R.Change>: 16 match store: 17 case Relation.Store{components,graph}:cleared(~S,~C,graph,clearBase(components,handle)) 18 def inserted(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~State:Type,graph:G.Graph,machines:Machines,result:(C & Resources) & State) -> (Relation.Store & Product.Owner) & State: 19 match result: 20 case ((components,resources),state):((Relation.Store{components,graph},Product.Owner{resources,machines}),state) 21 def insert(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clearBase:C -> W.Handle -> C & List<&2,R.Change>,~insertBase:C -> Resources -> State -> List<&2,R.Binding> -> Tick.Tick -> (C & Resources) & State,store:Relation.Store,resources:Product.Owner,state:State,bindings:List<&2,R.Binding>,tick:Tick.Tick) -> (Relation.Store & Product.Owner) & State: 22 match store resources: 23 case Relation.Store{components,graph} Product.Owner{resource,machines}:inserted(~S,~C,~Resources,~Machines,~State,graph,machines,insertBase(components,resource,state,bindings,tick)) 24 def lift(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~State:Type,~Custom:Data,~stage:State -> R.Position -> D.Field -> State & R.Dispatch,~release:State -> State,~clearBase:C -> W.Handle -> C & List<&2,R.Change>,~insertBase:C -> Resources -> State -> List<&2,R.Binding> -> Tick.Tick -> (C & Resources) & State,~Recovery:Type,~commit:State -> State,~takeRecovery:State -> State & Recovery,schema:Basic.Schema) -> Basic.Schema,Product.Owner,State,Custom,stage,release,clear(~S,~C,~clearBase),insert(~S,~C,~Resources,~Machines,~State,~Custom,~stage,~release,~clearBase,~insertBase),Recovery,commit,takeRecovery>: 25 match schema: 26 case Basic.Schema{Ordinary.Schema{entries}}:Basic.Schema{Ordinary.Schema{entries}} 27 def component_saved(~S:Data,~C:Type,graph:G.Graph,result:C & List<&2,D.Field>) -> Relation.Store & List<&2,D.Field>: 28 match result: 29 case (components,fields):(Relation.Store{components,graph},fields) 30 def save_components(~S:Data,~C:Type,~components:U32 -> C -> C & List<&2,D.Field>,id:U32,store:Relation.Store) -> Relation.Store & List<&2,D.Field>: 31 match store: 32 case Relation.Store{owner,graph}:component_saved(~S,~C,graph,components(id,owner)) 33 def resource_saved(~Resources:Type,~Machines:Type,machines:Machines,result:Resources & List<&2,D.Field>) -> Product.Owner & List<&2,D.Field>: 34 match result: 35 case (resources,fields):(Product.Owner{resources,machines},fields) 36 def save_resources(~Resources:Type,~Machines:Type,~resources:Resources -> Resources & List<&2,D.Field>,owner:Product.Owner) -> Product.Owner & List<&2,D.Field>: 37 match owner: 38 case Product.Owner{owner,machines}:resource_saved(~Resources,~Machines,machines,resources(owner)) 39 def save_schema(~S:Data,~C:Type,~Resources:Type,~Machines:Type,~components:U32 -> C -> C & List<&2,D.Field>,~resources:Resources -> Resources & List<&2,D.Field>,schema:Save.Schema) -> Save.Schema,Product.Owner,True{},save_components(~S,~C,~components),save_resources(~Resources,~Machines,~resources)>: 40 match schema: 41 case Save.Schema{Ordinary.Schema{entries}}:Save.Schema{Ordinary.Schema{entries}}