package net.clgd.ccemux;

import java.awt.SplashScreen;
import java.nio.file.Path;
import java.util.AbstractMap.SimpleEntry;
import java.util.stream.Collectors;
import java.util.HashMap;
import java.util.List;

import org.slf4j.Logger;
import org.squiddev.cctweaks.lua.lib.ApiRegister;

import net.clgd.ccemux.emulation.CCEmuX;
import net.clgd.ccemux.emulation.EmulatedComputer;
import net.clgd.ccemux.rendering.Renderer;
import net.clgd.ccemux.rendering.RenderingMethod;

public class Runner {
	public static void launch(Logger logger, Config config, List<Path> saveDirs, int count) {
		CCEmuX emu = new CCEmuX(logger, config);
		HashMap<EmulatedComputer, List<Renderer>> computers = new HashMap<>();

		for (int i = 0; i < count; i++) {
			EmulatedComputer ec = emu.createEmulatedComputer(-1, saveDirs.size() > 0 ? saveDirs.remove(0) : null);
			computers.put(ec, emu.conf.getRenderer().stream().map(r -> RenderingMethod.create(r, ec))
					.collect(Collectors.toList()));
		}
		
		if (SplashScreen.getSplashScreen() != null) SplashScreen.getSplashScreen().close();
		
		computers.forEach((ec, r) -> r.forEach(r2 -> r2.setVisible(true)));
		
		emu.run();
	}

	public static void launchCCTweaks(Logger logger, Config config, List<Path> saveDirs, int count) {
		config.addListener(new Runnable() {
			@Override
			public void run() {
				config.entrySet().stream().map(e -> new SimpleEntry<>((String) e.getKey(), (String) e.getValue()))
						.filter(e -> e.getKey().startsWith("cctweaks"))
						.forEach(e -> {
							System.setProperty(e.getKey(), e.getValue());
							logger.debug("Setting CCTweaks option {} -> {}", e.getKey(), e.getValue());
						});
			}
		});

		org.squiddev.patcher.Logger.instance = new org.squiddev.patcher.Logger() {
			@Override
			public void doDebug(String message) {
				logger.debug(message);
			}

			@Override
			public void doWarn(String message) {
				logger.warn(message);
			}

			@Override
			public void doError(String message, Throwable t) {
				logger.error(message, t);
			}
		};

		ApiRegister.init();

		launch(logger, config, saveDirs, count);
	}
}

@@ -225,24 +225,79 @@
 f4j.Logger;%0A
+import org.squiddev.cctweaks.lua.ConfigPropertyLoader;%0A
 import org.s
@@ -1707,16 +1707,54 @@
 %09%09%09%09%7D);%0A
+%09%09%09%09%0A%09%09%09%09ConfigPropertyLoader.init();%0A
 %09%09%09%7D%0A%09%09%7D
@@ -2113,16 +2113,18 @@
 %09%7D%0A%09%09%7D;%0A
+%09%09
 %0A%09%09ApiRe

Patch for CCTweaks config options