summaryrefslogtreecommitdiff
path: root/core/src/kz/ilotterytea/maxon/MaxonGame.java
blob: 63de3e87ee6debf4ff712baf0599fb64d136076d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package kz.ilotterytea.maxon;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import kz.ilotterytea.maxon.localization.LocalizationManager;
import kz.ilotterytea.maxon.pets.PetManager;
import kz.ilotterytea.maxon.screens.SplashScreen;
import kz.ilotterytea.maxon.utils.GameUpdater;

public class MaxonGame extends Game {
	public SpriteBatch batch;
	public AssetManager assetManager;
	public Preferences prefs;

	private LocalizationManager locale;
	private PetManager petManager;

	private DiscordActivityClient discordActivityClient;

	private static MaxonGame instance;

	public static MaxonGame getInstance() {
		if (instance == null) {
			instance = new MaxonGame();
		}
		return instance;
	}

	public PetManager getPetManager() {
		return petManager;
	}

	public DiscordActivityClient getDiscordActivityClient() {
		return discordActivityClient;
	}

	public LocalizationManager getLocale() {
		return locale;
	}

	public void setLocale(LocalizationManager locale) {
		this.locale = locale;
	}

	@Override
	public void create () {
		// Check the latest version
		new GameUpdater().checkLatestUpdate();

		batch = new SpriteBatch();
		prefs = Gdx.app.getPreferences(MaxonConstants.GAME_APP_PACKAGE);
		locale = new LocalizationManager(Gdx.files.internal("i18n/" + prefs.getString("lang", "en_us") + ".json"));

		Gdx.graphics.setVSync(prefs.getBoolean("vsync", true));

		if (prefs.getBoolean("fullscreen", false)) {
			Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
		} else if (
				prefs.contains("width") ||
				prefs.contains("height")
		) {
			int width = prefs.getInteger("width", 800);

			if (width < 800) {
				width = 800;
				prefs.putInteger("width", width);
			}

			int height = prefs.getInteger("height", 600);

			if (height < 600) {
				height = 600;
				prefs.putInteger("height", height);
			}

			prefs.flush();
			Gdx.graphics.setWindowedMode(width, height);
		}

		assetManager = new AssetManager();
		petManager = new PetManager(assetManager);

		discordActivityClient = new DiscordActivityClient();

		this.setScreen(new SplashScreen());
	}

	@Override
	public void dispose () {
		batch.dispose();
		for (String name : assetManager.getAssetNames()) {
			assetManager.unload(name);
		}
		assetManager.dispose();
		discordActivityClient.dispose();
	}
}