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

mlange-42 / ark / 13526736655

25 Feb 2025 05:02PM CUT coverage: 94.787%. Remained the same
13526736655

push

github

web-flow
Add an example to the README (#74)

3400 of 3587 relevant lines covered (94.79%)

51722.1 hits per line

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

96.15
/ecs/relation.go
1
package ecs
2

3
import "fmt"
4

5
var relationType = typeOf[Relation]()
6

7
// Relation is a marker for entity relation components.
8
// It must be embedded as first field of a component that represent an entity relation
9
// (see the example).
10
//
11
// Entity relations allow for fast queries using entity relationships.
12
// E.g. to iterate over all entities that are the child of a certain parent entity.
13
// Currently, each entity can only have a single relation component.
14
type Relation struct{}
15

16
type relationID struct {
17
        component ID
18
        target    Entity
19
}
20

21
// RelationIndex specifies an entity relation target by component index.
22
//
23
// Note that the index refers to the position of the component in the generics
24
// of e.g. a [Map2] or [Filter2].
25
// This should not be confused with component IDs as obtained by [ComponentID]!
26
type RelationIndex struct {
27
        index  uint8
28
        target Entity
29
}
30

31
// Rel creates a new RelationIndex.
32
func Rel(index int, target Entity) RelationIndex {
119✔
33
        return RelationIndex{
119✔
34
                index:  uint8(index),
119✔
35
                target: target,
119✔
36
        }
119✔
37
}
119✔
38

39
type relations []RelationIndex
40

41
func (r relations) toRelations(reg *componentRegistry, ids []ID, out []relationID) []relationID {
2,179✔
42
        out = out[:0]
2,179✔
43
        for _, rel := range r {
2,298✔
44
                id := ids[rel.index]
119✔
45
                if !reg.IsRelation[id.id] {
119✔
46
                        panic(fmt.Sprintf("component at index %d is not a relation component", rel.index))
×
47
                }
48
                out = append(out, relationID{
119✔
49
                        component: id,
119✔
50
                        target:    rel.target,
119✔
51
                })
119✔
52
        }
53
        return out
2,179✔
54
}
55

56
type relationEntities []Entity
57

58
func (r relationEntities) toRelation(id ID, out []relationID) []relationID {
497,289✔
59
        out = out[:0]
497,289✔
60
        for _, rel := range r {
497,561✔
61
                out = append(out, relationID{
272✔
62
                        component: id,
272✔
63
                        target:    rel,
272✔
64
                })
272✔
65
        }
272✔
66
        return out
497,289✔
67
}
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