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

Team Color refactor for modding #10302

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

CliffracerX
Copy link

@CliffracerX CliffracerX commented Oct 30, 2024

Implements setPalette() with two variants; either generating a palette from a single color (as the green & blue teams do), or filling one out from three manually provided colors. This doesn't de-Finalize color, palette, or palettei as the setters still work. This refactors the Team constructors to use setPalette as well to avoid code bloat.

This also allows overriding sprites that aren't in the atlas using sprite-overrides, though the warning has been left in to alert people to potential out-of-date mods.

This is realistically only going to matter to a small number of uber-nerds in the community by allowing team color editing in mods. If there's a performant way to alter colors at runtime, that could be cool for scripted maps or similar, but I otherwise expect this to mostly be used for some simple recoloring mods/use in full conversions to freshen things up.

  • [ X ] I have read the contribution guidelines.
  • [ X ] I have ensured that my code compiles, if applicable.
  • [ X ] I have ensured that any new features in this PR function correctly in-game, if applicable.

Proof of testing (and basic mod source code)

Team.all[0].setPalette(Color.valueOf("99aa77")); //derilect
Team.all[1].setPalette(Color.valueOf("aaff00")); //sharded
Team.all[2].setPalette(Color.valueOf("ffaa00")); //crux
Team.all[3].setPalette(Color.valueOf("aa00ff")); //malis
Team.all[4].setPalette(Color.valueOf("00ffaa")); //green
Team.all[5].setPalette(Color.valueOf("00aaff")); //blue
Team.all[6].setPalette(Color.valueOf("ff00aa")); //neoplastic

image
image

TODO

Considering mods can auto-pack team regions using the same palette-based system that the base-game sprite packer can, I'm wondering about applying it to base-game sprites, but that goes a bit beyond the scope of this PR.

De-Finalizes Team colors (Team.color, Team.palette, Team.palette1), and implements setPalette() with two variants; either generating a palette from a single color (as the green & blue teams do), or filling one out from three manually provided colors.  This refactors the  Team constructors to use setPalette as well.

This is realistically only going to matter to like 3 people in the community (and all of them are me) by allowing team color editing in mods.  If there's a performant way to alter colors at runtime, that could be cool for scripted maps or similar, but I otherwise expect this to mostly be used for some simple recoloring mods/use in full conversions to freshen things up.
@CliffracerX CliffracerX changed the title Team Color refactor Team Color refactor for modding Oct 30, 2024
@way-zer
Copy link
Contributor

way-zer commented Oct 31, 2024

It should keep final, as it doesn't block you use Color.set and palette[0] = xxx;.

This is one of those Java Moments that I hadn't encountered even after using it for ten years.
Official docs still say that you can override nonexistent sprites for use in scripts & similar- while it's probably helpful to warn people in the event of out-of-date mods wasting load time, custom use should still be possible.
Copy link
Contributor

@way-zer way-zer left a comment

Choose a reason for hiding this comment

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

Maybe this

@@ -16,7 +16,7 @@
public class Team implements Comparable<Team>{
public final int id;
public final Color color;
public final Color[] palette;
public final Color[] palette = new Color[3];;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public final Color[] palette = new Color[3];;
public final Color[] palette = {new Color(), new Color(), new Color()};

Comment on lines +66 to 68
palette[0] = color.cpy();
palette[1] = color.cpy().mul(0.75f);
palette[2] = color.cpy().mul(0.5f);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
palette[0] = color.cpy();
palette[1] = color.cpy().mul(0.75f);
palette[2] = color.cpy().mul(0.5f);

way-zer

This comment was marked as duplicate.

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