-
Notifications
You must be signed in to change notification settings - Fork 360
Updated the color setter so that it does not change the current alpha #1970
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
Conversation
Added an isintance check to the len3 check and moved those before the len4 check. So now if the user does a tuple of 3 (ie (255,255,255)) or uses the arcade.Color type (i.e. arcade.Color.BLACK) it will just reuse the old alpha.
|
Recognized that that wasn't enough to solve the open issue so I modified the code to check for use of the arcade.Color type. Now it should be ready for testing/merge. TO CLARIFY: I only modified the len = 3 check. Not len = 4, so users can still set the alpha through this if they wish. |
|
We probably should have separate |
|
That makes sense, it is a little late for me now, but I will try to draft something like this when I get up. |
|
I created a workable draft, larger part will be cleaning up the RGB class which for the moment is just a copy of the Color class. As of right now, it is functional just not clean. |
pushfoo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is marked as a draft, but I'm not sure I understand all the changes intended or mentioned. I've commented on two specific places in the source.
larger part will be cleaning up the RGB class
einarf's comment above seems relevant here:
We probably should have separate
.rgband.alphaproperties and let the color one just take whatever length is passed in.
I'm not yet sure having an RGB class is worth it at the moment. The main benefits I see are:
- Cleaner RGB-only behavior
- In theory, adding a
arcade.color.rgbsubmodule which only has RGB colors
However, that has risks and costs:
- Inheritance can slow things down, so copy and pasting code is a useful speed optimization
- Copy and pasting creates riskjs of desyncing things which should have the same API behavior
- Preventing that risk requires more complicated unit tests
These downsides are best dempnstrated by pyglet's shape, label, and sprite abstractions. The label and shape issues affect arcade since we depend on those classes. In C or C++, we could rely on the compiler to perform inlining, but Python doesn't have that option. For pyglet, we have to (eventually) rework tests to be better at enforcing API consistency in abstractions if we don't want to sacrifice execution speed.
| return | ||
| self._color = Color(color[0], color[1], color[2], self._color[3]) | ||
| self._rgb = color | ||
| self._color = Color.from_iterable(color) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is cleaner, but it's worth doing benchmarks to see if it's slower. The reason pyglet code and the from_iterable method use the strange-looking unpacking method is that it's faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"I'm not sure I understand all the changes intended or mentioned."
The intent is to make it so RGB and alpha are used together to create color and by default not changing the alpha value of a sprite unless specifically called on.
The idea being that RGB can more easily be manipulated separately.
| type: Optional[str] = None | ||
|
|
||
|
|
||
| if sys.version_info >= (3, 12): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why remove this? My concerns:
- We don't yet have 3.12 compatibility merged (see Make arcade 2.x python 3.12 compatible #1953)
- We aim to support the lowest non-EOL version unless forced to drop it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't intentional, I still have to clean it up before it is ready.
|
@FriendlyGecko Are you still interested in working on this? TL;DR
How?This is my opinion, but I'd take the following approach:
Why revert
|
|
Marking as closed due to features being implemented in #2060 |
Will allow the closure of #1838.
I just swapped the last value self.color[3] with self._alpha which will the alpha getter to maintain the current.