Interactions can now end themselves.

WorldChunkRefactoring
Martin Felis 2023-11-10 20:22:55 +01:00
parent 187dac2d85
commit d2611c6073
3 changed files with 20 additions and 6 deletions

View File

@ -10,6 +10,12 @@ public class InteractionComponent: Component
[Signal]
delegate void InteractionEnd(Spatial owningEntity, Spatial targetEntity);
public void EndInteraction()
{
hasStopped = true;
}
public bool hasStopped = false;
public Spatial OwningEntity;
public Spatial TargetEntity;
}

View File

@ -27,10 +27,8 @@ public class TaskQueueComponent : Component
do
{
var currentTask = Queue.Peek();
var interactionTask = currentTask as InteractionTask;
if (interactionTask != null) EmitSignal("StartInteraction", entity, interactionTask.TargetEntity);
if (currentTask.PerformTask(entity, delta))
if (currentTask.PerformTask(entity, this, delta))
Queue.Dequeue();
else
break;
@ -43,7 +41,7 @@ public class TaskQueueComponent : Component
/// Executes a Task on the specified entity.
/// </summary>
/// <returns>true when the Task is complete, false otherwise</returns>
public abstract bool PerformTask(Entity entity, float delta);
public abstract bool PerformTask(Entity entity, TaskQueueComponent taskQueueComponent, float delta);
}
/// <summary>
@ -59,7 +57,7 @@ public class TaskQueueComponent : Component
NavigationPoint = navigationPoint;
}
public override bool PerformTask(Entity entity, float delta)
public override bool PerformTask(Entity entity, TaskQueueComponent taskQueueComponent, float delta)
{
return NavigationPoint.IsReached(entity.GlobalTransform);
}
@ -74,8 +72,10 @@ public class TaskQueueComponent : Component
TargetEntity = entity;
}
public override bool PerformTask(Entity entity, float delta)
public override bool PerformTask(Entity entity, TaskQueueComponent taskQueueComponent, float delta)
{
taskQueueComponent.EmitSignal("StartInteraction", entity, TargetEntity);
return true;
}
}

View File

@ -80,6 +80,9 @@ public class World : Spatial
[Signal]
private delegate void OnHeightmapImageChanged(Image heightmapImage);
[Signal]
public delegate void EntityClicked(Entity entity);
public World()
{
Debug.Assert(ChunkSize % 2 == 0);
@ -500,4 +503,9 @@ public class World : Spatial
State = GenerationState.Done;
}
}
private void OnEntityClicked(Entity entity)
{
EmitSignal("EntityClicked", entity);
}
}