Skip to content

Commit

Permalink
chore: add missing API documentation where useful
Browse files Browse the repository at this point in the history
  • Loading branch information
Octol1ttle committed Feb 12, 2025
1 parent 46c542e commit 571eb92
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package ru.octol1ttle.flightassistant.api
// TODO: documentation for the whole package

import net.minecraft.util.Identifier

Expand Down
15 changes: 15 additions & 0 deletions src/main/kotlin/ru/octol1ttle/flightassistant/api/alert/Alert.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,26 @@ package ru.octol1ttle.flightassistant.api.alert

import ru.octol1ttle.flightassistant.api.computer.ComputerView

/**
* A class that represents an alert. Only a single instance of this class is present for each actual alert
*/
abstract class Alert(val computers: ComputerView) {
/**
* The data that this alert uses. Impacts the priority of this alert, its sound and category color
*/
abstract val data: AlertData

/**
* An offset for the priority of this alert, relative to the priority defined by the [data].
* A negative offset means this alert will be more important than others in its category
*/
open val priorityOffset: Int = 0

val priority: Int
get() = data.priority + priorityOffset

/**
* @return whether or not this alert should be active (displaying on a screen and/or playing a sound)
*/
abstract fun shouldActivate(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import net.minecraft.text.Text
import ru.octol1ttle.flightassistant.FlightAssistant
import ru.octol1ttle.flightassistant.api.computer.ComputerView

class AlertCategory(val categoryText: Text) {
/**
* A class that represents a category of alerts.
*/
sealed class AlertCategory(val categoryText: Text) {
private val registeredAlerts: MutableList<Alert> = ArrayList()
val activeAlerts: MutableList<Alert> = ArrayList()
val ignoredAlerts: MutableList<Alert> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ package ru.octol1ttle.flightassistant.api.alert
import net.minecraft.client.gui.DrawContext

interface CenteredAlert {
/**
* @return whether or not this alert has rendered and occupied the center of the screen
*/
fun render(drawContext: DrawContext, y: Int): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ interface ECAMAlert {
/**
* Renders the text of this alert
*
* @param firstLineX The X coordinate value that should be used only for the first line.
* @param otherLinesX The X coordinate value that should be used for the second line and onwards.
* @return the amount of lines rendered
*/
fun render(drawContext: DrawContext, firstLineX: Int, otherLinesX: Int, firstLineY: Int): Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ package ru.octol1ttle.flightassistant.api.autoflight
import net.minecraft.text.Text
import net.minecraft.util.Identifier

/**
* Represents an input that computers may provide to other computers.
*
* @param target The target value of this input (e.g. the target thrust)
* @param priority The priority of this input
* @param text The text that will be shown on the [ru.octol1ttle.flightassistant.impl.display.AutomationModesDisplay] when this input is being satisfied
* @param deltaTimeMultiplier The multiplier for the delta time, used to determine how fast an input will be satisfied
* @param active If the input is active, it will be satisfied. Otherwise, this input serves as a notification
* @param identifier The identifier of this input
*/
data class ControlInput(val target: Float, val priority: Priority, val text: Text? = null, val deltaTimeMultiplier: Float = 1.0f, val active: Boolean = true, val identifier: Identifier? = null) {
enum class Priority(val value: Int) {
HIGHEST(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@ package ru.octol1ttle.flightassistant.api.computer
* A class responsible for computing data and providing it to [ru.octol1ttle.flightassistant.api.display.Display]s and [ru.octol1ttle.flightassistant.api.alert.Alert]s
*/
abstract class Computer(val computers: ComputerView) {
/**
* Whether or not this computer is enabled. Disabled computers do not tick.
*/
var enabled: Boolean = true

/**
* Whether or not this computer has faulted. This value is set to false whenever the computer is reset.
*/
var faulted: Boolean = false

/**
* The amount of times this computer has faulted.
*/
var faultCount: Int = 0

fun disabledOrFaulted(): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package ru.octol1ttle.flightassistant.api.util

/**
* A class which can track changes to a list. Useful when a list is fully reconstructed each time it is updated.
* To use, call [startTracking], which will clear this list. Call [hasNewElements] to check if the list has changed after adding elements to it
*/
class ChangeTrackingArrayList<E> {
private var backingList: ArrayList<E> = ArrayList()
private var staleList: ArrayList<E> = ArrayList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ object FATickCounter {
private set
var timePassed: Float = 0.0f
private set
var tickDelta: Float = 0.0f
var tickProgress: Float = 0.0f
private set

fun tick(player: ClientPlayerEntity, tickDelta: Float, paused: Boolean) {
fun tick(player: ClientPlayerEntity, tickProgress: Float, paused: Boolean) {
if (!paused) {
if (player.age < lastPlayerAge) {
ticksSinceWorldLoad = player.age
Expand All @@ -27,7 +27,7 @@ object FATickCounter {
lastPlayerAge = player.age
totalTicks += ticksPassed
ticksSinceWorldLoad += ticksPassed
this.tickDelta = tickDelta
this.tickProgress = tickProgress
}

val millis: Long = Util.getMeasuringTimeMs()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package ru.octol1ttle.flightassistant.api.util.extensions

import ru.octol1ttle.flightassistant.api.alert.AlertData
import ru.octol1ttle.flightassistant.api.computer.Computer
import ru.octol1ttle.flightassistant.api.autoflight.ControlInput
import ru.octol1ttle.flightassistant.api.computer.Computer

/**
* Filters the current list to try and get an active input with the highest priority in the list.
* If there are no such inputs, the returned list contains all inputs with the highest priority in the list.
*/
fun List<ControlInput>.getActiveHighestPriority(): List<ControlInput> {
val activeInput: List<ControlInput> = this.filter { it.active && it.priority.value == this[0].priority.value }
if (activeInput.any()) {
Expand All @@ -13,10 +17,16 @@ fun List<ControlInput>.getActiveHighestPriority(): List<ControlInput> {
return this.filter { it.priority.value == this[0].priority.value }
}

/**
* Filters the current list to get alert datas that have the highest priority in the list.
*/
fun List<AlertData>.getHighestPriority(): List<AlertData> {
return this.filter { it.priority == this[0].priority }
}

/**
* Filters the current list to exclude faulted computers. If a list contains an object that is not a computer, that object remains in the returned list.
*/
fun <T> List<T>.filterNonFaulted(): List<T> {
return this.filter { it !is Computer || !it.faulted}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ val cautionColor: Int
val warningColor: Int
get() = FAConfig.display.warningColor.rgb

/**
* Scales this draw context's matrix and returns the adjusted coordinates.
*
* @return a pair of adjusted coordinates.
*/
fun DrawContext.scaleMatrix(scale: Float, trueX: Int, trueY: Int): Pair<Int, Int> {
matrices.scale(scale, scale, 1.0f)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import net.minecraft.world.RaycastContext
import ru.octol1ttle.flightassistant.FlightAssistant
import ru.octol1ttle.flightassistant.api.computer.Computer
import ru.octol1ttle.flightassistant.api.computer.ComputerView
import ru.octol1ttle.flightassistant.api.util.FATickCounter.tickDelta
import ru.octol1ttle.flightassistant.api.util.FATickCounter.tickProgress
import ru.octol1ttle.flightassistant.api.util.RenderMatrices
import ru.octol1ttle.flightassistant.api.util.degrees
import ru.octol1ttle.flightassistant.api.util.extensions.fallFlying
Expand Down Expand Up @@ -70,9 +70,9 @@ class AirDataComputer(computers: ComputerView, private val mc: MinecraftClient)
get() = world.chunkManager.isChunkLoaded(player.chunkPos.x, player.chunkPos.z)

override fun tick() {
position = player.getLerpedPos(tickDelta)
position = player.getLerpedPos(tickProgress)
groundLevel = computeGroundLevel()
velocity = player.lerpVelocity(tickDelta)
velocity = player.lerpVelocity(tickProgress)
forwardVelocity = computeForwardVelocity()
roll = degrees(atan2(-RenderMatrices.worldSpaceMatrix.m10(), RenderMatrices.worldSpaceMatrix.m11()))
}
Expand Down

0 comments on commit 571eb92

Please sign in to comment.