Skip to content

Commit

Permalink
Removed weirdness in VirtualKeybindings, fixed Unicode issues again
Browse files Browse the repository at this point in the history
-Removed doubled code
-Removed deprecated code
-Made VirtualKeybindings able to be played back or recorded. This will theoretically come up in #41
-Added more blocked keybindings
  • Loading branch information
Scribble authored and Scribble committed Sep 27, 2021
1 parent 9d9a26f commit c3397f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 39 deletions.
6 changes: 5 additions & 1 deletion src/main/java/de/scribble/lp/tasmod/ClientProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,15 @@ public void init(FMLInitializationEvent ev) {
ClientRegistry.registerKeyBinding(infoGuiKey);
ClientRegistry.registerKeyBinding(bufferViewKey);

VirtualKeybindings.registerBlockedKeyBinding(infoGuiKey);

VirtualKeybindings.registerBlockedKeyBinding(tickratezeroKey);
VirtualKeybindings.registerBlockedKeyBinding(tickAdvance);
VirtualKeybindings.registerBlockedKeyBinding(stopkey);
VirtualKeybindings.registerBlockedKeyBinding(savestateSaveKey);
VirtualKeybindings.registerBlockedKeyBinding(savestateLoadKey);
VirtualKeybindings.registerBlockedKeyBinding(testingKey);
VirtualKeybindings.registerBlockedKeyBinding(infoGuiKey);
VirtualKeybindings.registerBlockedKeyBinding(bufferViewKey);

createTASDir();
createSavestatesDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

Expand Down Expand Up @@ -112,14 +113,14 @@ public int getFileVersion(File file) throws IOException {

public InputContainer fromEntireFileV1(File file) throws IOException {

List<String> lines = FileUtils.readLines(file, Charset.defaultCharset());
List<String> lines = FileUtils.readLines(file, StandardCharsets.UTF_8);

File monitorFile=new File(file, "../"+file.getName().replace(".tas", "")+".mon");

List<String> monitorLines=null;

if(monitorFile.exists()) {
monitorLines = FileUtils.readLines(monitorFile, Charset.defaultCharset());
monitorLines = FileUtils.readLines(monitorFile, StandardCharsets.UTF_8);
}

InputContainer container = new InputContainer();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.google.common.collect.Maps;

import de.scribble.lp.tasmod.ClientProxy;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiControls;
Expand All @@ -31,7 +32,6 @@ public class VirtualKeybindings {
private static long cooldown = 20;
private static HashMap<KeyBinding, Long> cooldownHashMap = Maps.<KeyBinding, Long>newHashMap();
private static List<KeyBinding> blockedKeys = new ArrayList<>();
private static List<KeyBinding> blockedDuringRecordingKeys = new ArrayList<>();
private static long cooldowntimer = 0;
public static boolean focused = false;

Expand All @@ -45,7 +45,10 @@ public static void increaseCooldowntimer() {
* @return
*/
public static boolean isKeyDown(KeyBinding keybind) {
boolean down = Keyboard.isKeyDown(keybind.getKeyCode());

int keycode=keybind.getKeyCode();
boolean down = isKeyCodeAlwaysBlocked(keycode) ? Keyboard.isKeyDown(keycode) : ClientProxy.virtual.willKeyBeDown(keycode);

if (down) {
if (cooldownHashMap.containsKey(keybind)) {
if (cooldown <= cooldowntimer - (long) cooldownHashMap.get(keybind)) {
Expand Down Expand Up @@ -73,22 +76,7 @@ public static boolean isKeyDownExceptTextfield(KeyBinding keybind) {
if (mc.currentScreen instanceof GuiChat || mc.currentScreen instanceof GuiEditSign || (focused && mc.currentScreen != null) || mc.currentScreen instanceof GuiControls) {
return false;
}
boolean down = Keyboard.isKeyDown(keybind.getKeyCode());
if (down) {
if (cooldownHashMap.containsKey(keybind)) {
if (cooldown <= cooldowntimer - (long) cooldownHashMap.get(keybind)) {
cooldownHashMap.put(keybind, cooldowntimer);
cooldown=Minecraft.getDebugFPS()/3;
return true;
}
return false;
} else {
cooldownHashMap.put(keybind, cooldowntimer);
cooldown=Minecraft.getDebugFPS()/3;
return true;
}
}
return false;
return isKeyDown(keybind);
}

/**
Expand All @@ -99,11 +87,6 @@ public static void registerBlockedKeyBinding(KeyBinding keybind) {
blockedKeys.add(keybind);
}

@Deprecated
public static void registerBlockedDuringRecordingKeyBinding(KeyBinding keybind) {
blockedDuringRecordingKeys.add(keybind);
}

/**
* Checks whether the keycode should not be recorded or played back in a TAS
* @param keycode to block
Expand All @@ -116,18 +99,5 @@ public static boolean isKeyCodeAlwaysBlocked(int keycode) {
}
return false;
}
@Deprecated
public static boolean isKeyCodeBlockedDuringRecording(int keycode) {
for (KeyBinding keybind : blockedDuringRecordingKeys) {
if (keycode == keybind.getKeyCode()) {
blockedDuringRecordingKeys.remove(keybind);
return true;
}
}
return false;
}

public static void setCooldown(long cooldown) {
VirtualKeybindings.cooldown = cooldown;
}
}

0 comments on commit c3397f6

Please sign in to comment.