package cn.forevermc.launcher;

import cn.forevermc.launcher.bean.Config;
import cn.forevermc.launcher.ctrl.Main;
import javafx.application.Application;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import com.imyeyu.config.ConfigLoader;
import com.imyeyu.fx.config.BindingsConfig;
import com.imyeyu.fx.ui.TimiFXUI;
import com.imyeyu.inject.InjectApp;
import com.imyeyu.inject.annotation.TimiInjectApplication;
import com.imyeyu.java.TimiJava;
import com.imyeyu.lang.multi.ResourcesMultilingual;

import java.util.UUID;

/**
 * Forever Minecraft 启动器
 *
 * @author 夜雨
 * @since 2022-11-18 15:36
 */
@Slf4j
@TimiInjectApplication
public class ForeverMC {

	public static final String VERSION = "2.2.3";

	@Getter
	private static Config config;

	@Getter
	private static ConfigLoader<Config> configLoader;

	@Getter
	private static InjectApp injectApp;

	public static void main(String[] args) {
		injectApp = new InjectApp(ForeverMC.class);
		try {
			{
				configLoader = BindingsConfig.build("ForeverMC.yaml", Config.class);
				config = configLoader.load();
				if (TimiJava.isEmpty(config.getLauncher().getClientId().get())) {
					config.getLauncher().getClientId().set(UUID.randomUUID().toString());
				}

				ResourcesMultilingual multilingual = TimiFXUI.MULTILINGUAL;
				multilingual.addAll("lang/timi-fx-ui/%s.lang");
				multilingual.addAll("lang/%s.lang");
				multilingual.setActivated(config.getMain().getLanguage().get());

				// 禁止系统 DPI 缩放
				System.setProperty("prism.allowhidpi", "false");
				System.setProperty("glass.win.minHiDPI", "1");
			}
			Application.launch(Main.class);
		} catch (Exception e) {
			log.error("fatal error", e);
		}
	}
}
