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

Copy component values to clipboard wrong #672

Open
vincentfretin opened this issue Jan 5, 2023 · 2 comments
Open

Copy component values to clipboard wrong #672

vincentfretin opened this issue Jan 5, 2023 · 2 comments

Comments

@vincentfretin
Copy link
Contributor

Copy component values (values that are different from defaults) to clipboard is not working correctly for geometry and gltf-model, I get just geometry="", gltf-model="". For material component, I get all props with [object Object].
I didn't see an issue with my custom components.
The copy entity to clipboard implementation is correct for all three components.

I won't investigate this right away.

@vincentfretin
Copy link
Contributor Author

getComponentClipboardRepresentation here

export function getComponentClipboardRepresentation(entity, componentName) {
/**
* Get the list of modified properties
* @param {Element} entity Entity where the component belongs
* @param {string} componentName Component name
* @return {object} List of modified properties with their value
*/
function getModifiedProperties(entity, componentName) {
var data = entity.components[componentName].data;
var defaultData = entity.components[componentName].schema;
var diff = {};
for (var key in data) {
// Prevent adding unknown attributes
if (!defaultData[key]) {
continue;
}
var defaultValue = defaultData[key].default;
var currentValue = data[key];
// Some parameters could be null and '' like mergeTo
if ((currentValue || defaultValue) && currentValue !== defaultValue) {
diff[key] = data[key];
}
}
return diff;
}
const diff = getModifiedProperties(entity, componentName);
const attributes = AFRAME.utils.styleParser.stringify(diff);
return `${componentName}="${attributes}"`;
}

needs to be rewritten to use the same code than here
var result = getImplicitValue(component, source);
var isInherited = result[1];
var implicitValue = result[0];
var currentValue = source.getAttribute(name);
var optimalUpdate = getOptimalUpdate(
component,
implicitValue,
currentValue
);

Also it should be getDOMAttribute here to avoid exporting properties that were changed inside the component by setting this.data directly (I have this use case for my material-values component akbartus/A-Frame-Component-GLTF-Manipulator#2 so that it shows the correct values in the inspector but I don't want to export those)

@vincentfretin
Copy link
Contributor Author

Oh I understand why copy an entity to clipboard and copy component to clipboard are using a different implementation here.
If we do the above, that would actually produce an empty component representation if the component is coming from a mixin.
So yeah better fix getModifiedProperties implementation here.

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

No branches or pull requests

1 participant