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); }
protected T ReadAction <T>(string source) where T : ActionBase { var xAction = XElement.Parse(source); var action = XAction.FromXml(xAction); return((T)action); }
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; }
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); }
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); }
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)); } } }
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); } } }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
/// <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 }
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); }
//根据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); }
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); }
public WitchcraftNoParamsVoid(MethodInfo methodInfo) { _func = (XAction <Sandbox>)Delegate.CreateDelegate( typeof(XAction <Sandbox>), methodInfo); }
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); }
public WitchcraftNoParamsVoid(MethodInfo methodInfo) { _func = (XAction<Sandbox>)Delegate.CreateDelegate( typeof(XAction<Sandbox>), methodInfo); }