public void BatchDispatchTriggeringBySizeTest() { var dispatcher = new EventDispatcher(_logFactory, "testBC"); var handler = new EventHandlerWithBatchSupport(); dispatcher.Wire( "testBC", handler, 3, 0, typeof(FakeBatchContext), h => ((EventHandlerWithBatchSupport)h).OnBatchStart(), (h, c) => ((EventHandlerWithBatchSupport)h).OnBatchFinish((FakeBatchContext)c)); dispatcher.Dispatch("testBC", new[] { Tuple.Create <object, AcknowledgeDelegate>(new DateTime(2016, 3, 1), (delay, acknowledge) => { Tuple.Create(delay, acknowledge); }), Tuple.Create <object, AcknowledgeDelegate>(new DateTime(2016, 3, 2), (delay, acknowledge) => { }), }); Assert.AreEqual(0, handler.HandledEvents.Count, "Events were delivered before batch is filled"); dispatcher.Dispatch("testBC", new[] { Tuple.Create <object, AcknowledgeDelegate>(new DateTime(2016, 3, 3), (delay, acknowledge) => { }) }); Assert.AreEqual(3, handler.HandledEvents.Count, "Not all events were delivered"); Assert.True(handler.BatchStartReported, "Batch start callback was not called"); Assert.True(handler.BatchFinishReported, "Batch after apply callback was not called"); Assert.That( handler.HandledEvents.Select(t => t.Item2), Is.EqualTo(new object[] { handler.LastCreatedBatchContext, handler.LastCreatedBatchContext, handler.LastCreatedBatchContext }), "Batch context was not the same for all evants in the batch"); }
// プレイヤー関連のイベント受信用 public void OnNotify(Observable <PlayerEvent> observer, PlayerEvent e) { EventDispatcher dispatcher = new EventDispatcher(e); dispatcher.Dispatch <OnSpawnPlayerEvent>(UpdateSurvivingPlayersTextUI); dispatcher.Dispatch <OnDownPlayerEvent>(UpdateSurvivingPlayersTextUI); }
private void RestoreSettings() { _volume.value = _initialVolume; _mode.value = _initialMode; _dayMode.value = _initialDayMode; _volumeChangeDispatcher.Dispatch(); }
public void OnEvent(Event e) { AXProfiler.Capture(() => { var eventDispatcher = new EventDispatcher(e); eventDispatcher.Dispatch <MouseScrollEvent>(OnMouseScroll); eventDispatcher.Dispatch <WindowResizeEvent>(OnWindowResize); }); }
public void handles_play_after_paused_logic_keep_quite() { spotify.SetupGet(m => m.IsPlaying).Returns(false); EventDispatcher dsp1 = new EventDispatcher(new[] { spotify.Object }); dsp1.Dispatch(JukeboxCommand.Pause); spotify.SetupGet(m => m.IsPlaying).Returns(false); dsp1.Dispatch(JukeboxCommand.PlayAfterPaused); spotify.Verify(m => m.PerformAction(JukeboxCommand.Play), Times.Never()); }
// プレイヤー関連イベント受信用 public void OnNotify(Observable <PlayerEvent> observer, PlayerEvent e) { EventDispatcher dispatcher = new EventDispatcher(e); if (RoomManager.IsHost) { dispatcher.Dispatch <OnAllPlayerSpawnCompletedEvent>(OnAllPlayerSpawnCompleted); } dispatcher.Dispatch <OnDownPlayerEvent>(OnDownPlayer); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.TryGetComponent(out PlayerDropkick pd)) { if (pd.TriggerDropkick(this, collision.contacts[0].point)) { ed.Dispatch(new DropkickEvent(pd, pd.settings.onDropkickEvent, ed)); } } }
public void handles_play_after_paused_logic_start_playing() { itunes.SetupGet(m => m.IsPlaying).Returns(true); EventDispatcher dsp1 = new EventDispatcher(new[] { itunes.Object }); dsp1.Dispatch(JukeboxCommand.Pause); itunes.SetupGet(m => m.IsPlaying).Returns(false); dsp1.Dispatch(JukeboxCommand.PlayAfterPaused); itunes.Verify(m => m.PerformAction(JukeboxCommand.Play), Times.Once()); }
public void ignores_inactive_jukeboxes() { itunes.SetupGet(m => m.IsPlaying).Returns(true); itunes.SetupGet(m => m.IsActive).Returns(false); EventDispatcher dsp1 = new EventDispatcher(new[] { itunes.Object }); dsp1.Dispatch(JukeboxCommand.Pause); dsp1.Dispatch(JukeboxCommand.Play); dsp1.Dispatch(JukeboxCommand.NextTrack); itunes.Verify(m => m.PerformAction(It.IsAny <JukeboxCommand>()), Times.Never()); }
public int StartBattle(IEnumerable <Player> participants) { lock (_lock) { var battleId = _battleRepository.GetNextId(); var battle = new Battle(battleId, _playerActivity, participants); _battleRepository.Save(battle); _eventDispatcher.Dispatch(battle); return(battleId); } }
public void Dispatch_PassNullAsOrEmptyEventArray_ShouldNotThrowException() { // Arrange var serviceScopeFactoryMock = new Mock <IServiceScopeFactory>(); var dispatcher = new EventDispatcher <object>(serviceScopeFactoryMock.Object); // Act / Assert Func <Task> action = () => dispatcher.Dispatch(null, default); action.Should().NotThrow(); action = () => dispatcher.Dispatch(Array.Empty <object>(), default); action.Should().NotThrow(); }
private void OnTrackingFound() { if (gameObjects != null) { for (int i = 0; i < gameObjects.Length; i++) { gameObjects[i].SetActive(true); } } _markerVisible = true; _onTrackerStatusModified.Dispatch(true, this); Debug.Log("Trackable " + _trackableBehaviour.TrackableName + " found"); }
public void ClearEventsTest() { EventDispatcher eventManager = new EventDispatcher(); EventListener listener = new EventListener(); eventManager.RegisterListener <Event1>(listener); eventManager.Raise(new Event1(new Entity(0, 0), 10)); eventManager.Dispatch(); Assert.AreEqual(10, listener.ValueSum); eventManager.Dispatch(); Assert.AreEqual(10, listener.ValueSum); }
public void uses_last_jukebox_only_if_still_available() { itunes.SetupGet(m => m.IsPlaying).Returns(true); EventDispatcher dsp1 = new EventDispatcher(new[] { itunes.Object, spotify.Object }); dsp1.Dispatch(JukeboxCommand.Pause); itunes.SetupGet(m => m.IsPlaying).Returns(false); itunes.SetupGet(m => m.IsAvailable).Returns(false); dsp1.Dispatch(JukeboxCommand.Play); itunes.Verify(m => m.PerformAction(JukeboxCommand.Pause), Times.Once()); spotify.Verify(m => m.PerformAction(JukeboxCommand.Play), Times.Once()); }
/// <summary> /// Loads a scene by its index. If <paramref name="index"/> is negative, this method will load the scene /// with the index "currentSceneIndex - <paramref name="index"/>," or /// "currentSceneIndex + |<paramref name="index"/>|." /// </summary> /// <param name="index">The index of the scene to load.</param> public void LoadScene(int index) { //If index is positive or zero, simply use index. Otherwise, go forward by that many indices. int indexToLoad = index >= 0 ? index : SceneManager.GetActiveScene().buildIndex - index; EventDispatcher.Dispatch(new EventDefiner.MenuExit(indexToLoad)); }
/// <summary> /// Swaps to another menu and sets the selection to the first selectable object in that menu. /// <para>Can optionally be set to not trigger a flash, or set to select a particular GameObject /// after swapping.</para> /// </summary> /// <param name="destination">The menu to swap to.</param> /// <param name="shouldFlash">Whether a flash transition should happend during the swap.</param> /// <param name="objToSelect">The object to select after swapping. Defaults to the first selectable /// child of <paramref name="destination"/>.</param> public void SwapMenu(GameObject destination, bool shouldFlash = true, GameObject objToSelect = null) { //If we don't have a reference to any menu in currentMenu, get one. //If currentMenu was assigned, assign defaultMenu as well. if (GetCurrentMenu()) { defaultMenu = currentMenu; } //If destination isn't null... if (destination) { EventDispatcher.Dispatch(new EventDefiner.MenuSwap(shouldFlash)); //Make destination active, and the current menu inactive. Destination is now the current menu. destination.SetActive(true); currentMenu.SetActive(false); currentMenu = destination; //If objToSelect is not null, select it. If it is, get the first selectable in current menu and //select that. if (EventSyst) { EventSyst.SetSelectedGameObject(objToSelect ? objToSelect : GetFirstSelectable(currentMenu)); } } }
private void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { _roadTriggerEventDispatcher.Dispatch(); } }
private async Task <TReadModel> GenerateFromEventStreamAsync(Guid aggregateRootId, CancellationToken cancellationToken, DateTime pointInTime = default(DateTime)) { var eventStream = await _eventStreamReader.GetEventStreamAsync(aggregateRootId, cancellationToken); var domainEvents = pointInTime == default(DateTime) ? eventStream.DomainEvents : eventStream.DomainEvents.TakeWhile(e => e.UtcTimeStamp <= pointInTime).ToArray(); if (domainEvents.Length == 0) { throw new AggregateRootException($"Aggregate root {aggregateRootId} exists but event stream does not include any domain events."); } else if (!(domainEvents[0] is IAggregateRootCreatedEvent)) { throw new AggregateRootException($"Expected first event of aggregate root {aggregateRootId} to be of type {nameof(IAggregateRootCreatedEvent)}"); } ReadModel = new TReadModel(); foreach (var domainEvent in domainEvents) { EventDispatcher.Dispatch(domainEvent as TAggregateRootEventInterface); } var result = ReadModel; ReadModel = null; return(result); }
private void OnCollisionEnter(Collision collision) { if (canVoidOut && collision.gameObject.CompareTag("Player")) { EventDispatcher.Dispatch(new EventDefiner.LevelEnd(false)); } }
private void OnTriggerEnter(Collider other) { if (canVoidOut && other.CompareTag("Player")) { EventDispatcher.Dispatch(new EventDefiner.LevelEnd(false)); } }
public void GetMoveInput(InputAction.CallbackContext context) { //Get the direction of move input, then assign that direction to the X and Z of a vector3. Vector2 direction = context.ReadValue <Vector2>(); EventDispatcher.Dispatch(new EventDefiner.MoveInput(new Vector3(direction.x, 0, direction.y))); }
private int OnMusicDelivery(IntPtr sessionHandle, IntPtr audioFormatHandle, IntPtr frames, int numFrames) { if (numFrames == 0) { return(0); } if (frames == IntPtr.Zero) { return(0); } AudioFormat audioFormat = LibSpotify.AudioFormatFromHandle(audioFormatHandle); int n = numFrames * FrameSize(audioFormat); byte[] pcmData = new byte[n]; Marshal.Copy(frames, pcmData, 0, n); EventDispatcher.Dispatch(this, sessionHandle, MusicDelivered, new MusicDeliveryEventArgs(pcmData, audioFormat)); pcmData = null; return(numFrames); }
private void OnDestroy() { //Set pause state to false when destroyed, such as when a new scene is loaded. EventDispatcher.Dispatch(new EventDefiner.PauseStateChange(false)); EventDispatcher.RemoveListener <EventDefiner.PauseStateChange>(OnPauseStateChanged); }
public void ChangeGamestate(GameState state) { if (gameState == state) { return; } EventDispatcher.Dispatch(GameEvent.GE_GAMESTATE_CHANGE, gameState, state); gameState = state; switch (gameState) { case GameState.PreGame: playedTime = 0; score = 0; HUDManager.instance.ShowBeginGame(); HUDManager.instance.UpdateScore(); HUDManager.instance.UpdateHighScore(); break; case GameState.InGame: hardMode = GetHardMode(); board.StartGame(); break; case GameState.EndGame: board.EndGame(); HUDManager.instance.ShowEndGame(); break; default: break; } }
private void OnTriggerEnter(Collider other) { if (!levelEnding && other.CompareTag("Player")) { EventDispatcher.Dispatch(new EventDefiner.LevelEnd(true)); } }
/// <summary> /// Turns the record cooldown on or off, and does other relevant logic. /// </summary> /// <param name="onCooldown"></param> private void SetCooldown(bool onCooldown) { //Set the cooldown status accordingly and reset the cooldownTimer. onRecordCooldown = onCooldown; cooldownTimer = 0f; //Set the outer core's scale to the inner core if on cooldown. Otherwise, set it to its normal scale. //This is so the outer core can grow during cooldown. outerCore.localScale = onCooldown ? innerCoreScale : outerCoreScale; //Make the outer core transparent if on cooldown. Otherwise, make it normally colored. //This is so the outer core fades in during cooldown. outerCoreRend.material.color = onCooldown ? Color.clear : outerCoreColor; //Enable the recovery burst object, which will let out a burst of particles and disable itself if (!onCooldown) { recoveryBurst.SetActive(true); } //Pause everything for a short time after rewinding time else { rewindPause = true; Time.timeScale = 0; EventDispatcher.Dispatch(new EventDefiner.Rewind(rewindPauseTime)); } }
void IntroSequenceFinished() { Debug.Log("IntroSequenceFinished"); _running = false; _introSequenceFinished.Dispatch(); introCamera.gameObject.SetActive(false); }
public void Dispatch_WithSubscriber_WillDispatchToTheSubscriber() { // Given var subscriber = new Mock <IEventSubscriber>(); subscriber.Setup(x => x.GetSubscribedEvents()) .Returns(new Dictionary <string, short>() { { "dummy", 0 } }); var subscribers = new List <IEventSubscriber>() { subscriber.Object }; var container = new Mock <IContainer>(); container.Setup(x => x.GetAllInstances <IEventSubscriber>()) .Returns(subscribers); var dispatcher = new EventDispatcher(container.Object); // When dispatcher.Scan(); dispatcher.Dispatch(new DummyEvent()); // Then subscriber.Verify(x => x.OnEvent(It.IsAny <DummyEvent>()), Times.Once); }
void Dispatch(EventDispatcher e) { if (e.isValid) { e.Dispatch(); } }
private void CheckForReset() { if (Input.GetKeyDown(KeyCode.R)) { EventDispatcher.Dispatch(new EventDefiner.LevelEnd(false)); } }