@Test public void testSkipFiringEvent_UnknownEventType() { GameObject producer = gameWorld.addObject(); producer.setType("producer"); GameObject event = gameWorld.addObject(); event.setType("unknown-event"); producer.setDimensions(16, 16); event.setDimensions(16, 16); gameEventRouter.update(event, producer, 0f); gameEventRouter.update(event, producer, 0f); assertThat(eventListener.getEvents()).isEmpty(); }
@Override public void update(GameObject source, GameObject target, float delta) { if (eventFactory == null || identifiers == null || identifiers.length < 1) { return; } if (!isSupported(source)) { return; } if (source.getType().equals(target.getType())) { return; } String producer = extractor.getProducer(source); if (producer != null && !producer.equals(target.getType())) { return; } sourceRect.set(source.getLeft(), source.getTop(), source.getWidth(), source.getHeight()); targetRect.set(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight()); if (sourceRect.contains(targetRect) || sourceRect.overlaps(targetRect)) { if (extractor.isTriggerOnEnter(source)) { if (!enterMap.containsKey(source.getId()) || !enterMap.get(source.getId()).contains(target.getId())) { return; } else { enterMap.get(source.getId()).remove(target.getId()); } } if (eventIds.contains(source.getId())) { gameWorld.remove(source); enterMap.remove(source.getId()); return; } eventIds.add(source.getId()); GameEvent event = eventFactory.create(source, target); if (event != null) { eventManager.publish(event); } else { Gdx.app.log("WARN", "Unable to publish event for " + source + "! Not supported by EventFactory!"); } } else if (extractor.isTriggerOnEnter(source) && target.hasMoved()) { if (!enterMap.containsKey(source.getId())) { enterMap.put(source.getId(), new ArrayList<String>()); } List<String> objects = enterMap.get(source.getId()); if (!objects.contains(target.getId())) { objects.add(target.getId()); } } if (extractor.isSticky(source)) { if (eventIds.contains(source.getId())) { eventIds.remove(source.getId()); } } }
GameEventRouter extends BehaviorAdapter { @Override public void update(GameObject source, GameObject target, float delta) { if (eventFactory == null || identifiers == null || identifiers.length < 1) { return; } if (!isSupported(source)) { return; } if (source.getType().equals(target.getType())) { return; } String producer = extractor.getProducer(source); if (producer != null && !producer.equals(target.getType())) { return; } sourceRect.set(source.getLeft(), source.getTop(), source.getWidth(), source.getHeight()); targetRect.set(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight()); if (sourceRect.contains(targetRect) || sourceRect.overlaps(targetRect)) { if (extractor.isTriggerOnEnter(source)) { if (!enterMap.containsKey(source.getId()) || !enterMap.get(source.getId()).contains(target.getId())) { return; } else { enterMap.get(source.getId()).remove(target.getId()); } } if (eventIds.contains(source.getId())) { gameWorld.remove(source); enterMap.remove(source.getId()); return; } eventIds.add(source.getId()); GameEvent event = eventFactory.create(source, target); if (event != null) { eventManager.publish(event); } else { Gdx.app.log("WARN", "Unable to publish event for " + source + "! Not supported by EventFactory!"); } } else if (extractor.isTriggerOnEnter(source) && target.hasMoved()) { if (!enterMap.containsKey(source.getId())) { enterMap.put(source.getId(), new ArrayList<String>()); } List<String> objects = enterMap.get(source.getId()); if (!objects.contains(target.getId())) { objects.add(target.getId()); } } if (extractor.isSticky(source)) { if (eventIds.contains(source.getId())) { eventIds.remove(source.getId()); } } } }
GameEventRouter extends BehaviorAdapter { @Override public void update(GameObject source, GameObject target, float delta) { if (eventFactory == null || identifiers == null || identifiers.length < 1) { return; } if (!isSupported(source)) { return; } if (source.getType().equals(target.getType())) { return; } String producer = extractor.getProducer(source); if (producer != null && !producer.equals(target.getType())) { return; } sourceRect.set(source.getLeft(), source.getTop(), source.getWidth(), source.getHeight()); targetRect.set(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight()); if (sourceRect.contains(targetRect) || sourceRect.overlaps(targetRect)) { if (extractor.isTriggerOnEnter(source)) { if (!enterMap.containsKey(source.getId()) || !enterMap.get(source.getId()).contains(target.getId())) { return; } else { enterMap.get(source.getId()).remove(target.getId()); } } if (eventIds.contains(source.getId())) { gameWorld.remove(source); enterMap.remove(source.getId()); return; } eventIds.add(source.getId()); GameEvent event = eventFactory.create(source, target); if (event != null) { eventManager.publish(event); } else { Gdx.app.log("WARN", "Unable to publish event for " + source + "! Not supported by EventFactory!"); } } else if (extractor.isTriggerOnEnter(source) && target.hasMoved()) { if (!enterMap.containsKey(source.getId())) { enterMap.put(source.getId(), new ArrayList<String>()); } List<String> objects = enterMap.get(source.getId()); if (!objects.contains(target.getId())) { objects.add(target.getId()); } } if (extractor.isSticky(source)) { if (eventIds.contains(source.getId())) { eventIds.remove(source.getId()); } } } GameEventRouter(GameEventManager eventManager, GameWorld gameWorld, GameEventInfoExtractor extractor); }
GameEventRouter extends BehaviorAdapter { @Override public void update(GameObject source, GameObject target, float delta) { if (eventFactory == null || identifiers == null || identifiers.length < 1) { return; } if (!isSupported(source)) { return; } if (source.getType().equals(target.getType())) { return; } String producer = extractor.getProducer(source); if (producer != null && !producer.equals(target.getType())) { return; } sourceRect.set(source.getLeft(), source.getTop(), source.getWidth(), source.getHeight()); targetRect.set(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight()); if (sourceRect.contains(targetRect) || sourceRect.overlaps(targetRect)) { if (extractor.isTriggerOnEnter(source)) { if (!enterMap.containsKey(source.getId()) || !enterMap.get(source.getId()).contains(target.getId())) { return; } else { enterMap.get(source.getId()).remove(target.getId()); } } if (eventIds.contains(source.getId())) { gameWorld.remove(source); enterMap.remove(source.getId()); return; } eventIds.add(source.getId()); GameEvent event = eventFactory.create(source, target); if (event != null) { eventManager.publish(event); } else { Gdx.app.log("WARN", "Unable to publish event for " + source + "! Not supported by EventFactory!"); } } else if (extractor.isTriggerOnEnter(source) && target.hasMoved()) { if (!enterMap.containsKey(source.getId())) { enterMap.put(source.getId(), new ArrayList<String>()); } List<String> objects = enterMap.get(source.getId()); if (!objects.contains(target.getId())) { objects.add(target.getId()); } } if (extractor.isSticky(source)) { if (eventIds.contains(source.getId())) { eventIds.remove(source.getId()); } } } GameEventRouter(GameEventManager eventManager, GameWorld gameWorld, GameEventInfoExtractor extractor); void setEventFactory(GameEventFactory eventFactory); @Override void update(GameObject source, GameObject target, float delta); }
GameEventRouter extends BehaviorAdapter { @Override public void update(GameObject source, GameObject target, float delta) { if (eventFactory == null || identifiers == null || identifiers.length < 1) { return; } if (!isSupported(source)) { return; } if (source.getType().equals(target.getType())) { return; } String producer = extractor.getProducer(source); if (producer != null && !producer.equals(target.getType())) { return; } sourceRect.set(source.getLeft(), source.getTop(), source.getWidth(), source.getHeight()); targetRect.set(target.getLeft(), target.getTop(), target.getWidth(), target.getHeight()); if (sourceRect.contains(targetRect) || sourceRect.overlaps(targetRect)) { if (extractor.isTriggerOnEnter(source)) { if (!enterMap.containsKey(source.getId()) || !enterMap.get(source.getId()).contains(target.getId())) { return; } else { enterMap.get(source.getId()).remove(target.getId()); } } if (eventIds.contains(source.getId())) { gameWorld.remove(source); enterMap.remove(source.getId()); return; } eventIds.add(source.getId()); GameEvent event = eventFactory.create(source, target); if (event != null) { eventManager.publish(event); } else { Gdx.app.log("WARN", "Unable to publish event for " + source + "! Not supported by EventFactory!"); } } else if (extractor.isTriggerOnEnter(source) && target.hasMoved()) { if (!enterMap.containsKey(source.getId())) { enterMap.put(source.getId(), new ArrayList<String>()); } List<String> objects = enterMap.get(source.getId()); if (!objects.contains(target.getId())) { objects.add(target.getId()); } } if (extractor.isSticky(source)) { if (eventIds.contains(source.getId())) { eventIds.remove(source.getId()); } } } GameEventRouter(GameEventManager eventManager, GameWorld gameWorld, GameEventInfoExtractor extractor); void setEventFactory(GameEventFactory eventFactory); @Override void update(GameObject source, GameObject target, float delta);  }