Skip to content

Commit

Permalink
The refactor starts now.
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
  • Loading branch information
Octol1ttle committed Oct 5, 2023
1 parent 2252d0a commit 8a7e96f
Show file tree
Hide file tree
Showing 48 changed files with 283 additions and 1,062 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '1.2-SNAPSHOT'
id 'fabric-loom' version '1.4-SNAPSHOT'
id 'maven-publish'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ loader_version=0.14.7
fabric_version=0.83.0
immediatelyfast_version=1.2.0
# Mod Properties
mod_version=1.20.1-fabric-8
mod_version=2.0.0-alpha.1+mc1.20.1
maven_group=net.torocraft
archives_base_name=flighthud
106 changes: 0 additions & 106 deletions src/main/java/net/torocraft/flighthud/AutoFlightManager.java

This file was deleted.

96 changes: 1 addition & 95 deletions src/main/java/net/torocraft/flighthud/FlightHud.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
package net.torocraft.flighthud;

import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.tree.LiteralCommandNode;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import net.torocraft.flighthud.alerts.Alert;
import net.torocraft.flighthud.commands.AltitudeResetCommand;
import net.torocraft.flighthud.commands.AltitudeSelectCommand;
import net.torocraft.flighthud.commands.DestinationResetCommand;
import net.torocraft.flighthud.commands.DestinationSelectCommand;
import net.torocraft.flighthud.commands.SwitchDisplayModeCommand;
import net.torocraft.flighthud.components.FlightStatusIndicator;
import net.torocraft.flighthud.config.HudConfig;
import net.torocraft.flighthud.config.SettingsConfig;
import net.torocraft.flighthud.config.loader.ConfigLoader;
import org.lwjgl.glfw.GLFW;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument;
import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;

public class FlightHud implements ClientModInitializer {
Expand Down Expand Up @@ -52,91 +43,16 @@ public class FlightHud implements ClientModInitializer {
config -> FlightHud.CONFIG_MIN = config);

private static KeyBinding keyBinding;
private static KeyBinding hideAlertSwitch;
private static KeyBinding showAlertSwitch;
private static KeyBinding flightLawSwitch;
private static KeyBinding gpwsSwitch;
private static KeyBinding fdSwitch;
private static KeyBinding aThrSwitch;
private static KeyBinding apSwitch;

private static void setupKeycCode() {
keyBinding = new KeyBinding("key.flighthud.toggleDisplayMode", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_GRAVE_ACCENT, "category.flighthud.toggleDisplayMode");

hideAlertSwitch = new KeyBinding("key.flighthud.hideAlertSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_0, "category.flighthud.toggleDisplayMode");

showAlertSwitch = new KeyBinding("key.flighthud.showAlertSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_DECIMAL, "category.flighthud.toggleDisplayMode");

flightLawSwitch = new KeyBinding("key.flighthud.flightLawSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_ENTER, "category.flighthud.toggleDisplayMode");

gpwsSwitch = new KeyBinding("key.flighthud.gpwsSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_ADD, "category.flighthud.toggleDisplayMode");

fdSwitch = new KeyBinding("key.flighthud.fdSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_1, "category.flighthud.toggleDisplayMode");

aThrSwitch = new KeyBinding("key.flighthud.aThrSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_2, "category.flighthud.toggleDisplayMode");

apSwitch = new KeyBinding("key.flighthud.apSwitch", InputUtil.Type.KEYSYM,
GLFW.GLFW_KEY_KP_3, "category.flighthud.toggleDisplayMode");

KeyBindingHelper.registerKeyBinding(keyBinding);
KeyBindingHelper.registerKeyBinding(hideAlertSwitch);
KeyBindingHelper.registerKeyBinding(showAlertSwitch);
KeyBindingHelper.registerKeyBinding(flightLawSwitch);
KeyBindingHelper.registerKeyBinding(gpwsSwitch);
KeyBindingHelper.registerKeyBinding(fdSwitch);
KeyBindingHelper.registerKeyBinding(aThrSwitch);
KeyBindingHelper.registerKeyBinding(apSwitch);

ClientTickEvents.END_CLIENT_TICK.register(client -> {
while (keyBinding.wasPressed()) {
CONFIG_SETTINGS.toggleDisplayMode();
}

while (hideAlertSwitch.wasPressed()) {
for (Alert alert : FlightStatusIndicator.activeAlerts) {
if (alert.hidden) continue;
alert.hidden = true;
break;
}
}

while (showAlertSwitch.wasPressed()) {
for (int i = FlightStatusIndicator.activeAlerts.size() - 1; i >= 0; i--) {
Alert alert = FlightStatusIndicator.activeAlerts.get(i);
if (!alert.hidden) continue;
alert.hidden = false;
break;
}
}

while (flightLawSwitch.wasPressed()) {
FlightSafetyMonitor.flightProtectionsEnabled = !FlightSafetyMonitor.flightProtectionsEnabled;
}

while (gpwsSwitch.wasPressed()) {
CONFIG_SETTINGS.gpws = !CONFIG_SETTINGS.gpws;
}

while (fdSwitch.wasPressed()) {
AutoFlightManager.flightDirectorsEnabled = !AutoFlightManager.flightDirectorsEnabled;
}

while (aThrSwitch.wasPressed()) {
AutoFlightManager.autoThrustEnabled = !AutoFlightManager.autoThrustEnabled;
if (!AutoFlightManager.autoThrustEnabled)
FlightSafetyMonitor.thrustLocked = false;
}

while (apSwitch.wasPressed()) {
AutoFlightManager.autoPilotEnabled = !AutoFlightManager.autoPilotEnabled;
}
});
}

Expand All @@ -145,17 +61,7 @@ private static void setupCommand() {

LiteralCommandNode<FabricClientCommandSource> node = dispatcher.register(literal("flighthud")
.then(literal("toggle").executes(new SwitchDisplayModeCommand()))
.then(literal("nav")
.then(argument("destinationX", IntegerArgumentType.integer(-30_000_000, 30_000_000))
.then(argument("destinationZ", IntegerArgumentType.integer(-30_000_000, 30_000_000))
.executes(new DestinationSelectCommand())))
.then(literal("reset")
.executes(new DestinationResetCommand())))
.then(literal("alt")
.then(argument("targetAltitude", IntegerArgumentType.integer(0, 640))
.executes(new AltitudeSelectCommand()))
.then(literal("reset")
.executes(new AltitudeResetCommand()))));
);
dispatcher.register(literal("fhud").redirect(node));
dispatcher.register(literal("fh").redirect(node));
});
Expand Down
Loading

0 comments on commit 8a7e96f

Please sign in to comment.