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

mlange-42 / arche-pixel / 9206262010

23 May 2024 10:17AM CUT coverage: 88.275% (+0.03%) from 88.246%
9206262010

push

github

web-flow
Add optional property `XLim` to `Lines` plot (#54)

4 of 4 new or added lines in 1 file covered. (100.0%)

1438 of 1629 relevant lines covered (88.28%)

222101.43 hits per line

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

78.13
/plot/systems.go
1
package plot
2

3
import (
4
        "fmt"
5
        "io"
6
        "reflect"
7

8
        px "github.com/gopxl/pixel/v2"
9
        "github.com/gopxl/pixel/v2/backends/opengl"
10
        "github.com/gopxl/pixel/v2/ext/text"
11
        "github.com/mlange-42/arche-model/model"
12
        "github.com/mlange-42/arche/ecs"
13
        "github.com/mlange-42/arche/generic"
14
)
15

16
// Systems drawer for inspecting ECS systems.
17
//
18
// Lists all systems and UI systems in their scheduling order,
19
// with their public fields.
20
//
21
// Details can be adjusted using the HideXxx fields.
22
// Further, keys U, F, T, V and N can be used to toggle details during a running simulation.
23
// The view can be scrolled using arrow keys or the mouse wheel.
24
type Systems struct {
25
        HideUISystems bool // Hides UI systems.
26
        HideFields    bool // Hides components fields.
27
        HideTypes     bool // Hides field types.
28
        HideValues    bool // Hides field values.
29
        HideNames     bool // Hide field names of nested structs.
30
        scroll        int
31
        systemsRes    generic.Resource[model.Systems]
32
        text          *text.Text
33
        helpText      *text.Text
34
}
35

36
// Initialize the system
37
func (i *Systems) Initialize(w *ecs.World, win *opengl.Window) {
2✔
38
        i.systemsRes = generic.NewResource[model.Systems](w)
2✔
39

2✔
40
        i.text = text.New(px.V(0, 0), defaultFont)
2✔
41
        i.helpText = text.New(px.V(0, 0), defaultFont)
2✔
42

2✔
43
        i.text.AlignedTo(px.BottomRight)
2✔
44
        i.helpText.AlignedTo(px.BottomRight)
2✔
45

2✔
46
        fmt.Fprint(i.helpText, "Toggle [u]i systems, [f]ields, [t]ypes, [v]alues or [n]ames, scroll with arrows or mouse wheel.")
2✔
47
}
2✔
48

49
// Update the drawer.
50
func (i *Systems) Update(w *ecs.World) {}
200✔
51

52
// UpdateInputs handles input events of the previous frame update.
53
func (i *Systems) UpdateInputs(w *ecs.World, win *opengl.Window) {
111✔
54
        if win.JustPressed(px.KeyF) {
111✔
55
                i.HideFields = !i.HideFields
×
56
                return
×
57
        }
×
58
        if win.JustPressed(px.KeyT) {
111✔
59
                i.HideTypes = !i.HideTypes
×
60
                return
×
61
        }
×
62
        if win.JustPressed(px.KeyV) {
111✔
63
                i.HideValues = !i.HideValues
×
64
                return
×
65
        }
×
66
        if win.JustPressed(px.KeyN) {
111✔
67
                i.HideNames = !i.HideNames
×
68
                return
×
69
        }
×
70
        if win.JustPressed(px.KeyU) {
111✔
71
                i.HideUISystems = !i.HideUISystems
×
72
                return
×
73
        }
×
74
        if win.JustPressed(px.KeyDown) {
111✔
75
                i.scroll++
×
76
                return
×
77
        }
×
78
        if win.JustPressed(px.KeyUp) {
111✔
79
                if i.scroll > 0 {
×
80
                        i.scroll--
×
81
                }
×
82
                return
×
83
        }
84
        scr := win.MouseScroll()
111✔
85
        if scr.Y != 0 {
111✔
86
                i.scroll -= int(scr.Y)
×
87
                if i.scroll < 0 {
×
88
                        i.scroll = 0
×
89
                }
×
90
        }
91
}
92

93
// Draw the system
94
func (i *Systems) Draw(w *ecs.World, win *opengl.Window) {
111✔
95
        i.helpText.Draw(win, px.IM.Moved(px.V(10, 20)))
111✔
96

111✔
97
        if !i.systemsRes.Has() {
111✔
98
                return
×
99
        }
×
100
        systems := i.systemsRes.Get()
111✔
101

111✔
102
        height := win.Canvas().Bounds().H()
111✔
103
        x0 := 10.0
111✔
104
        y0 := height - 10.0
111✔
105

111✔
106
        i.text.Clear()
111✔
107
        fmt.Fprint(i.text, "Systems\n\n")
111✔
108

111✔
109
        scroll := i.scroll
111✔
110

111✔
111
        for _, sys := range systems.Systems() {
333✔
112
                if i.HideUISystems {
244✔
113
                        if _, ok := sys.(model.UISystem); ok {
33✔
114
                                continue
11✔
115
                        }
116
                }
117

118
                val := reflect.ValueOf(sys).Elem()
211✔
119
                tp := val.Type()
211✔
120

211✔
121
                if scroll <= 0 {
422✔
122
                        fmt.Fprintf(i.text, "  %s\n", tp.Name())
211✔
123
                }
211✔
124
                scroll--
211✔
125

211✔
126
                if !i.HideFields {
422✔
127
                        for k := 0; k < val.NumField(); k++ {
1,344✔
128
                                field := tp.Field(k)
1,133✔
129
                                if field.IsExported() {
1,644✔
130
                                        if scroll <= 0 {
1,022✔
131
                                                i.printField(i.text, tp, field, val.Field(k))
511✔
132
                                        }
511✔
133
                                        scroll--
511✔
134
                                }
135
                        }
136
                        if scroll <= 0 {
422✔
137
                                fmt.Fprint(i.text, "\n")
211✔
138
                        }
211✔
139
                        scroll--
211✔
140
                }
141
        }
142

143
        if i.HideUISystems {
122✔
144
                i.text.Draw(win, px.IM.Moved(px.V(x0, y0)))
11✔
145
                return
11✔
146
        }
11✔
147

148
        fmt.Fprint(i.text, "\nUI Systems\n\n")
100✔
149
        for _, sys := range systems.UISystems() {
200✔
150
                val := reflect.ValueOf(sys).Elem()
100✔
151
                tp := val.Type()
100✔
152

100✔
153
                if scroll <= 0 {
200✔
154
                        fmt.Fprintf(i.text, "  %s\n", tp.Name())
100✔
155
                }
100✔
156
                scroll--
100✔
157

100✔
158
                if !i.HideFields {
200✔
159
                        for k := 0; k < val.NumField(); k++ {
900✔
160
                                field := tp.Field(k)
800✔
161
                                if field.IsExported() {
1,200✔
162
                                        if scroll <= 0 {
800✔
163
                                                i.printField(i.text, tp, field, val.Field(k))
400✔
164
                                        }
400✔
165
                                        scroll--
400✔
166
                                }
167
                        }
168
                        if scroll <= 0 {
200✔
169
                                fmt.Fprint(i.text, "\n")
100✔
170
                        }
100✔
171
                        scroll--
100✔
172
                }
173
        }
174

175
        i.text.Draw(win, px.IM.Moved(px.V(x0, y0)))
100✔
176
}
177

178
func (i *Systems) printField(w io.Writer, tp reflect.Type, field reflect.StructField, value reflect.Value) {
911✔
179
        fmt.Fprintf(w, "    %-20s ", field.Name)
911✔
180
        if !i.HideTypes {
1,822✔
181
                fmt.Fprintf(w, "    %-16s ", value.Type())
911✔
182
        }
911✔
183
        if !i.HideValues {
1,822✔
184
                if i.HideNames {
922✔
185
                        fmt.Fprintf(w, "= %v", value.Interface())
11✔
186
                } else {
911✔
187
                        fmt.Fprintf(w, "= %+v", value.Interface())
900✔
188
                }
900✔
189
        }
190
        fmt.Fprint(i.text, "\n")
911✔
191
}
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