mirror of
https://gitee.com/onvia/ccc-tnt-psd2ui
synced 2025-10-16 12:08:43 +00:00
两个版本的插件
This commit is contained in:
@@ -0,0 +1,153 @@
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.imageCacheMgr = exports.ImageCacheMgr = void 0;
|
||||
const fs_extra_1 = __importDefault(require("fs-extra"));
|
||||
const path_1 = __importDefault(require("path"));
|
||||
const config_1 = require("../config");
|
||||
const EditorVersion_1 = require("../EditorVersion");
|
||||
const FileUtils_1 = require("../utils/FileUtils");
|
||||
class ImageCacheMgr {
|
||||
constructor() {
|
||||
this._imageMap = new Map();
|
||||
this._cachePath = null;
|
||||
}
|
||||
initWithPath(_path) {
|
||||
if (!fs_extra_1.default.existsSync(_path)) {
|
||||
console.log(`ImageCacheMgr-> 文件不存在: ${_path}`);
|
||||
return;
|
||||
}
|
||||
this._cachePath = _path;
|
||||
let content = fs_extra_1.default.readFileSync(_path, "utf-8");
|
||||
this.initWithFile(content);
|
||||
}
|
||||
initWithFile(file) {
|
||||
let json = JSON.parse(file);
|
||||
this.initWithJson(json);
|
||||
}
|
||||
initWithJson(json) {
|
||||
for (const key in json) {
|
||||
if (Object.prototype.hasOwnProperty.call(json, key)) {
|
||||
this._imageMap.set(key, json[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
set(md5, warp) {
|
||||
this._imageMap.set(md5, warp);
|
||||
}
|
||||
has(md5) {
|
||||
return this._imageMap.has(md5);
|
||||
}
|
||||
get(md5) {
|
||||
return this._imageMap.get(md5);
|
||||
}
|
||||
saveImageMap(_path) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (!_path) {
|
||||
_path = this._cachePath;
|
||||
}
|
||||
if (!_path) {
|
||||
console.log(`ImageCacheMgr-> 缓存路径 [${_path}] 不存在,无法保存 `);
|
||||
return;
|
||||
}
|
||||
let obj = Object.create(null);
|
||||
this._imageMap.forEach((v, k) => {
|
||||
obj[k] = v;
|
||||
});
|
||||
let content = JSON.stringify(obj, null, 2);
|
||||
yield FileUtils_1.fileUtils.writeFile(_path, content);
|
||||
});
|
||||
}
|
||||
// 获取已存在的图片,生成 md5: uuid 映射,
|
||||
loadImages(dir) {
|
||||
if (this._imageMap.size > 0) {
|
||||
console.error(`ImageCacheMgr-> 暂时只能在 启动时加载`);
|
||||
return;
|
||||
}
|
||||
let pngs = FileUtils_1.fileUtils.filterFile(dir, (fileName) => {
|
||||
let extname = path_1.default.extname(fileName);
|
||||
if (extname == ".png") {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
for (let i = 0; i < pngs.length; i++) {
|
||||
const png = pngs[i];
|
||||
let md5 = FileUtils_1.fileUtils.getMD5(png);
|
||||
console.log(`ImageCacheMgr->缓存 `, png);
|
||||
let imageWarp = this._loadImageMetaWarp(`${png}.meta`);
|
||||
if (imageWarp) {
|
||||
this.set(md5, imageWarp);
|
||||
}
|
||||
}
|
||||
}
|
||||
_loadImageMetaWarp(_path) {
|
||||
let content = fs_extra_1.default.readFileSync(_path, { encoding: "utf-8" });
|
||||
let imageWarp = null;
|
||||
switch (config_1.config.editorVersion) {
|
||||
case EditorVersion_1.EditorVersion.v249:
|
||||
imageWarp = this._loadImageMeta249(content, _path);
|
||||
break;
|
||||
case EditorVersion_1.EditorVersion.v342:
|
||||
imageWarp = this._loadImageMeta34x(content, _path);
|
||||
break;
|
||||
default:
|
||||
console.log(`ImageCacheMgr-> 暂未实现 ${EditorVersion_1.EditorVersion[config_1.config.editorVersion]} 版本`);
|
||||
break;
|
||||
}
|
||||
return imageWarp;
|
||||
}
|
||||
_loadImageMeta249(metaContent, _path) {
|
||||
var _a;
|
||||
let filename = path_1.default.basename(_path, ".png.meta");
|
||||
let fullpath = path_1.default.join(path_1.default.dirname(_path), `${filename}.png`);
|
||||
let metaJson = JSON.parse(metaContent);
|
||||
if (!((_a = metaJson === null || metaJson === void 0 ? void 0 : metaJson.subMetas) === null || _a === void 0 ? void 0 : _a[filename])) {
|
||||
return null;
|
||||
}
|
||||
let imageWarp = {
|
||||
path: fullpath,
|
||||
textureUuid: metaJson.subMetas[filename].uuid,
|
||||
uuid: metaJson.uuid,
|
||||
isOutput: true,
|
||||
};
|
||||
return imageWarp;
|
||||
}
|
||||
_loadImageMeta34x(metaContent, _path) {
|
||||
var _a;
|
||||
let filename = path_1.default.basename(_path, ".png.meta");
|
||||
let fullpath = path_1.default.join(path_1.default.dirname(_path), `${filename}.png`);
|
||||
let metaJson = JSON.parse(metaContent);
|
||||
if (!((_a = metaJson === null || metaJson === void 0 ? void 0 : metaJson.subMetas) === null || _a === void 0 ? void 0 : _a["6c48a"])) {
|
||||
return null;
|
||||
}
|
||||
let uuid = metaJson.subMetas["6c48a"].uuid.replace("@6c48a", "");
|
||||
let imageWarp = {
|
||||
path: fullpath,
|
||||
textureUuid: uuid,
|
||||
uuid: uuid,
|
||||
isOutput: true,
|
||||
};
|
||||
return imageWarp;
|
||||
}
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new ImageCacheMgr();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
}
|
||||
exports.ImageCacheMgr = ImageCacheMgr;
|
||||
ImageCacheMgr._instance = null;
|
||||
exports.imageCacheMgr = ImageCacheMgr.getInstance();
|
56
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/assets-manager/ImageMgr.js
Normal file
56
ccc-tnt-psd2ui-v2.4.x/libs/psd2ui/assets-manager/ImageMgr.js
Normal file
@@ -0,0 +1,56 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.imageMgr = void 0;
|
||||
class ImageMgr {
|
||||
constructor() {
|
||||
// 镜像图像管理
|
||||
this._imageIdKeyMap = new Map();
|
||||
// 当前 psd 所有的图片
|
||||
this._imageArray = new Map();
|
||||
}
|
||||
add(psdImage) {
|
||||
var _a;
|
||||
// 不忽略导出图片
|
||||
if (!psdImage.isIgnore() && !psdImage.isBind()) {
|
||||
if (!this._imageArray.has(psdImage.md5)) {
|
||||
this._imageArray.set(psdImage.md5, psdImage);
|
||||
}
|
||||
}
|
||||
if (typeof ((_a = psdImage.attr.comps.img) === null || _a === void 0 ? void 0 : _a.id) != "undefined") {
|
||||
let id = psdImage.attr.comps.img.id;
|
||||
if (this._imageIdKeyMap.has(id)) {
|
||||
console.warn(`ImageMgr-> ${psdImage.source.name} 已有相同 @img{id:${id}},请检查 psd 图层`);
|
||||
}
|
||||
this._imageIdKeyMap.set(id, psdImage);
|
||||
}
|
||||
}
|
||||
getAllImage() {
|
||||
return this._imageArray;
|
||||
}
|
||||
/** 尝试获取有编号的图像图层 */
|
||||
getSerialNumberImage(psdImage) {
|
||||
var _a, _b, _c;
|
||||
let bind = (_b = (_a = psdImage.attr.comps.flip) === null || _a === void 0 ? void 0 : _a.bind) !== null && _b !== void 0 ? _b : (_c = psdImage.attr.comps.img) === null || _c === void 0 ? void 0 : _c.bind;
|
||||
if (typeof bind != 'undefined') {
|
||||
if (this._imageIdKeyMap.has(bind)) {
|
||||
return this._imageIdKeyMap.get(bind);
|
||||
}
|
||||
else {
|
||||
console.warn(`ImageMgr-> ${psdImage.source.name} 未找到绑定的图像 {${bind}},请检查 psd 图层`);
|
||||
}
|
||||
}
|
||||
return psdImage;
|
||||
}
|
||||
clear() {
|
||||
this._imageIdKeyMap.clear();
|
||||
this._imageArray.clear();
|
||||
}
|
||||
static getInstance() {
|
||||
if (!this._instance) {
|
||||
this._instance = new ImageMgr();
|
||||
}
|
||||
return this._instance;
|
||||
}
|
||||
}
|
||||
ImageMgr._instance = null;
|
||||
exports.imageMgr = ImageMgr.getInstance();
|
Reference in New Issue
Block a user