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

Systems lua to json #5911

Merged
merged 2 commits into from
Aug 30, 2024
Merged

Conversation

impaktor
Copy link
Member

@impaktor impaktor commented Aug 30, 2024

Convert the local stars and bright stars tables to json (from lua)

Commit message:

Note following comments could not be carried over:

  • 44 Boötis B/C are a W-Ursae-Majoris-type shallow contact binary system,
    both G class,

  • '40 Eridani' - Problem: the secondary and tertiary are co-orbital,
    and as a system orbit the primary.

  • 'Mu Herculis' - Problem: the secondary and tertiary are co-orbital,
    and as a system orbit the primary.

  • 'Alpha Centauri' - Comment: "Gliese 559", "FK5 538", "GC 19728",
    "CCDM J14396-6050"

EDIT: I've updated above comments into the comment field I did not know our json format had.

@impaktor impaktor force-pushed the systems-lua-to-json branch 4 times, most recently from 3df6c14 to 41f459a Compare August 30, 2024 20:30
@impaktor
Copy link
Member Author

Comparison:

Master

master-sector-2024-08-30-223105_1276x697_scrot

This branch

branch-sector-2024-08-30-222505_1275x715_scrot

Master

master-44-2024-08-30-223116_1270x715_scrot

This branch

branch-44-2024-08-30-222753_1275x721_scrot

Master

master-system-2024-08-30-223126_1283x722_scrot

This branch

branch-system-2024-08-30-222806_1274x715_scrot

@impaktor
Copy link
Member Author

OK, positions above were off by factor 8, below is script to fix it, and gif now comparing. There's one star that seems to be moving south east of Sol:

Code

import json

# fpath = "partial/02_local_stars.json"
fpath = "partial/03_bright_stars.json"


with open(fpath) as f:
    systems = json.load(f)

# All Lua values for in-sector position need to be multiplied by 8 to
# turn them into lightyears (TLDR: json uses ly for units, lua uses
# percent-of-a-sector)
for i in range(len(systems)):
    systems[i]['pos'] = [s * 8 for s in systems[i]['pos']]

# Dump as is
# with open('data.json', 'w') as f:
#     json.dump(systems, f)

# Don't json format
out = json.dumps(systems, indent=None)

# Make one system per line:
out = out.replace("}, {", "},\n{")

with open('data.json', 'w') as f:
    f.write(out)

Comparison

sector
44

@impaktor
Copy link
Member Author

Just checked on master. The star that's popping in/out above is "GJ 1075", this was the only star in 02_local_stars.json on master, and was copied over from it's lua counterpart and had already been multiplied with x8, thus I should rollback the x8 my parsing just did for that line.

@impaktor impaktor force-pushed the systems-lua-to-json branch from 41f459a to 73a3f34 Compare August 30, 2024 21:17
{"name": "Xi Bo\u00f6tis", "stars": ["STAR_G", "STAR_K"], "sector": [-2, 1, 0], "pos": [1.96, 7.136, 7.152]},
{"name": "Gliese 205", "stars": ["STAR_M"], "sector": [2, -1, -1], "pos": [2.376, 5.696, 6.808]},
{"name": "NN 3976", "stars": ["STAR_M"], "sector": [-4, 1, 1], "pos": [3.216, 0.944, 4.456]},
{"name": "Alpha Centauri", "stars": ["STAR_G", "STAR_K"], "otherNames": ["Bungula", "Toliman", "\u03b1 Centauri", "Rigil Kentaurus", "Gliese 551", "Gliese 559", "FK5 538", "HIP 70890"], "sector": [-1, 0, -1], "pos": [6.624, 1.632, 4.16]},
Copy link
Member

Choose a reason for hiding this comment

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

These should be using utf-8 codepoints, not ASCII-fied UTF-16 escapes (which is the default python json.dump behavior).

Copy link
Member Author

@impaktor impaktor Aug 30, 2024

Choose a reason for hiding this comment

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

fixed & good catch

@impaktor impaktor force-pushed the systems-lua-to-json branch from 73a3f34 to d026aee Compare August 30, 2024 21:30
{"name": "Gliese 102", "stars": ["STAR_M"], "sector": [2, -3, 1], "pos": [1.944, 1.368, 5.432]},
{"name": "Gliese 103", "stars": ["STAR_K"], "sector": [2, -3, -4], "pos": [0.904, 2.816, 6.016]},
{"name": "Upsilon Andromedae", "stars": ["STAR_F"], "sector": [1, -4, 3], "pos": [5.504, 1.944, 5.056]},
{"name": "Luyten\"s Star", "stars": ["STAR_M"], "sector": [1, 0, 0], "pos": [3.448, 4.592, 1.128]},
Copy link
Member

Choose a reason for hiding this comment

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

One final issue - the apostrophe-to-double quote path is converting this Lua-side escaped apostrophe into an escaped double-quote. Feel free to manually fix it (with a grep for other occurrences).

@impaktor impaktor force-pushed the systems-lua-to-json branch from d026aee to 0c9f716 Compare August 30, 2024 21:45
@sturnclaw sturnclaw merged commit d19b663 into pioneerspacesim:master Aug 30, 2024
@impaktor impaktor deleted the systems-lua-to-json branch August 30, 2024 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants