diff --git a/src/components/BowShotEffect.vue b/src/components/BowShotEffect.vue index 3901536..4f4b3e9 100644 --- a/src/components/BowShotEffect.vue +++ b/src/components/BowShotEffect.vue @@ -34,6 +34,7 @@ const phase = ref("idle"); const activePlayKey = ref(""); const animationKey = ref(""); const impactEmitted = ref(false); +const activeShot = ref(null); let timers = []; const isActive = computed(() => phase.value !== "idle"); @@ -54,9 +55,17 @@ const safeTargetSize = computed(() => { }; }); +function hasShotPoint(shot) { + const x = Number(shot?.x); + const y = Number(shot?.y); + return Number.isFinite(x) && Number.isFinite(y); +} + +const effectiveShot = computed(() => activeShot.value || props.shot); + const shotPoint = computed(() => { - const x = Number(props.shot?.x); - const y = Number(props.shot?.y); + const x = Number(effectiveShot.value?.x); + const y = Number(effectiveShot.value?.y); return { x: Number.isFinite(x) ? x : 0, y: Number.isFinite(y) ? y : 0, @@ -179,16 +188,20 @@ function finish(playKey) { clearTimers(); phase.value = "idle"; activePlayKey.value = ""; + activeShot.value = null; emit("complete", playKey); } function play() { - if (!props.playKey || !props.shot || !props.shot.ring) return; + if (!props.playKey || !props.shot || !props.shot.ring || !hasShotPoint(props.shot)) { + return; + } clearTimers(); activePlayKey.value = props.playKey; animationKey.value = `${props.playKey}`; impactEmitted.value = false; + activeShot.value = { ...props.shot }; phase.value = "playing"; queueTimer(() => { diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue index 0c9745a..997daf7 100644 --- a/src/components/BowTarget.vue +++ b/src/components/BowTarget.vue @@ -1,5 +1,13 @@ @@ -461,6 +499,9 @@ onBeforeUnmount(() => { :shot="shotEffect && shotEffect.shot" :playKey="shotEffect ? shotEffect.key : ''" :targetRadius="safeTargetRadius" + :targetWidth="targetSize.width" + :targetHeight="targetSize.height" + :hitOffsetPx="currentHitRadiusPx" @impact="shakeTarget" @complete="completeShotEffect" />