This commit is contained in:
2026-09-29 15:36:03 +02:00
parent 7f1c7d70f8
commit 312dbf7e92
2 changed files with 72 additions and 3 deletions
+47 -2
View File
@@ -8,7 +8,7 @@ function createHarness() {
const file = path.join(__dirname, '..', 'AnimationDirector.js');
const source = fs.readFileSync(file, 'utf8').replace(
' Plugin.register(PLUGIN_ID, {',
' globalThis.adTest = { showAnimationDefinitionReviewDialog };\n Plugin.register(PLUGIN_ID, {'
' globalThis.adTest = { showAnimationDefinitionReviewDialog, createInjectorGenderDefaultHandler };\n Plugin.register(PLUGIN_ID, {'
);
const dialogs = [];
const exports = [];
@@ -45,7 +45,8 @@ function createHarness() {
context.adTest.showAnimationDefinitionReviewDialog(group, analysis);
return dialogs.at(-1);
}
return { open, exports, errors, project, analysis, setFormResult(result) { formResult = result; } };
return { open, exports, errors, project, analysis, createInjectorGenderDefaultHandler: context.adTest.createInjectorGenderDefaultHandler,
setFormResult(result) { formResult = result; } };
}
function defaults(form) {
@@ -54,6 +55,50 @@ function defaults(form) {
.map(([key, field]) => [key, field.value]));
}
test('selecting an injector adds an editable male tag without enforcing it on export', () => {
for (const role of ['V', 'A', 'M']) {
const h = createHarness(), dialog = h.open(), result = defaults(dialog.form), updates = [];
const instance = { form: { setValues(values, notify) { updates.push(values); assert.equal(notify, false); } } };
result.stub_actor_1_actor_tags = 'custom.tag';
result.stub_actor_1_injector = role;
dialog.onFormChange.call(instance, result);
assert.equal(result.stub_actor_1_actor_tags, 'custom.tag, gender.male');
assert.equal(updates.length, 1);
result.stub_actor_1_actor_tags = 'custom.tag';
dialog.onFormChange.call(instance, result);
result.display_name = 'Unrelated edit';
dialog.onFormChange.call(instance, result);
assert.equal(updates.length, 1, 'Manual removal survives unrelated changes');
result.stub_actor_2_entity_types = 'minecraft:wolf';
dialog.onConfirm(result);
assert.equal(h.errors.length, 0);
assert.equal(h.exports[0].actors[0].injector, role);
assert.deepEqual(h.exports[0].actors[0].actor_tags, ['custom.tag']);
}
});
test('injector defaults preserve loaded roles, existing tags, and actor preferences edits', () => {
const h = createHarness();
const form = {
preferences_animdef_1_injector: { value: 'V' },
preferences_animdef_2_injector: { value: '' },
};
const update = h.createInjectorGenderDefaultHandler(form), writes = [];
const dialog = { form: { setValues(values) { writes.push(values); } } };
const result = { preferences_animdef_1_injector: 'V', preferences_animdef_1_actor_tags: 'custom.tag',
preferences_animdef_2_injector: '', preferences_animdef_2_actor_tags: 'gender.male, other.tag' };
update(dialog, result);
assert.equal(writes.length, 0, 'Opening an imported/saved role does not add a tag');
result.preferences_animdef_2_injector = 'A'; update(dialog, result);
assert.equal(writes.length, 0, 'Existing male tags are not duplicated');
result.preferences_animdef_2_injector = ''; update(dialog, result);
assert.equal(result.preferences_animdef_2_actor_tags, 'gender.male, other.tag', 'Deselecting a role does not remove explicit tags');
result.preferences_animdef_2_actor_tags = 'other.tag';
result.preferences_animdef_2_injector = 'M'; update(dialog, result);
assert.equal(result.preferences_animdef_2_actor_tags, 'other.tag, gender.male');
assert.equal(result.preferences_animdef_1_actor_tags, 'custom.tag', 'Only the changed actor is affected');
});
test('Save retains definition fields in the project without exporting and restores them on reopen', () => {
const h = createHarness(), dialog = h.open(), result = defaults(dialog.form);
assert.deepEqual(Array.from(dialog.buttons), ['Cancel', 'Save', 'Create Animdef']);