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

Best practices for nyan API #1150

Open
heinezen opened this issue Aug 31, 2019 · 0 comments
Open

Best practices for nyan API #1150

heinezen opened this issue Aug 31, 2019 · 0 comments
Labels
area: nyan Involves our data description language/database documentation Involves the project documentation to-discuss Idea or suggestion that needs some discussion before implementation

Comments

@heinezen
Copy link
Member

heinezen commented Aug 31, 2019

The API (and nyan itself) sometimes allows us to do the same thing in different ways. For common cases, we should figure out what the "best" approach is (i.e. the most resilient/readable/clean/understandable approach) and document them. We also need them for #970 when we write the converter. Best practices could be established for simple things such as object/member names or involve larger concepts.

Simple example

Removing 5 HP to a unit via a patch can be done in two ways:

  • Subtract 5 from HP value: hp -= 5
  • Add -5 to HP value: hp += -5

Here, the former version is probably more intuitive.

API example

Adding 20% HP to all units of a civilization can be done in multiple ways:

  • Patch all HP values and HP upgrades by multiplying with 1.2
  • Patch a Attribute(MultiplierModifier) with multiplier = 1.2 into every unit
  • Patch a Attribute(MultiplierModifier) with multiplier = 1.2 into the civilization

Solution 1 works, but is probably too complex and does not work well with other mods. Solution 2 works with other stat modifying mods. Solution 3 is the easiest as we only need to add a modifier to the civilization. However, in comparison to solution 2 the modifier will not carry over when the unit is converted and there is no control over it during state changes (construction, damage, etc.).

@heinezen heinezen added documentation Involves the project documentation to-discuss Idea or suggestion that needs some discussion before implementation area: nyan Involves our data description language/database labels Aug 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: nyan Involves our data description language/database documentation Involves the project documentation to-discuss Idea or suggestion that needs some discussion before implementation
Projects
None yet
Development

No branches or pull requests

1 participant