2021-06-11 23:38:16 -05:00
|
|
|
<template>
|
2022-03-13 11:00:44 -05:00
|
|
|
<button
|
2023-02-15 20:00:36 -06:00
|
|
|
v-if="isVisible(visibility)"
|
2022-03-13 11:00:44 -05:00
|
|
|
:style="[
|
2023-02-15 20:00:36 -06:00
|
|
|
{ visibility: isHidden(visibility) ? 'hidden' : undefined },
|
2022-03-13 11:00:44 -05:00
|
|
|
unref(style) ?? []
|
|
|
|
]"
|
|
|
|
@click="onClick"
|
|
|
|
@mousedown="start"
|
|
|
|
@mouseleave="stop"
|
|
|
|
@mouseup="stop"
|
2022-05-02 21:10:18 -05:00
|
|
|
@touchstart.passive="start"
|
|
|
|
@touchend.passive="stop"
|
|
|
|
@touchcancel.passive="stop"
|
2022-03-13 11:00:44 -05:00
|
|
|
:class="{
|
|
|
|
feature: true,
|
|
|
|
clickable: true,
|
|
|
|
can: unref(canClick),
|
|
|
|
locked: !unref(canClick),
|
|
|
|
small,
|
|
|
|
...unref(classes)
|
|
|
|
}"
|
2022-02-27 13:49:34 -06:00
|
|
|
>
|
2022-03-13 11:00:44 -05:00
|
|
|
<component v-if="unref(comp)" :is="unref(comp)" />
|
|
|
|
<MarkNode :mark="unref(mark)" />
|
2022-03-20 13:57:45 -05:00
|
|
|
<Node :id="id" />
|
2022-03-13 11:00:44 -05:00
|
|
|
</button>
|
2021-06-11 23:38:16 -05:00
|
|
|
</template>
|
|
|
|
|
2024-10-20 05:47:59 -05:00
|
|
|
<script setup lang="tsx">
|
2022-03-03 21:39:48 -06:00
|
|
|
import "components/common/features.css";
|
|
|
|
import MarkNode from "components/MarkNode.vue";
|
2022-06-26 19:17:22 -05:00
|
|
|
import Node from "components/Node.vue";
|
|
|
|
import type { GenericClickable } from "features/clickables/clickable";
|
|
|
|
import type { StyleValue } from "features/feature";
|
2023-02-15 20:00:36 -06:00
|
|
|
import { isHidden, isVisible, jsx, Visibility } from "features/feature";
|
2022-02-27 13:49:34 -06:00
|
|
|
import {
|
|
|
|
coerceComponent,
|
|
|
|
isCoercableComponent,
|
2024-10-20 05:47:59 -05:00
|
|
|
setupHoldToClick
|
2022-03-03 21:39:48 -06:00
|
|
|
} from "util/vue";
|
2024-10-20 05:47:59 -05:00
|
|
|
import type { Component, UnwrapRef } from "vue";
|
|
|
|
import { shallowRef, toRef, unref, watchEffect } from "vue";
|
2022-01-13 22:25:47 -06:00
|
|
|
|
2024-10-20 05:47:59 -05:00
|
|
|
const props = defineProps<{
|
|
|
|
display: UnwrapRef<GenericClickable["display"]>;
|
|
|
|
visibility: Visibility | boolean;
|
|
|
|
style?: StyleValue;
|
|
|
|
classes?: Record<string, boolean>;
|
|
|
|
onClick?: (e?: MouseEvent | TouchEvent) => void;
|
|
|
|
onHold?: VoidFunction;
|
|
|
|
canClick: boolean;
|
|
|
|
small?: boolean;
|
|
|
|
mark?: boolean | string;
|
|
|
|
id: string;
|
|
|
|
}>();
|
2021-06-11 23:38:16 -05:00
|
|
|
|
2024-10-20 05:47:59 -05:00
|
|
|
const comp = shallowRef<Component | string>("");
|
2022-02-27 13:49:34 -06:00
|
|
|
|
2024-10-20 05:47:59 -05:00
|
|
|
watchEffect(() => {
|
|
|
|
const currDisplay = props.display;
|
|
|
|
if (currDisplay == null) {
|
|
|
|
comp.value = "";
|
|
|
|
return;
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-16 23:30:54 -05:00
|
|
|
}
|
2024-10-20 05:47:59 -05:00
|
|
|
if (isCoercableComponent(currDisplay)) {
|
|
|
|
comp.value = coerceComponent(currDisplay);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const Title = coerceComponent(currDisplay.title ?? "", "h3");
|
|
|
|
const Description = coerceComponent(currDisplay.description, "div");
|
|
|
|
comp.value = coerceComponent(
|
|
|
|
jsx(() => (
|
|
|
|
<span>
|
|
|
|
{currDisplay.title != null ? (
|
|
|
|
<div>
|
|
|
|
<Title />
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
<Description />
|
|
|
|
</span>
|
|
|
|
))
|
|
|
|
);
|
First pass at typescript support
Oh man did this end up requiring a *ton* of other work as well.
There's still a few typing issues I still can't quite work out,
and others I'd like to improve when I have time. In fact, this version
doesn't even really work, it has a stack overflow error caused by
a tooltip for some reason have a tree inside it, which in turn has
another tooltip, etc. There's also 17 errors that I *really* feel like
shouldn't be there, but they are, and 113 warnings - mostly using !
to assert that things are non-null. Lots of work left to do, to sum up.
The reason I'm committing this now is because I really need to get to
work on my game jam, and since it won't use a tree or really many of
TMT-X's features, I can get away with using a broken engine :)
2021-08-16 23:30:54 -05:00
|
|
|
});
|
2024-10-20 05:47:59 -05:00
|
|
|
|
|
|
|
const { start, stop } = setupHoldToClick(toRef(props, "onClick"), toRef(props, "onHold"));
|
2021-06-11 23:38:16 -05:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2021-06-24 22:15:10 -05:00
|
|
|
.clickable {
|
|
|
|
min-height: 120px;
|
|
|
|
width: 120px;
|
|
|
|
font-size: 10px;
|
|
|
|
}
|
2022-02-27 13:49:34 -06:00
|
|
|
|
|
|
|
.clickable.small {
|
|
|
|
min-height: unset;
|
|
|
|
}
|
2022-04-24 01:03:25 -05:00
|
|
|
|
|
|
|
.clickable > * {
|
|
|
|
pointer-events: none;
|
|
|
|
}
|
2021-06-11 23:38:16 -05:00
|
|
|
</style>
|