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

Allow coordinates input for JDAMs of F-15E #140

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{}
{
"tabWidth": 2,
}
19 changes: 18 additions & 1 deletion TheWay.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ local lastDevice = ""
local lastCode = ""
local lastNeedDepress = true
local whenToDepress = nil
local moreWait = false
local waitTime = nil
function LuaExportBeforeNextFrame()
if upstreamLuaExportBeforeNextFrame ~= nil then
successful, err = pcall(upstreamLuaExportBeforeNextFrame)
Expand All @@ -58,6 +60,11 @@ function LuaExportBeforeNextFrame()
isPressed = false
currCommandIndex = currCommandIndex + 1
end
elseif moreWait then
local currTime = socket.gettime()
if currTime >= waitTime then
moreWait = false
end
else
-- Prepare for new button push
local keys = JSON:decode(data)
Expand All @@ -66,9 +73,19 @@ function LuaExportBeforeNextFrame()
lastDevice = keys[currCommandIndex]["device"]
lastCode = keys[currCommandIndex]["code"]
local stringtoboolean = { ["true"] = true,["false"] = false }
lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]]
local addDepress_str = keys[currCommandIndex]["addDepress"]
--lastNeedDepress = stringtoboolean[keys[currCommandIndex]["addDepress"]]
local delay = tonumber(keys[currCommandIndex]["delay"])
local activate = tonumber(keys[currCommandIndex]["activate"])

if addDepress_str == "fa18wait" then
moreWait = true
waitTime = socket.gettime() + (delay / 1000) + 0.05
lastNeedDepress = true
else
lastNeedDepress = stringtoboolean[addDepress_str]
end

-- Push the button
GetDevice(lastDevice):performClickableAction(lastCode, activate)
--Store the time when we will need to depress
Expand Down
28 changes: 28 additions & 0 deletions src/components/FourOptionsDialog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
Button,
Dialog,
DialogTitle,
Stack,
} from "@mui/material";
import { createModal } from "react-modal-promise";

const FourSimpleDialog = ({ isOpen, onResolve, onReject, title, op1, op2, op3, op4 }) => {
const handleOptionSelected = (option) => {
onResolve(option);
};

return (
<Dialog open={isOpen} onClose={onReject}>
<DialogTitle>{title}</DialogTitle>
<Stack>
<Button onClick={() => handleOptionSelected(op1)}>{op1}</Button>
<Button onClick={() => handleOptionSelected(op2)}>{op2}</Button>
<Button onClick={() => handleOptionSelected(op3)}>{op3}</Button>
<Button onClick={() => handleOptionSelected(op4)}>{op4}</Button>
</Stack>
</Dialog>
);
};

export const FourOptionsSimpleDialog = createModal(FourSimpleDialog);

17 changes: 17 additions & 0 deletions src/components/TwoOptionsDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ const MuiDialog = ({ isOpen, onResolve, onReject, title, op1, op2 }) => {
);
};

const SimpleDialog = ({ isOpen, onResolve, onReject, title, op1, op2 }) => {
const handleOptionSelected = (option) => {
onResolve(option);
};

return (
<Dialog open={isOpen} onClose={onReject}>
<DialogTitle>{title}</DialogTitle>
<Stack>
<Button onClick={() => handleOptionSelected(op1)}>{op1}</Button>
<Button onClick={() => handleOptionSelected(op2)}>{op2}</Button>
</Stack>
</Dialog>
);
};

export const TwoOptionsDialog = createModal(MuiDialog);
export const TwoOptionsSimpleDialog = createModal(SimpleDialog);
17 changes: 13 additions & 4 deletions src/moduleCommands/GetModuleCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import uh60l from "./uh60l";

export default function getModuleCommands(module, waypoints, buttonExtraDelay) {
switch (module) {
case "F-15ESE_pilotA":
case "F-15ESE_wsoA":
case "F-15ESE_pilotB":
case "F-15ESE_wsoB":
case "F-15ESE_pilotAJDAM":
case "F-15ESE_wsoAJDAM":
case "F-15ESE_pilotBJDAM":
case "F-15ESE_wsoBJDAM":
case "F-15ESE_pilotANOJDAM":
case "F-15ESE_wsoANOJDAM":
case "F-15ESE_pilotBNOJDAM":
case "F-15ESE_wsoBNOJDAM":
f15e.slotVariant = module;
f15e.extraDelay = buttonExtraDelay;
return f15e.createButtonCommands(waypoints);
Expand All @@ -30,9 +34,14 @@ export default function getModuleCommands(module, waypoints, buttonExtraDelay) {
return f16.createButtonCommands(waypoints);
}
case "FA-18C_hornet":
case "FA-18C_hornetPP1":
case "FA-18C_hornetPP2":
case "FA-18C_hornetPP3":
case "FA-18C_hornetPP4":
case "FA-18E":
case "FA-18F":
case "EA-18G": {
fa18.slotVariant = module;
fa18.extraDelay = buttonExtraDelay;
return fa18.createButtonCommands(waypoints);
}
Expand Down
90 changes: 79 additions & 11 deletions src/moduleCommands/askUserAboutSeat.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { TwoOptionsDialog } from "../components/TwoOptionsDialog";
import {
TwoOptionsDialog,
TwoOptionsSimpleDialog,
} from "../components/TwoOptionsDialog";
import { FourOptionsSimpleDialog } from "../components/FourOptionsDialog";
import { AlertDialog } from "../components/AlertDialog";

const askUserAboutSeat = async (module, userPreferences) => {
Expand All @@ -24,16 +28,45 @@ const askUserAboutSeat = async (module, userPreferences) => {
module === "FA-18F" ||
module === "EA-18G"
) {
if (moduleSpecificPreferences?.includes("Hide")) return "FA-18C_hornet";
else {
return AlertDialog({
title: "Please make sure that",
content:
"1. PRECISE option is boxed in HSI > DATA\n" +
"2. You are not in the TAC menu\n" +
"3. You are in the 00°00.0000' coordinate format",
}).then(() => "FA-18C_hornet");
let PPinput;
await TwoOptionsSimpleDialog({
title: "Input as PP MSN?",
op1: "YES",
op2: "NO",
}).then((pp) => (PPinput = pp));

let stations = "";
if (PPinput === "YES") {
await FourOptionsSimpleDialog({
title: "How many STATIONs carry this weapon?",
op1: "1",
op2: "2",
op3: "3",
op4: "4",
}).then((sta) => (stations = sta));
}

let hide = false;
if (moduleSpecificPreferences?.includes("Hide")) {
hide = true;
}
if (hide === false) {
if (PPinput === "YES") {
await AlertDialog({
title: "Please make sure that",
content: "Your LEFT MDI is on PP MSN Page!\n",
});
} else {
await AlertDialog({
title: "Please make sure that",
content:
"1. PRECISE option is boxed in HSI > DATA\n" +
"2. You are not in the TAC menu\n" +
"3. You are in the 00°00.0000' coordinate format",
});
}
}
return `FA-18C_hornet${PPinput === "YES" ? "PP" : ""}${stations}`;
} else if (module === "F-15ESE") {
let seat;
if (moduleSpecificPreferences?.includes("Pilot")) seat = "Pilot";
Expand All @@ -56,7 +89,42 @@ const askUserAboutSeat = async (module, userPreferences) => {
op2: "B{1/B}", // op2: "B" // removed because its a nice touch to keep the explicitness of this here, instead of making it more inline.
}).then((chosenRoute) => (route = chosenRoute));
}
return `F-15ESE_${seat.toLowerCase()}${route === "A{1/A}" ? "A" : "B"}`;

let jdam;
await TwoOptionsSimpleDialog({
title: "Input for JDAMs?",
op1: "YES",
op2: "NO",
}).then((forJDAM) => (jdam = forJDAM));

let hide = false;
if (moduleSpecificPreferences?.includes("Hide")) {
hide = true;
}
if (hide === false) {
if (seat === "Pilot" && jdam === "YES") {
await AlertDialog({
title: "Make sure:",
content:
"1. Your RIGHT MPD is on Smart Weapons page.\n" +
"2. Used 'NXT STA' to select the bomb you want to start with.\n" +
"3. Do not program the JDAMs in PACS.(Recommend)",
});
} else if (seat === "WSO" && jdam === "YES") {
await AlertDialog({
title: "Make sure:",
content:
"1. The airplane's master mode is A/G\n" +
"2. Your RIGHT MPD(Green display) is on Smart Weapons page.\n" +
"3. Used 'NXT STA' to select the bomb you want to start with.\n" +
"4. Do not program the JDAMs in PACS.(Recommend)",
});
}
}

return `F-15ESE_${seat.toLowerCase()}${route === "A{1/A}" ? "A" : "B"}${
jdam === "YES" ? "JDAM" : "NOJDAM"
}`;
} else if (module === "UH-60L") {
if (moduleSpecificPreferences?.includes("Hide")) return "UH-60L";
else {
Expand Down
Loading