Skip to content

Commit e07d24a

Browse files
committed
fix: double craft
1 parent df7699e commit e07d24a

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

apps/frontend/src/components/alchemy-board.vue

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,29 @@ function checkCollision(boardElement: AlchemyElementOnBoard): void {
2828
if (boardItem.uuid === boardElement.uuid) continue
2929
if (boardElement.ended || boardItem.ended) continue
3030
if (
31-
boardElement.position.x < boardItem.position.x + elementSize.value.width
32-
&& boardElement.position.x + elementSize.value.width > boardItem.position.x
33-
&& boardElement.position.y < boardItem.position.y + elementSize.value.height
34-
&& boardElement.position.y + elementSize.value.height > boardItem.position.y
31+
boardElement.position.x >= boardItem.position.x + elementSize.value.width
32+
|| boardElement.position.x + elementSize.value.width <= boardItem.position.x
33+
|| boardElement.position.y >= boardItem.position.y + elementSize.value.height
34+
|| boardElement.position.y + elementSize.value.height <= boardItem.position.y
3535
) {
36-
const elements = checkRecipe([boardElement.id, boardItem.id])
37-
if (!elements.length) return
38-
39-
elements.forEach((element, index) => {
40-
if (element.id === 'freak_games') {
41-
sounds.playSound('freakGames')
42-
}
43-
44-
removeElement(boardItem)
45-
removeElement(boardElement)
46-
createElement(boardItem, element, index === 1)
47-
openedElements.addElement(element)
48-
})
36+
continue
4937
}
38+
39+
const elements = checkRecipe([boardElement.id, boardItem.id])
40+
if (!elements.length) break
41+
42+
elements.forEach((element, elementIndex) => {
43+
if (element.id === 'freak_games') {
44+
sounds.playSound('freakGames')
45+
}
46+
47+
removeElement(boardItem)
48+
removeElement(boardElement)
49+
createElement(boardItem.position, element, elementIndex >= 1)
50+
openedElements.addElement(element)
51+
})
52+
53+
break
5054
}
5155
}
5256
@@ -83,16 +87,16 @@ function removeElement(boardElement: AlchemyElementOnBoard): void {
8387
}
8488
8589
function createElement(
86-
boardElement: AlchemyElementOnBoard,
87-
newElement: AlchemyElement,
90+
position: Position,
91+
element: AlchemyElement,
8892
isCopy = false,
8993
): void {
9094
board.value.push({
91-
...newElement,
95+
...element,
9296
uuid: crypto.randomUUID(),
9397
position: {
94-
x: isCopy ? boardElement.position.x + 30 : boardElement.position.x,
95-
y: isCopy ? boardElement.position.y + 30 : boardElement.position.y,
98+
x: isCopy ? position.x + 30 : position.x,
99+
y: isCopy ? position.y + 30 : position.y,
96100
},
97101
})
98102
}
@@ -151,7 +155,7 @@ function onDrop(event: DragEvent) {
151155
:key="boardElement.uuid"
152156
:alchemy-element="boardElement"
153157
@position="updatePosition(boardElement, $event)"
154-
@clone-element="createElement(boardElement, $event, true)"
158+
@clone-element="createElement(boardElement.position, $event, true)"
155159
@remove-element="removeElement(boardElement)"
156160
@dragover.prevent
157161
@dragenter.prevent

0 commit comments

Comments
 (0)