package manager;
import constants.EnvironmentConstants;
import constants.TimeConstants;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
import parameters.LocalWorldParams;
import parameters.UserGuiParams;
/**
*
* @author Marco Celesti
*/
public class Configurator {
protected static void readConfig(File fileConfig) throws IOException {
Scanner scanner = new Scanner(fileConfig);
String line;
do {
line = scanner.nextLine();
if (!line.matches("@")) {
String command = line.split(":")[0];
String value = line.split(":")[1];
if (command.equals("nWorlds")) {
EnvironmentConstants.N_WORLDS_DEF = Short.parseShort(value);
} else if (command.equals("stopTime")) {
TimeConstants.STOP_TIME_IS_ACTIVE = Boolean.parseBoolean(value);
} else if (command.equals("stopCountMinutes")) {
TimeConstants.STOP_COUNT_MINUTES = Integer.parseInt(value);
} else if (command.equals("sleepingTime")) {
TimeConstants.SLEEPING_TIME = Integer.parseInt(value);
} else if (command.equals("commandPanel")) {
UserGuiParams.COMMAND_PANEL = Boolean.parseBoolean(value);
} else if (command.equals("gui")) {
UserGuiParams.GUI = Boolean.parseBoolean(value);
} else if (command.equals("gridVisible")) {
UserGuiParams.GRID = Boolean.parseBoolean(value);
} else if (command.equals("askfolder")) {
UserGuiParams.ASK_FOLDER = Boolean.parseBoolean(value);
} else if (command.equals("tracerColor")) {
String rgb[] = value.split(",");
int r = Integer.parseInt(rgb[0]);
int g = Integer.parseInt(rgb[1]);
int b = Integer.parseInt(rgb[2]);
Color c = new Color(r, g, b);
UserGuiParams.RESOURCE_COLOR = c;
}
}
} while (!line.matches("@"));
God.getInstance().createGUIController();
for (int i = 0; i < EnvironmentConstants.N_WORLDS_DEF; i++) {
LocalWorldParams params = new LocalWorldParams();
do {
line = scanner.nextLine();
if (!line.matches("#")) {
String command = line.split(":")[0];
String value = line.split(":")[1];
if (command.equals("idWorld")) {
params.setIdWorld(Short.parseShort(value));
} else if (command.equals("initNAgentsPainter")) {
params.setInitNAgentsPainter(Short.parseShort(value));
} else if (command.equals("initNAgentsTracer")) {
params.setInitNAgentsTracer(Short.parseShort(value));
} else if (command.equals("externalAgent")) {
params.setExternalAgent(Boolean.parseBoolean(value));
} else if (command.equals("mapFile")) {
params.setMapFile(new File(value));
} else if (command.equals("cols")) {
params.setCols(Short.parseShort(value));
} else if (command.equals("rows")) {
params.setRows(Short.parseShort(value));
} else if (command.equals("colorInUse")) {
params.setColorInUse(Short.parseShort(value));
} else if (command.equals("duplication")) {
params.setDuplication(Boolean.parseBoolean(value));
} else if (command.equals("hunger")) {
params.setHunger(Boolean.parseBoolean(value));
} else if (command.equals("tracerMovement")) {
params.setMovement(Short.parseShort(value));
}
}
} while (!line.matches("#"));
God.getInstance().createWorld(params);
God.getInstance().createInitialAgents(params);
}
scanner.close();
if (UserGuiParams.GUI) {
God.getInstance().packController();
}
}
}