-
Notifications
You must be signed in to change notification settings - Fork 12
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
instrumented color Property can only support values of type scenery.Color #1115
Comments
This seems intimately related to #948 (comment). I don't this it is ColorIO's responsibility to serialize ColorDefIO. We should instead just create a ColorDefIO to manage that when that is what your Property's value should be.
these are I'm happy to discuss creating a ColorDefIO to support the case that you are thinking above, but I feel like we should pick up #948 (comment) first to see what |
I didn't say they were |
ColorDefIO is not appropriate. ColorDef is What is the current recommended method of instrumenting a |
If One example was given as: new Property( 'rgb( 255, 200 ,200 )') Could we use this instead? new Property( new Color(255, 200 ,200 )) |
If CSS color strings are a valid color value, then I should be able to use them with a Property. But I'd like to hear @jonathanolson's opinion. |
ColorDefIO would presumably be able to serialize the subset of It seems like here, we should ideally have a way of handling ColorDef nicely (which would probably handle this case), but if we want to do something atypical/custom, then a custom IO type seems appropriate. |
@jonathanolson here's a valid new Property( new Property( new Color( 255, 230, 220 ) ) ); Do things like Node.fill support this? If not, then |
I was recommending |
PhET-iO does not support union types at the moment. |
I feel like we're going in circles here. Going back to the beginning... I have an instrumented Property whose value is restricted to And yes, I know that I could restrict this to |
I tried to answer that in #1115 (comment). Should we try one of those options? |
So would it be I think I'll just stop using CSS color strings and start using Any reason to keep this issue open, or OK to just close? |
The first sentence from #1115 (comment) is:
That could look something like: PropertyIO(NullColorStringIO)
// or
PropertyIO(NullableIO(ColorStringIO)) In any case |
Thanks. I'll convert to |
Reopening. I converted Fourier to If we're going to continue to use CSS strings for Colors, then it seems like we need an instrumented "color Property" that accepts all valid "color" values. Maybe that's described in phetsims/axon#221 (comment), maybe not. Assigning to the iO team. In the meantime, I'll continue to convert/debug. |
The previous comment sounds reasonable to me, thanks for working on this! @pixelzoom can you please review the last 3 comments and recommend if anything remains to be done for this issue? |
I've reread the previous 3 comments multiple times, and I'm not at all clear on what has been proposed/decided. I'm still left with these questions:
|
In almost all cases, it will not have a valueType of ColorDefIO, because the Property doesn't support a Property VALUE of another Property.
Alternatively, we could use
ColorProperty could become that with this patch, but then it is more like "ColorValue" Property. Basically you are asking to typify something that doesn't currently have a type in the project. I feel totally good about the above patch, but I think we should ask @samreid before committing. Index: js/util/ColorProperty.js
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/js/util/ColorProperty.js b/js/util/ColorProperty.js
--- a/js/util/ColorProperty.js (revision c0011bdb63f8386fccefb92280bbc03d48900338)
+++ b/js/util/ColorProperty.js (date 1609357739678)
@@ -2,8 +2,12 @@
import Property from '../../../axon/js/Property.js';
import merge from '../../../phet-core/js/merge.js';
-import Color from './Color.js';
+import NullableIO from '../../../tandem/js/types/NullableIO.js';
+import OrIO from '../../../tandem/js/types/OrIO.js';
+import StringIO from '../../../tandem/js/types/StringIO.js';
import scenery from '../scenery.js';
+import Color from './Color.js';
+import ColorDef from './ColorDef.js';
/**
* Convenience type for creating Property<Color>
@@ -21,8 +25,8 @@
}
options = merge( {
- valueType: Color,
- phetioType: Property.PropertyIO( Color.ColorIO )
+ isValidValue: color => ColorDef.isColorDef( color ) && !( color instanceof Property ),
+ phetioType: Property.PropertyIO( NullableIO( OrIO( [ Color.ColorIO, StringIO ] ) ) )
}, options );
super( color, options );
}
Most likely as Does all this make more sense @pixelzoom? If so, please toss over to @samreid to potentially commit the above patch if he wants to. |
I'm still not OK with this. I don't believe @jonathanolson would be either. ColorDefIO (as currently defined) does not belong in ColorDef. + isValidValue: color => ColorDef.isColorDef( color ) && !( color instanceof Property ), So while sticking ColorDefIO in ColorDef may be convenient for addressing this issue, imo it's just plain wrong. We need a type definition that is {Color|string|null}, and a type-specific Property for that type definition. And that shouldn't be shoehorned into ColorDef. |
Here's a sketch of ColorValue, ColorValueIO, and ColorValueProperty, all of which deal with values of type const ColorValue = {
...
isColorValue( value ) {
return color === null || typeof color === 'string' || color instanceof Color;
}
}
ColorValue.ColorValueO = new IOType( 'ColorValueIO', {
isValidValue: ColorValue.isColorValue,
supertype: ?????
} );
class ColorValueProperty {
...
phetioType: Property.PropertyIO( ColorValue.ColorValueIO )
} As a bonus, duplication in ColorDef.isColorDef can be removed like this: isColorDef( color ) {
return ColorValue.isColorValue( color ) ||
( color instanceof Property && ColorValue.isColorValue( color.value ) );
} It would also be nice to have something that validates that EDIT: I also think that ColorProperty (as currently implemented) should be renamed to ColorDefProperty. It takes a value of type ColorDef. |
It seems like the implementation hurdle to just have a
Added this in the above commit on the |
Self-unassigning until we hear from @zepumph. |
We may want to defer this until we discuss #1135 (revisit "color" and "paint"). |
Sounds good to me! |
This:
... requires the value to be a
Color
, and makes it impossible to use other valid color values (a CSS color{string}
ornull
) with an instrumented color Property.E.g. this:
fails with this:
This seems like an undesirable restriction on instrumented color Properties. I can workaround it by replacing strings with Color instances, but not sure what I'll do if I need
null
.The text was updated successfully, but these errors were encountered: