@dcl/react-ecs
Version:
Decentraland ECS
52 lines (51 loc) • 1.43 kB
JavaScript
const parseTextureMode = {
'nine-slices': 0 /* BackgroundTextureMode.NINE_SLICES */,
center: 1 /* BackgroundTextureMode.CENTER */,
stretch: 2 /* BackgroundTextureMode.STRETCH */
};
/**
* @internal
*/
export function getTextureMode(mode) {
const value = mode ? parseTextureMode[mode] : 1 /* BackgroundTextureMode.CENTER */;
return { textureMode: value };
}
/**
* @internal
*/
export function getTexture(props) {
if (props.texture) {
return {
tex: {
$case: 'texture',
texture: parseTexture(props.texture)
}
};
}
if (props.avatarTexture) {
return {
tex: {
$case: 'avatarTexture',
avatarTexture: parseTexture(props.avatarTexture)
}
};
}
return undefined;
}
function parseTexture(texture) {
return {
...texture,
wrapMode: texture.wrapMode ? parseWrap[texture.wrapMode] : undefined,
filterMode: texture.filterMode ? parseFilter[texture.filterMode] : undefined
};
}
const parseWrap = {
repeat: 0 /* TextureWrapMode.TWM_REPEAT */,
clamp: 1 /* TextureWrapMode.TWM_CLAMP */,
mirror: 2 /* TextureWrapMode.TWM_MIRROR */
};
const parseFilter = {
point: 0 /* TextureFilterMode.TFM_POINT */,
'bi-linear': 1 /* TextureFilterMode.TFM_BILINEAR */,
'tri-linear': 2 /* TextureFilterMode.TFM_TRILINEAR */
};