gg/cmd/test/debug.go

116 lines
2.5 KiB
Go
Raw Normal View History

2023-12-23 00:09:07 +03:00
package main
2024-05-19 21:11:58 +03:00
import "surdeus.su/core/gg"
2024-06-01 16:07:28 +03:00
import "surdeus.su/core/gg/ox"
import "surdeus.su/core/gg/mx"
2023-12-23 00:09:07 +03:00
import (
"strings"
"fmt"
)
type Debug struct {
2024-06-01 16:07:28 +03:00
ox.ObjectImpl
ox.Visibility
}
2024-06-01 16:07:28 +03:00
func (d *Debug) OnUpdate(c Context) {
for _, key := range c.Events().Keyboard.KeyDowns {
switch key.Key {
case gg.KeyF11:
d.ToggleVisibility()
//d.Visible = !d.IsVisible()
}
2024-05-19 21:11:58 +03:00
}
2023-12-23 00:09:07 +03:00
}
2024-06-01 22:01:17 +03:00
func (d *Debug) OnStart(c Context) {
d.Visible = true
}
2024-06-01 16:07:28 +03:00
func (d *Debug) GetLayer() gg.Layer {return LayerHighest}
func (d *Debug) Draw(c Context) *gg.Drawing {
e := c.Engine()
2024-01-18 06:06:27 +03:00
relTri := tri.Rel()
relPlayer := player.Rel()
2024-05-19 21:11:58 +03:00
2023-12-23 00:09:07 +03:00
keyStrs := []string{}
2024-01-08 07:12:35 +03:00
keyStrs = append(keyStrs, fmt.Sprintf(
"counter: %d", counter,
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"tps: %d", int(c.Engine().TPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"fps: %d", int(c.Engine().FPS()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"dframe: %d", int(c.Engine().Dframe()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"frame: %d", int(c.Engine().Frame()),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"relPlayerPos: %v", relPlayer.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"absPlayerPos: %v", player.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"relTriPos: %v", relTri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"absTriPos: %v", tri.GetPosition(),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"absTriRot: %v", mx.Degree(tri.GetRotation()),
))
2023-12-24 15:05:34 +03:00
keys := []string{}
2024-06-01 16:07:28 +03:00
for _, k := range e.GetKeyboardKeys() {
2023-12-24 15:05:34 +03:00
keys = append(keys, k.String())
2023-12-23 00:09:07 +03:00
}
2023-12-24 15:05:34 +03:00
keyStrs = append(keyStrs, fmt.Sprintf(
"keys: %s", strings.Join(keys, ", "),
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"buttons: %v", c.Engine().MouseButtons(),
2023-12-24 15:05:34 +03:00
))
keyStrs = append(keyStrs, fmt.Sprintf(
2024-06-01 16:07:28 +03:00
"wheel: %v", c.Engine().Wheel(),
2023-12-24 15:05:34 +03:00
))
/*if rectMove.ContainsPoint(e.AbsCursorPosition()) {
2023-12-23 00:09:07 +03:00
keyStrs = append(keyStrs, "contains cursor")
}
if rectMove.Vertices().Contained(rect).Len() > 0 ||
rect.Vertices().Contained(rectMove).Len() > 0 {
keyStrs = append(keyStrs, "rectangles intersect")
2023-12-24 15:05:34 +03:00
}*/
keyStrs = append(keyStrs, fmt.Sprintf(
"camera position: %v %v",
2024-06-01 16:07:28 +03:00
camera.GetPosition().X,
camera.GetPosition().Y,
2023-12-24 15:05:34 +03:00
))
2024-06-01 16:07:28 +03:00
keyStrs = append(keyStrs, fmt.Sprintf(
"realCursorPos: %v", e.GetRealCursorPosition()))
keyStrs = append(keyStrs, fmt.Sprintf(
"absCursorPos: %v", e.GetAbsCursorPosition() ))
keyStrs = append(keyStrs,
fmt.Sprintf(
"absWinSize: %v",
c.Engine().GetAbsWinSize(),
),
)
2023-12-23 00:09:07 +03:00
2024-06-01 16:07:28 +03:00
e.DebugPrint(c.Image(),
2023-12-23 00:09:07 +03:00
strings.Join(keyStrs, "\n"))
2024-05-19 21:11:58 +03:00
return nil
2023-12-23 00:09:07 +03:00
}