mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-12 13:15:54 +00:00
Selector changes
This commit is contained in:
parent
176c1050b7
commit
690ac102dc
3 changed files with 140 additions and 34 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using Cirno.Scripts.Components.Actors;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Components.Actors;
|
||||
using Cirno.Scripts.Interactables;
|
||||
using Godot;
|
||||
|
||||
|
|
@ -29,6 +31,8 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
|
||||
public IStateMachine<PlayerState, CharacterBody3D> StateMachine { get; private set; }
|
||||
|
||||
private CollisionShape3D _collisionShape;
|
||||
|
||||
public void EnterState(PlayerState state)
|
||||
{
|
||||
Enabled = true;
|
||||
|
|
@ -47,6 +51,8 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
{
|
||||
StateMachine = machine;
|
||||
|
||||
_collisionShape = GetNode<CollisionShape3D>("CollisionShape");
|
||||
|
||||
_selectorController.Hide();
|
||||
|
||||
SpawnSelector();
|
||||
|
|
@ -102,13 +108,14 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
|
||||
public void PhysicsProcess(double delta)
|
||||
{
|
||||
//_selectorController.PhysicsProcess(delta);
|
||||
_selectorController.PhysicsProcess(delta);
|
||||
|
||||
HandleInteraction();
|
||||
}
|
||||
|
||||
public void HandleInteraction()
|
||||
{
|
||||
if (!_selectorController.CanSelect) return;
|
||||
if (_inputProvider.GetUseJustPressed())
|
||||
{
|
||||
if (!TrySelect())
|
||||
|
|
@ -121,6 +128,7 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
|
||||
if (_inputProvider.GetScanJustPressed())
|
||||
{
|
||||
var items = ScanTargets();
|
||||
_selectorController.SelectNext();
|
||||
}
|
||||
}
|
||||
|
|
@ -143,9 +151,13 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
if (success)
|
||||
{
|
||||
// Deselect and scan for next
|
||||
_selectorController.RemoveInteractable(selected);
|
||||
_selectorController.SelectNext();
|
||||
//_selector.RemoveInteractable(selected);
|
||||
//_selectorController.RemoveInteractable(selected);
|
||||
_selectorController.DeselectWithCooldown();
|
||||
|
||||
// Do this at end of frame instead
|
||||
//_selectorController.SelectNext();
|
||||
_selectorController.SelectNextDelayed();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -157,6 +169,41 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
|
|||
|
||||
//var query = PhysicsRayQueryParameters2D.Create(Vector2.Zero, )
|
||||
}
|
||||
|
||||
|
||||
|
||||
private List<IInteractable> ScanTargets()
|
||||
{
|
||||
var spaceState = GetWorld3D().DirectSpaceState;
|
||||
var query = new PhysicsShapeQueryParameters3D()
|
||||
{
|
||||
Shape = _collisionShape.Shape,
|
||||
CollideWithBodies = false,
|
||||
CollideWithAreas = true,
|
||||
CollisionMask = this.CollisionMask,
|
||||
Exclude = [GetRid()],
|
||||
|
||||
};
|
||||
|
||||
var targets = spaceState.IntersectShape(query);
|
||||
if (targets.Count is 0) return null;
|
||||
var found = targets.Select(resDict =>
|
||||
{
|
||||
var collider = resDict["collider"].As<Node3D>();
|
||||
if (collider.IsInGroup("Interactable") && collider is IInteractable interactable &&
|
||||
interactable.CanActivate())
|
||||
{
|
||||
return interactable;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
).Where(x => x is not null).ToList();
|
||||
|
||||
return found;
|
||||
}
|
||||
|
||||
private void _on_interaction_controller_area_entered(Area3D area)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue