diff --git a/src/main/java/dansapps/interakt/misc/CONFIG.java b/src/main/java/dansapps/interakt/misc/CONFIG.java index 87098f9..4f35d3a 100644 --- a/src/main/java/dansapps/interakt/misc/CONFIG.java +++ b/src/main/java/dansapps/interakt/misc/CONFIG.java @@ -5,9 +5,9 @@ * @since January 15th, 2022 */ public class CONFIG { - public static boolean DEBUG_FLAG = true; - public static final int TIME_SLOT_LENGTH_IN_SECONDS = 60; - public static final int GRID_SIZE = 2; + public static boolean DEBUG_FLAG = false; + public static final int TIME_SLOT_LENGTH_IN_SECONDS = 16; + public static final int GRID_SIZE = 10; public static final int MAX_CHANCE_TO_MOVE = 25; public static final int MAX_CHANCE_TO_BEFRIEND = 50; public static final int MAX_CHANCE_TO_ATTACK = 50; diff --git a/src/main/java/dansapps/interakt/objects/Actor.java b/src/main/java/dansapps/interakt/objects/Actor.java index 5160152..d977b9e 100644 --- a/src/main/java/dansapps/interakt/objects/Actor.java +++ b/src/main/java/dansapps/interakt/objects/Actor.java @@ -271,7 +271,7 @@ public String toString() { "Num friends: " + friends.size() + "\n"; if (CONFIG.SHOW_LINEAGE_INFO) { if (parentIDs.size() > 0) { - toReturn += "Parents: " + getParentNamesSeparatedByCommas(); + toReturn += "Parents: " + getParentNamesSeparatedByCommas() + "\n"; } if (childIDs.size() > 0) { toReturn += "Children: " + getChildrenNamesSeparatedByCommas(); diff --git a/src/main/java/dansapps/interakt/services/LocalStorageService.java b/src/main/java/dansapps/interakt/services/LocalStorageService.java index 4bf01ed..2f08fd4 100644 --- a/src/main/java/dansapps/interakt/services/LocalStorageService.java +++ b/src/main/java/dansapps/interakt/services/LocalStorageService.java @@ -21,7 +21,7 @@ */ public class LocalStorageService { private static LocalStorageService instance; - private final static String FILE_PATH = "/Interakt/"; + public final static String FILE_PATH = "/Interakt/"; private final static String ACTORS_FILE_NAME = "actors.json"; private final static String WORLDS_FILE_NAME = "worlds.json"; private final static String REGIONS_FILE_NAME = "regions.json"; diff --git a/src/main/java/dansapps/interakt/utils/Logger.java b/src/main/java/dansapps/interakt/utils/Logger.java index 47cdc57..b02cba2 100644 --- a/src/main/java/dansapps/interakt/utils/Logger.java +++ b/src/main/java/dansapps/interakt/utils/Logger.java @@ -7,8 +7,14 @@ import dansapps.interakt.Interakt; import dansapps.interakt.objects.Event; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; import java.time.format.DateTimeFormatter; +import static dansapps.interakt.services.LocalStorageService.FILE_PATH; + /** * @author Daniel McCoy Stephenson * @since January 7th, 2022 @@ -16,9 +22,16 @@ public class Logger { private static Logger instance; private boolean localDebugFlag = false; + private boolean logEventsToConsoleFlag = false; + private static String PATH = FILE_PATH + "log.txt"; + private File file = new File(PATH); private Logger() { - + try { + file.createNewFile(); + } catch (IOException e) { + e.printStackTrace(); + } } public static Logger getInstance() { @@ -33,12 +46,14 @@ public static Logger getInstance() { * @param message The message to log to the console. */ public void logInfo(String message) { + writeToFile(message); if (isLocalDebugFlagEnabled() || Interakt.getInstance().isDebugEnabled()) { System.out.println("[INFO] " + message); } } public void logError(String errorMessage) { + writeToFile(errorMessage); if (Interakt.getInstance().isDebugEnabled()) { System.out.println("[ERROR] " + errorMessage); } @@ -47,7 +62,11 @@ public void logError(String errorMessage) { public void logEvent(Event event) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); String formattedDateTime = event.getTimestamp().format(formatter); - System.out.println("[" + formattedDateTime + "] " + event.getMessage()); + String datemessage = "[" + formattedDateTime + "] " + event.getMessage(); + writeToFile(datemessage); + if (logEventsToConsoleFlag) { + System.out.println(datemessage); + } } public static void setInstance(Logger instance) { @@ -61,4 +80,16 @@ public boolean isLocalDebugFlagEnabled() { public void setLocalDebugFlagEnabled(boolean localDebugFlag) { this.localDebugFlag = localDebugFlag; } + + private void writeToFile(String toWrite) { + try { + FileWriter fileWriter = new FileWriter(file, true); + BufferedWriter out = new BufferedWriter(fileWriter); + out.write(toWrite + "\n"); + out.close(); + fileWriter.close(); + } catch(IOException e) { + e.printStackTrace(); + } + } } \ No newline at end of file