Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ansi support #56

Merged
merged 6 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ public Room Instantiate()
new Paragraph("Squarrrkkk!"),
new Paragraph("Would you like to change modes?")
{
Responses = new[]
{
Responses =
[
new Response("Yes please, change to default."),
new Response("Yes please, change to simple.", 2),
new Response("Yes please, change to legacy.", 3),
new Response("No thanks, keep things as they are.", 4)
}
]
},
new Paragraph("Arrk! Color it is.", g => g.FrameBuilders = FrameBuilderCollections.Default, -1),
new Paragraph("Eeek, simple be fine too!", g => g.FrameBuilders = FrameBuilderCollections.Simple, -2),
new Paragraph("Squarrk! Legacy, looks old. Arrk!", g => g.FrameBuilders = FrameBuilderCollections.Legacy, -3),
new Paragraph("Eeek, simple be fine too! Shame it's been deleted. Maybe it will be implmented again one day! Eeek!", -2),
new Paragraph("Squarrk! Legacy, looks old. Shame it's been deleted. Maybe it will be implmented again one day! Arrk!", -3),
new Paragraph("Fine, suit yourself! Squarrk!", -4)
);

Expand Down
12 changes: 6 additions & 6 deletions BP.AdventureFramework.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ private static void PopulateHub(Region hub, Overworld overworld, Region[] otherR
{
room.AddItem(new Item($"{otherRegion.Identifier.Name} Sphere", "A glass sphere, about the size of a snooker ball. Inside you can see a swirling mist.", true)
{
Commands = new[]
{
Commands =
[
new CustomCommand(new CommandHelp($"Warp {otherRegion.Identifier.Name}", $"Use the {otherRegion.Identifier.Name} Sphere to warp to the {otherRegion.Identifier.Name}."), true, (g, _) =>
{
var move = overworld?.Move(otherRegion) ?? false;
Expand All @@ -60,7 +60,7 @@ private static void PopulateHub(Region hub, Overworld overworld, Region[] otherR

return new Reaction(ReactionResult.Internal, string.Empty);
})
}
]
});
}
}
Expand Down Expand Up @@ -92,8 +92,8 @@ private static void Main(string[] args)
foreach (var region in regions)
overworld.AddRegion(region);

overworld.Commands = new[]
{
overworld.Commands =
[
// add a hidden custom command to the overworld that allows jumping around a region for debugging purposes
new CustomCommand(new CommandHelp("Jump", "Jump to a location in a region."), false, (g, a) =>
{
Expand All @@ -115,7 +115,7 @@ private static void Main(string[] args)

return new Reaction(ReactionResult.OK, $"Jumped to {x} {y} {z}.");
})
};
];

return overworld;
};
Expand Down
12 changes: 6 additions & 6 deletions BP.AdventureFramework.Tests/Assets/ExaminableObject_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public void GivenExamine_WhenDefaultExamination_ThenExaminableDescriptionIsInclu
public void GivenExamine_WhenDefaultExaminationWith1CustomCommand_ThenCustomCommandIsIncuded()
{
var i = new Item("Test", "Test Description.");
i.Commands = new[]
{
i.Commands =
[
new CustomCommand(new CommandHelp("Test Command", "Test Command Descritpion."), true, (_, _) =>
{
return new Reaction(ReactionResult.OK, "");
})
};
];

var result = i.Examine();

Expand All @@ -40,8 +40,8 @@ public void GivenExamine_WhenDefaultExaminationWith1CustomCommand_ThenCustomComm
public void GivenExamine_WhenDefaultExaminationWith2CustomCommands_ThenCustomCommandsAreBothIncuded()
{
var i = new Item("Test", "Test Description.");
i.Commands = new[]
{
i.Commands =
[
new CustomCommand(new CommandHelp("A*", "Test Command Descritpion."), true, (_, _) =>
{
return new Reaction(ReactionResult.OK, "");
Expand All @@ -50,7 +50,7 @@ public void GivenExamine_WhenDefaultExaminationWith2CustomCommands_ThenCustomCom
{
return new Reaction(ReactionResult.OK, "");
})
};
];

var result = i.Examine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void GivenValidGame_WhenInvoke_ThenInternal()
{
var game = AdventureFramework.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var response = new Response("");
var paragraph = new Paragraph(string.Empty) { Responses = new[] { response } };
var paragraph = new Paragraph(string.Empty) { Responses = [response] };
var conversation = new AdventureFramework.Conversations.Conversation(paragraph);
var converser = new NonPlayableCharacter(string.Empty, string.Empty) { Conversation = conversation };
game.StartConversation(converser);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void GivenCurrentParagraphWithResponse_WhenRespond_ThenReactionIsInternal
{
var game = AdventureFramework.Logic.Game.Create(string.Empty, string.Empty, string.Empty, null, null, null, null).Invoke();
var response = new Response(string.Empty, 0);
var paragraph = new Paragraph(string.Empty, 0) { Responses = new[] { response }};
var paragraph = new Paragraph(string.Empty, 0) { Responses = [response] };
var npc = new NonPlayableCharacter(string.Empty, string.Empty) { Conversation = new Conversation(paragraph) };
game.StartConversation(npc);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BP.AdventureFramework.Assets;
using System;
using BP.AdventureFramework.Assets;
using BP.AdventureFramework.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand Down Expand Up @@ -30,7 +31,7 @@ public void GivenOneElement_WhenRemoveADifferentElement_Then1Element()
[TestMethod]
public void GivenEmptyArray_WhenRemove_ThenNotNull()
{
var value = new Item[0];
var value = Array.Empty<Item>();

var result = value.Remove(new Item(string.Empty, string.Empty));

Expand All @@ -40,7 +41,7 @@ public void GivenEmptyArray_WhenRemove_ThenNotNull()
[TestMethod]
public void GivenEmptyArray_WhenAdd_ThenOneElement()
{
var value = new Item[0];
var value = Array.Empty<Item>();

var result = value.Remove(new Item(string.Empty, string.Empty));

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ public void GivenActiveConverser1CustomCommand_WhenGetContextualCommands_ThenRet
npc.Conversation = new Conversation(
new Paragraph("Test")
{
Responses = new[]
{
Responses =
[
new Response("First")
}
]
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void GivenNoCustomCommands_WhenGetContextualCommands_ThenReturnEmptyArray
public void GivenNoCustomCommands_WhenGetContextualCommands_ThenReturn1CommandHelp()
{
var interpreter = new CustomCommandInterpreter();
overworld.Commands = new[] { new CustomCommand(new CommandHelp("Test", string.Empty), true, (_, _) => new Reaction(ReactionResult.Error, string.Empty)) };
overworld.Commands = [new CustomCommand(new CommandHelp("Test", string.Empty), true, (_, _) => new Reaction(ReactionResult.Error, string.Empty))];
var game = Game.Create(string.Empty, string.Empty, string.Empty, _ => overworld, () => new PlayableCharacter(Identifier.Empty, Description.Empty), _ => EndCheckResult.NotEnded, _ => EndCheckResult.NotEnded).Invoke();

var result = interpreter.GetContextualCommandHelp(game);
Expand All @@ -51,12 +51,15 @@ public void GivenNoCustomCommands_WhenGetContextualCommands_ThenReturn1CommandHe
public void GivenValidCustomCommand_WhenInterpret_ThenCommandInvoked()
{
var interpreter = new CustomCommandInterpreter();
overworld.Commands = new[] { new CustomCommand(new CommandHelp("Test", string.Empty), true, (_, _) =>
overworld.Commands =
[
new CustomCommand(new CommandHelp("Test", string.Empty), true, (_, _) =>
{
Assert.IsTrue(true);
return new Reaction(ReactionResult.Error, string.Empty);

}) };
})
];
var game = Game.Create(string.Empty, string.Empty, string.Empty, _ => overworld, () => new PlayableCharacter(Identifier.Empty, Description.Empty), _ => EndCheckResult.NotEnded, _ => EndCheckResult.NotEnded).Invoke();

interpreter.Interpret("Test", game);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading