예제 #1
0
        protected void WriteAction <T>(T action, string etalon) where T : ActionBase
        {
            var xAction = XAction.ToXml(action);
            var xEtalon = XElement.Parse(etalon);

            new XmlComparision(Assert.Fail).Compare(xAction, xEtalon);
        }
예제 #2
0
        protected T ReadAction <T>(string source) where T : ActionBase
        {
            var xAction = XElement.Parse(source);
            var action  = XAction.FromXml(xAction);

            return((T)action);
        }
예제 #3
0
        public static ButtonCondition FromXml(XElement xCondition)
        {
            var xKeyPress          = xCondition.Attribute("key");
            var xIdleToOverDown    = xCondition.Attribute("menuEnter");
            var xOutDownToIdle     = xCondition.Attribute("pointerReleaseOutside");
            var xOutDownToOverDown = xCondition.Attribute("pointerDragEnter");
            var xOverDownToOutDown = xCondition.Attribute("pointerDragLeave");
            var xOverDownToOverUp  = xCondition.Attribute("pointerReleaseInside");
            var xOverUpToOverDown  = xCondition.Attribute("pointerPush");
            var xOverUpToIdle      = xCondition.Attribute("pointerLeave");
            var xIdleToOverUp      = xCondition.Attribute("pointerEnter");
            var xOverDownToIdle    = xCondition.Attribute("menuLeave");

            var res = new ButtonCondition {
                KeyPress          = byte.Parse(xKeyPress.Value),
                IdleToOverDown    = CommonFormatter.ParseBool(xIdleToOverDown.Value),
                OutDownToIdle     = CommonFormatter.ParseBool(xOutDownToIdle.Value),
                OutDownToOverDown = CommonFormatter.ParseBool(xOutDownToOverDown.Value),
                OverDownToOutDown = CommonFormatter.ParseBool(xOverDownToOutDown.Value),
                OverDownToOverUp  = CommonFormatter.ParseBool(xOverDownToOverUp.Value),
                OverUpToOverDown  = CommonFormatter.ParseBool(xOverUpToOverDown.Value),
                OverUpToIdle      = CommonFormatter.ParseBool(xOverUpToIdle.Value),
                IdleToOverUp      = CommonFormatter.ParseBool(xIdleToOverUp.Value),
                OverDownToIdle    = CommonFormatter.ParseBool(xOverDownToIdle.Value)
            };

            var xActions = xCondition.Elements("actions");

            foreach (var xAction in xActions.Elements())
            {
                res.Actions.Add(XAction.FromXml(xAction));
            }
            return(res);
        }
        protected override void OnBindToContext()
        {
            base.OnBindToContext();

            Applicable &= Context.ChessResult != null;
            if (!Applicable)
            {
                return;
            }

            XAction     = Context.ChessResult.GetChessXActionMatchingStartOf(this.Text);
            Applicable &= XAction != null;
            if (!Applicable)
            {
                return;
            }

            Enabled &= !Context.TestRun.HasTestSourceChanged;

            Text = Text.Replace("Repro", GetSpecializedReproName());

            var opts = new MChessOptions();

            opts.EnableRepro   = true;
            opts.EnableTracing = true;
            opts.TargetRace    = (int?)XAction.Attribute(XChessNames.ARace);
            opts.XSchedule     = Context.ChessResult.DataElement.Element(XChessNames.Schedule);

            // Merge with existing options
            opts.MergeWith(MChessOptions);
            MChessOptions = opts;
        }
예제 #5
0
        protected override void FormatTagElement(DoActionTag tag, XElement xTag)
        {
            var actions = new XElement(ACTIONS_ELEM);

            foreach (var action in tag.ActionRecords)
            {
                actions.Add(XAction.ToXml(action));
            }
            xTag.Add(actions);
        }
예제 #6
0
        protected override void FormatTagElement(DoInitActionTag tag, XElement xTag)
        {
            xTag.Add(new XAttribute("sprite", tag.SpriteId));
            var actions = new XElement(ACTIONS_ELEM);

            foreach (var action in tag.ActionRecords)
            {
                actions.Add(XAction.ToXml(action));
            }
            xTag.Add(actions);
        }
예제 #7
0
        public void WriteOneByteActionsTest()
        {
            var vals    = Enum.GetValues(typeof(ActionCode));
            var factory = new ActionsFactory();

            foreach (ActionCode type in vals)
            {
                if ((byte)type < 0x80)
                {
                    var action  = factory.Create(type);
                    var xAction = XAction.ToXml(action);
                    Assert.AreEqual(xAction.Name.LocalName, XActionNames.FromActionCode(type));
                }
            }
        }
예제 #8
0
        public void ReadOneByteActionsTest()
        {
            var vals = Enum.GetValues(typeof(ActionCode));

            foreach (ActionCode type in vals)
            {
                if ((byte)type < 0x80)
                {
                    var xAction = new XElement(XActionNames.FromActionCode(type));
                    var action  = XAction.FromXml(xAction);
                    Assert.IsNotNull(action);
                    var actualType = action.ActionCode;
                    Assert.AreEqual(type, actualType);
                }
            }
        }
예제 #9
0
        protected override bool AcceptTagElement(DoInitActionTag tag, XElement element)
        {
            switch (element.Name.LocalName)
            {
            case ACTIONS_ELEM:
                foreach (var xAction in element.Elements())
                {
                    var action = XAction.FromXml(xAction);
                    tag.ActionRecords.Add(action);
                }
                break;

            default:
                return(false);
            }
            return(true);
        }
예제 #10
0
    public bool UseAction(int id, int num)
    {
        XAction action = DataDBSAction.GetDataById(id);

        if (action == null)
        {
            return(false);
        }
        if (action.Num < num)
        {
            return(false);
        }
        action.Num -= num;
        DataDBSAction.Update(id, action);
        GTEventCenter.FireEvent(GTEventID.TYPE_CHANGE_ACTION, (EAction)(id - 100));
        return(true);
    }
예제 #11
0
    public bool UseAction(int id, int num)
    {
        XAction action = DataManager.Instance.Actions[id];

        if (action == null)
        {
            return(false);
        }
        if (action.Num < num)
        {
            return(false);
        }
        action.Num -= num;
        DataAction.Update(id, action);

        ZTEvent.FireEvent(EventID.CHANGE_ACTION, (EAction)(id - 100));
        return(true);
    }
예제 #12
0
        public static ClipActionRecord FromXml(XElement xClipAction)
        {
            var res      = new ClipActionRecord();
            var xActions = xClipAction.Element("actions");

            if (xActions != null)
            {
                foreach (var xAction in xActions.Elements())
                {
                    res.Actions.Add(XAction.FromXml(xAction));
                }
            }
            XClipEventFlags.SetFlags1(ref res.Flags, int.Parse(xClipAction.Attribute("flags1").Value));
            XClipEventFlags.SetFlags2(ref res.Flags, int.Parse(xClipAction.Attribute("flags2").Value));

            res.KeyCode = byte.Parse(xClipAction.Attribute("keyCode").Value);
            return(res);
        }
예제 #13
0
        public static XAction MakeAction(ActionCfg cfg, XApp app)
        {
            XAction action   = null;
            String  nametype = cfg.ActionType;

            nametype = "XSheet.v2.Data.XSheetAction.Action" + nametype;
            //XNamedTable
            try
            {
                Type type = Type.GetType(nametype, true);
                action = (XAction)Activator.CreateInstance(type);
                action.init(cfg, app);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                System.Windows.Forms.MessageBox.Show("Action类型不存在,设置的类型为:" + cfg.ActionType + "\n" + e.ToString());
            }
            return(action);
        }
예제 #14
0
        public static XElement ToXml(ClipActionRecord clipAction)
        {
            var res = new XElement("Event");

            if (clipAction.Actions.Count > 0)
            {
                var xActions = new XElement("actions");
                foreach (var action in clipAction.Actions)
                {
                    xActions.Add(XAction.ToXml(action));
                }
                res.Add(xActions);
            }

            res.Add(new XAttribute("flags1", XClipEventFlags.GetFlags1(clipAction.Flags)));
            res.Add(new XAttribute("flags2", XClipEventFlags.GetFlags2(clipAction.Flags)));

            res.Add(new XAttribute("keyCode", clipAction.KeyCode));
            return(res);
        }
예제 #15
0
    public void AddAction(int id, int num)
    {
        XAction action = DataDBSAction.GetDataById(id);

        if (action != null)
        {
            action.Num += num;
            DataDBSAction.Update(id, action);
        }
        else
        {
            action     = new XAction();
            action.Id  = id;
            action.Num = num;
            DataDBSAction.Insert(id, action);
        }
        DItem   db   = ReadCfgItem.GetDataById(id);
        EAction type = (EAction)(id - 100);

        GTEventCenter.FireEvent(GTEventID.TYPE_CHANGE_ACTION, type);
    }
예제 #16
0
    public void AddAction(int id, int num)
    {
        XAction action;

        if (DataManager.Instance.Actions.ContainsKey(id))
        {
            action      = DataManager.Instance.Actions[id];
            action.Num += num;
            DataAction.Update(id, action);
        }
        else
        {
            action     = new XAction();
            action.Id  = id;
            action.Num = num;
            DataAction.Insert(id, action);
        }
        DBItem  db   = ZTConfig.Instance.GetDBItem(id);
        EAction type = ZTConfig.Instance.GetActionType(id);

        ZTEvent.FireEvent(EventID.CHANGE_ACTION, type);
    }
예제 #17
0
        /// <summary>Загружает проект кодогенерации</summary>
        public GenerationProject Load()
        {
            XDocument document = XDocument.Load(_fileName);

            if (document.Root == null)
            {
                throw new ApplicationException();
            }

            // ReSharper disable PossibleNullReferenceException
            return(new GenerationProject(
                       document.Root.Element("GenerationTasks").Elements()
                       .Select(XGenerationTask =>
                               new GenerationTask(
                                   XGenerationTask.Element("Globals").Elements()
                                   .ToDictionary(XGlobalVariable => XGlobalVariable.Name.LocalName, XGlobalVariable => XGlobalVariable.Value),
                                   XGenerationTask.Element("Actions").Elements()
                                   .Select(XAction => new GenerationActionCalling(XAction.Name.LocalName, (string)XAction.Attribute("file")))
                                   .ToList(),
                                   LoadItems(XGenerationTask.Element("SourceItems"))))
                       .ToList(),
                       document.Root.Element("GenerationActions").Elements()
                       .Select(XAction =>
                               new GenerationAction(XAction.Name.LocalName,
                                                    XAction.Elements("InjectionTemplate")
                                                    .Select(XTemplate =>
                                                            new InjectionTemplate((string)XTemplate.Attribute("anchor"),
                                                                                  XTemplate.Nodes().OfType <XText>().First().Value.TrimEnd().Trim('\n').TrimIndents(),
                                                                                  XTemplate.Elements("Template").ToDictionary(
                                                                                      XInternalTemplate => XInternalTemplate.Attribute("name").Value,
                                                                                      XInternalTemplate => XInternalTemplate.Value.TrimEnd().Trim('\n').TrimIndents()),
                                                                                  (string)XTemplate.Attribute("filter")))
                                                    .ToList()))
                       .ToList()
                       ));
            // ReSharper restore PossibleNullReferenceException
        }
예제 #18
0
        public static XElement ToXml(ButtonCondition condition)
        {
            var res = new XElement("Condition",
                                   new XAttribute("key", condition.KeyPress),
                                   new XAttribute("menuEnter", CommonFormatter.Format(condition.IdleToOverDown)),
                                   new XAttribute("pointerReleaseOutside", CommonFormatter.Format(condition.OutDownToIdle)),
                                   new XAttribute("pointerDragEnter", CommonFormatter.Format(condition.OutDownToOverDown)),
                                   new XAttribute("pointerDragLeave", CommonFormatter.Format(condition.OverDownToOutDown)),
                                   new XAttribute("pointerReleaseInside", CommonFormatter.Format(condition.OverDownToOverUp)),
                                   new XAttribute("pointerPush", CommonFormatter.Format(condition.OverUpToOverDown)),
                                   new XAttribute("pointerLeave", CommonFormatter.Format(condition.OverUpToIdle)),
                                   new XAttribute("pointerEnter", CommonFormatter.Format(condition.IdleToOverUp)),
                                   new XAttribute("menuLeave", CommonFormatter.Format(condition.OverDownToIdle))
                                   );

            var xActions = new XElement("actions");

            foreach (var action in condition.Actions)
            {
                xActions.Add(XAction.ToXml(action));
            }
            res.Add(xActions);
            return(res);
        }
예제 #19
0
        //根据ActionCfg初始化单个Action
        private void initAction(ActionCfg cfg)
        {
            XAction action = ActionFactory.MakeAction(cfg, this);

            if (action == null)
            {
                statu = SysStatu.Error;
                return;
            }
            XCommand cmd = getCommandByName(cfg.CommandName);

            try
            {
                action.cmd = cmd;
                cmd        = getCommandByName(cfg.CommandName);
                cmd.actions.Add(action.actionSeq, action);
            }
            catch (Exception)
            {
                MessageBox.Show("Action:" + action.ActionName + "与命令:" + cfg.CommandName + "绑定失败,请检查Action配置是否正确!");
                return;
            }
            this.actions.Add(action.ActionName, action);
        }
예제 #20
0
    public int    GetItemCountById(int id)
    {
        DItem db = ReadCfgItem.GetDataById(id);

        if (db == null)
        {
            return(0);
        }
        int value = 0;

        switch (db.ItemType)
        {
        case EItemType.MONEY:
        {
            XMoney data = DataDBSMoney.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.ACTION:
        {
            XAction data = DataDBSAction.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.PETSOUL:
        {
            XSoul data = DataDBSSoul.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.BOX:
        case EItemType.KEY:
        case EItemType.DRUG:
        case EItemType.MAT:
            foreach (KeyValuePair <int, XItem> pair in DataDBSBagItem.Dict)
            {
                if (pair.Value.Id == id)
                {
                    value = pair.Value.Num;
                }
            }
            break;

        case EItemType.CHIP:
            foreach (KeyValuePair <int, XItem> pair in DataDBSBagChip.Dict)
            {
                if (pair.Value.Id == id)
                {
                    value = pair.Value.Num;
                }
            }
            break;

        default:
            break;
        }
        return(value);
    }
예제 #21
0
파일: Witchcraft.cs 프로젝트: sizzles/Rant
 public WitchcraftNoParamsVoid(MethodInfo methodInfo)
 {
     _func = (XAction <Sandbox>)Delegate.CreateDelegate(
         typeof(XAction <Sandbox>), methodInfo);
 }
예제 #22
0
    public int GetItemCountById(int id)
    {
        DBItem db = ZTConfig.Instance.GetDBItem(id);

        if (db == null)
        {
            return(0);
        }
        int value = 0;

        switch (db.ItemType)
        {
        case EItemType.MONEY:
        {
            XMoney data = DataMoney.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.ACTION:
        {
            XAction data = DataAction.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.PETSOUL:
        {
            XSoul data = DataSoul.GetDataById(id);
            value = data == null ? 0 : data.Num;
        }
        break;

        case EItemType.BOX:
        case EItemType.KEY:
        case EItemType.DRUG:
        case EItemType.MAT:
            foreach (KeyValuePair <int, XItem> pair in BagItems)
            {
                if (pair.Value.Id == id)
                {
                    value = pair.Value.Num;
                }
            }
            break;

        case EItemType.CHIP:
            foreach (KeyValuePair <int, XItem> pair in BagChips)
            {
                if (pair.Value.Id == id)
                {
                    value = pair.Value.Num;
                }
            }
            break;

        default:
            break;
        }
        return(value);
    }
예제 #23
0
 public WitchcraftNoParamsVoid(MethodInfo methodInfo)
 {
     _func = (XAction<Sandbox>)Delegate.CreateDelegate(
         typeof(XAction<Sandbox>), methodInfo);
 }