Skip to content

Commit 018a0f6

Browse files
committed
now things happen
Signed-off-by: Octol1ttle <[email protected]>
1 parent c48b4ff commit 018a0f6

File tree

9 files changed

+58
-25
lines changed

9 files changed

+58
-25
lines changed

src/main/kotlin/ru/octol1ttle/flightassistant/impl/alert/flight_controls/ProtectionsLostAlert.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProtectionsLostAlert(computers: ComputerBus) : Alert(computers), ECAMAlert
1515
override val data: AlertData = AlertData.MASTER_CAUTION
1616

1717
override fun shouldActivate(): Boolean {
18-
return computers.protections.protectionsLost
18+
return computers.protections.isDisabledOrFaulted()
1919
}
2020

2121
override fun render(guiGraphics: GuiGraphics, firstLineX: Int, otherLinesX: Int, firstLineY: Int): Int {

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/autoflight/FlightPlanComputer.kt

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
11
package ru.octol1ttle.flightassistant.impl.computer.autoflight
22

33
import kotlin.math.abs
4+
import net.minecraft.network.chat.Component
45
import net.minecraft.resources.ResourceLocation
56
import ru.octol1ttle.flightassistant.FlightAssistant
67
import ru.octol1ttle.flightassistant.api.computer.Computer
78
import ru.octol1ttle.flightassistant.api.computer.ComputerBus
9+
import ru.octol1ttle.flightassistant.api.computer.ComputerQuery
810
import ru.octol1ttle.flightassistant.impl.computer.autoflight.builtin.SpeedReferenceVerticalMode
911
import ru.octol1ttle.flightassistant.impl.computer.autoflight.builtin.TakeoffThrustMode
12+
import ru.octol1ttle.flightassistant.impl.display.StatusDisplay
1013

1114
class FlightPlanComputer(computers: ComputerBus) : Computer(computers) {
12-
private var currentPhase: FlightPhase = FlightPhase.ON_GROUND
13-
var departureData: DepartureData = DepartureData()
15+
var currentPhase: FlightPhase = FlightPhase.ON_GROUND
16+
private set
17+
var departureData: DepartureData = DepartureData.DEFAULT
18+
val enrouteData: MutableList<EnrouteWaypoint> = ArrayList()
1419

1520
override fun tick() {
1621
currentPhase = updateFlightPhase()
1722
}
1823

1924
private fun updateFlightPhase(): FlightPhase {
20-
if (computers.data.player.onGround()) {
21-
return FlightPhase.ON_GROUND
25+
if (!departureData.isDefault() && abs(computers.data.position.x - departureData.coordinatesX) < 20 && abs(computers.data.position.z - departureData.coordinatesZ) < 20) {
26+
return FlightPhase.TAKEOFF
2227
}
2328

24-
if (abs(computers.data.position.x - departureData.coordinatesX) < 20 && abs(computers.data.position.z - departureData.coordinatesZ) < 20) {
25-
return FlightPhase.TAKEOFF
29+
if (!computers.data.flying) {
30+
return FlightPhase.ON_GROUND
2631
}
2732
if (currentPhase == FlightPhase.TAKEOFF) {
2833
return FlightPhase.TAKEOFF
@@ -46,7 +51,15 @@ class FlightPlanComputer(computers: ComputerBus) : Computer(computers) {
4651
}
4752

4853
fun getLateralMode(): AutoFlightComputer.LateralMode? {
49-
return null
54+
return when (currentPhase) {
55+
else -> null
56+
}
57+
}
58+
59+
override fun <Response> processQuery(query: ComputerQuery<Response>) {
60+
if (query is StatusDisplay.StatusMessageQuery && currentPhase != FlightPhase.UNKNOWN && (!departureData.isDefault() || enrouteData.isNotEmpty())) {
61+
query.respond(Component.translatable("status.flightassistant.flight_phase.${currentPhase.name.lowercase()}"))
62+
}
5063
}
5164

5265
override fun reset() {
@@ -64,7 +77,15 @@ class FlightPlanComputer(computers: ComputerBus) : Computer(computers) {
6477
CLIMB
6578
}
6679

67-
data class DepartureData(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val elevation: Int = 0, val takeoffThrust: Float = 1.0f, val minimumClimbSpeed: Int = 15)
80+
data class DepartureData(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val elevation: Int = 0, val takeoffThrust: Float = 1.0f, val minimumClimbSpeed: Int = 15) {
81+
fun isDefault(): Boolean {
82+
return this == DEFAULT
83+
}
84+
85+
companion object {
86+
val DEFAULT: DepartureData = DepartureData()
87+
}
88+
}
6889
data class EnrouteWaypoint(val coordinatesX: Int = 0, val coordinatesZ: Int = 0, val altitude: Int = 0, val speed: Int = 0, val active: Active? = null) {
6990
enum class Active {
7091
ORIGIN,

src/main/kotlin/ru/octol1ttle/flightassistant/impl/computer/autoflight/builtin/BuiltInLateralModes.kt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ru.octol1ttle.flightassistant.api.util.degrees
88
import ru.octol1ttle.flightassistant.impl.computer.autoflight.AutoFlightComputer
99

1010
data class HeadingLateralMode(val target: Int) : AutoFlightComputer.LateralMode {
11-
override fun getControlInput(computers: ComputerBus): ControlInput? {
11+
override fun getControlInput(computers: ComputerBus): ControlInput {
1212
return ControlInput(
1313
target.toFloat(),
1414
ControlInput.Priority.NORMAL,
@@ -17,12 +17,18 @@ data class HeadingLateralMode(val target: Int) : AutoFlightComputer.LateralMode
1717
}
1818
}
1919

20-
data class CoordinatesLateralMode(val targetX: Int, val targetZ: Int) : AutoFlightComputer.LateralMode {
21-
override fun getControlInput(computers: ComputerBus): ControlInput? {
20+
data class DirectCoordinatesLateralMode(val targetX: Int, val targetZ: Int) : AutoFlightComputer.LateralMode {
21+
override fun getControlInput(computers: ComputerBus): ControlInput {
2222
return ControlInput(
2323
degrees(atan2(-(targetX - computers.data.position.x), targetZ - computers.data.position.z)).toFloat() + 180.0f,
2424
ControlInput.Priority.NORMAL,
25-
Component.translatable("mode.flightassistant.lateral.selected_coordinates")
25+
Component.translatable("mode.flightassistant.lateral.direct_coordinates")
2626
)
2727
}
28+
}
29+
30+
data class TrackNavigationLateralMode(val originX: Int, val originZ: Int, val targetX: Int, val targetZ: Int) : AutoFlightComputer.LateralMode {
31+
override fun getControlInput(computers: ComputerBus): ControlInput {
32+
TODO()
33+
}
2834
}

src/main/kotlin/ru/octol1ttle/flightassistant/impl/display/CoordinatesDisplay.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import ru.octol1ttle.flightassistant.api.display.HudFrame
1010
import ru.octol1ttle.flightassistant.api.util.extensions.*
1111
import ru.octol1ttle.flightassistant.config.FAConfig
1212
import ru.octol1ttle.flightassistant.impl.computer.autoflight.AutoFlightComputer
13-
import ru.octol1ttle.flightassistant.impl.computer.autoflight.builtin.CoordinatesLateralMode
13+
import ru.octol1ttle.flightassistant.impl.computer.autoflight.builtin.DirectCoordinatesLateralMode
1414

1515
class CoordinatesDisplay(computers: ComputerBus) : Display(computers) {
1616
override fun allowedByConfig(): Boolean {
@@ -29,7 +29,7 @@ class CoordinatesDisplay(computers: ComputerBus) : Display(computers) {
2929

3030
val color: Int
3131
val active: AutoFlightComputer.LateralMode? = computers.autoflight.activeLateralMode
32-
if (FAConfig.display.showAutomationModes && computers.autoflight.getHeadingInput() != null && active is CoordinatesLateralMode) {
32+
if (FAConfig.display.showAutomationModes && computers.autoflight.getHeadingInput() != null && active is DirectCoordinatesLateralMode) {
3333
color = if (active == computers.autoflight.selectedLateralMode) primaryAdvisoryColor else secondaryAdvisoryColor
3434
drawString(active.targetX.toString(), x + textWidth(xText) + 3, y, color)
3535
drawString(active.targetX.toString(), x + textWidth(zText) + 3, y + lineHeight, color)

src/main/kotlin/ru/octol1ttle/flightassistant/screen/autoflight/AutoFlightScreenState.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AutoFlightScreenState {
3333
}
3434
autoFlight.selectedLateralMode = when (lateralMode) {
3535
LateralMode.HEADING -> HeadingLateralMode(targetHeading)
36-
LateralMode.COORDINATES -> CoordinatesLateralMode(targetCoordinatesX, targetCoordinatesZ)
36+
LateralMode.COORDINATES -> DirectCoordinatesLateralMode(targetCoordinatesX, targetCoordinatesZ)
3737
LateralMode.FLIGHT_PLAN -> null
3838
}
3939
}

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/departure/DepartureScreenState.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ data class DepartureScreenState(
99
var takeoffThrustPercent: Int = 100,
1010
var minimumClimbSpeed: Int = 15
1111
) {
12-
fun save(flightPlan: FlightPlanComputer) {
13-
flightPlan.departureData = FlightPlanComputer.DepartureData(coordinatesX, coordinatesZ, elevation, takeoffThrustPercent / 100.0f, minimumClimbSpeed)
14-
}
15-
1612
fun load(flightPlan: FlightPlanComputer) {
1713
TODO()
1814
}
15+
16+
fun save(flightPlan: FlightPlanComputer) {
17+
flightPlan.departureData = FlightPlanComputer.DepartureData(coordinatesX, coordinatesZ, elevation, takeoffThrustPercent / 100.0f, minimumClimbSpeed)
18+
}
1919
}

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/enroute/EnrouteScreen.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class EnrouteScreen(parent: Screen) : FABaseScreen(parent, Component.translatabl
4545

4646
save = this.addRenderableWidget(Button.builder(Component.translatable("menu.flightassistant.fms.save")) { _: Button? ->
4747
lastState = state.copy()
48+
state.save(computers.plan)
4849
list.rebuildEntries()
4950
}.pos(this.width - 180, this.height - 30).width(80).build())
5051

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/enroute/EnrouteScreenState.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ import ru.octol1ttle.flightassistant.impl.computer.autoflight.FlightPlanComputer
55
class EnrouteScreenState(
66
val waypoints: MutableList<Waypoint> = ArrayList()
77
) {
8-
fun save(flightPlan: FlightPlanComputer) {
8+
fun load(flightPlan: FlightPlanComputer) {
9+
this.waypoints.clear()
10+
this.waypoints.addAll(flightPlan.enrouteData.map { Waypoint(it.coordinatesX, it.coordinatesZ, it.altitude, it.speed, it.active) })
911
}
1012

11-
fun load(flightPlan: FlightPlanComputer) {
13+
fun save(flightPlan: FlightPlanComputer) {
14+
flightPlan.enrouteData.clear()
15+
flightPlan.enrouteData.addAll(this.waypoints.map(Waypoint::toEnrouteWaypoint))
1216
}
1317

1418
fun copy(): EnrouteScreenState {
@@ -28,8 +32,8 @@ class EnrouteScreenState(
2832
}
2933

3034
data class Waypoint(var coordinatesX: Int = 0, var coordinatesZ: Int = 0, var altitude: Int = 0, var speed: Int = 0, var active: FlightPlanComputer.EnrouteWaypoint.Active? = null) {
31-
fun toEnrouteWaypoint() {
32-
TODO()
35+
fun toEnrouteWaypoint(): FlightPlanComputer.EnrouteWaypoint {
36+
return FlightPlanComputer.EnrouteWaypoint(coordinatesX, coordinatesZ, altitude, speed, active)
3337
}
3438
}
3539
}

src/main/kotlin/ru/octol1ttle/flightassistant/screen/fms/enroute/EnrouteWaypointsList.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ class EnrouteWaypointsList(y0: Int, y1: Int, width: Int, val columns: Float, val
5656
this.index = index
5757
this.hovering = hovering
5858
this.directToButton.active = getActiveSymbol() != DIRECT_TO_SYMBOL
59-
this.directToButton.tooltip = Tooltip.create(DIRECT_TO_TOOLTIP_TEXT)
59+
@Suppress("UsePropertyAccessSyntax")
60+
this.directToButton.setTooltip(Tooltip.create(DIRECT_TO_TOOLTIP_TEXT))
6061
if (index == 0) {
6162
this.moveUpButton.active = false
6263
}

0 commit comments

Comments
 (0)