示例#1
0
        public void TestAddCommand()
        {
            //setup
            using Datapack pack = new Datapack("datapacks", "pack", "a pack", 0, new NoneFileCreator());
            PackNamespace space              = pack.Namespace("space");
            Function      autoFunction       = space.Function("autofunction");
            TextWriter    autoFunctionWriter = (pack.FileCreator.GetWriters().First(w => w.path == "datapacks/pack/data/space/functions/autofunction.mcfunction").writer as TextWriter) !;
            Function      onDisposeFunction  = space.Function("disposefunction", BaseFile.WriteSetting.OnDispose);

            //test
            autoFunction.AddCommand(new SayCommand("hello world"));
            autoFunction.AddCommand(new ClearCommand(ID.Selector.s));
            Assert.AreEqual(0, autoFunction.Commands.Count, "Commands wasn't removed from command list");
            Assert.AreEqual("say hello world" + Environment.NewLine + "clear @s" + Environment.NewLine, autoFunctionWriter.ToString(), "AddCommand failed to write the commands correctly");

            //text execute
            autoFunction       = space.Function("autofunction2");
            autoFunctionWriter = (pack.FileCreator.GetWriters().First(w => w.path == "datapacks/pack/data/space/functions/autofunction2.mcfunction").writer as TextWriter) !;
            autoFunction.AddCommand(new ExecuteAs(ID.Selector.s));
            Assert.AreEqual("", autoFunctionWriter.ToString(), "Execute command with no end shouldn't write anything yet");
            autoFunction.AddCommand(new ExecuteAt(ID.Selector.s));
            Assert.AreEqual(1, autoFunction.Commands.Count, "Commands wasn't added correctly to command list");
            autoFunction.AddCommand(new SayCommand("end"));
            Assert.AreEqual("execute as @s at @s run say end" + Environment.NewLine, autoFunctionWriter.ToString(), "Execute command with end should write");
        }
示例#2
0
        public void TestDispose()
        {
            //setup
            using Datapack pack = new Datapack("datapacks", "pack", "a pack", 0, new NoneFileCreator());
            PackNamespace space              = pack.Namespace("space");
            Function      onDisposeFunction  = space.Function("disposefunction", BaseFile.WriteSetting.OnDispose);
            Function      autoFunction       = space.Function("autofunction", BaseFile.WriteSetting.Auto);
            TextWriter    autoFunctionWriter = (pack.FileCreator.GetWriters().First(w => w.path == "datapacks/pack/data/space/functions/autofunction.mcfunction").writer as TextWriter) !;

            //test
            onDisposeFunction.AddCommand(new SayCommand("hello world"));
            onDisposeFunction.AddCommand(new ExecuteAs(ID.Selector.a));
            Assert.AreEqual(2, onDisposeFunction.Commands.Count, "Commands wasn't added to command list");
            onDisposeFunction.Dispose();
            TextWriter onDisposeFunctionWriter = (pack.FileCreator.GetWriters().First(w => w.path == "datapacks/pack/data/space/functions/disposefunction.mcfunction").writer as TextWriter) !;

            Assert.AreEqual("say hello world" + Environment.NewLine + "execute as @a" + Environment.NewLine, onDisposeFunctionWriter.ToString(), "Dispose function isn't writing commands correctly on dispose");
            Assert.IsNull(onDisposeFunction.Commands, "Commands wasn't cleared");

            autoFunction.AddCommand(new SayCommand("hello world"));
            autoFunction.AddCommand(new ExecuteAs(ID.Selector.a));
            autoFunction.Dispose();
            Assert.AreEqual("say hello world" + Environment.NewLine + "execute as @a" + Environment.NewLine, autoFunctionWriter.ToString(), "Auto function isn't writing commands correctly on dispose");
        }
示例#3
0
 /// <summary>
 /// Loads the chunks containing the coordinates from corner to oppesiteCorner
 /// </summary>
 /// <param name="corner">One of the corners of the square to load</param>
 /// <param name="oppesiteCorner">The oppesite corner in the square to load</param>
 public void ForceLoad(Vector corner, Vector oppesiteCorner)
 {
     function.AddCommand(new ForceloadChunksCommand(corner, oppesiteCorner, true));
 }
示例#4
0
 /// <summary>
 /// Adds the given data to the <see cref="Storage"/>
 /// </summary>
 /// <param name="data">The data to give to the <see cref="Storage"/></param>
 /// <param name="storage">the <see cref="Storage"/> to give the data to</param>
 public void Change(Storage storage, Data.SimpleDataHolder data)
 {
     function.AddCommand(new DataMergeStorageCommand(storage, data));
 }
示例#5
0
        public void TestCustomGroupCommands()
        {
            //setup
            using Datapack pack = new Datapack("datapacks", "pack", "a pack", 0, new NoneFileCreator());
            PackNamespace space    = pack.Namespace("space");
            Function      function = space.Function("function", BaseFile.WriteSetting.OnDispose);

            BaseCommand command1 = new ExecuteAt(ID.Selector.s);
            BaseCommand command2 = new SayCommand("123");
            BaseCommand command3 = new SayMeCommand("123");
            BaseCommand command4 = new ExecuteAs(ID.Selector.s);

            //test
            //without execute at start
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command2);
                f.AddCommand(command3);
            });
            Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first grouped command string returned wrong string");
            Assert.AreEqual("me 123", function.Commands[1].GetCommandString(), "Get second grouped command string returned wrong string");

            //with execute at start
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command4.ShallowClone());
                f.AddCommand(command3);
            });
            Assert.AreEqual("execute at @s run say 123", function.Commands[0].GetCommandString(), "Get first executed grouped command string returned wrong string");
            Assert.AreEqual("execute at @s as @s run me 123", function.Commands[1].GetCommandString(), "Get second executed grouped command string returned wrong string");

            //using function
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command3);
            }, true);
            Function addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !;

            Assert.AreEqual("say 123", addedFunction.Commands[0].GetCommandString(), "Get first function grouped command string returned wrong string");
            Assert.AreEqual("execute at @s run me 123", addedFunction.Commands[1].GetCommandString(), "Get second function grouped command string returned wrong string");
            Assert.AreEqual(2, addedFunction.Commands.Count, "function grouped command doesn't contain the correct amount of commands");

            space.AddSetting(NamespaceSettings.GetSettings().FunctionGroupedCommands());
            function.Commands.Clear();
            function.AddCommand(command1.ShallowClone());
            function.Custom.GroupCommands((f) =>
            {
                f.AddCommand(command2);
                f.AddCommand(command1.ShallowClone());
                f.AddCommand(command3);
            });
            addedFunction = (((function.Commands[0] as BaseExecuteCommand) !.ExecuteCommand as RunFunctionCommand) !.Function as Function) !;
            Assert.AreEqual(2, addedFunction.Commands.Count, "automatic function grouped command doesn't get the correct commands");
        }