Skip to content

Instantly share code, notes, and snippets.

@Synesso
Created July 27, 2009 12:11
Show Gist options
  • Save Synesso/156175 to your computer and use it in GitHub Desktop.
Save Synesso/156175 to your computer and use it in GitHub Desktop.
new Request.JSON({url: "moves.json.jsp", onSuccess: function(movesRawHash) {
viableMoves = new Hash(movesRawHash);
viableMoves.each(function(to, from, hash) {
console.log('adding events to ' + from)
var toElements = []
to.each(function(dest, i, ary) {toElements = toElements.include($(dest))});
new Drag.Move($(piecesPerSquare.get(from)), {
droppables: toElements,
precalculate: true,
onDrop: function(el, droppable) {
console.log('dropping ' + el.get('id') + ' on ' + droppable.get('id'));
el.position({relativeTo: droppable});
},
onComplete: function(el) {
console.log('completed - todo: action next turn');
}
});
$(piecesPerSquare.get(from)).addEvent('mousedown', function(square) {
console.log('mousedown ' + from)
to.each(function(dest, i, ary) {
var morph = new Fx.Morph(dest, {duration: 400, transition: Fx.Transitions.Cubic.easeOut});
morph.start('.highlight');
});
});
$(piecesPerSquare.get(from)).addEvent('mouseup', function(square) {
console.log('mouseup ' + from)
to.each(function(dest, i, ary) {
var morph = new Fx.Morph(dest, {duration: 400, transition: Fx.Transitions.Cubic.easeOut});
morph.start(darkSquares.contains(dest) ? '.dark' : '.light');
});
});
$(piecesPerSquare.get(from)).addClass('movable');
});
}}).get({'game': 1});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment