mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2024-12-25 19:28:25 +00:00
psd2ui 处理同名不同 md5 图层
This commit is contained in:
parent
81f10c1625
commit
49100d1c57
37
psd2ui-tools/dist/index.js
vendored
37
psd2ui-tools/dist/index.js
vendored
@ -1022,14 +1022,17 @@
|
|||||||
// 镜像图像管理
|
// 镜像图像管理
|
||||||
this._imageIdKeyMap = new Map();
|
this._imageIdKeyMap = new Map();
|
||||||
// 当前 psd 所有的图片
|
// 当前 psd 所有的图片
|
||||||
this._imageArray = new Map();
|
this._imageMapMd5Key = new Map();
|
||||||
|
this._imageMapImgNameKey = new Map();
|
||||||
}
|
}
|
||||||
|
// /** 相同名称不同 md5 图片的后缀id */
|
||||||
|
// private _sameImgNameId: Record<string, number> = {};
|
||||||
add(psdImage) {
|
add(psdImage) {
|
||||||
var _a;
|
var _a;
|
||||||
// 不忽略导出图片
|
// 不忽略导出图片
|
||||||
if (!psdImage.isIgnore() && !psdImage.isBind()) {
|
if (!psdImage.isIgnore() && !psdImage.isBind()) {
|
||||||
if (!this._imageArray.has(psdImage.md5)) {
|
if (!this._imageMapMd5Key.has(psdImage.md5)) {
|
||||||
this._imageArray.set(psdImage.md5, psdImage);
|
this._imageMapMd5Key.set(psdImage.md5, psdImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (typeof ((_a = psdImage.attr.comps.img) === null || _a === void 0 ? void 0 : _a.id) != "undefined") {
|
if (typeof ((_a = psdImage.attr.comps.img) === null || _a === void 0 ? void 0 : _a.id) != "undefined") {
|
||||||
@ -1039,9 +1042,33 @@
|
|||||||
}
|
}
|
||||||
this._imageIdKeyMap.set(id, psdImage);
|
this._imageIdKeyMap.set(id, psdImage);
|
||||||
}
|
}
|
||||||
|
this.handleSameImgName(psdImage, psdImage.imgName, 0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 处理相同名称的图片
|
||||||
|
*
|
||||||
|
* @param {PsdImage} psdImage
|
||||||
|
* @param {string} imgName
|
||||||
|
* @param {number} idx
|
||||||
|
* @memberof ImageMgr
|
||||||
|
*/
|
||||||
|
handleSameImgName(psdImage, imgName, idx) {
|
||||||
|
if (this._imageMapImgNameKey.has(imgName)) {
|
||||||
|
let _psdImage = this._imageMapImgNameKey.get(imgName);
|
||||||
|
if (_psdImage.md5 != psdImage.md5) {
|
||||||
|
this.handleSameImgName(psdImage, `${psdImage.imgName}_R${idx}`, idx + 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
psdImage.imgName = imgName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
psdImage.imgName = imgName;
|
||||||
|
this._imageMapImgNameKey.set(imgName, psdImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getAllImage() {
|
getAllImage() {
|
||||||
return this._imageArray;
|
return this._imageMapMd5Key;
|
||||||
}
|
}
|
||||||
/** 尝试获取有编号的图像图层 */
|
/** 尝试获取有编号的图像图层 */
|
||||||
getSerialNumberImage(psdImage) {
|
getSerialNumberImage(psdImage) {
|
||||||
@ -1059,7 +1086,7 @@
|
|||||||
}
|
}
|
||||||
clear() {
|
clear() {
|
||||||
this._imageIdKeyMap.clear();
|
this._imageIdKeyMap.clear();
|
||||||
this._imageArray.clear();
|
this._imageMapMd5Key.clear();
|
||||||
}
|
}
|
||||||
static getInstance() {
|
static getInstance() {
|
||||||
if (!this._instance) {
|
if (!this._instance) {
|
||||||
|
@ -11,7 +11,8 @@
|
|||||||
"help": "node dist/index.js --h",
|
"help": "node dist/index.js --h",
|
||||||
"test-init": "node dist/index.js --init --project-assets ./out/ --cache E:\\Git\\ccc-framework-3d\\tools\\psd2ui\\cache\\cache.json",
|
"test-init": "node dist/index.js --init --project-assets ./out/ --cache E:\\Git\\ccc-framework-3d\\tools\\psd2ui\\cache\\cache.json",
|
||||||
"test-png9": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/",
|
"test-png9": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/",
|
||||||
"test-png9-2": "node dist/index.js --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/"
|
"test-png9-2": "node dist/index.js --engine-version v342 --pinyin --input ./test/png9.psd --output ./out/",
|
||||||
|
"test-same-name": "ts-node src/index.ts --engine-version v342 --pinyin --input ./test/sameName.psd --output ./out/"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
@ -1,55 +1,89 @@
|
|||||||
|
import { PsdDocument } from "../psd/PsdDocument";
|
||||||
|
import { PsdGroup } from "../psd/PsdGroup";
|
||||||
import { PsdImage } from "../psd/PsdImage";
|
import { PsdImage } from "../psd/PsdImage";
|
||||||
|
interface Layer {
|
||||||
class ImageMgr{
|
name: string;
|
||||||
|
md5: string;
|
||||||
|
}
|
||||||
|
class ImageMgr {
|
||||||
// 镜像图像管理
|
// 镜像图像管理
|
||||||
private _imageIdKeyMap: Map<number,PsdImage> = new Map();
|
private _imageIdKeyMap: Map<number, PsdImage> = new Map();
|
||||||
|
|
||||||
// 当前 psd 所有的图片
|
// 当前 psd 所有的图片
|
||||||
private _imageArray: Map<string,PsdImage> = new Map();
|
private _imageMapMd5Key: Map<string, PsdImage> = new Map();
|
||||||
|
|
||||||
add(psdImage: PsdImage){
|
private _imageMapImgNameKey: Map<string, PsdImage> = new Map();
|
||||||
|
|
||||||
|
// /** 相同名称不同 md5 图片的后缀id */
|
||||||
|
// private _sameImgNameId: Record<string, number> = {};
|
||||||
|
|
||||||
|
add(psdImage: PsdImage) {
|
||||||
// 不忽略导出图片
|
// 不忽略导出图片
|
||||||
if(!psdImage.isIgnore() && !psdImage.isBind()){
|
if (!psdImage.isIgnore() && !psdImage.isBind()) {
|
||||||
if(!this._imageArray.has(psdImage.md5)){
|
if (!this._imageMapMd5Key.has(psdImage.md5)) {
|
||||||
this._imageArray.set(psdImage.md5,psdImage);
|
this._imageMapMd5Key.set(psdImage.md5, psdImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof psdImage.attr.comps.img?.id != "undefined"){
|
if (typeof psdImage.attr.comps.img?.id != "undefined") {
|
||||||
let id = psdImage.attr.comps.img.id;
|
let id = psdImage.attr.comps.img.id;
|
||||||
if(this._imageIdKeyMap.has(id)){
|
if (this._imageIdKeyMap.has(id)) {
|
||||||
console.warn(`ImageMgr-> ${psdImage.source.name} 已有相同 @img{id:${id}},请检查 psd 图层`);
|
console.warn(`ImageMgr-> ${psdImage.source.name} 已有相同 @img{id:${id}},请检查 psd 图层`);
|
||||||
}
|
}
|
||||||
this._imageIdKeyMap.set(id,psdImage);
|
this._imageIdKeyMap.set(id, psdImage);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.handleSameImgName(psdImage, psdImage.imgName, 0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 处理相同名称的图片
|
||||||
|
*
|
||||||
|
* @param {PsdImage} psdImage
|
||||||
|
* @param {string} imgName
|
||||||
|
* @param {number} idx
|
||||||
|
* @memberof ImageMgr
|
||||||
|
*/
|
||||||
|
handleSameImgName(psdImage: PsdImage, imgName: string, idx: number) {
|
||||||
|
if (this._imageMapImgNameKey.has(imgName)) {
|
||||||
|
let _psdImage = this._imageMapImgNameKey.get(imgName);
|
||||||
|
if (_psdImage.md5 != psdImage.md5) {
|
||||||
|
this.handleSameImgName(psdImage, `${psdImage.imgName}_R${idx}`, idx + 1);
|
||||||
|
} else {
|
||||||
|
psdImage.imgName = imgName;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
psdImage.imgName = imgName;
|
||||||
|
this._imageMapImgNameKey.set(imgName, psdImage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllImage(){
|
|
||||||
return this._imageArray;
|
getAllImage() {
|
||||||
|
return this._imageMapMd5Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 尝试获取有编号的图像图层 */
|
/** 尝试获取有编号的图像图层 */
|
||||||
getSerialNumberImage(psdImage: PsdImage){
|
getSerialNumberImage(psdImage: PsdImage) {
|
||||||
let bind = psdImage.attr.comps.flip?.bind ?? psdImage.attr.comps.img?.bind;
|
let bind = psdImage.attr.comps.flip?.bind ?? psdImage.attr.comps.img?.bind;
|
||||||
if(typeof bind != 'undefined'){
|
if (typeof bind != 'undefined') {
|
||||||
if(this._imageIdKeyMap.has(bind)){
|
if (this._imageIdKeyMap.has(bind)) {
|
||||||
return this._imageIdKeyMap.get(bind)
|
return this._imageIdKeyMap.get(bind)
|
||||||
}else{
|
} else {
|
||||||
console.warn(`ImageMgr-> ${psdImage.source.name} 未找到绑定的图像 {${bind}},请检查 psd 图层`);
|
console.warn(`ImageMgr-> ${psdImage.source.name} 未找到绑定的图像 {${bind}},请检查 psd 图层`);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return psdImage;
|
return psdImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear(){
|
clear() {
|
||||||
this._imageIdKeyMap.clear();
|
this._imageIdKeyMap.clear();
|
||||||
this._imageArray.clear()
|
this._imageMapMd5Key.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
private static _instance:ImageMgr = null
|
private static _instance: ImageMgr = null
|
||||||
public static getInstance(): ImageMgr{
|
public static getInstance(): ImageMgr {
|
||||||
if(!this._instance){
|
if (!this._instance) {
|
||||||
this._instance = new ImageMgr();
|
this._instance = new ImageMgr();
|
||||||
}
|
}
|
||||||
return this._instance;
|
return this._instance;
|
||||||
|
BIN
psd2ui-tools/test/sameName.psd
Normal file
BIN
psd2ui-tools/test/sameName.psd
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user