fixed clip lengths not syncing
This commit is contained in:
+14
-7
@@ -3612,10 +3612,14 @@
|
|||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
function readStageDefinitionFromForm(result, stage, isLastStage) {
|
function readStageDefinitionFromForm(result, stage, isLastStage, syncCycleSeconds = true) {
|
||||||
const base = `stub_stage_${stage.stageNumber}`;
|
const base = `stub_stage_${stage.stageNumber}`;
|
||||||
const loop = !!result?.[`${base}_loop`];
|
const loop = !!result?.[`${base}_loop`];
|
||||||
const cycleSeconds = parseRequiredPositiveNumber(result?.[`${base}_cycle_seconds`], `Stage p${stage.stageNumber} cycle seconds`);
|
// Newly created definitions follow the authored GeckoLib clip length. Imported
|
||||||
|
// definitions may retain their explicitly authored cycle_seconds metadata.
|
||||||
|
const cycleSeconds = syncCycleSeconds
|
||||||
|
? parseRequiredPositiveNumber(stage.cycleSeconds, `Stage p${stage.stageNumber} cycle seconds`)
|
||||||
|
: parseRequiredPositiveNumber(result?.[`${base}_cycle_seconds`], `Stage p${stage.stageNumber} cycle seconds`);
|
||||||
const speed = parseOptionalNumber(result?.[`${base}_speed`], `Stage p${stage.stageNumber} speed`, (value) => value > 0);
|
const speed = parseOptionalNumber(result?.[`${base}_speed`], `Stage p${stage.stageNumber} speed`, (value) => value > 0);
|
||||||
const midpointOffset = parseOptionalNumber(
|
const midpointOffset = parseOptionalNumber(
|
||||||
loop ? result?.[`${base}_midpoint_offset`] : '',
|
loop ? result?.[`${base}_midpoint_offset`] : '',
|
||||||
@@ -3829,7 +3833,7 @@
|
|||||||
if (props.warnings.length) Blockbench.showQuickMessage(`Item props: ${props.warnings.join(' ')}`, 6000);
|
if (props.warnings.length) Blockbench.showQuickMessage(`Item props: ${props.warnings.join(' ')}`, 6000);
|
||||||
void refreshPropPreviews(true);
|
void refreshPropPreviews(true);
|
||||||
if (blockRequirementPanel?.vue) blockRequirementPanel.vue.load(group.id);
|
if (blockRequirementPanel?.vue) blockRequirementPanel.vue.load(group.id);
|
||||||
showAnimationDefinitionReviewDialog(group, analysis);
|
showAnimationDefinitionReviewDialog(group, analysis, { syncCycleSeconds: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
function importAnimationDefinition() {
|
function importAnimationDefinition() {
|
||||||
@@ -3867,7 +3871,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function showAnimationDefinitionReviewDialog(group, analysis) {
|
function showAnimationDefinitionReviewDialog(group, analysis, options = {}) {
|
||||||
|
const syncCycleSeconds = options.syncCycleSeconds !== false;
|
||||||
const savedMetadata = getProjectActorAnimdefMetadata();
|
const savedMetadata = getProjectActorAnimdefMetadata();
|
||||||
const saved = getSavedAnimdef(group.id);
|
const saved = getSavedAnimdef(group.id);
|
||||||
const savedActors = new Map((Array.isArray(saved.actors) ? saved.actors : []).map((actor) => [actor.label, actor]));
|
const savedActors = new Map((Array.isArray(saved.actors) ? saved.actors : []).map((actor) => [actor.label, actor]));
|
||||||
@@ -4137,10 +4142,12 @@
|
|||||||
form[`${base}_cycle_seconds`] = {
|
form[`${base}_cycle_seconds`] = {
|
||||||
label: 'Cycle seconds',
|
label: 'Cycle seconds',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
value: savedStage.cycle_seconds ?? stage.cycleSeconds,
|
value: syncCycleSeconds ? stage.cycleSeconds : savedStage.cycle_seconds ?? stage.cycleSeconds,
|
||||||
min: 0.001,
|
min: 0.001,
|
||||||
step: 0.001,
|
step: 0.001,
|
||||||
description: 'Detected from the compiled GeckoLib animation_length.',
|
description: syncCycleSeconds
|
||||||
|
? 'Automatically synced from the current compiled GeckoLib animation_length.'
|
||||||
|
: 'Imported from the animation definition.',
|
||||||
};
|
};
|
||||||
form[`${base}_allow_join`] = {
|
form[`${base}_allow_join`] = {
|
||||||
label: 'Allow joins',
|
label: 'Allow joins',
|
||||||
@@ -4230,7 +4237,7 @@
|
|||||||
|
|
||||||
const stages = analysis.stages.map((stage, index) => ({
|
const stages = analysis.stages.map((stage, index) => ({
|
||||||
...unmanagedAnimdefFields(savedStages.get(stage.stageNumber), STAGE_GENERATOR_KEYS),
|
...unmanagedAnimdefFields(savedStages.get(stage.stageNumber), STAGE_GENERATOR_KEYS),
|
||||||
...readStageDefinitionFromForm(result, stage, index === analysis.stages.length - 1),
|
...readStageDefinitionFromForm(result, stage, index === analysis.stages.length - 1, syncCycleSeconds),
|
||||||
}));
|
}));
|
||||||
const actorsByLabel = new Map(actors.map((actor) => [actor.label, actor]));
|
const actorsByLabel = new Map(actors.map((actor) => [actor.label, actor]));
|
||||||
const explicitReceivers = actors.some((actor) => actor.receiver);
|
const explicitReceivers = actors.some((actor) => actor.receiver);
|
||||||
|
|||||||
@@ -167,6 +167,19 @@ test('Save retains definition fields in the project without exporting and restor
|
|||||||
assert.equal(h.exports[0].display_name, result.display_name);
|
assert.equal(h.exports[0].display_name, result.display_name);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('cycle seconds always follow the current stage lengths', () => {
|
||||||
|
const h = createHarness(), dialog = h.open(), result = defaults(dialog.form);
|
||||||
|
result.stub_stage_1_cycle_seconds = 99;
|
||||||
|
result.stub_stage_2_cycle_seconds = 88;
|
||||||
|
h.setFormResult(result);
|
||||||
|
assert.equal(dialog.onConfirm(result), true);
|
||||||
|
assert.deepEqual(h.exports[0].stages.map((stage) => stage.cycle_seconds), [1, 2]);
|
||||||
|
|
||||||
|
const reopened = h.open();
|
||||||
|
assert.equal(reopened.form.stub_stage_1_cycle_seconds.value, 1);
|
||||||
|
assert.equal(reopened.form.stub_stage_2_cycle_seconds.value, 2);
|
||||||
|
});
|
||||||
|
|
||||||
test('invalid Save leaves previously saved fields intact', () => {
|
test('invalid Save leaves previously saved fields intact', () => {
|
||||||
const h = createHarness(), dialog = h.open(), result = defaults(dialog.form);
|
const h = createHarness(), dialog = h.open(), result = defaults(dialog.form);
|
||||||
result.display_name = 'Original';
|
result.display_name = 'Original';
|
||||||
|
|||||||
Reference in New Issue
Block a user