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

Local missions should list distances in AU rather than Ly #5756

Merged
merged 1 commit into from
Feb 16, 2024

Conversation

impaktor
Copy link
Member

When listing table of all player's accepted missions, local deliveries all have distance "0 ly". Switch to AU instead.

Fixes #5755

Demonstration

2024-02-10-122202_1266x687_scrot

Pondering

  • do we have AU units defined elsewhere that I should use, or defining it in the local file is good?
  • under which circumstances would mission.location:GetSystemBody() return nil, and what should one display in that circumstance?

Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Before accessing the result of SystemPath:GetSystemBody() you should check to make sure mission.location:IsBodyPath() is true. The location might be a path to a system rather than a body in that system, in which case the system body will be nil and dereferencing .body will raise an error.
    (Checking :IsSameSystem() means that the system body will have a "physical" Body representation since the system it refers to is currently "reified", and thus you don't need to worry about nil-checking .body.)
  • Use ui.Format.Distance to display any in-system distances (passing the raw distance to the target). It will handle dividing by meters/km/AU as needed and format the result accordingly.
  • Off the top of my head, we don't have a pre-built formatter for inter-system distances, so keeping the old string.format method for LY is fine.

@impaktor impaktor force-pushed the fix-location-dist-format branch 5 times, most recently from 1a37df6 to 647a303 Compare February 14, 2024 14:37
@impaktor impaktor requested a review from sturnclaw February 14, 2024 19:19
Copy link
Member

@sturnclaw sturnclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, if it's been tested then it gets my thumbs up. There's one variable name that should be changed before merge, but otherwise looks solid.

Comment on lines 111 to 112
local systemBody = mission.location:GetSystemBody().body
dist = Game.player:GetPositionRelTo(systemBody):length()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This body is not a SystemBody, it's just a regular Body. Would strongly recommend the variable not be named systemBody as that usually implies the type of the variable is actually the SystemBody returned from GetSystemBody().

(Variable names are important in dynamically-typed languages...)

@impaktor impaktor force-pushed the fix-location-dist-format branch from 647a303 to d20e04d Compare February 16, 2024 07:40
In table of all player's accepted missions, display distance for
local deliveries in AU, and interstellar in LY.
@impaktor impaktor force-pushed the fix-location-dist-format branch from d20e04d to 7efc2ce Compare February 16, 2024 08:02
@impaktor impaktor merged commit 5a616cc into pioneerspacesim:master Feb 16, 2024
@impaktor impaktor deleted the fix-location-dist-format branch February 16, 2024 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Local missions have mission distance 0 Ly
3 participants