Skip to content

Commit

Permalink
save settings to pac (cocos#14917)
Browse files Browse the repository at this point in the history
  • Loading branch information
nianba23 authored Apr 26, 2023
1 parent 46da89a commit 2bb1c36
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion editor/inspector/assets/texture/auto-atlas.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const texture = require('./texture');
const { readFileSync, writeFileSync } = require('fs');

exports.template = texture.template;

Expand All @@ -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;

Expand Down

0 comments on commit 2bb1c36

Please sign in to comment.