import Base import ./change_tick.bend as Tick import ./restore_schema.bend as Basic import ./snapshot_schema.bend as Save import ./restore_data.bend as R import ./relation_commands.bend as Relation import ./relation_types.bend as G import ./owner_product.bend as Product import ./ordinary_schema.bend as Ordinary import ./world.bend as W import ./decode_data.bend as D def cleared(~S:Data,~C:Type,graph:G.Graph,result:C & List<&2,R.Change>) -> Relation.Store & List<&2,R.Change>: match result: case (components,changes):(Relation.Store{components,graph},changes) 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>: match store: case Relation.Store{components,graph}:cleared(~S,~C,graph,clearBase(components,handle)) 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: match result: case ((components,resources),state):((Relation.Store{components,graph},Product.Owner{resources,machines}),state) 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: match store resources: case Relation.Store{components,graph} Product.Owner{resource,machines}:inserted(~S,~C,~Resources,~Machines,~State,graph,machines,insertBase(components,resource,state,bindings,tick)) 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>: match schema: case Basic.Schema{Ordinary.Schema{entries}}:Basic.Schema{Ordinary.Schema{entries}} def component_saved(~S:Data,~C:Type,graph:G.Graph,result:C & List<&2,D.Field>) -> Relation.Store & List<&2,D.Field>: match result: case (components,fields):(Relation.Store{components,graph},fields) 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>: match store: case Relation.Store{owner,graph}:component_saved(~S,~C,graph,components(id,owner)) def resource_saved(~Resources:Type,~Machines:Type,machines:Machines,result:Resources & List<&2,D.Field>) -> Product.Owner & List<&2,D.Field>: match result: case (resources,fields):(Product.Owner{resources,machines},fields) def save_resources(~Resources:Type,~Machines:Type,~resources:Resources -> Resources & List<&2,D.Field>,owner:Product.Owner) -> Product.Owner & List<&2,D.Field>: match owner: case Product.Owner{owner,machines}:resource_saved(~Resources,~Machines,machines,resources(owner)) 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)>: match schema: case Save.Schema{Ordinary.Schema{entries}}:Save.Schema{Ordinary.Schema{entries}}