<commit_before>package jsettlers.main;

import jsettlers.common.map.IMapDataProvider;
import jsettlers.common.map.MapLoadException;
import jsettlers.graphics.ISettlersGameDisplay;
import jsettlers.graphics.action.Action;
import jsettlers.graphics.action.EActionType;
import jsettlers.graphics.map.IMapInterfaceListener;
import jsettlers.graphics.map.MapInterfaceConnector;
import jsettlers.graphics.map.UIState;
import jsettlers.graphics.map.draw.ImageProvider;
import jsettlers.graphics.progress.EProgressState;
import jsettlers.graphics.progress.ProgressConnector;
import jsettlers.input.GuiInterface;
import jsettlers.logic.map.newGrid.MainGrid;
import jsettlers.logic.timer.Timer100Milli;
import network.NetworkManager;
import random.RandomSingleton;
import synchronic.timer.NetworkTimer;

/**
 * This is a running jsettlers game. It can be started and then stopped once.
 * 
 * @author michael
 */
public class JSettlersGame {

	private final long randomSheed;

	private boolean stopped = false;
	private Object stopMutex = new Object();
	private final ISettlersGameDisplay content;

	private Listener listener;
	private MapInterfaceConnector gameConnector;

	private final IGameCreator mapcreator;

	/**
	 * Creates a new game by a given random mapname.
	 * 
	 * @param map
	 *            The name of the random map and some settings
	 */
	@Deprecated
	public JSettlersGame(ISettlersGameDisplay content, IMapDataProvider map, long randomSheed) {
		this(content, new MapDataMapCreator(map), randomSheed);
	}

	public JSettlersGame(ISettlersGameDisplay content, IGameCreator map, long randomSheed) {
		this.content = content;
		this.mapcreator = map;
		this.randomSheed = randomSheed;
	}

	/**
	 * Starts the game in a new thread. Returns immeadiately
	 */
	public void start() {
		new Thread(new GameRunner()).start();
	}

	private class GameRunner implements Runnable, IMapInterfaceListener {

		@Override
		public void run() {
			NetworkManager manager = new NetworkManager();

			ProgressConnector progress = content.showProgress();

			RandomSingleton.load(randomSheed);

			Timer100Milli.start();
			NetworkTimer.get().setPausing(true);

			progress.setProgressState(EProgressState.LOADING_MAP);

			ImageProvider.getInstance().startPreloading();

			MainGrid grid;

			UIState uiState;
			try {
				grid = mapcreator.getMainGrid();
				uiState = mapcreator.getUISettings(0);
			} catch (MapLoadException e1) {
				e1.printStackTrace();
				listener.gameEnded();
				return;
			}

			NetworkTimer.get().setPausing(false);

			/** random map */
			// RandomMapFile file =
			// RandomMapFile.getByName(mapSettings.getMap().getName());
			// RandomMapEvaluator evaluator = new
			// RandomMapEvaluator(file.getInstructions(), (byte)
			// mapSettings.getPlayerCount());
			// evaluator.createMap(RandomSingleton.get());
			// IMapData mapGrid = evaluator.getGrid();

			// GameSerializer gameSerializer = new GameSerializer();
			// try {<commit_msg>- fixed bug in rev 890 causing a NullPointerException in NetworkTimer<commit_after>package jsettlers.main;

import jsettlers.common.map.IMapDataProvider;
import jsettlers.common.map.MapLoadException;
import jsettlers.graphics.ISettlersGameDisplay;
import jsettlers.graphics.action.Action;
import jsettlers.graphics.action.EActionType;
import jsettlers.graphics.map.IMapInterfaceListener;
import jsettlers.graphics.map.MapInterfaceConnector;
import jsettlers.graphics.map.UIState;
import jsettlers.graphics.map.draw.ImageProvider;
import jsettlers.graphics.progress.EProgressState;
import jsettlers.graphics.progress.ProgressConnector;
import jsettlers.input.GuiInterface;
import jsettlers.logic.map.newGrid.MainGrid;
import jsettlers.logic.timer.Timer100Milli;
import network.NetworkManager;
import random.RandomSingleton;
import synchronic.timer.NetworkTimer;

/**
 * This is a running jsettlers game. It can be started and then stopped once.
 * 
 * @author michael
 */
public class JSettlersGame {

	private final long randomSheed;

	private boolean stopped = false;
	private Object stopMutex = new Object();
	private final ISettlersGameDisplay content;

	private Listener listener;
	private MapInterfaceConnector gameConnector;

	private final IGameCreator mapcreator;

	/**
	 * Creates a new game by a given random mapname.
	 * 
	 * @param map
	 *            The name of the random map and some settings
	 */
	@Deprecated
	public JSettlersGame(ISettlersGameDisplay content, IMapDataProvider map, long randomSheed) {
		this(content, new MapDataMapCreator(map), randomSheed);
	}

	public JSettlersGame(ISettlersGameDisplay content, IGameCreator map, long randomSheed) {
		this.content = content;
		this.mapcreator = map;
		this.randomSheed = randomSheed;
	}

	/**
	 * Starts the game in a new thread. Returns immeadiately
	 */
	public void start() {
		new Thread(new GameRunner()).start();
	}

	private class GameRunner implements Runnable, IMapInterfaceListener {

		@Override
		public void run() {
			NetworkManager manager = new NetworkManager();

			ProgressConnector progress = content.showProgress();

			RandomSingleton.load(randomSheed);

			NetworkTimer.get().setPausing(true);
			Timer100Milli.start();

			progress.setProgressState(EProgressState.LOADING_MAP);

			ImageProvider.getInstance().startPreloading();

			MainGrid grid;

			UIState uiState;
			try {
				grid = mapcreator.getMainGrid();
				uiState = mapcreator.getUISettings(0);
			} catch (MapLoadException e1) {
				e1.printStackTrace();
				listener.gameEnded();
				return;
			}

			NetworkTimer.get().setPausing(false);

			/** random map */
			// RandomMapFile file =
			// RandomMapFile.getByName(mapSettings.getMap().getName());
			// RandomMapEvaluator evaluator = new
			// RandomMapEvaluator(file.getInstructions(), (byte)
			// mapSettings.getPlayerCount());
			// evaluator.createMap(RandomSingleton.get());
			// IMapData mapGrid = evaluator.getGrid();

			// GameSerializer gameSerializer = new GameSerializer();
			// try {
{'fraction_non_alphanumeric': 0.09728734092431346, 'fraction_numerical': 0.0035164099129269925, 'mean_word_length': 4.603189493433396, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4732795', 'n_tokens_mistral': 1985, 'n_tokens_neox': 1741, 'n_words': 410}