private IEnumerator _Fade(float from, float to, Texture img, bool applyBgColor, Color bgColor, float tFadeSec, float tFadeDelaySec, CommandChain cc) { if( applyBgColor ) { m_image.setBackgroundColor(bgColor); } if(img != null) { m_image.image = img; } m_image.opacity = from; m_image.enabled = true; if( tFadeDelaySec > 0.0f ) { yield return new WaitForSeconds(tFadeDelaySec); } float tStart = Time.time; while( Time.time - tStart < tFadeSec ) { float t = (Time.time - tStart) / tFadeSec; float v = (to - from) * t; if( to < from && v <= 0.0f) v = 1.0f + v; // v is negative m_image.opacity = v; yield return new WaitForEndOfFrame(); } m_image.opacity = to; m_image.enabled = to > 0.0f; if(cc) { cc.FireCommand(); } }
public void Execute_ShouldCompleteAction() { var result = 0; var expected = 10; var command = new Command(() => result += expected / 2, () => result -= expected / 2); CommandChain.StartWith(command).Then(command).Execute(); Assert.That(result, Is.EqualTo(expected)); }
internal WalletTransferTransaction(Decimal amount, AbstractWallet sourceWallet, AbstractWallet destinationWallet) : base ( amount, CommandChain .StartWith(new ReduceBalanceCommand(sourceWallet, amount)) .Then(new IncreaseBalanceCommand(destinationWallet, amount)) ) { }
public void Execute_ShouldThrowExceptionAndRevertAction() { var result = 0; var expected = result; var command = new Command(() => result += 2, () => result -= 2); var badCommand = new Command(() => throw new InvalidOperationException(), () => throw new InvalidOperationException()); var chain = CommandChain.StartWith(command).Then(badCommand); Assert.Throws <CommandExecutionException>(chain.Execute); Assert.That(result, Is.EqualTo(expected)); }
public void Revert_ShouldCompleteRevertAction() { var result = 0; var expected = result; var command = new Command(() => result += 2, () => result -= 2); var chain = CommandChain.StartWith(command).Then(command); chain.Execute(); chain.Revert(); Assert.That(result, Is.EqualTo(expected)); }
public void RandomizeCommandChain() { bool chainFull = false; do { //Gets current selection string currentSelection = GetRandomCommand(); //Selection cost variable int selectionCost = 0; //Checks to see what selection it was switch (currentSelection) { case "Rest": selectionCost = 5; break; case "Set Up": selectionCost = 3; break; default: if (knownAttacks.ContainsKey(currentSelection)) { selectionCost = knownAttacks[currentSelection].Cost; } else if (knownTaunts.ContainsKey(currentSelection)) { selectionCost = knownTaunts[currentSelection].Cost; } break; } if (currentTurnCost + selectionCost < MaxTurnCost) { currentTurnCost += selectionCost; CommandChain.Add(currentSelection); } else { chainFull = true; } } while (!chainFull); }
public void VisitCommand(CommandChain chain) { if (!_filters.MatchesAll(chain)) { return; } var matchesDescriptions = _filters.GetDescriptionOfMatches(chain).Join(", "); if( matchesDescriptions == string.Empty) { matchesDescriptions = "(no filters defined)"; } chain.Calls.Each(call => _observer.RecordCallStatus(call, "Visiting: {0}. Matched on filters [{1}]".ToFormat (_reasonToVisit, matchesDescriptions))); _actions.Do(chain); }
public void ExecuteWithRevertExceptions_ShouldThrowExceptionWithCorrectRevertExceptionsAndRevertAction() { var result = 0; var expected = 4; var command = new Command(() => result += 2, () => result -= 2); var badRevertCommand = new Command(() => result += 2, () => throw new InvalidOperationException()); var badCommand = new Command(() => throw new InvalidOperationException(), () => throw new InvalidOperationException()); var chain = CommandChain.StartWith(command).Then(badRevertCommand).Then(badRevertCommand).Then(badCommand); try { chain.Execute(); } catch (CommandChainExecutionException exception) { Assert.That(exception.RevertException.InnerExceptions.Count, Is.EqualTo(2)); } Assert.That(result, Is.EqualTo(expected)); }
// private void _AfterFadeInHowToPlay(object[] args, CommandChain cc) { // Debug.Log ("[Tutorial] _AfterFadeInHowToPlay"); // StartCoroutine(_HowToPlay(cc)); // } private IEnumerator _HowToPlay(CommandChain cc) { Debug.Log ("[Howtoplay] started"); yield return new WaitForSeconds(0.5f); m_bProceed = false; UserInput.GetUserInput().AddToConformCancelEvent(TutorialButton_Proceed,TutorialButton_Proceed); Debug.Log ("[Howtoplay] Waiting for key in"); while ( !m_bProceed ) { yield return new WaitForEndOfFrame(); } UserInput.GetUserInput().RemoveFromConformCancelEvent(TutorialButton_Proceed,TutorialButton_Proceed); Debug.Log ("[Howtoplay] calling fadeout"); GUIManager.GetManager().Fadeout(0.5f, 0.0f, cc); Destroy (gameObject, 1.0f); yield return null; }
public void FadeInImage(Texture img, float tFadeSec, float tFadeDelaySec = 0.0f, CommandChain cc = null) { m_fsControl.FadeInImage(img, tFadeSec, tFadeDelaySec, cc); }
public void ExecuteAndRollback(int numberOfCommands, int falseExecutionIndex) { Fixture fixture = new Fixture(); CommandChain commandChain = new CommandChain(); Assert.IsFalse(commandChain.InputDataSet); Assert.IsFalse(commandChain.WasExecuted); Assert.IsFalse(commandChain.WasRolledBack); Assert.IsNotNull(commandChain.Name); List <string> names = new List <string>(numberOfCommands); List <TestCommand> commands = new List <TestCommand>(numberOfCommands); List <string> executionNames = new List <string>(numberOfCommands); List <string> rollbackNames = new List <string>(numberOfCommands); for (int i = 0; i < numberOfCommands; i++) { string name = fixture.Create <string>(); names.Add(name); bool executionOk = i != falseExecutionIndex; TestCommand command = new TestCommand ( name, () => { executionNames.Add(name); return(executionOk); }, () => { rollbackNames.Add(name); } ); commandChain.Add(command); commands.Add(command); } Assert.IsTrue(commandChain.InputDataSet); Assert.IsFalse(commandChain.WasExecuted); Assert.IsFalse(commandChain.WasRolledBack); Assert.AreEqual(falseExecutionIndex == -1, commandChain.Execute()); Assert.IsTrue(commandChain.WasExecuted); Assert.IsFalse(commandChain.WasRolledBack); Assert.AreEqual(falseExecutionIndex == -1 ? numberOfCommands : falseExecutionIndex + 1, executionNames.Count); Assert.IsTrue(executionNames.SequenceEqual(names.Take(executionNames.Count))); Assert.AreEqual(0, rollbackNames.Count); Assert.AreEqual(executionNames.Count, commands.Take(executionNames.Count).Count(p => p.WasExecuted)); Assert.AreEqual(numberOfCommands - executionNames.Count, commands.Skip(executionNames.Count).Count(p => !p.WasExecuted)); commandChain.Rollback(); Assert.IsTrue(commandChain.WasExecuted); Assert.IsTrue(commandChain.WasRolledBack); Assert.AreEqual(executionNames.Count, rollbackNames.Count); Assert.IsTrue(executionNames.SequenceEqual(((IEnumerable <string>)rollbackNames).Reverse())); Assert.AreEqual(rollbackNames.Count, commands.Take(rollbackNames.Count).Count(p => p.WasRolledBack)); Assert.AreEqual(numberOfCommands - rollbackNames.Count, commands.Skip(rollbackNames.Count).Count(p => !p.WasRolledBack)); }
public void FadeInImage(Texture img, float tFadeSec, float tFadeDelaySec = 0.0f, CommandChain cc = null) { StartCoroutine(_Fade(0.0f,1.0f, img, true, Color.white,tFadeSec,tFadeDelaySec, cc)); }
public void FadeoutFromBlack(float tFadeSec, float tFadeDelaySec = 0.0f, CommandChain cc = null) { m_fsControl.FadeoutFromBlack(tFadeSec, tFadeDelaySec, cc); }
public void FadeoutFromBlack(float tFadeSec, float tFadeDelaySec = 0.0f, CommandChain cc = null) { StartCoroutine(_Fade(1.0f,0.0f, m_white, true, Color.black,tFadeSec,tFadeDelaySec, cc)); }
public void Fadeout(float tFadeSec, float tFadeDelaySec = 0.0f, CommandChain cc = null) { StartCoroutine(_Fade(1.0f,0.0f, null, false, Color.white, tFadeSec,tFadeDelaySec, cc)); }
public static CommandChain UseStaticMessage(this CommandChain commandChain, string message) => commandChain.Use(new LoggerChain(message));
public void RegisterTutorialCommands(CommandChain cc) { cc.InturrptAdd(new CommandChain.Command(_AfterFadeInHowToPlay)); cc.InturrptAdd(new CommandChain.Command(_BeginTutorial)); }
private static void ModifyChain(CommandChain chain, IConfigurationObserver observer) { chain.Calls.Each(c => observer.RecordCallStatus(c, "Wrapping with invocation tracer")); chain.ToArray().Each(node => node.AddBefore(new Wrapper(typeof(InvocationTracer<>).MakeGenericType(chain.EntityType)))); }
public void FireCommand(CommandChain cc) { func(args, cc); }
/// <summary> /// <p>Constructs a food spawning facade which simplifies the process of food spawning. It sets some defaults /// for the various strategies that are available to use. It also:</p> /// <list type="bullet"> /// <item> /// <description>Sets the default food spawning strategy to random scattering.</description> /// </item> /// <item> /// <description>Sets the frequency at which the food may potentially spawn at to 20 ticks.</description> /// </item> /// <item> /// <description>Sets the chance for food to spawn during the spawn tick at 5% chance.</description> /// </item> /// </list> /// All these options may be later modified by the user. /// </summary> /// <param name="arena">Arena where food will be spawned</param> /// <param name="rng">Random number generator to use during the spawning process</param> public FoodSpawningFacade(Arena arena, Random rng) { _arena = arena; _rng = rng; // Construct strategies, provide some defaults. _randomScatterScatterStrategy = new FoodSpawningRandomScatterStrategy(5, _rng); _squareStrategy = new FoodSpawningSquareStrategy(2, _rng); _plusStrategy = new FoodSpawningPlusStrategy(5, _rng); // Set the default chosen strategy to random scattering. _currentStrategy = _randomScatterScatterStrategy; // Set spawning frequency at 20 ticks. SpawnFrequency = 5; // Set chance for food spawn during spawn ticks to 5% SpawnChance = 50.0; // Notify with message to console. // Logger.Instance.LogMessage("Food spawning facade constructed!"); TickLogic = new CommandChain(async next => { // Increment the tick. CurrentTick++; await next(); }) .Use(async next => { // Block chain if not spawnig tick if (CurrentTick % SpawnFrequency != 0) { return; } await next(); }) .Use(async next => { Logger.Instance.LogMessage($"Food spawning facade: current tick {CurrentTick} is spawn tick!"); await next(); }) .Use(async next => { // Roll for chance to spawn food. var roll = _rng.NextDouble() * 100.0; // Block chain if failed spawning. if (roll >= SpawnChance) { Logger.Instance.LogMessage($"Food spawning facade: roll unsuccessful!"); return; } await next(); }) .UseStaticMessage($"Food spawning facade: roll successful! Spawning food...") .Use(next => { // Roll for chance to switch strategy. var roll = _rng.Next(4); // Block chain if failed spawning. if (roll == 0) { SwitchStrategyAtRandom(); } // Spawn food _currentStrategy.Spawn(_arena); // Ending element in the chain. return(Task.CompletedTask); }); }
private void _BeginTutorial(object[] args, CommandChain cc) { Debug.Log ("[Tutorial] BeginTutorial"); GUIManager.GetManager().FadeInImage(m_howToPlay, 0.5f, 1.0f, cc); }
private void _AfterFadeInHowToPlay(object[] args, CommandChain cc) { Debug.Log ("[Tutorial] _AfterFadeInHowToPlay"); StartCoroutine(_HowToPlay(cc)); }