private <T extends ControlWidget> void initialiseOverlay(T overlay, ResourceUrn screenUri) { InjectionHelper.inject(overlay); overlay.initialise(); }
private void initialiseSystem(ComponentSystem system) { InjectionHelper.inject(system); if (console != null) { MethodCommand.registerAvailable(system, console, context); } try { system.initialise(); } catch (RuntimeException e) { logger.error("Failed to initialise system {}", system, e); } }
public <T extends ControlWidget> T addHUDElement(ResourceUrn urn, T widget, Rect2f region) { InjectionHelper.inject(widget); widget.onOpened(); elementsLookup.put(urn, new HUDElement(widget, region)); return widget; }
@Override public boolean step() { BlockManager blockManager = context.get(BlockManager.class); for (BlockFamily blockFamily : blockManager.listRegisteredBlockFamilies()) { InjectionHelper.inject(blockFamily, context); } return true; }
@SuppressWarnings({"rawtypes", "unchecked"}) private static void registerTypeHandlers(Context context, TypeSerializationLibrary library, ModuleEnvironment environment) { for (Class<? extends TypeHandler> handler : environment.getSubtypesOf(TypeHandler.class)) { RegisterTypeHandler register = handler.getAnnotation(RegisterTypeHandler.class); if (register != null) { Optional<Type> opt = GenericsUtil.getTypeParameterBindingForInheritedClass(handler, TypeHandler.class, 0); if (opt.isPresent()) { TypeHandler instance = InjectionHelper.createWithConstructorInjection(handler, context); InjectionHelper.inject(instance, context); library.add((Class) opt.get(), instance); } } } } }
private void addAction(ActionNode node, Action action) { action.setId(nextId); nextId++; node.setAction(action); InjectionHelper.inject(action); action.setup(); }
InjectionHelper.inject(result); if (result.getURI() == null) { throw new Exception("Family Is missng a BlockUri");
InjectionHelper.inject(result);
private void initialiseScreen(CoreScreenLayer screen, ResourceUrn uri) { InjectionHelper.inject(screen); screen.setId(uri.toString()); screen.setManager(this); screen.initialise(); }
/** * @param uri uri of the world generator to create. * @param context that will be used to inject teh world generator. * @param environment to be searched for the world generator class. * @return a new world generator with the specified uri. */ public static WorldGenerator createWorldGenerator(SimpleUri uri, Context context, ModuleEnvironment environment) throws UnresolvedWorldGeneratorException { for (Class<?> generatorClass : environment.getTypesAnnotatedWith(RegisterWorldGenerator.class)) { RegisterWorldGenerator annotation = generatorClass.getAnnotation(RegisterWorldGenerator.class); SimpleUri generatorUri = new SimpleUri(environment.getModuleProviding(generatorClass), annotation.id()); if (generatorUri.equals(uri)) { WorldGenerator worldGenerator = loadGenerator(generatorClass, generatorUri); InjectionHelper.inject(worldGenerator, context); return worldGenerator; } } throw new UnresolvedWorldGeneratorException("Unable to resolve world generator '" + uri + "' - not found"); }
@Before public void setup() throws Exception { this.system = new VisualCharacterSystem(); Context context = new ContextImpl(); this.localPlayer = Mockito.mock(LocalPlayer.class); context.put(LocalPlayer.class, localPlayer); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return clientEntityReturnedByLocalPlayer; } }).when(localPlayer).getClientEntity(); this.entityManager = Mockito.mock(EntityManager.class); Mockito.doReturn(Mockito.mock(EntityBuilder.class)).when(entityManager).newBuilder(); context.put(EntityManager.class, this.entityManager); InjectionHelper.inject(system, context); system.setCreateAndAttachVisualEntityStrategy((entityBuilder, characterEntity) -> Mockito.mock(EntityRef.class)); }
@Test public void testInjectUnavailableObject() { InjectionHelper.share(serviceA); // InjectionHelper.share(serviceB); FieldInjectionAB fieldInjectionAB = new FieldInjectionAB(); InjectionHelper.inject(fieldInjectionAB); assertThat(fieldInjectionAB.getServiceA(), is(serviceA)); assertThat(fieldInjectionAB.getServiceB(), is(nullValue())); }
@Test public void testDefaultFieldInjection() { InjectionHelper.share(serviceA); InjectionHelper.share(serviceB); //no default constructor required FieldInjectionAB fieldInjectionAB = new FieldInjectionAB(); InjectionHelper.inject(fieldInjectionAB); assertThat(fieldInjectionAB.getServiceA(), is(serviceA)); assertThat(fieldInjectionAB.getServiceB(), is(serviceB)); }
@Before public void setUp() { Context context = new ContextImpl(); setUpLocalPlayer(context); setUpDisplayDevice(context); setUpBindsManager(context); setUpTargetSystem(context); context.put(Time.class, new TimeSystem()); inputSystem = new InputSystem(); InjectionHelper.inject(inputSystem, context); testKeyboard = new TestKeyboard(); inputSystem.setKeyboardDevice(testKeyboard); clientEntityKeyEvents = new ArrayList<>(); characterEntityKeyEvents = new ArrayList<>(); }
public NUIManagerInternal(CanvasRenderer renderer, Context context) { this.context = context; this.hudScreenLayer = new HUDScreenLayer(); InjectionHelper.inject(hudScreenLayer, context); this.canvas = new CanvasImpl(this, context, renderer); this.keyboard = context.get(InputSystem.class).getKeyboard(); this.mouse = context.get(InputSystem.class).getMouseDevice(); this.renderingConfig = context.get(Config.class).getRendering(); this.uiScale = this.renderingConfig.getUiScale() / 100f; this.renderingConfig.subscribe(RenderingConfig.UI_SCALE, this); this.display = context.get(DisplayDevice.class); this.assetManager = context.get(AssetManager.class); refreshWidgetsLibrary(); TranslationSystem system = context.get(TranslationSystem.class); system.subscribe(proj -> invalidate()); // All UIElement instances are disposed so that they are not automatically reloaded // by the AssetTypeManager. Reloading would not trigger the initialise() method // and UI screens should be created on demand anyway. ModuleAwareAssetTypeManager maaTypeManager = context.get(ModuleAwareAssetTypeManager.class); maaTypeManager.getAssetType(UIElement.class).ifPresent(type -> type.disposeAll()); }