Add mouse/touch events to more onClicks

This commit is contained in:
thepaperpilot 2023-02-15 14:57:22 -06:00
parent fe25ea71b6
commit 1bfa66e1c9
4 changed files with 10 additions and 10 deletions

View file

@ -73,7 +73,7 @@ export type ResetButton<T extends ResetButtonOptions> = Replace<
display: GetComputableTypeWithDefault<T["display"], Ref<JSX.Element>>; display: GetComputableTypeWithDefault<T["display"], Ref<JSX.Element>>;
canClick: GetComputableTypeWithDefault<T["canClick"], Ref<boolean>>; canClick: GetComputableTypeWithDefault<T["canClick"], Ref<boolean>>;
minimumGain: GetComputableTypeWithDefault<T["minimumGain"], 1>; minimumGain: GetComputableTypeWithDefault<T["minimumGain"], 1>;
onClick: VoidFunction; onClick: (event?: MouseEvent | TouchEvent) => void;
} }
>; >;
@ -153,7 +153,7 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
} }
const onClick = resetButton.onClick; const onClick = resetButton.onClick;
resetButton.onClick = function () { resetButton.onClick = function (event?: MouseEvent | TouchEvent) {
if (unref(resetButton.canClick) === false) { if (unref(resetButton.canClick) === false) {
return; return;
} }
@ -162,7 +162,7 @@ export function createResetButton<T extends ClickableOptions & ResetButtonOption
if (resetButton.resetTime) { if (resetButton.resetTime) {
resetButton.resetTime.value = resetButton.resetTime[DefaultValue]; resetButton.resetTime.value = resetButton.resetTime[DefaultValue];
} }
onClick?.(); onClick?.(event);
}; };
return resetButton; return resetButton;

View file

@ -277,9 +277,9 @@ export function createGrid<T extends GridOptions>(
if (grid.onClick) { if (grid.onClick) {
const onClick = grid.onClick.bind(grid); const onClick = grid.onClick.bind(grid);
grid.onClick = function (id, state) { grid.onClick = function (id, state, e) {
if (unref((grid as GenericGrid).cells[id].canClick)) { if (unref((grid as GenericGrid).cells[id].canClick)) {
onClick(id, state); onClick(id, state, e);
} }
}; };
} }

View file

@ -79,7 +79,7 @@ export interface BaseRepeatable {
/** Whether or not this repeatable can be clicked. */ /** Whether or not this repeatable can be clicked. */
canClick: ProcessedComputable<boolean>; canClick: ProcessedComputable<boolean>;
/** A function that gets called when this repeatable is clicked. */ /** A function that gets called when this repeatable is clicked. */
onClick: VoidFunction; onClick: (event?: MouseEvent | TouchEvent) => void;
/** A symbol that helps identify features of the same type. */ /** A symbol that helps identify features of the same type. */
type: typeof RepeatableType; type: typeof RepeatableType;
/** The Vue component used to render this feature. */ /** The Vue component used to render this feature. */
@ -172,7 +172,7 @@ export function createRepeatable<T extends RepeatableOptions>(
}); });
repeatable.canClick = computed(() => requirementsMet(repeatable.requirements)); repeatable.canClick = computed(() => requirementsMet(repeatable.requirements));
const onClick = repeatable.onClick; const onClick = repeatable.onClick;
repeatable.onClick = function (this: GenericRepeatable) { repeatable.onClick = function (this: GenericRepeatable, event?: MouseEvent | TouchEvent) {
const genericRepeatable = repeatable as GenericRepeatable; const genericRepeatable = repeatable as GenericRepeatable;
if (!unref(genericRepeatable.canClick)) { if (!unref(genericRepeatable.canClick)) {
return; return;
@ -184,7 +184,7 @@ export function createRepeatable<T extends RepeatableOptions>(
: 1 : 1
); );
genericRepeatable.amount.value = Decimal.add(genericRepeatable.amount.value, 1); genericRepeatable.amount.value = Decimal.add(genericRepeatable.amount.value, 1);
onClick?.(); onClick?.(event);
}; };
processComputable(repeatable as T, "display"); processComputable(repeatable as T, "display");
const display = repeatable.display; const display = repeatable.display;

View file

@ -87,9 +87,9 @@ export function createTreeNode<T extends TreeNodeOptions>(
if (treeNode.onClick) { if (treeNode.onClick) {
const onClick = treeNode.onClick.bind(treeNode); const onClick = treeNode.onClick.bind(treeNode);
treeNode.onClick = function () { treeNode.onClick = function (e) {
if (unref(treeNode.canClick) !== false) { if (unref(treeNode.canClick) !== false) {
onClick(); onClick(e);
} }
}; };
} }