• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlange-42 / arche / 4846030190

30 Apr 2023 07:29PM CUT coverage: 100.0%. Remained the same
4846030190

push

github

GitHub
Lock registered filters, partial recompile (#241)

136 of 136 new or added lines in 2 files covered. (100.0%)

3095 of 3095 relevant lines covered (100.0%)

2585.35 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/ecs/builder.go
1
package ecs
2

3
// Builder for more flexible entity creation.
4
type Builder struct {
5
        world     *World
6
        ids       []ID
7
        comps     []Component
8
        hasTarget bool
9
        targetID  ID
10
}
11

12
// NewBuilder creates a builder from component IDs.
13
func NewBuilder(w *World, comps ...ID) *Builder {
6✔
14
        return &Builder{
6✔
15
                world: w,
6✔
16
                ids:   comps,
6✔
17
                comps: nil,
6✔
18
        }
6✔
19
}
6✔
20

21
// NewBuilderWith creates a builder from component pointers.
22
func NewBuilderWith(w *World, comps ...Component) *Builder {
2✔
23
        return &Builder{
2✔
24
                world: w,
2✔
25
                ids:   nil,
2✔
26
                comps: comps,
2✔
27
        }
2✔
28
}
2✔
29

30
// WithRelation sets the relation component for the builder.
31
//
32
// Use in conjunction with the optional target argument of [Builder.New], [Builder.NewBatch] and [Builder.NewQuery].
33
func (b *Builder) WithRelation(comp ID) *Builder {
2✔
34
        b.hasTarget = true
2✔
35
        b.targetID = comp
2✔
36
        return b
2✔
37
}
2✔
38

39
// New creates an entity.
40
//
41
// The optional argument can be used to set the target [Entity] for the Builder's [Relation].
42
// See [Builder.WithRelation].
43
func (b *Builder) New(target ...Entity) Entity {
8✔
44
        if len(target) > 0 {
12✔
45
                if !b.hasTarget {
6✔
46
                        panic("entity builder has no target")
2✔
47
                }
48
                if b.comps == nil {
3✔
49
                        return b.world.newEntityTarget(b.targetID, target[0], b.ids...)
1✔
50
                }
1✔
51
                return b.world.newEntityTargetWith(b.targetID, target[0], b.comps...)
1✔
52
        }
53
        if b.comps == nil {
6✔
54
                return b.world.NewEntity(b.ids...)
2✔
55
        }
2✔
56
        return b.world.NewEntityWith(b.comps...)
2✔
57
}
58

59
// NewBatch creates many entities.
60
//
61
// The optional argument can be used to set the target [Entity] for the Builder's [Relation].
62
// See [Builder.WithRelation].
63
func (b *Builder) NewBatch(count int, target ...Entity) {
10✔
64
        if len(target) > 0 {
14✔
65
                if !b.hasTarget {
6✔
66
                        panic("entity builder has no target")
2✔
67
                }
68
                if b.comps == nil {
3✔
69
                        b.world.newEntities(count, int8(b.targetID), target[0], b.ids...)
1✔
70
                        return
1✔
71
                }
1✔
72
                b.world.newEntitiesWith(count, int8(b.targetID), target[0], b.comps...)
1✔
73
                return
1✔
74
        }
75
        if b.comps == nil {
11✔
76
                b.world.newEntities(count, -1, Entity{}, b.ids...)
5✔
77
        } else {
6✔
78
                b.world.newEntitiesWith(count, -1, Entity{}, b.comps...)
1✔
79
        }
1✔
80
}
81

82
// NewQuery creates many entities and returns a query over them.
83
//
84
// The optional argument can be used to set the target [Entity] for the Builder's [Relation].
85
// See [Builder.WithRelation].
86
func (b *Builder) NewQuery(count int, target ...Entity) Query {
6✔
87
        if len(target) > 0 {
10✔
88
                if !b.hasTarget {
6✔
89
                        panic("entity builder has no target")
2✔
90
                }
91
                if b.comps == nil {
3✔
92
                        return b.world.newEntitiesQuery(count, int8(b.targetID), target[0], b.ids...)
1✔
93
                }
1✔
94
                return b.world.newEntitiesWithQuery(count, int8(b.targetID), target[0], b.comps...)
1✔
95
        }
96
        if b.comps == nil {
3✔
97
                return b.world.newEntitiesQuery(count, -1, Entity{}, b.ids...)
1✔
98
        }
1✔
99
        return b.world.newEntitiesWithQuery(count, -1, Entity{}, b.comps...)
1✔
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc