Fix trackResetTime not working after the layer is removed and re-added

This commit is contained in:
thepaperpilot 2022-07-17 19:27:53 -05:00
parent 9ad2a80e0b
commit faff8c328c

View file

@ -69,8 +69,13 @@ export function createReset<T extends ResetOptions>(
const listeners: Record<string, Unsubscribe | undefined> = {};
export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent<Decimal> {
const resetTime = persistent<Decimal>(new Decimal(0));
listeners[layer.id] = layer.on("preUpdate", diff => {
resetTime.value = Decimal.add(resetTime.value, diff);
globalBus.on("addLayer", layerBeingAdded => {
if (layer === layerBeingAdded) {
listeners[layer.id]?.();
listeners[layer.id] = layer.on("preUpdate", diff => {
resetTime.value = Decimal.add(resetTime.value, diff);
});
}
});
globalBus.on("reset", currentReset => {
if (currentReset === reset) {