* 批量添加L7texture使用到的图片,从雪碧图上裁剪 * @param layers * @param sprite * @param scene
({ layers, sprite, spriteJson, scene, options })
| 1653 | * @param scene |
| 1654 | */ |
| 1655 | async function addTextures({ layers, sprite, spriteJson, scene, options }) { |
| 1656 | const timestamp = +new Date(); |
| 1657 | for (let index = 0; index < layers.length; index++) { |
| 1658 | const l = layers[index]; |
| 1659 | const texture = (l.texture || {}).values; |
| 1660 | const iconInfo = spriteJson[texture]; |
| 1661 | if (iconInfo) { |
| 1662 | const image = await changeSpriteIconToImgData(sprite, { ...iconInfo, id: texture }, options); |
| 1663 | const style = l.style || {}; |
| 1664 | const color = style.textureColor, |
| 1665 | rotate = style.textureRotate; |
| 1666 | if (color || rotate) { |
| 1667 | const modifiedImg = await processImage(imgDataToBlob(image), { |
| 1668 | color, |
| 1669 | rotate |
| 1670 | }); |
| 1671 | const newImageId = `${texture}_${timestamp}_${index}`; |
| 1672 | Object.assign(l.texture || {}, { values: newImageId }); |
| 1673 | scene.addImage(newImageId, modifiedImg); |
| 1674 | } else if (!scene.hasImage(texture)) { |
| 1675 | scene.addImage(texture, imgDataToBlob(image)); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | /** |
| 1682 | * 过滤统计图表数据 |
no test coverage detected