* Refactor collectable components to C# and update resource scripts for consistency * Update resource paths and refactor properties for consistency * Refactor UI components to inherit from Control and update node paths for consistency * Update node paths and group assignments for consistency across scenes * Refactor GameManager and PlayerDeathComponent for improved state management and logging; update scene connections for player death handling * Add PhantomCamera components and UI elements for improved scene management; refactor existing components for better integration * Refactor skill components and update resource paths for consistency; enhance skill management in scenes * Add new UID files and update scene configurations for dialogue components; refactor skill management and input handling * Add next level command and refactor player retrieval in GameManager; update scene files for consistency * Add skill upgrade system and refactor skill components for enhanced functionality; update resource paths and configurations * Enhance ChargeProgressBar and Marketplace functionality; add owner exit handling and update skill button states * Refactor ChargeProgressBar and SkillManager; update skill handling and improve component interactions * Refactor player and level configurations; streamline FlipPlayerComponent and reposition Spaceship Enter
103 lines
2.7 KiB
C#
103 lines
2.7 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
using Mr.BrickAdventures.scripts.interfaces;
|
|
|
|
namespace Mr.BrickAdventures.scripts.components;
|
|
|
|
public partial class PlayerController : CharacterBody2D
|
|
{
|
|
[Export]
|
|
public string DefaultMovementType { get; set; } = "platform";
|
|
|
|
[Export]
|
|
public Godot.Collections.Dictionary<string, NodePath> MovementTypes { get; set; }
|
|
|
|
[Export]
|
|
public Sprite2D ShipSprite { get; set; }
|
|
|
|
public IMovement CurrentMovement = null;
|
|
[Signal]
|
|
public delegate void MovementSwitchedEventHandler(string movementType);
|
|
|
|
public override void _Ready()
|
|
{
|
|
base._Ready();
|
|
|
|
foreach (var movementType in MovementTypes.Keys)
|
|
{
|
|
var movementNode = GetNodeOrNull(movementType);
|
|
if (movementNode is IMovement playerMovement)
|
|
{
|
|
playerMovement.Enabled = false;
|
|
}
|
|
}
|
|
|
|
SwitchMovement(DefaultMovementType);
|
|
}
|
|
|
|
public override void _UnhandledInput(InputEvent @event)
|
|
{
|
|
base._UnhandledInput(@event);
|
|
|
|
if (@event is InputEventKey inputEventKey && inputEventKey.IsActionPressed("switch_movement"))
|
|
{
|
|
var nextMovementType = GetNextMovementType();
|
|
SwitchMovement(nextMovementType);
|
|
}
|
|
}
|
|
|
|
private void SwitchMovement(string movementType)
|
|
{
|
|
if (CurrentMovement != null)
|
|
{
|
|
CurrentMovement.Enabled = false;
|
|
}
|
|
|
|
if (MovementTypes.TryGetValue(movementType, out var movement))
|
|
{
|
|
CurrentMovement = GetNodeOrNull<IMovement>(movement);
|
|
if (CurrentMovement == null)
|
|
{
|
|
GD.PushError($"Movement type '{movementType}' not found in MovementTypes.");
|
|
return;
|
|
}
|
|
CurrentMovement.Enabled = true;
|
|
EmitSignalMovementSwitched(movementType);
|
|
}
|
|
else
|
|
{
|
|
GD.PushError($"Movement type '{movementType}' not found in MovementTypes.");
|
|
}
|
|
|
|
if (CurrentMovement == null)
|
|
{
|
|
GD.PushError("No current movement set after switching.");
|
|
}
|
|
}
|
|
|
|
private string GetNextMovementType()
|
|
{
|
|
var keys = new List<string>(MovementTypes.Keys);
|
|
var currentIndex = keys.IndexOf(CurrentMovement?.MovementType);
|
|
|
|
if (currentIndex == -1)
|
|
{
|
|
return DefaultMovementType;
|
|
}
|
|
|
|
currentIndex = (currentIndex + 1) % keys.Count;
|
|
return keys[currentIndex];
|
|
}
|
|
|
|
public void OnSpaceshipEntered()
|
|
{
|
|
SwitchMovement("ship");
|
|
ShipSprite.Visible = true;
|
|
}
|
|
|
|
public void OnSpaceshipExited()
|
|
{
|
|
SwitchMovement(DefaultMovementType);
|
|
ShipSprite.Visible = false;
|
|
}
|
|
} |