@Override public Component getComponent(ImageButton component) { // Create the component ControlComponent controlComponent = gameLoop.createComponent(ControlComponent.class); // Load basic skin for the image component Skin skin = gameAssets.getSkin(); final ImageButtonStyle imageButtonStyle = new ImageButtonStyle(skin.get(component.getStyle(), ImageButtonStyle.class)); com.badlogic.gdx.scenes.scene2d.ui.ImageButton button = new com.badlogic.gdx.scenes.scene2d.ui.ImageButton(imageButtonStyle); controlComponent.setControl(button); // If the imageUp is defined, load it and add it to style if (component.getImageUp() != null) { gameAssets.get( component.getImageUp(), Texture.class, new Assets.AssetLoadedCallback<Texture>() { @Override public void loaded(String fileName, Texture asset) { imageButtonStyle.imageUp = new TextureRegionDrawable(new TextureRegion(asset)); } @Override public void error(String fileName, Class type, Throwable exception) { Gdx.app.error("ImageButtonProcessor", "Impossible to load " + fileName, exception); } }); } // If the imageDown is defined, load it and add it to style if (component.getImageDown() != null) { gameAssets.get( component.getImageDown(), Texture.class, new Assets.AssetLoadedCallback<Texture>() { @Override public void loaded(String fileName, Texture asset) { imageButtonStyle.imageDown = new TextureRegionDrawable(new TextureRegion(asset)); } @Override public void error(String fileName, Class type, Throwable exception) { Gdx.app.error("ImageButtonProcessor", "Impossible to load " + fileName, exception); } }); } return controlComponent; }
@Before public void setUp() { gameAssets = new GameAssets(new MockFiles()); gameLoop = new GameLoop(); gameView = new DefaultGameView(gameLoop); accessor = new Accessor(); operationsFactory = new OperationsFactory(gameLoop, accessor, gameView); variablesManager = new VariablesManager(accessor, operationsFactory); componentLoader = new ComponentLoader(gameAssets, variablesManager); accessor.setComponentLoader(componentLoader); entitiesLoader = new EntitiesLoader(gameLoop, gameAssets, componentLoader); // Mock initialization componentLoader.registerComponentProcessor( MockModelComponent.class, new MockComponentProcessor(gameLoop)); gameAssets.addClassTag("mockeffect", MockEffect.class); gameAssets.addClassTag("mockcomponent", MockModelComponent.class); }
@Override public Component getComponent(Sound sound) { final SoundComponent soundComponent = createComponent(); // files over 150k should be streamed as music; asume ~ 10x compression if (gameAssets.resolve(sound.getUri()).length() < MAX_COMPRESSED_SOUND_SIZE) { gameAssets.get( sound.getUri(), com.badlogic.gdx.audio.Sound.class, new AssetLoadedCallback<com.badlogic.gdx.audio.Sound>() { @Override public void loaded(String fileName, com.badlogic.gdx.audio.Sound asset) { soundComponent.setSound(asset); } @Override public void error(String fileName, Class type, Throwable exception) { Gdx.app.error("SoundProcessor", "Impossible to play sound " + fileName, exception); } }); } else { gameAssets.get( sound.getUri(), com.badlogic.gdx.audio.Music.class, new AssetLoadedCallback<com.badlogic.gdx.audio.Music>() { @Override public void loaded(String fileName, com.badlogic.gdx.audio.Music asset) { soundComponent.setMusic(asset); } @Override public void error(String fileName, Class type, Throwable exception) { Gdx.app.error("SoundProcessor", "Impossible to play music " + fileName, exception); } }); } soundComponent.setConfig(sound); return soundComponent; }