Example #1
0
        public override void Action(CommandCaller player, string input, string[] args)
        {
            //try{
            string     itemName;
            ActionItem item;
            string     literal;

            ActionContext.Default.Caster = player.Player;
            for (int i = 0; i < args.Length; i++)
            {
                mod.Logger.Info($"parsing \'{args[i]}\'");
                itemName = args[i].Split('.')[0];
                item     = Jailbreak.GetAction(itemName);
                if (item.hasLiteral)
                {
                    literal = args[i].Substring(itemName.Length + 1);
                    item    = Jailbreak.CreateNew(item);
                    item.ApplyLiteral(literal);
                    mod.Logger.Info($"set literal of {item} to {literal}");
                }
                ActionContext.Default.lastReturn = item.Execute(0) ?? ActionContext.Default.lastReturn;
            }

            /*}catch (Exception e){
             *  Main.NewText(e.Message);
             * }*/
        }
        public void AddGeneralMatcherAddsTheMatcher()
        {
            var aggregateMatcher = new AggregateMatcher();

            aggregateMatcher.Add(new ContainsMatcher("abc"));

            dynamic jailBrokenMatcher = new Jailbreak <AggregateMatcher>(aggregateMatcher);
            var     count             = (int)jailBrokenMatcher._matchers.Count;

            count.ShouldBe(1);
        }
        public void AddNullMatcherSkipsAdd()
        {
            var aggregateMatcher = new AggregateMatcher();

            aggregateMatcher.Add(NullMatcher.Instance);

            dynamic jailBrokenMatcher = new Jailbreak <AggregateMatcher>(aggregateMatcher);
            var     count             = (int)jailBrokenMatcher._matchers.Count;

            count.ShouldBe(0);
        }
        public void AddMultipleMatcherAddsAllTheMatchers()
        {
            var aggregateMatcher = new AggregateMatcher();

            aggregateMatcher.Add(new IMatcher[]
            {
                new ContainsMatcher("abc"),
                new RegexMatcher("def"),
            });

            dynamic jailBrokenMatcher = new Jailbreak <AggregateMatcher>(aggregateMatcher);
            var     count             = (int)jailBrokenMatcher._matchers.Count;

            count.ShouldBe(2);
        }
Example #5
0
        public override void Action(CommandCaller player, string input, string[] args)
        {
            //try{
            string     itemName;
            ActionItem item;
            string     literal;

            ActionContext.Default.Caster = player.Player;
            int i = 0;

            if (args[0] == "+=")
            {
                i++;
            }
            else
            {
                TestItem.actions = new List <ActionItem>()
                {
                };
            }

            for (; i < args.Length; i++)
            {
                mod.Logger.Info($"parsing \'{args[i]}\'");
                itemName = args[i].Split('.')[0];
                item     = Jailbreak.GetAction(itemName);
                if (item.hasLiteral)
                {
                    literal = args[i].Substring(itemName.Length + 1);
                    item    = Jailbreak.CreateNew(item);
                    item.ApplyLiteral(literal);
                    mod.Logger.Info($"set literal of {item} to {literal}");
                }
                TestItem.actions.Add(item);
            }

            /*}catch (Exception e){
             *  Main.NewText(e.Message);
             * }*/
        }
        public void BuilderWithMultipleMatchersShouldReturnAggregateMatcher()
        {
            var matcherOne = new ContainsMatcher("abc");
            var matcherTwo = new RegexMatcher("def");
            var matcher    = new KeyMatchBuilder()
                             .Add(new IMatcher[]
            {
                matcherOne,
                matcherTwo,
            })
                             .Build();

            matcher.ShouldNotBeNull();
            matcher.ShouldBeOfType <AggregateMatcher>();

            dynamic         aggregateMatcher = new Jailbreak <AggregateMatcher>((AggregateMatcher)matcher);
            List <IMatcher> matchers         = aggregateMatcher._matchers;

            matchers.Count.ShouldBe(2);
            matchers.ShouldContain(m => m.GetType() == typeof(ContainsMatcher));
            matchers.ShouldContain(m => m.GetType() == typeof(RegexMatcher));
        }
Example #7
0
        public override void OnInitialize()
        {
            int l = 1;

            if (drive != null)
            {
                if (drive.Actions == null)
                {
                    drive.Actions = new List <ActionItem>()
                    {
                    }
                }
                ;
                l += drive.Actions.Count;
            }
            if (maxSize > 0 && l > maxSize)
            {
                l = maxSize;
            }
            Main.UIScaleMatrix.Decompose(out Vector3 scale, out Quaternion ignore, out Vector3 ignore2);
            ActionItem current;
            int        layers = 0;
            int        xPos   = 0;

            for (int i = 0; i < l; i++)
            {
                currIndex = i;
                if (drive.Readonly && drive.Actions.Count <= i)
                {
                    break;
                }
                if (i >= itemSlots.Count)
                {
                    itemSlots.Add(null);
                }
                current      = drive.Actions.Count > i?drive.Actions[i]:null;
                itemSlots[i] = new GlyphItemSlot(scale: 0.75f, context: drive.Readonly ? ItemSlot.Context.CraftingMaterial : ItemSlot.Context.InventoryItem,
                                                 colorContext: drive.Readonly ? ItemSlot.Context.TrashItem : ItemSlot.Context.CraftingMaterial)
                {
                    Left          = { Pixels = (float)((Main.screenWidth * 0.05) + (xPos++ *40 * scale.X)) },
                    Top           = { Pixels = (float)((Main.screenHeight * 0.4) + (layers * 40 * scale.Y)) },
                    ValidItemFunc = item => item.IsAir || (!item.IsAir && (item.modItem is ActionItem)),
                    index         = i
                };
                if (xPos * 40 * scale.X > Main.screenWidth * 0.4)
                {
                    xPos = 0;
                    layers++;
                }
                if (drive != null)
                {
                    if (current != null)
                    {
                        itemSlots[i].item = current?.item ?? Jailbreak.CreateNew(current).item;
                    }
                }
                Append(itemSlots[i]);
                if (current == null)
                {
                    break;
                }
            }
        }