107 lines
2.7 KiB
Go
107 lines
2.7 KiB
Go
|
package game
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"gitea.boner.be/bdnugget/goonscape/game/testutils"
|
||
|
"gitea.boner.be/bdnugget/goonscape/types"
|
||
|
pb "gitea.boner.be/bdnugget/goonserver/actions"
|
||
|
rl "github.com/gen2brain/raylib-go/raylib"
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestGame_HandleInput(t *testing.T) {
|
||
|
game := New()
|
||
|
game.Player = &types.Player{
|
||
|
ID: 1,
|
||
|
Speed: 50.0,
|
||
|
}
|
||
|
|
||
|
// Test valid click
|
||
|
simulateMouseRay(rl.Ray{
|
||
|
Position: rl.Vector3{X: 0, Y: 10, Z: 0},
|
||
|
Direction: rl.Vector3{X: 0, Y: -1, Z: 0},
|
||
|
})
|
||
|
simulateMouseButton(toInt32(rl.MouseLeftButton), true)
|
||
|
game.HandleInput()
|
||
|
assert.NotEmpty(t, game.Player.TargetPath)
|
||
|
|
||
|
// Test invalid click (outside map)
|
||
|
simulateMouseRay(rl.Ray{
|
||
|
Position: rl.Vector3{X: 1000, Y: 10, Z: 1000},
|
||
|
Direction: rl.Vector3{X: 0, Y: -1, Z: 0},
|
||
|
})
|
||
|
simulateMouseButton(toInt32(rl.MouseLeftButton), true)
|
||
|
game.HandleInput()
|
||
|
assert.Empty(t, game.Player.TargetPath)
|
||
|
}
|
||
|
|
||
|
func TestGame_UpdateCamera(t *testing.T) {
|
||
|
game := New()
|
||
|
|
||
|
// Test zoom limits
|
||
|
testutils.SimulateMouseWheel(1.0) // Zoom in
|
||
|
testutils.SimulateMouseWheel(1.0)
|
||
|
assert.GreaterOrEqual(t, cameraDistance, float32(10.0))
|
||
|
|
||
|
testutils.SimulateMouseWheel(-1.0) // Zoom out
|
||
|
testutils.SimulateMouseWheel(-1.0)
|
||
|
assert.LessOrEqual(t, cameraDistance, float32(250.0))
|
||
|
|
||
|
// Test camera rotation
|
||
|
originalYaw := cameraYaw
|
||
|
testutils.SimulateKeyDown(rl.KeyRight, true)
|
||
|
game.Update(0.1)
|
||
|
assert.Greater(t, cameraYaw, originalYaw)
|
||
|
|
||
|
// Test pitch limits
|
||
|
simulateKeyDown(rl.KeyUp, true)
|
||
|
for i := 0; i < 100; i++ {
|
||
|
game.Update(0.1)
|
||
|
}
|
||
|
assert.GreaterOrEqual(t, cameraPitch, float32(20.0))
|
||
|
assert.LessOrEqual(t, cameraPitch, float32(85.0))
|
||
|
}
|
||
|
|
||
|
func TestGame_ChatIntegration(t *testing.T) {
|
||
|
game := New()
|
||
|
game.Player = &types.Player{ID: 1}
|
||
|
|
||
|
// Test chat message to action queue
|
||
|
testutils.SimulateKeyPress(rl.KeyT)
|
||
|
game.Update(0.1)
|
||
|
assert.True(t, game.Chat.isTyping)
|
||
|
|
||
|
testutils.SimulateCharInput('h')
|
||
|
testutils.SimulateCharInput('i')
|
||
|
testutils.SimulateKeyPress(rl.KeyEnter)
|
||
|
game.Update(0.1)
|
||
|
|
||
|
assert.Equal(t, 1, len(game.Player.ActionQueue))
|
||
|
assert.Equal(t, pb.Action_CHAT, game.Player.ActionQueue[0].Type)
|
||
|
assert.Equal(t, "hi", game.Player.ActionQueue[0].ChatMessage)
|
||
|
}
|
||
|
|
||
|
func TestGame_MenuHandling(t *testing.T) {
|
||
|
game := New()
|
||
|
|
||
|
// Test menu toggle
|
||
|
assert.False(t, game.MenuOpen)
|
||
|
testutils.SimulateKeyPress(rl.KeyEscape)
|
||
|
game.Update(0.1)
|
||
|
assert.True(t, game.MenuOpen)
|
||
|
|
||
|
// Test input blocking when menu is open
|
||
|
game.Player = &types.Player{ID: 1}
|
||
|
testutils.SimulateMouseButton(testutils.ToInt32(rl.MouseLeftButton), true)
|
||
|
game.Update(0.1)
|
||
|
assert.Empty(t, game.Player.TargetPath)
|
||
|
|
||
|
// Test menu close
|
||
|
testutils.SimulateKeyPress(rl.KeyEscape)
|
||
|
game.Update(0.1)
|
||
|
assert.False(t, game.MenuOpen)
|
||
|
}
|
||
|
|
||
|
// Add more test helpers as needed...
|