tengri/Content/Blueprints/BP_MainCharacter.ts

130 lines
5.1 KiB
TypeScript

// Blueprints/BP_MainCharacter.ts
import { AC_DebugHUD } from '#root/Debug/Components/AC_DebugHUD.ts';
import { IMC_Default } from '#root/Input/IMC_Default.ts';
import { AC_Movement } from '#root/Movement/Components/AC_Movement.ts';
import { AC_ToastSystem } from '#root/Toasts/Components/AC_ToastSystem.ts';
import { Cast } from '#root/UE/Cast.ts';
import type { Controller } from '#root/UE/Controller.ts';
import { EnhancedInputLocalPlayerSubsystem } from '#root/UE/EnhancedInputLocalPlayerSubsystem.ts';
import type { Float } from '#root/UE/Float.ts';
import { Pawn } from '#root/UE/Pawn.ts';
import type { PlayerController } from '#root/UE/PlayerController.ts';
import { SystemLibrary } from '#root/UE/SystemLibrary.ts';
/**
* Main Character Blueprint
* Core player character with deterministic movement system
* Integrates debug HUD and toast notification systems
*/
export class BP_MainCharacter extends Pawn {
// ════════════════════════════════════════════════════════════════════════════════════════
// GRAPHS
// ════════════════════════════════════════════════════════════════════════════════════════
// ────────────────────────────────────────────────────────────────────────────────────────
// EventGraph
// ────────────────────────────────────────────────────────────────────────────────────────
/**
* Handle controller change events - sets up Enhanced Input mapping context
*/
EventReceiveControllerChanged(NewController: Controller): void {
const controller = Cast<PlayerController>(NewController);
const system = new EnhancedInputLocalPlayerSubsystem();
if (controller) {
system.AddMappingContext(IMC_Default);
}
}
/** Navigate to previous debug page */
EnhancedInputActionPrevDebugMode(): void {
if (this.ShowDebugInfo) {
this.DebugHUDComponent.PreviousPage();
}
}
/** Navigate to next debug page */
EnhancedInputActionINextDebugMode(): void {
if (this.ShowDebugInfo) {
this.DebugHUDComponent.NextPage();
}
}
/** Toggle debug HUD visibility */
EnhancedInputActionToggleHUD(): void {
if (this.ShowDebugInfo) {
this.DebugHUDComponent.ToggleDebugHUD();
}
}
/** Toggle visual debug rendering */
EnhancedInputActionToggleVisualDebug(): void {
if (this.ShowDebugInfo) {
this.DebugHUDComponent.ToggleVisualDebug();
}
}
/**
* Initialize all systems when character spawns
* Order: Toast → Debug → Movement (movement last as it may generate debug output)
*/
EventBeginPlay(): void {
// Initialize debug systems first if enabled
if (this.ShowDebugInfo) {
this.ToastSystemComponent.InitializeToastSystem();
this.DebugHUDComponent.InitializeDebugHUD(
this.MovementComponent,
this.ToastSystemComponent
);
}
// Initialize movement system last (may generate debug output)
this.MovementComponent.InitializeMovementSystem();
}
/**
* Update all systems each frame
* Called by Unreal Engine game loop
*/
EventTick(DeltaTime: Float): void {
if (this.ShowDebugInfo) {
this.DebugHUDComponent.UpdateHUD(
SystemLibrary.GetGameTimeInSeconds(),
DeltaTime
);
this.ToastSystemComponent.UpdateToastSystem();
}
}
// ════════════════════════════════════════════════════════════════════════════════════════
// VARIABLES
// ════════════════════════════════════════════════════════════════════════════════════════
/**
* Core movement system component - handles deterministic 3D platformer movement
* @category Components
*/
MovementComponent = new AC_Movement();
/**
* Debug HUD system - displays movement parameters and performance metrics
* @category Components
*/
DebugHUDComponent = new AC_DebugHUD();
/**
* Toast notification system - displays temporary status messages
* @category Components
*/
ToastSystemComponent = new AC_ToastSystem();
/**
* Master debug toggle - controls all debug systems (HUD, toasts, visual debug)
* @category Debug
* @instanceEditable true
*/
private ShowDebugInfo: boolean = true;
}