Add setupAutoClick
This commit is contained in:
parent
1f48622314
commit
9c45653b8b
1 changed files with 16 additions and 1 deletions
|
@ -9,6 +9,8 @@ import {
|
||||||
StyleValue,
|
StyleValue,
|
||||||
Visibility
|
Visibility
|
||||||
} from "features/feature";
|
} from "features/feature";
|
||||||
|
import { GenericLayer } from "game/layers";
|
||||||
|
import { Unsubscribe } from "nanoevents";
|
||||||
import {
|
import {
|
||||||
Computable,
|
Computable,
|
||||||
GetComputableType,
|
GetComputableType,
|
||||||
|
@ -17,7 +19,7 @@ import {
|
||||||
ProcessedComputable
|
ProcessedComputable
|
||||||
} from "util/computed";
|
} from "util/computed";
|
||||||
import { createLazyProxy } from "util/proxies";
|
import { createLazyProxy } from "util/proxies";
|
||||||
import { unref } from "vue";
|
import { computed, unref } from "vue";
|
||||||
|
|
||||||
export const ClickableType = Symbol("Clickable");
|
export const ClickableType = Symbol("Clickable");
|
||||||
|
|
||||||
|
@ -131,3 +133,16 @@ export function createClickable<T extends ClickableOptions>(
|
||||||
return clickable as unknown as Clickable<T>;
|
return clickable as unknown as Clickable<T>;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setupAutoClick(
|
||||||
|
layer: GenericLayer,
|
||||||
|
clickable: GenericClickable,
|
||||||
|
autoActive: Computable<boolean> = true
|
||||||
|
): Unsubscribe {
|
||||||
|
const isActive = typeof autoActive === "function" ? computed(autoActive) : autoActive;
|
||||||
|
return layer.on("update", () => {
|
||||||
|
if (unref(isActive) && unref(clickable.canClick)) {
|
||||||
|
clickable.onClick?.();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue