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

API: Make string and ID enums more accessible to users #1621

Open
Faenre opened this issue Aug 23, 2024 · 1 comment
Open

API: Make string and ID enums more accessible to users #1621

Faenre opened this issue Aug 23, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Faenre
Copy link
Contributor

Faenre commented Aug 23, 2024

[This is to encourage Programming Best Practices, as well as bring us closer to offering localization in the future. It also helps enable us to change strings once they've been in the wild for some time.]

We have a bunch of constants made available in the API, some of which are available in ns.enums, many of which are locked behind functions like getSkillNames(), and many of which have RAM costs associated, for what is essentially just getting a list of API-recognized strings for a given function. They don't provide logic, and their scattered use encourages people to just hardcode names and numbers. This also makes it difficult in case we ever want to change strings for any reason at all. Because there are not player-facing methods to avoid problems, any player-facing strings and IDs become permanent fixtures that cannot be later changed. I'd like to, well, fix that.

After a brief discussion in Discord, I've been given the clear to reduce the string-constant functions to 0 RAM:

The first change will, very simply, be an API cost reduction for the pre-existing functions. This is the lowest lift.


After reducing the above RAM costs, I want to present a lot of this information to the player in the form of enums, and deprecate many of the existing functions (in a similar way to how the console warns a player who uses timeSinceLastAugInstall and similar.

I want to enum-ify or otherwise make available the following static information:

  • Stanek.fragmentDefinitions()
    • I'd like to index the strings based on their function and their Tetris and Pentomino letter names. This would give us:
      • ns.stanek.fragment.HACK_S => Fragment<id=0, ...>
      • ns.stanek.fragment.HACK_Z => Fragment<id=1, ...>
      • ns.stanek.fragment.POWER_F => Fragment<id=100, ...>
      • ns.stanek.fragment.POWER_J => Fragment<id=101, ...>
  • Hacknet.getHashUpgrades()
    • Right now this is an unsorted list of strings, which is pretty difficult to make useful. Array-indexing is never going to be used by a player (there's no formulaic value for iterating across their functionality by index), so I'd like to turn this into ns.hacknet.hashUpgrade.SELL_FOR_MONEY => 'Sell for money' etc.
  • CodingContract.getContractTypes()
    • Similar to the hacknet upgrades, right now this is just a list of strings thrown into an array. I'd like to make them available as ns.codingcontract.type.ALGORITHMIC_STOCK_TRADER_I etc.

I also have marked the following Corporation constants that appear to be in a similar position:

  • Employee positions
  • Industry names
  • Material names
  • Research names
  • Smart supply options
  • State names
  • Unlock names
  • Upgrade names

If there are others, or if any of the above are dynamic, then let me know. Otherwise I'd like to turn those into string enums as well.

@d0sboots
Copy link
Collaborator

One thing I'll point out is that for many of these APIs, the strings are effectively frozen and cannot be changed anyway. But it's still useful to make enums for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants