forked from profectus/Profectus
Fix trackResetTime not working after the layer is removed and re-added
This commit is contained in:
parent
9202fa174a
commit
7d1346746f
1 changed files with 7 additions and 2 deletions
|
@ -69,9 +69,14 @@ export function createReset<T extends ResetOptions>(
|
||||||
const listeners: Record<string, Unsubscribe | undefined> = {};
|
const listeners: Record<string, Unsubscribe | undefined> = {};
|
||||||
export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent<Decimal> {
|
export function trackResetTime(layer: BaseLayer, reset: GenericReset): Persistent<Decimal> {
|
||||||
const resetTime = persistent<Decimal>(new Decimal(0));
|
const resetTime = persistent<Decimal>(new Decimal(0));
|
||||||
|
globalBus.on("addLayer", layerBeingAdded => {
|
||||||
|
if (layer === layerBeingAdded) {
|
||||||
|
listeners[layer.id]?.();
|
||||||
listeners[layer.id] = layer.on("preUpdate", diff => {
|
listeners[layer.id] = layer.on("preUpdate", diff => {
|
||||||
resetTime.value = Decimal.add(resetTime.value, diff);
|
resetTime.value = Decimal.add(resetTime.value, diff);
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
globalBus.on("reset", currentReset => {
|
globalBus.on("reset", currentReset => {
|
||||||
if (currentReset === reset) {
|
if (currentReset === reset) {
|
||||||
resetTime.value = new Decimal(0);
|
resetTime.value = new Decimal(0);
|
||||||
|
|
Loading…
Reference in a new issue