commit 02

This commit is contained in:
Moritz Ruth 2024-12-26 19:14:30 +01:00
parent 08b0f87596
commit 6b9b020c5d
Signed by: moritzruth
GPG key ID: C9BBAB79405EE56D
3 changed files with 48 additions and 6 deletions

View file

@ -20,18 +20,32 @@
touch-action: none; touch-action: none;
transition: transform 50ms ease, background-color 200ms ease; transition: transform 50ms ease, background-color 200ms ease;
} }
.combineFirst {
animation: 500ms ease-in-out alternate infinite combineFirst;
}
@keyframes combineFirst {
from {
@apply border-blue-400;
}
to {
@apply border-blue-700;
}
}
</style> </style>
<script setup lang="ts"> <script setup lang="ts">
import type { GameObject } from "../shared/script/types" import type { GameObject } from "../shared/script/types"
import interact from "@interactjs/interact" import interact from "@interactjs/interact"
import { useCurrentElement } from "@vueuse/core" import { useCurrentElement } from "@vueuse/core"
import { computed, onMounted, onUnmounted, ref } from "vue" import { computed, onMounted, onUnmounted, ref, useCssModule } from "vue"
const props = defineProps<{ const props = defineProps<{
object: GameObject object: GameObject
isOverDropzone: boolean isOverDropzone: boolean
markedFor: null | "use" | "combine" markedFor: null | "use" | "combine" | "combine-first"
}>() }>()
const emit = defineEmits<{ const emit = defineEmits<{
@ -72,11 +86,14 @@
onUnmounted(() => interactable.unset()) onUnmounted(() => interactable.unset())
}) })
const style = useCssModule()
const borderClass = computed(() => { const borderClass = computed(() => {
switch (props.markedFor) { switch (props.markedFor) {
case null: return "border-dark-600" case null: return "border-dark-600"
case "use": return "border-green-600" case "use": return "border-green-600"
case "combine": return "border-blue-900" case "combine": return "border-blue-500"
case "combine-first": return style.combineFirst
} }
}) })
</script> </script>

View file

@ -25,8 +25,9 @@ export const useGame = defineStore("gameState", () => {
currentInteraction.value = interaction currentInteraction.value = interaction
trpcClient.player.voteForInteraction.mutate({ interaction }) trpcClient.player.voteForInteraction.mutate({ interaction })
}, },
removeInteractionVote(queueItemId: string) { revokeCurrentInteractionVote() {
trpcClient.player.removeInteractionVote.mutate({ queueItemId }) if (currentInteractionId.value === null) return
trpcClient.player.removeInteractionVote.mutate({ queueItemId: currentInteractionId.value })
currentInteraction.value = null currentInteraction.value = null
}, },
switchRoom(roomId: string) { switchRoom(roomId: string) {

View file

@ -13,6 +13,7 @@
class="bg-blue-900" class="bg-blue-900"
:has-floating="combineFloatingObjectIds.size > 0" :has-floating="combineFloatingObjectIds.size > 0"
@object-change="(v, i) => createSetInclusionSetter(combineFloatingObjectIds)(v, i)" @object-change="(v, i) => createSetInclusionSetter(combineFloatingObjectIds)(v, i)"
@object-drop="onObjectInteractionDrop"
/> />
</div> </div>
<div ref="objectsContainerElement" class="grid gap-3 grid-cols-2 flex-grow auto-rows-min p-4"> <div ref="objectsContainerElement" class="grid gap-3 grid-cols-2 flex-grow auto-rows-min p-4">
@ -50,6 +51,8 @@
const combineFloatingObjectIds = reactive(new Set()) const combineFloatingObjectIds = reactive(new Set())
const allFloatingObjectIds = computed(() => new Set([...useFloatingObjectIds, ...combineFloatingObjectIds])) const allFloatingObjectIds = computed(() => new Set([...useFloatingObjectIds, ...combineFloatingObjectIds]))
const firstCombinationObjectId = ref<null | string>(null)
function createSetInclusionSetter<T>(set: Set<T>) { function createSetInclusionSetter<T>(set: Set<T>) {
return (value: T, isIncluded: boolean) => { return (value: T, isIncluded: boolean) => {
if (isIncluded) set.add(value) if (isIncluded) set.add(value)
@ -58,7 +61,9 @@
} }
function getMarkedFor(objectId: string) { function getMarkedFor(objectId: string) {
if (game.currentInteraction !== null) { if (firstCombinationObjectId.value !== null) {
if (firstCombinationObjectId.value === objectId) return "combine-first"
} else if (game.currentInteraction !== null) {
switch (game.currentInteraction.type) { switch (game.currentInteraction.type) {
case "use": case "use":
if (game.currentInteraction.objectId === objectId) return "use" if (game.currentInteraction.objectId === objectId) return "use"
@ -88,4 +93,23 @@
objectId objectId
}) })
} }
function onObjectInteractionDrop(objectId: string) {
if (firstCombinationObjectId.value === null) {
game.revokeCurrentInteractionVote()
firstCombinationObjectId.value = objectId
} else {
if (firstCombinationObjectId.value === objectId) {
firstCombinationObjectId.value = null
return
}
game.voteForInteraction({
type: "combine",
objectIds: new Set([firstCombinationObjectId.value, objectId])
})
firstCombinationObjectId.value = null
}
}
</script> </script>