Add Camera library integration and testing: include Camera.csproj reference, create FirstPersonCamera and OrbitCamera instances with runtime mode switching and effects demonstration
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using EinSoftworks.Camera;
|
||||
using EinSoftworks.Events;
|
||||
using EinSoftworks.Input;
|
||||
using EinSoftworks.StateManagement;
|
||||
@@ -17,6 +18,12 @@ public partial class LibraryTest : Node
|
||||
private RunningPlayerState _runningState;
|
||||
private JumpingPlayerState _jumpingState;
|
||||
|
||||
// Camera test fields
|
||||
private FirstPersonCamera _fpCamera;
|
||||
private OrbitCamera _orbitCamera;
|
||||
private Node3D _cameraTarget;
|
||||
private CameraController _activeCamera;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
GD.Print("=== EinSoftworks Library Integration Test ===\n");
|
||||
@@ -26,6 +33,7 @@ public partial class LibraryTest : Node
|
||||
TestInput();
|
||||
TestStateMachine();
|
||||
TestHierarchicalStateMachine();
|
||||
TestCamera();
|
||||
|
||||
GD.Print("\n=== All Tests Initialized Successfully ===");
|
||||
GD.Print("Watch console for runtime behavior...\n");
|
||||
@@ -55,6 +63,27 @@ public partial class LibraryTest : Node
|
||||
GD.Print("\n[Frame 180] Testing hierarchical state change...");
|
||||
_hierarchicalSM?.ChangeState("Combat");
|
||||
}
|
||||
else if (_frameCount == 240)
|
||||
{
|
||||
GD.Print("\n[Frame 240] Testing camera mode switch to Orbit...");
|
||||
if (_orbitCamera != null && _activeCamera != null)
|
||||
{
|
||||
_activeCamera.SetCameraMode(CameraController.CameraMode.Orbit, 1.5f);
|
||||
_orbitCamera.Visible = true;
|
||||
_fpCamera.Visible = false;
|
||||
_activeCamera = _orbitCamera;
|
||||
}
|
||||
}
|
||||
else if (_frameCount == 360)
|
||||
{
|
||||
GD.Print("\n[Frame 360] Testing camera shake effect...");
|
||||
_activeCamera?.Shake(0.3f, 0.5f);
|
||||
}
|
||||
else if (_frameCount == 420)
|
||||
{
|
||||
GD.Print("\n[Frame 420] Testing camera zoom effect...");
|
||||
_activeCamera?.Zoom(60f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
private void TestUtilities()
|
||||
@@ -190,6 +219,64 @@ public partial class LibraryTest : Node
|
||||
GD.Print("");
|
||||
}
|
||||
|
||||
private void TestCamera()
|
||||
{
|
||||
GD.Print("--- Testing EinSoftworks.Camera ---");
|
||||
|
||||
// Create a target node for cameras to follow
|
||||
_cameraTarget = new Node3D();
|
||||
_cameraTarget.Name = "CameraTarget";
|
||||
_cameraTarget.Position = new Vector3(0, 1, 0);
|
||||
AddChild(_cameraTarget);
|
||||
|
||||
// Create FirstPersonCamera
|
||||
_fpCamera = new FirstPersonCamera();
|
||||
_fpCamera.Name = "FirstPersonCamera";
|
||||
_fpCamera.Target = _cameraTarget;
|
||||
_fpCamera.MouseSensitivity = 0.15f;
|
||||
_fpCamera.MinPitch = -85f;
|
||||
_fpCamera.MaxPitch = 85f;
|
||||
_fpCamera.Position = new Vector3(0, 1.6f, 0);
|
||||
AddChild(_fpCamera);
|
||||
_fpCamera.Camera.MakeCurrent();
|
||||
_activeCamera = _fpCamera;
|
||||
|
||||
GD.Print($"✓ Created FirstPersonCamera (Active)");
|
||||
GD.Print($" - Target: {_fpCamera.Target?.Name}");
|
||||
GD.Print($" - Mouse Sensitivity: {_fpCamera.MouseSensitivity}");
|
||||
GD.Print($" - Pitch Range: {_fpCamera.MinPitch}° to {_fpCamera.MaxPitch}°");
|
||||
|
||||
// Create OrbitCamera (initially hidden)
|
||||
_orbitCamera = new OrbitCamera();
|
||||
_orbitCamera.Name = "OrbitCamera";
|
||||
_orbitCamera.Target = _cameraTarget;
|
||||
_orbitCamera.MinDistance = 3f;
|
||||
_orbitCamera.MaxDistance = 10f;
|
||||
_orbitCamera.ZoomSpeed = 1f;
|
||||
_orbitCamera.EnableCollisionAvoidance = true;
|
||||
_orbitCamera.Visible = false;
|
||||
AddChild(_orbitCamera);
|
||||
|
||||
GD.Print($"✓ Created OrbitCamera (Standby)");
|
||||
GD.Print($" - Distance Range: {_orbitCamera.MinDistance} to {_orbitCamera.MaxDistance}");
|
||||
GD.Print($" - Collision Avoidance: {_orbitCamera.EnableCollisionAvoidance}");
|
||||
|
||||
// Subscribe to camera events
|
||||
_fpCamera.EventBus.Subscribe(evt =>
|
||||
{
|
||||
GD.Print($" → Camera event: {evt.OldMode} → {evt.NewMode} (Transition: {evt.TransitionTime}s)");
|
||||
});
|
||||
|
||||
_fpCamera.CameraModeChanged += (oldMode, newMode) =>
|
||||
{
|
||||
GD.Print($" → Camera signal: Mode changed from {oldMode} to {newMode}");
|
||||
};
|
||||
|
||||
GD.Print("✓ Subscribed to camera events and signals");
|
||||
GD.Print(" (Camera will switch modes and demonstrate effects during runtime)");
|
||||
GD.Print("");
|
||||
}
|
||||
|
||||
private void OnTestEvent(TestEvent evt)
|
||||
{
|
||||
GD.Print($" → Event received: {evt.Message} (Value: {evt.Value})");
|
||||
@@ -201,6 +288,11 @@ public partial class LibraryTest : Node
|
||||
_eventBus?.Unsubscribe(OnTestEvent);
|
||||
_stateMachine?.Clear();
|
||||
_hierarchicalSM?.Clear();
|
||||
|
||||
// Camera cleanup happens automatically
|
||||
_fpCamera?.QueueFree();
|
||||
_orbitCamera?.QueueFree();
|
||||
_cameraTarget?.QueueFree();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,5 +11,6 @@
|
||||
<ProjectReference Include="..\..\libraries\input\Input.csproj" />
|
||||
<ProjectReference Include="..\..\libraries\events\Events.csproj" />
|
||||
<ProjectReference Include="..\..\libraries\state-management\StateManagement.csproj" />
|
||||
<ProjectReference Include="..\..\libraries\camera\Camera.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user