save settings to pac (#14917)

This commit is contained in:
changhua
2023-04-26 18:40:56 +08:00
committed by GitHub
parent 46da89a5f7
commit 2bb1c366b3
+22 -1
View File
@@ -1,6 +1,7 @@
'use strict';
const texture = require('./texture');
const { readFileSync, writeFileSync } = require('fs');
exports.template = texture.template;
@@ -10,7 +11,27 @@ exports.$ = texture.$;
const Elements = texture.Elements;
exports.methods = texture.methods;
exports.methods = Object.assign({}, texture.methods, {
// before save meta
apply() {
const file = this.asset.file;
if (file) {
try {
const pacData = JSON.parse(readFileSync(file, 'utf8'));
Object.assign(pacData, {
ver: this.meta.ver,
importer: this.meta.importer,
userData: this.meta.userData,
});
writeFileSync(file, JSON.stringify(pacData, null, 2), 'utf8');
} catch (error) {
console.error('Failed to save auto atlas settings!');
return false;
}
}
return;
}
});
exports.ready = texture.ready;