snapshot.bend
bendvy-ecs-core@0.1.0.4 · 32 lines · 4 definitions
1import Base
2import entity_key.bend as Key
3import bendvy-ecs-core@0.1.0.4/snapshot_schema.bend as Schema
4import bendvy-ecs-core@0.1.0.4/snapshot_data.bend as Export
5import bendvy-ecs-core@0.1.0.4/decode_data.bend as D
6import bendvy-ecs-core@0.1.0.4/world.bend as W
7
8def prepend(~C:Type,entity:Export.Entity,observed:C & List<&2,Export.Entity>) -> C & List<&2,Export.Entity>:
9 match observed:
10 case (owner,entities):(owner,entity <> entities)
11def stepped(~C:Type,next:C -> C & List<&2,Export.Entity>,id:Key.Key,observed:C & List<&2,D.Field>) -> C & List<&2,Export.Entity>:
12 match observed:
13 case (owner,fields):prepend(~C,Export.Entity{id,fields},next(owner))
14def rows(~S:Data,~C:Type,~components:U32 -> C -> C & List<&2,D.Field>,handles:List<&2,W.Handle<S>>,owner:C) -> C & List<&2,Export.Entity>:
15 match handles:
16 case []:(owner,[])
17 case W.Handle{_,+id} <> rest:stepped(~C,next => rows(~S,~C,~components,rest,next),id,components(Key.index(id),owner))
18
19
20
21
22
23
24
25
26
27
28
29
30
31def save(~S:Data,~C:Type,~R:Type,~E:Data,~components:U32 -> C -> C & List<&2,D.Field>,~resources:R -> R & List<&2,D.Field>,schema:Schema.Schema<S,C,R,True{},components,resources>,world:W.World<S,C,R,E>) -> W.World<S,C,R,E> & Export.Outcome<Export.Snapshot>:
32 Export.basic(~S,~C,~R,~E,~rows(~S,~C,~components),~resources,world)