com.codeheadsystems.gamelib.core.GameLauncher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gamelib-core Show documentation
Show all versions of gamelib-core Show documentation
Dagger support for libGDX for quick project setup.
/*
* Copyright (c) 2023. Ned Wolpert
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.codeheadsystems.gamelib.core;
import static com.codeheadsystems.gamelib.core.util.LoggerHelper.logger;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.utils.Logger;
import com.codeheadsystems.gamelib.core.manager.DisposableManager;
import com.codeheadsystems.gamelib.core.manager.ResizeManager;
import com.codeheadsystems.gamelib.core.screen.LoadingScreen;
import com.codeheadsystems.gamelib.core.util.GameListener;
import dagger.Lazy;
import java.util.Set;
import javax.inject.Inject;
import javax.inject.Singleton;
/**
* Use this as the main game for libGDX.
*/
@Singleton
public class GameLauncher extends Game {
private static final Logger LOGGER = logger(GameLauncher.class);
/**
* This has to be lazy. The rest of the GDX app needs to be initialized before we get the loading screen.
* By making this lazy, the app is initialized later.
*/
private final Lazy loadingScreen;
private final Lazy> gameListeners;
private final Lazy resizeManager;
private final Lazy disposableManager;
private final AssetManager assetManager;
/**
* Instantiates a new Game launcher.
*
* @param loadingScreen the loading screen
* @param gameListeners the game listeners
* @param resizeManager the resize manager
* @param disposableManager the disposable manager
* @param assetManager the asset manager
*/
@Inject
public GameLauncher(final Lazy loadingScreen,
final Lazy> gameListeners,
final Lazy resizeManager,
final Lazy disposableManager,
final AssetManager assetManager) {
this.loadingScreen = loadingScreen;
this.gameListeners = gameListeners;
this.resizeManager = resizeManager;
this.assetManager = assetManager;
this.disposableManager = disposableManager;
}
@Override
public void create() {
gameListeners.get().forEach(l -> l.setGame(this));
final LoadingScreen screen = loadingScreen.get();
LOGGER.info("Setting screen: " + screen);
setScreen(screen);
}
@Override
public void resize(final int width, final int height) {
LOGGER.info("resize: X:" + width + " Y:" + height);
resizeManager.get().resize(width, height);
super.resize(width, height);
}
/**
* We're dead.... remove all the assets.
*/
@Override
public void dispose() {
LOGGER.info("Disposing...");
super.dispose();
assetManager.dispose();
disposableManager.get().dispose();
LOGGER.info("Disposed");
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy