Skip to content

Commit

Permalink
Add prompt methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaioru committed Sep 18, 2024
1 parent 9092c0c commit 44af2ee
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Threading.Tasks;
using Edelstein.Protocol.Gameplay.Game.Conversations;
using Edelstein.Protocol.Gameplay.Game.Conversations.Speakers;

namespace Edelstein.Common.Gameplay.Game.Conversations;

public class SystemConversation(
Action<IConversationSpeaker, IConversationSpeaker> action
) : IConversation<IConversationSpeaker, IConversationSpeaker>
{

public Task Start(IConversationContext ctx, IConversationSpeaker self, IConversationSpeaker target)
{
action.Invoke(self, target);
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Edelstein.Common.Gameplay.Game.Conversations;
using Edelstein.Common.Gameplay.Game.Conversations.Speakers;
using Edelstein.Common.Gameplay.Game.Objects.Users.Stats;
using Edelstein.Protocol.Gameplay.Entities;
using Edelstein.Protocol.Gameplay.Game;
Expand Down Expand Up @@ -127,7 +128,24 @@ public async Task Modify(Action<IFieldUserModify> action)
_lock.Release();
}
}

public Task<T?> Prompt<T>(Func<IConversationSpeaker, T> prompt)
=> Prompt((s1, s2) => prompt.Invoke(s1));

public async Task<T?> Prompt<T>(Func<IConversationSpeaker, IConversationSpeaker, T> prompt)
{
T? result = default;

await Converse(
new SystemConversation((self, target)
=> result = prompt.Invoke(self, target)),
ctx => new ConversationSpeaker(ctx),
ctx => new ConversationSpeaker(ctx)
);

return result;
}

public async Task Converse<TSelf, TTarget>(
IConversation<TSelf, TTarget> conversation,
Func<IConversationContext, TSelf> getSpeakerSelf,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public interface IFieldUser :

Task Initialize();
Task Modify(Action<IFieldUserModify> action);

Task<T?> Prompt<T>(Func<IConversationSpeaker, T> prompt);
Task<T?> Prompt<T>(Func<IConversationSpeaker, IConversationSpeaker, T> prompt);

Task Converse<TSelf, TTarget>(
IConversation<TSelf, TTarget> conversation,
Expand Down

0 comments on commit 44af2ee

Please sign in to comment.