-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8cd97aa
commit 81216bd
Showing
10 changed files
with
172 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/MineCase.Server.Interfaces/Game/Commands/TildeNotationArgument.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace MineCase.Server.Game.Commands | ||
{ | ||
/// <summary> | ||
/// 波浪号记号参数 | ||
/// </summary> | ||
/// <remarks>用于表示一个相对的值,具体含义由具体命令定义</remarks> | ||
public class TildeNotationArgument : UnresolvedArgument | ||
{ | ||
internal const char PrefixToken = '~'; | ||
|
||
/// <summary> | ||
/// Gets 波浪号记号参数表示的偏移量 | ||
/// </summary> | ||
public int Offset { get; } | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="TildeNotationArgument"/> class. | ||
/// 构造并分析一个波浪号记号参数 | ||
/// </summary> | ||
/// <param name="rawContent">作为波浪号记号的内容</param> | ||
public TildeNotationArgument(string rawContent) | ||
: base(rawContent) | ||
{ | ||
if (rawContent.Length == 1) | ||
{ | ||
Offset = 0; | ||
return; | ||
} | ||
|
||
var strToParse = rawContent.Substring(1); | ||
if (!int.TryParse(strToParse, out int offset)) | ||
{ | ||
throw new ArgumentException($"\"{strToParse}\" 不是合法的 offset 值", nameof(rawContent)); | ||
} | ||
|
||
Offset = offset; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using MineCase.Server.Game; | ||
using MineCase.Server.Game.Commands; | ||
using Xunit; | ||
|
||
namespace MineCase.UnitTest | ||
{ | ||
public class CommandTest | ||
{ | ||
private class OutputCommandSender : ICommandSender | ||
{ | ||
private readonly TextWriter _tw; | ||
|
||
public OutputCommandSender(TextWriter tw) | ||
{ | ||
_tw = tw; | ||
} | ||
|
||
public Task<bool> HasPermission(Permission permission) | ||
{ | ||
return Task.FromResult(true); | ||
} | ||
|
||
public Task SendMessage(string msg) | ||
{ | ||
_tw.WriteLine(msg); | ||
return Task.CompletedTask; | ||
} | ||
} | ||
|
||
private class TestCommand : SimpleCommand | ||
{ | ||
public TestCommand() | ||
: base("test", null, null, null) | ||
{ | ||
} | ||
|
||
public override bool Execute(ICommandSender commandSender, IList<ICommandArgument> args) | ||
{ | ||
commandSender.SendMessage(string.Join(", ", args.Select(arg => arg.ToString()))); | ||
return true; | ||
} | ||
} | ||
|
||
[Fact] | ||
public void Test1() | ||
{ | ||
var commandMap = new CommandMap(); | ||
commandMap.RegisterCommand(new TestCommand()); | ||
|
||
var sb = new StringBuilder(); | ||
using (var sw = new StringWriter(sb)) | ||
{ | ||
commandMap.Dispatch(new OutputCommandSender(sw), "/test 1 ~2 @p[arg1=233,arg2=]"); | ||
var str = sb.ToString(); | ||
Console.Write(str); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,4 +121,4 @@ public void Test1() | |
} | ||
} | ||
} | ||
} | ||
} |