/// <summary>Execute a sequence of commands.</summary> public void ExecuteCommandSequence(CommandContext contextBefore, CommandContext contextAfter, params ICommand[] commands) { redoableCommands.Clear(); foreach (ICommand command in commands) { command.Do(); } // aggregate command if possible if (commands.Length == 1 && undoableCommands.Count > 0) { AggregableCommand thisCommand = commands[0] as AggregableCommand; if (thisCommand != null) { CommandSequence previousCommandSequence = undoableCommands[undoableCommands.Count - 1]; if (previousCommandSequence.Commands.Length == 1) { AggregableCommand previousCommand = previousCommandSequence.Commands[0] as AggregableCommand; if (previousCommand != null && previousCommand.CanAggregateWith(thisCommand)) { previousCommand.AggregateWith(thisCommand); return; } } } } // aggregation was not possible -> stack command normally if (undoableCommands.Count > 99) { undoableCommands.RemoveAt(0); } undoableCommands.Add(new CommandSequence(contextBefore, contextAfter, commands)); }
private void OnCellMouseUp(BoardCell cell) { if (!Skill.UseStrategy.IsValidCell(Skill, cell) || !cell.IsAvailable) { UiErrorFrame.Instance.Push(I18N.Instance.Get("exception_invalid_target")); this.interactor.EnterSelectionState(); return; } var withinSkillRange = this.boardNavigator .WithinSkillRange(cell.transform.position, this.entity.transform.position, Skill) .ToList(); if (withinSkillRange.All(element => element.OccupiedBy != this.entity)) { var target = withinSkillRange .Where(c => !c.IsOccupied) .OrderBy(c => (c.transform.position - this.entity.transform.position).sqrMagnitude) .First(); var sequence = new CommandSequence() .Add(new MoveCommand(this.entity, target.transform.position)) .Add(new CastCommand(Skill, cell)) .Start(); this.interactor.EnterWaitState(() => sequence.IsDone); return; } TargetSkill(Skill, cell); this.interactor.EnterSelectionState(); }
private CharacterPath Run(CommandSequence sequence) { var context = new Type1BuildCharContext(Subroutines, i => { if (!charStringIndexToName.TryGetValue(i, out var name)) { throw new InvalidOperationException($"Tried to retrieve Type 1 charstring by index {i} which did not exist."); } if (glyphs.TryGetValue(name, out var result)) { return(result); } if (!CharStrings.TryGetValue(name, out var charstring)) { throw new InvalidOperationException($"Tried to retrieve Type 1 charstring by index {i} which mapped to name {name} but was not found in the charstrings."); } var path = Run(charstring); glyphs[name] = path; return(path); }); foreach (var command in sequence.Commands) { command.Match(x => context.Stack.Push(x), x => x.Run(context)); } return(context.Path); }
public SetSequences(SetSequencesData data, PlayerControllerInput playerController, IShooter controller) { this.data = data; this.playerController = playerController; this.controller = controller; commands = new List <CommandSequence>(); foreach (CommandSequenceData sequences in data.comboSections) { CommandSequence command = new CommandSequence(sequences, this.playerController, this.controller); command.onCompletedSequence += NextSection; command.onWrongInput += RemoveSequence; commands.Add(command); } commands[0].onStartSequence += StartSection; this.playerController.OnInputPressed += CheckPressedInput; this.controller.OnDestroy += UnsubscribeEvent; currentSection = commands[0]; canExecute = true; cooldownCorutine = CooldownCorutine(); }
public void ComposerSequence_OnComplete_Exception() { // Arrange var panels = new List <IPanel> { new PanelTest() }; var modesController = new ModesController(); var composer = new Composer(panels, modesController); var root = new CommandSequence(); var actual = false; // Act var composerSequence = new ComposerSequence(root, modesController, composer); try { var unused = composerSequence.OnComplete(null); } catch (ArgumentNullException) { actual = true; } // Assert Assert.IsTrue(actual); }
public void Execute() { if (Target != null) { var sequence = new CommandSequence(); IAction action = Events.Prepare <GoTinyAction>(); action.Configure(Target); sequence.Add(action); action = Events.Prepare <ColorCycleAction>(); action.Configure(Target); sequence.Add(action); action = Events.Prepare <GoTinyAction>(); action.Configure(Target); sequence.Add(action); sequence.OnCompleted((ep) => { this.Completed(); }); sequence.Execute(); } else { this.Completed(); } }
public IComposerSequence InSequence() { var root = new CommandSequence(); var sequence = new ComposerSequence(root, modesController, this); return(sequence); }
public IComposerBatch InParallel() { var root = new CommandSequence(); var sequence = new ComposerBatch(root, modesController, this); return(sequence); }
public void ComposerBatch_Constructor_Exception2() { // Arrange var panels = new List <IPanel> { new PanelTest() }; var modesController = new ModesController(); var composer = new Composer(panels, modesController); var root = new CommandSequence(); var actual = false; // Act try { var unused = new ComposerBatch(root, null, composer); } catch (ArgumentNullException) { actual = true; } // Assert Assert.IsTrue(actual); }
private static Type2Glyph Run(CommandSequence sequence) { var context = new Type2BuildCharContext(); var hasRunStackClearingCommand = false; foreach (var command in sequence.Commands) { command.Match(x => context.Stack.Push(x), x => { if (!hasRunStackClearingCommand) { /* * The first stack-clearing operator, which must be one of hstem, hstemhm, vstem, vstemhm, cntrmask, hintmask, hmoveto, vmoveto, * rmoveto, or endchar, takes an additional argument — the width (as described earlier), which may be expressed as zero or one numeric argument. */ hasRunStackClearingCommand = true; switch (x.Name) { case "hstem": case "hstemhm": case "vstemhm": case "vstem": { var oddArgCount = context.Stack.Length % 2 != 0; if (oddArgCount) { context.Width = context.Stack.PopBottom(); } break; } case "hmoveto": case "vmoveto": SetWidthFromArgumentsIfPresent(context, 1); break; case "rmoveto": SetWidthFromArgumentsIfPresent(context, 2); break; case "cntrmask": case "hintmask": case "endchar:": SetWidthFromArgumentsIfPresent(context, 0); break; default: hasRunStackClearingCommand = false; break; } } x.Run(context); }); } return(new Type2Glyph(context.Path, context.Width)); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { var input = ChooseInput(possibleElements); var generated = input.GetNextElement(); CommandSequence.Add(CommandType.Generate, generated, this, input.Molecule.ID); return(generated); }
static void OnDbInitComplete() { DataBaseProxy.Instance.OnInitialized -= OnDbInitComplete; CommandSequence sequence = new CommandSequence(_initStoragesCommands.ToArray()); sequence.OnComplete += () => OnInitComplete.Invoke(); CommandManager.Execute(sequence); }
private PdfPath Run(CommandSequence sequence) { var context = new Type1BuildCharContext(Subroutines, i => { if (!charStringIndexToName.TryGetValue(i, out var name)) { throw new InvalidOperationException($"Tried to retrieve Type 1 charstring by index {i} which did not exist."); } if (glyphs.TryGetValue(name, out var result)) { return(result); } if (!CharStrings.TryGetValue(name, out var charstring)) { throw new InvalidOperationException($"Tried to retrieve Type 1 charstring by index {i} which mapped to name {name} but was not found in the charstrings."); } var path = Run(charstring); glyphs[name] = path; return(path); }, s => { if (glyphs.TryGetValue(s, out var result)) { return(result); } if (!CharStrings.TryGetValue(s, out var charstring)) { throw new InvalidOperationException($"Tried to retrieve Type 1 charstring by name {s} but it was not found in the charstrings."); } var path = Run(charstring); glyphs[s] = path; return(path); }); foreach (var command in sequence.Commands) { if (command.TryGetFirst(out var num)) { context.Stack.Push(num); } else if (command.TryGetSecond(out var lazyCommand)) { lazyCommand.Run(context); } } return(context.Path); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Quintessence), this); AddPendingElement(Element.Air); AddPendingElement(Element.Water); AddPendingElement(Element.Fire); CommandSequence.Add(CommandType.Generate, Element.Earth, this); return(Element.Earth); }
public void Init(CommandSequence _sequence) { percent = 1.0f / _sequence.data.inputDatas.Length; slider.fillAmount = 0; sequence = _sequence; sequence.onCorrectInput += FillSlider; sequence.onResetSequence += EmptySlider; inited = true; }
void NextSection(CommandSequence sequence) { currentSection = commands[currentSectionIndex]; onCompletedSection?.Invoke(this); currentSectionIndex++; if (currentSectionIndex == data.level) { completed = true; onCompletedSet?.Invoke(this); } }
protected void OnDbInitComplete() { _dbProxy.OnInitialized -= OnDbInitComplete; CommandSequence sequence = new CommandSequence(_initStoragesCommands.ToArray()); sequence.OnComplete += () => { OnInitComplete.Invoke(); }; CommandManager.Execute(sequence); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { Used = true; CommandSequence.Add(CommandType.Generate, m_elementSequence.First(), this); foreach (var element in m_elementSequence.Skip(1)) { AddPendingElement(element); } return(m_elementSequence.First()); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Salt), this); CommandSequence.Add(CommandType.Consume, Parent.RequestElement(Element.Salt), this); var firstElement = possibleElements.First(); var secondElement = firstElement == Element.Mors ? Element.Vitae : Element.Mors; CommandSequence.Add(CommandType.Generate, firstElement, this); AddPendingElement(secondElement); return(firstElement); }
protected override void OnExit() { ViewSys.Instance.Close("FightView"); PvpPlayerMgr.Instance.Clear(); GameObjectPool.Instance.Clear(); if (m_cJoinSequence != null) { m_cJoinSequence.OnDestroy(); m_cJoinSequence = null; } //断开连接操作 }
public ComposerComplete( CommandSequence root, IModesController modesController, Composer composer) { Requires.NotNull(root, nameof(root)); Requires.NotNull(modesController, nameof(modesController)); Requires.NotNull(composer, nameof(composer)); this.root = root; this.composer = composer; this.modesController = modesController; }
/// <summary>Rollback the previous cancellation of the latest command.</summary> public void Redo() { if (redoableCommands.Count > 0) { CommandSequence commandSequence = redoableCommands.Pop(); restoreContext(commandSequence.ContextAfter); foreach (ICommand command in commandSequence.Commands) { command.Redo(); } undoableCommands.Add(commandSequence); } }
/// <summary> /// Starting method of the program. /// </summary> /// <param name="args"></param> static void Main(string[] args) { ICalculatePosition calculatePosition = new CalculatePosition(); IRoverPosition roverPosition = new RoverPosition(); ICommandSequence command = new CommandSequence(); Tuple <int, int> gridSize = Tuple.Create(40, 30); //Initial Position is set only for the new Rovers, existing Rovers use last executed position Tuple <int, int, string> initialPosition = Tuple.Create(10, 10, "N"); while (true) { Console.WriteLine("Enter name of the new or existing Rover:"); string roverName = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(roverName)) { Console.WriteLine("Please enter a valid name for Rover:"); roverName = Console.ReadLine().Trim(); } if (roverName.Equals("exit", StringComparison.OrdinalIgnoreCase)) { break; } Console.WriteLine($"Enter the move sequence for the Rover : {roverName}"); string roverMovement = Console.ReadLine().Trim(); while (string.IsNullOrEmpty(roverMovement)) { Console.WriteLine($"Please enter valid move sequence for the Rover : {roverName}"); roverMovement = Console.ReadLine().Trim(); } if (roverMovement.Equals("exit", StringComparison.OrdinalIgnoreCase)) { break; } try { var roverNewPosition = new RobotSpecification(command, roverPosition, calculatePosition).RobotAction(gridSize, roverMovement, roverName, initialPosition); Console.WriteLine($"{roverNewPosition.Item1} {roverNewPosition.Item2} {roverNewPosition.Item3}"); } catch (ArgumentOutOfRangeException) { Console.WriteLine($"The given sequence {roverMovement} for Rover {roverName} is taking it out side of the boundary which is invalid."); } catch (Exception ex) { Console.WriteLine("There is an error during the Rover move. Detailed Exception : " + ex.ToString()); } } Environment.Exit(0); }
/// <summary>Cancel the result of the latest command.</summary> public void Undo() { if (undoableCommands.Count > 0) { CommandSequence commandSequence = undoableCommands[undoableCommands.Count - 1]; restoreContext(commandSequence.ContextBefore); for (int i = commandSequence.Commands.Length - 1; i >= 0; --i) { commandSequence.Commands[i].Undo(); } undoableCommands.RemoveAt(undoableCommands.Count - 1); redoableCommands.Push(commandSequence); } }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { var inputs = new HashSet <Element>(PeriodicTable.Cardinals); while (inputs.Any()) { var element = Parent.RequestElement(inputs); CommandSequence.Add(CommandType.Consume, element, this); inputs.Remove(element); } CommandSequence.Add(CommandType.Generate, Element.Quintessence, this); return(Element.Quintessence); }
private void OnJoinScene(CommandBase obj) { m_cJoinSequence = null; CLog.Log("进入场景成功"); //初始化一些数据 PvpPlayerMgr.Instance.Init(); GlobalEventDispatcher.Instance.AddEvent(GameEvent.StartBattle, OnStartBattle); GlobalEventDispatcher.Instance.AddEvent(GameEvent.PvpPlayerCreate, OnPlayerCreate); //向服务器发送准备完成消息 C2S_GameReady_Data data = new C2S_GameReady_Data(); NetSys.Instance.SendMsg(NetChannelType.Game, (short)PacketOpcode.C2S_GameReady, data); }
protected override void GenerateMetal(Element sourceMetal, Element destMetal) { int diff = PeriodicTable.GetMetalDifference(sourceMetal, destMetal); m_maxSize = Math.Max(m_maxSize, diff); int numAtoms = 1 << diff; for (int i = 1; i < numAtoms; i++) { CommandSequence.Add(CommandType.Consume, Parent.RequestElement(sourceMetal), this); } CommandSequence.Add(CommandType.Generate, destMetal, this); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { foreach (var element in possibleElements) { var stack = m_stacks.FirstOrDefault(s => s.Elements.Any() && s.Elements.First() == element); if (stack != null) { CommandSequence.Add(CommandType.Generate, element, this, stack.ID); stack.UsedPop = true; return(stack.Elements.Pop()); } } throw new SolverException(Invariant($"Can't find any of {String.Join(", ", possibleElements)} in buffer.")); }
public ComposerSequence( CommandSequence root, IModesController modesController, Composer composer) { Requires.NotNull(root, nameof(root)); Requires.NotNull(modesController, nameof(modesController)); Requires.NotNull(composer, nameof(composer)); this.root = root; this.modesController = modesController; this.composer = composer; sequence = new CommandSequence(); root.Add(sequence); }
protected override Element GenerateElement(IEnumerable <Element> possibleElements) { var generated = Parent.RequestElement(new[] { Element.Salt }.Concat(PeriodicTable.Cardinals)); if (generated != Element.Salt) { CommandSequence.Add(CommandType.Consume, generated, this); CommandSequence.Add(CommandType.Generate, Element.Salt, this); } else { PassThrough(generated); } return(Element.Salt); }