clumsy-graphics
Version:
a tool for rapidly developing animations where frames are described using svg elements à la react 🙃
99 lines (98 loc) • 5.55 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.animationDevelopmentStateReducer = void 0;
function animationDevelopmentStateReducer(currentAnimationDevelopmentState = {
animationModuleBundlerState: {
bundlerStatus: 'bundlerInitializing',
},
availableAssetsFilePathMap: {},
}, someAnimationDevelopmentAction) {
switch (someAnimationDevelopmentAction.type) {
case 'animationModuleBundlerStateUpdated':
return handleAnimationModuleBundlerStateUpdated(currentAnimationDevelopmentState, someAnimationDevelopmentAction.actionPayload);
case 'graphicsRendererProcessActive':
return handleGraphicsRendererProcessActive(currentAnimationDevelopmentState, someAnimationDevelopmentAction.actionPayload);
case 'graphicsRendererProcessStdoutLogUpdated':
return handleGraphicsRendererProcessStdoutLogUpdated(currentAnimationDevelopmentState, someAnimationDevelopmentAction.actionPayload);
case 'graphicsRendererProcessSuccessful':
return handleGraphicsRendererProcessSuccessful(currentAnimationDevelopmentState, someAnimationDevelopmentAction.actionPayload);
case 'graphicsRendererProcessFailed':
return handleGraphicsRendererProcessFailed(currentAnimationDevelopmentState, someAnimationDevelopmentAction.actionPayload);
default:
return currentAnimationDevelopmentState;
}
}
exports.animationDevelopmentStateReducer = animationDevelopmentStateReducer;
function handleAnimationModuleBundlerStateUpdated(currentAnimationDevelopmentState, animationModuleBundlerStateUpdatedActionPayload) {
const { nextAnimationModuleBundlerState } = animationModuleBundlerStateUpdatedActionPayload;
return {
...currentAnimationDevelopmentState,
animationModuleBundlerState: nextAnimationModuleBundlerState,
};
}
function handleGraphicsRendererProcessActive(currentAnimationDevelopmentState, graphicsRendererProcessActiveActionPayload) {
const { newGraphicsRendererProcessKey, newGraphicsRendererProcessState } = graphicsRendererProcessActiveActionPayload;
if (currentAnimationDevelopmentState.animationModuleBundlerState
.bundlerStatus === 'bundlerInitializing') {
throw new Error('wtf? handleGraphicsRendererProcessActive');
}
else {
return {
...currentAnimationDevelopmentState,
animationModuleBundlerState: {
...currentAnimationDevelopmentState.animationModuleBundlerState,
graphicsRendererProcessStates: {
...currentAnimationDevelopmentState.animationModuleBundlerState
.graphicsRendererProcessStates,
[newGraphicsRendererProcessKey]: newGraphicsRendererProcessState,
},
},
};
}
}
function handleGraphicsRendererProcessStdoutLogUpdated(currentAnimationDevelopmentState, graphicsRendererProcessUpdateActionPayload) {
return handleGraphicsRendererProcessUpdated(currentAnimationDevelopmentState, graphicsRendererProcessUpdateActionPayload);
}
function handleGraphicsRendererProcessSuccessful(currentAnimationDevelopmentState, graphicsRendererProcessSuccessfulActionPayload) {
const { targetGraphicAssetKey, targetGraphicAssetPath } = graphicsRendererProcessSuccessfulActionPayload;
return {
...handleGraphicsRendererProcessUpdated(currentAnimationDevelopmentState, graphicsRendererProcessSuccessfulActionPayload),
availableAssetsFilePathMap: {
...currentAnimationDevelopmentState.availableAssetsFilePathMap,
[targetGraphicAssetKey]: targetGraphicAssetPath,
},
};
}
function handleGraphicsRendererProcessFailed(currentAnimationDevelopmentState, graphicsRendererProcessFailedActionPayload) {
return handleGraphicsRendererProcessUpdated(currentAnimationDevelopmentState, graphicsRendererProcessFailedActionPayload);
}
function handleGraphicsRendererProcessUpdated(currentAnimationDevelopmentState, graphicsRendererProcessFailedActionPayload) {
const { buildVersion, targetGraphicsRendererProcessKey, targetGraphicsRendererProcessStateUpdates, } = graphicsRendererProcessFailedActionPayload;
const currentAnimationModuleSourceState = currentAnimationDevelopmentState.animationModuleBundlerState
.bundlerStatus === 'bundlerActive' &&
currentAnimationDevelopmentState.animationModuleBundlerState;
const currentTargetGraphicRendererProcessState = currentAnimationModuleSourceState &&
currentAnimationModuleSourceState.buildVersion === buildVersion &&
currentAnimationModuleSourceState.graphicsRendererProcessStates[targetGraphicsRendererProcessKey];
if (!currentAnimationModuleSourceState) {
throw new Error('wtf? handleGraphicsRendererProcessFailed');
}
else if (currentTargetGraphicRendererProcessState) {
return {
...currentAnimationDevelopmentState,
animationModuleBundlerState: {
...currentAnimationModuleSourceState,
graphicsRendererProcessStates: {
...currentAnimationModuleSourceState.graphicsRendererProcessStates,
[targetGraphicsRendererProcessKey]: {
...currentTargetGraphicRendererProcessState,
...targetGraphicsRendererProcessStateUpdates,
},
},
},
};
}
else {
return currentAnimationDevelopmentState;
}
}