Stash bunch of broken generated test with shitty broken mocking
This commit is contained in:
+82
-3
@@ -3,16 +3,95 @@ package game
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gitea.boner.be/bdnugget/goonscape/game/mock"
|
||||
"gitea.boner.be/bdnugget/goonscape/types"
|
||||
rl "github.com/gen2brain/raylib-go/raylib"
|
||||
)
|
||||
|
||||
// InputHandler abstracts raylib input functions for testing
|
||||
type InputHandler interface {
|
||||
IsKeyPressed(key int32) bool
|
||||
IsKeyDown(key int32) bool
|
||||
IsMouseButtonPressed(button int32) bool
|
||||
GetMousePosition() rl.Vector2
|
||||
GetMouseRay(mousePos rl.Vector2, camera rl.Camera3D) rl.Ray
|
||||
GetMouseWheelMove() float32
|
||||
GetCharPressed() rune
|
||||
}
|
||||
|
||||
// RaylibInput implements InputHandler using actual raylib functions
|
||||
type RaylibInput struct{}
|
||||
|
||||
func (r *RaylibInput) IsKeyPressed(key int32) bool { return rl.IsKeyPressed(key) }
|
||||
func (r *RaylibInput) IsKeyDown(key int32) bool { return rl.IsKeyDown(key) }
|
||||
func (r *RaylibInput) IsMouseButtonPressed(button int32) bool {
|
||||
return rl.IsMouseButtonPressed(rl.MouseButton(button))
|
||||
}
|
||||
func (r *RaylibInput) GetMousePosition() rl.Vector2 { return rl.GetMousePosition() }
|
||||
func (r *RaylibInput) GetMouseRay(mousePos rl.Vector2, camera rl.Camera3D) rl.Ray {
|
||||
return rl.GetMouseRay(mousePos, camera)
|
||||
}
|
||||
func (r *RaylibInput) GetMouseWheelMove() float32 { return rl.GetMouseWheelMove() }
|
||||
func (r *RaylibInput) GetCharPressed() rune { return rl.GetCharPressed() }
|
||||
|
||||
// MockInput implements InputHandler using our mock functions
|
||||
type MockInput struct{}
|
||||
|
||||
func (m *MockInput) IsKeyPressed(key int32) bool {
|
||||
if mock.IsKeyPressed == nil {
|
||||
return false
|
||||
}
|
||||
return mock.IsKeyPressed(key)
|
||||
}
|
||||
|
||||
func (m *MockInput) IsKeyDown(key int32) bool {
|
||||
if mock.IsKeyDown == nil {
|
||||
return false
|
||||
}
|
||||
return mock.IsKeyDown(key)
|
||||
}
|
||||
|
||||
func (m *MockInput) IsMouseButtonPressed(button int32) bool {
|
||||
if mock.IsMouseButtonPressed == nil {
|
||||
return false
|
||||
}
|
||||
return mock.IsMouseButtonPressed(button)
|
||||
}
|
||||
|
||||
func (m *MockInput) GetMousePosition() rl.Vector2 {
|
||||
if mock.GetMousePosition == nil {
|
||||
return rl.Vector2{}
|
||||
}
|
||||
return mock.GetMousePosition()
|
||||
}
|
||||
|
||||
func (m *MockInput) GetMouseRay(mousePos rl.Vector2, camera rl.Camera3D) rl.Ray {
|
||||
if mock.GetMouseRay == nil {
|
||||
return rl.Ray{}
|
||||
}
|
||||
return mock.GetMouseRay(mousePos, camera)
|
||||
}
|
||||
|
||||
func (m *MockInput) GetMouseWheelMove() float32 {
|
||||
if mock.GetMouseWheelMove == nil {
|
||||
return 0
|
||||
}
|
||||
return mock.GetMouseWheelMove()
|
||||
}
|
||||
|
||||
func (m *MockInput) GetCharPressed() rune {
|
||||
if mock.GetCharPressed == nil {
|
||||
return 0
|
||||
}
|
||||
return mock.GetCharPressed()
|
||||
}
|
||||
|
||||
func (g *Game) GetTileAtMouse() (types.Tile, bool) {
|
||||
if !rl.IsMouseButtonPressed(rl.MouseLeftButton) {
|
||||
if !g.input.IsMouseButtonPressed(toInt32(rl.MouseLeftButton)) {
|
||||
return types.Tile{}, false
|
||||
}
|
||||
mouse := rl.GetMousePosition()
|
||||
ray := rl.GetMouseRay(mouse, g.Camera)
|
||||
mouse := g.input.GetMousePosition()
|
||||
ray := g.input.GetMouseRay(mouse, g.Camera)
|
||||
|
||||
for x := 0; x < types.MapWidth; x++ {
|
||||
for y := 0; y < types.MapHeight; y++ {
|
||||
|
||||
Reference in New Issue
Block a user