How to track moves / onDrop event? AND How to properly validate connection? #61
-
Hello - love this framework! Just a couple of questions, and please forgive if they seem too n00b :) Question 1: The API is great, however doesn't really show examples. For instance, is there an event exposed to track each move? I see the events for pieces, where you can programmatically drag or drop - but are there exposed onUp or onDown or onDrop or even an onDragStart somewhere to more easily track things such as incrementing a move counter each time a piece is moved? Question 2: I want to make sure that valid connections stick and persist, but invalid connections do not. The forceConnectionWhileDragging method is perfect, but not when invalid piece connections happen. I want to disallow invalid connections in conjunction. What's the proper rubik's cube pattern for this to properly work? :) Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 8 replies
-
As an update: I've gotten my move counter going, via iterating through the pieces shown on another post in here. I also have validations I'm happy with - HOWEVER - the issue I'm having now, is that once I call disconnect() on a piece, suddenly the whole puzzle now allows disconnections, and forceConnectionWhileDragging() stops working at that point. Tried calling it again onDisconnect, but no avail. So - I can indeed verify that a piece belongs to its target or not, and then do a 'disconnect' if it does not. But that breaks the forced puzzle progress to stay in place, and pieces can then just detach willy nilly. No errors in the console, so I'm not sure what the proper method to do this might be just yet. Will keep picking at it and see what I can come up with unless someone else has suggestions? |
Beta Was this translation helpful? Give feedback.
-
👋 Hi @cyborat! Thanks for your comments!
There are not such fine-grained events at the model layer. However, you can track:
In addition, you can use the low-level events of the Konva UI layer, like
That's a nice idea. It is not bundled out-of-the-box. I would try:
Could you please provide some working code/codepen here to better understand your approach and error? |
Beta Was this translation helpful? Give feedback.
-
OK, I see that both That said, if you hack the headbreaker.connector.horizontal.canConnectWith = function(one, other, proximity) {
return this.closeTo(one, other, proximity) && this.match(one, other) &&
one.metadata.id.replace('-kanji') == other.metadata.id.replace('-emoji') ;
} Screencast.from.22-05-23.09.57.55.webmThis is currently just a hack, but I think that may be reified into a better concept within the framework. Hope that helps! |
Beta Was this translation helpful? Give feedback.
-
PS: |
Beta Was this translation helpful? Give feedback.
PS:
headbreaker >= 3.0
now ships with connection requirements: https://flbulgarelli.github.io/headbreaker/#labels.