Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #4 , also socket connection issues #10

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/battleaimod/BattleAiMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
import ludicrousspeed.simulator.commands.GridSelectConfrimCommand;
import ludicrousspeed.simulator.commands.HandSelectCommand;
import ludicrousspeed.simulator.commands.HandSelectConfirmCommand;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import savestate.PotionState;
import savestate.SaveState;
import savestate.SaveStateMod;
import savestate.fastobjects.ScreenShakeFast;

import java.awt.event.WindowEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
Expand All @@ -53,6 +56,7 @@
import java.util.function.Function;

import static com.megacrit.cardcrawl.dungeons.AbstractDungeon.actionManager;
import static javax.swing.WindowConstants.DISPOSE_ON_CLOSE;

@SpireInitializer
public class BattleAiMod implements PostInitializeSubscriber, PostUpdateSubscriber, OnStartBattleSubscriber, PreUpdateSubscriber, EditRelicsSubscriber {
Expand Down Expand Up @@ -88,6 +92,9 @@ public BattleAiMod() {
// Shut off the MTS console window, It increasingly slows things down
ModSelectWindow window = ReflectionHacks.getPrivateStatic(Loader.class, "ex");
window.removeAll();
window.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
window.dispatchEvent(new WindowEvent(window, WindowEvent.WINDOW_CLOSING));
window.setVisible(false);

CardCrawlGame.screenShake = new ScreenShakeFast();

Expand Down Expand Up @@ -151,6 +158,7 @@ public void receivePostInitialize() {
}
}

Configurator.setRootLevel(Level.ERROR);
ReflectionHacks.setPrivateStaticFinal(MummifiedHand.class, "logger", new SilentLogger());
ReflectionHacks.setPrivateStaticFinal(BaseMod.class, "logger", new SilentLogger());
ReflectionHacks.setPrivateStaticFinal(TheSpecimen.class, "logger", new SilentLogger());
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/battleaimod/networking/AiServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

public class AiServer {
Expand All @@ -32,10 +34,9 @@ public class AiServer {
public static int fileIndex = 0;

public AiServer() {
ExecutorService executor = Executors.newSingleThreadExecutor();
executor.submit(() -> {
try {
ServerSocket serverSocket = new ServerSocket(PORT_NUMBER);
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleWithFixedDelay(() -> {
try (ServerSocket serverSocket = new ServerSocket(PORT_NUMBER)) {

Socket socket = serverSocket.accept();

Expand Down Expand Up @@ -134,8 +135,9 @@ public AiServer() {
e.printStackTrace();
System.err.println("Client Disconnected, clearing server for reset");
BattleAiMod.aiServer = null;
BattleAiMod.battleAiController = null;
}
});
}, 0,5, TimeUnit.SECONDS);
}

public static JsonArray commandsForStateNode(StateNode root, boolean shouldPrint) {
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/battleaimod/patches/DisableSound.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package battleaimod.patches;

import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.evacipated.cardcrawl.modthespire.lib.SpirePatch;
import com.megacrit.cardcrawl.desktop.DesktopLauncher;

@SpirePatch(
clz = DesktopLauncher.class,
paramtypez = {String[].class},
method = "main"
)
public class DisableSound {

public static void Prefix(String[] args) {
if(Boolean.parseBoolean(System.getProperty("isServer"))) {
LwjglApplicationConfiguration.disableAudio = true;
}
}
}