cortico-world-extra-actions 0.3.28 → 0.3.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/writer.js +12 -3
package/package.json
CHANGED
package/src/writer.js
CHANGED
|
@@ -228,9 +228,13 @@ function applyVocab(packDir, actions, managed) {
|
|
|
228
228
|
added.push(a.word);
|
|
229
229
|
}
|
|
230
230
|
const removed = current.filter((w) => !have.has(w?.id)).map((w) => w?.id);
|
|
231
|
+
// 没有实质变化就不落盘:figure.json 也是宿主在读的文件,多余的重写会让
|
|
232
|
+
// 「外观跟着形象走」这类逻辑重新求值,用户改的配色看起来就"掉回默认"。
|
|
233
|
+
const unchanged = sameIds(current.map((w) => w?.id), kept.map((w) => w?.id));
|
|
234
|
+
if (unchanged) return { added, removed, baseVocab: base, written: kept.map((w) => w?.id), wrote: false };
|
|
231
235
|
fig.vocab = kept;
|
|
232
236
|
writeJson(file, fig);
|
|
233
|
-
return { added, removed, baseVocab: base, written: kept.map((w) => w?.id) };
|
|
237
|
+
return { added, removed, baseVocab: base, written: kept.map((w) => w?.id), wrote: true };
|
|
234
238
|
}
|
|
235
239
|
|
|
236
240
|
/** 清空时把词表还回去:先回到 base,实在对不上就只摘掉自己加的那些。 */
|
|
@@ -241,13 +245,18 @@ function restoreVocab(packDir, managed) {
|
|
|
241
245
|
const current = Array.isArray(fig.vocab) ? fig.vocab : [];
|
|
242
246
|
const clean = managed?.written && sameIds(current.map((w) => w?.id), managed.written);
|
|
243
247
|
let restored = false;
|
|
248
|
+
let next;
|
|
244
249
|
if (clean && Array.isArray(managed.baseVocab)) {
|
|
245
|
-
|
|
250
|
+
next = managed.baseVocab;
|
|
246
251
|
restored = true;
|
|
247
252
|
} else {
|
|
248
253
|
const drop = new Set(Array.isArray(managed?.added) ? managed.added : []);
|
|
249
|
-
|
|
254
|
+
next = current.filter((w) => !drop.has(w?.id));
|
|
250
255
|
}
|
|
256
|
+
if (sameIds((next ?? []).map((w) => w?.id), current.map((w) => w?.id))) {
|
|
257
|
+
return { added: [], removed: [], restored, wrote: false }; // 已经是这个状态,不碰文件
|
|
258
|
+
}
|
|
259
|
+
fig.vocab = next;
|
|
251
260
|
writeJson(file, fig);
|
|
252
261
|
return { added: [], removed: [], restored };
|
|
253
262
|
}
|