Interactable interface

This commit is contained in:
MaddoScientisto 2025-03-09 21:58:25 +01:00
commit 54d9824581
27 changed files with 102 additions and 61 deletions

View file

@ -5,8 +5,9 @@ using Cirno.Scripts;
public partial class Activable : Area2D, IActivable
{
public virtual void Activate(ActivationType activationType = ActivationType.Toggle)
public virtual bool Activate(ActivationType activationType = ActivationType.Toggle)
{
//Debug.WriteLine("Activated");
return true;
}
}

View file

@ -1124,31 +1124,36 @@ stretch_mode = 5
[node name="l1_forest" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro1"]
layout_mode = 0
offset_right = 256.0
offset_left = -13.915
offset_right = 242.085
offset_bottom = 100.0
texture = ExtResource("20_jmnog")
[node name="l2_forest" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro1"]
layout_mode = 0
offset_right = 256.0
offset_left = -37.65
offset_right = 218.35
offset_bottom = 100.0
texture = ExtResource("21_kvayf")
[node name="l3_forest" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro1"]
layout_mode = 0
offset_right = 256.0
offset_left = -80.0
offset_right = 176.0
offset_bottom = 100.0
texture = ExtResource("22_ypu2s")
[node name="l4_forest" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro1"]
layout_mode = 0
offset_right = 256.0
offset_left = -100.0
offset_right = 156.0
offset_bottom = 100.0
texture = ExtResource("23_1hkdx")
[node name="l5_forest" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro1"]
layout_mode = 0
offset_right = 256.0
offset_left = -120.0
offset_right = 136.0
offset_bottom = 100.0
texture = ExtResource("24_mqbwl")
@ -1312,10 +1317,9 @@ stretch_mode = 5
[node name="Intro11-Crystal" type="TextureRect" parent="MarginContainer/ImagesContainer/Intro11"]
layout_mode = 2
offset_left = 41.0
offset_top = 34.0
offset_right = 89.0
offset_bottom = 66.0
offset_left = 150.0
offset_right = 198.0
offset_bottom = 32.0
texture = ExtResource("19_paaiq")
stretch_mode = 5

View file

@ -44,7 +44,7 @@ public partial class Interactable : Area2D, IInteractable
return true;
}
public virtual bool Activate()
public virtual bool Activate(ActivationType activationType = ActivationType.Toggle)
{
return true;
}

File diff suppressed because one or more lines are too long

View file

@ -16,7 +16,7 @@ public partial class BlackCover : Sprite2D, IActivable
UpdateSprite();
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
@ -36,6 +36,7 @@ public partial class BlackCover : Sprite2D, IActivable
break;
}
UpdateSprite();
return true;
}
private void UpdateSprite()

View file

@ -55,7 +55,7 @@ public partial class BulletEmitter : Node2D, IActivable
_bulletSpawner.SpawnBullet(BulletResource.MakeBullet(this.GlobalPosition, Count, Spread, EmissionRotation));
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
@ -77,5 +77,7 @@ public partial class BulletEmitter : Node2D, IActivable
case ActivationType.Destroy:
break;
}
return true;
}
}

View file

@ -35,7 +35,7 @@ public partial class DialogueStarter : ChainActivable
DialogueEndAction();
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
_dialogic.Connect("timeline_ended", Callable.From(OnTimelineEnded));
@ -43,6 +43,7 @@ public partial class DialogueStarter : ChainActivable
((Node)dialogicNode).ProcessMode = ProcessModeEnum.Always;
_gameManager.ChangeState(GameState.Dialogue);
return true;
// Script dialogic = ResourceLoader.Load("res://addons/dialogic/Other/DialogicClass.gd") as Script;
// var dialog = (Node) dialogic.Call("start","timeline");
// AddChild(dialog);

View file

@ -66,7 +66,7 @@ public partial class HealthStation : Activable
_healingTimer = 0;
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
@ -90,6 +90,8 @@ public partial class HealthStation : Activable
// Destroys
break;
}
return true;
}
private void _on_area_entered(Area2D area)

View file

@ -34,11 +34,13 @@ public partial class PlayerMover : ChainActivable
_gameManager = this.GetGameManager();
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (_gameManager.Player is null) return;
if (_gameManager.Player is null) return false;
_ = MovePlayer();
return true;
}
private async Task MovePlayer()

View file

@ -1,4 +1,5 @@
using System;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources.Events;
using Godot;
using Godot.Collections;
@ -63,8 +64,15 @@ public partial class ScriptableBase : Node2D, IActivable
// }
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
Start();
return true;
}
public bool CanActivate()
{
return true;
}
}

View file

@ -76,7 +76,7 @@ public partial class Teleporter : Activable
}
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
@ -100,6 +100,8 @@ public partial class Teleporter : Activable
// Destroys
break;
}
return true;
}
public void PrepareForReceiving()

View file

@ -17,7 +17,7 @@ public partial class ActorSpawner : Node2D, IActivable
SpawnedActor = this.CreateSibling<Actor>(ActorPrefab);
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (!WaitForActorDeath)
{
@ -27,5 +27,7 @@ public partial class ActorSpawner : Node2D, IActivable
{
Spawn();
}
return true;
}
}

View file

@ -140,7 +140,7 @@ public partial class Boss : Enemy, IActivable
_currentHealth -= amount;
}
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
_started = true;
if (_bossHud is not null)
@ -149,6 +149,8 @@ public partial class Boss : Enemy, IActivable
}
_gameManager.CameraTargetObject(_cameraMarker);
StartPhase(CurrentPhase);
return true;
}
private async Task Switchphase(BossPhase phase)

View file

@ -13,7 +13,7 @@ public partial class Chest : Interactable
private AnimatedSprite2D _sprite;
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
GD.Print("Attempting to open chest");
if (State != ChestState.Closed) return false;

View file

@ -1,4 +1,5 @@
using Cirno.Scripts.Components.FSM;
using Cirno.Scripts.Interactables;
using Godot;
namespace Cirno.Scripts.Components.Actors;
@ -17,11 +18,11 @@ public partial class ActivationProvider : Area2D
[Export] private AudioStreamPlayer2D _errorSound;
[Signal]
public delegate void InteractableAreaEnteredEventHandler(Interactable interactable);
//[Signal]
//public delegate void InteractableAreaEnteredEventHandler(Interactable interactable);
[Signal]
public delegate void InteractableAreaExitedEventHandler(Interactable interactable);
//[Signal]
//public delegate void InteractableAreaExitedEventHandler(Interactable interactable);
public void Init(CharacterBody2D actor)
{
@ -80,9 +81,9 @@ public partial class ActivationProvider : Area2D
private void _on_interaction_controller_area_entered(Area2D area)
{
if (!Enabled) return;
if (area.IsInGroup("Interactable") && area is Interactable interactable && interactable.CanActivate())
if (area.IsInGroup("Interactable") && area is IInteractable interactable && interactable.CanActivate())
{
EmitSignal(nameof(InteractableAreaEntered), interactable);
//EmitSignal(nameof(InteractableAreaEntered), interactable);
if (_selector == null) return;
@ -93,9 +94,9 @@ public partial class ActivationProvider : Area2D
private void _on_interaction_controller_area_exited(Area2D area)
{
if (!Enabled) return;
if (area.IsInGroup("Interactable") && area is Interactable interactable)
if (area.IsInGroup("Interactable") && area is IInteractable interactable)
{
EmitSignal(nameof(InteractableAreaExited), interactable);
//EmitSignal(nameof(InteractableAreaExited), interactable);
if (_selector == null) return;
_selector.RemoveInteractable(interactable);

View file

@ -30,9 +30,10 @@ public partial class ElevatorProxy : Area2D, IActivable
public InteractionController CachedPlayer { get; private set; }
public void Activate(ActivationType activationType = ActivationType.Toggle)
public bool Activate(ActivationType activationType = ActivationType.Toggle)
{
EmitSignal(SignalName.Activated, (int)activationType);
return true;
}
private void _on_area_entered(Area2D area)

View file

@ -79,7 +79,7 @@ public partial class Door : Activable
//_solidShape.Disabled = state;
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
switch (activationType)
{
@ -108,6 +108,8 @@ public partial class Door : Activable
ToggleDoor();
break;
}
return true;
}
private void ToggleDoor()

View file

@ -2,7 +2,7 @@
public interface IActivable
{
void Activate(ActivationType activationType = ActivationType.Toggle);
bool Activate(ActivationType activationType = ActivationType.Toggle);
}
public enum ActivationType

View file

@ -33,7 +33,7 @@ public partial class AlarmBox : Interactable
_sprite.Play("alarmed");
}
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (MeetsRequirements() && _alarmManager.IsAlarmOn)
{

View file

@ -1,10 +1,11 @@
using Godot;
using System;
using Cirno.Scripts;
public partial class Computer : Interactable
{
[Export] public Activable Target { get; set; }
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (MeetsRequirements())
{

View file

@ -1,8 +1,12 @@
namespace Cirno.Scripts.Interactables;
using Godot;
namespace Cirno.Scripts.Interactables;
public interface IInteractable
{
public bool Activate();
public bool Activate(ActivationType activationType = ActivationType.Toggle);
public bool CanActivate();
public Vector2 GetPosition();
//protected bool MeetsRequirements();
}

View file

@ -8,7 +8,7 @@ public partial class ItemPickup : Interactable
{
[Export] public Array<LootItem> LootTable = new Array<LootItem>();
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
GD.Print("Attempting to Pickup Item");

View file

@ -7,7 +7,7 @@ namespace Cirno.Scripts.Interactables;
public partial class Switch : Interactable
{
[Export] public Node2D Target { get; set; }
[Export] public Array<Node2D> Targets { get; private set; } = new Array<Node2D>();
[Export] public Array<Node2D> Targets { get; private set; } = [];
[Export] public ActivationType ActivationType { get; set; } = ActivationType.Toggle;
private AudioStreamPlayer2D _activationSound;
@ -19,7 +19,7 @@ public partial class Switch : Interactable
_activationSound = GetNodeOrNull<AudioStreamPlayer2D>(_activationSoundName);
}
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (!MeetsRequirements()) return false;
_activationSound?.Play();

View file

@ -19,7 +19,7 @@ public partial class Valve : Interactable
SetState(_activationState);
}
public override bool Activate()
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
if (MeetsRequirements() && Target is IActivable activatable)
{

View file

@ -16,7 +16,7 @@ public partial class Pickupper : Activable
_inventoryManager = GetNode<InventoryManager>("/root/GameScene/InventoryManager");
}
public override void Activate(ActivationType activationType = ActivationType.Toggle)
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
{
foreach (var item in LootTable)
{
@ -27,6 +27,6 @@ public partial class Pickupper : Activable
//GetParent().QueueFree(); // TODO: send a signal instead
return true;
}
}

View file

@ -1,19 +1,20 @@
using Godot;
using System;
using System.Collections.Generic;
using Cirno.Scripts.Interactables;
public partial class Selector : Node2D
{
private Interactable _lastInteractable;
private List<Interactable> _interactables = new List<Interactable>();
private List<IInteractable> _interactables = [];
private int _selectedInteractable;
[Signal]
public delegate void SelectedItemInteractableChangedEventHandler(Interactable interactable);
//[Signal]
//public delegate void SelectedItemInteractableChangedEventHandler(IInteractable interactable);
public Interactable SelectedInteractable
public IInteractable SelectedInteractable
{
get =>
_interactables.Count > 0
@ -79,12 +80,12 @@ public partial class Selector : Node2D
UpdatePosition();
}
private void NotifyChanged(Interactable interactable)
private void NotifyChanged(IInteractable interactable)
{
EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
//EmitSignal(nameof(SelectedItemInteractableChanged), interactable);
}
public void AddInteractable(Interactable interactable)
public void AddInteractable(IInteractable interactable)
{
if (!_interactables.Contains(interactable)) {
_interactables.Add(interactable);
@ -98,7 +99,7 @@ public partial class Selector : Node2D
UpdatePosition();
}
public void RemoveInteractable(Interactable interactable)
public void RemoveInteractable(IInteractable interactable)
{
if (_interactables.Contains(interactable))
{
@ -117,7 +118,7 @@ public partial class Selector : Node2D
{
if (SelectedInteractable != null)
{
this.Position = SelectedInteractable.Position;
this.Position = SelectedInteractable.GetPosition();
this.Visible = true;
}
else

BIN
Tilesets/factory.aseprite (Stored with Git LFS)

Binary file not shown.