This repository has been archived on 2024-04-29. You can view files and clone it, but cannot push or open issues or pull requests.
node-fftcg/client/scripts/20-component-card.coffee

77 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2018-09-30 20:23:16 +00:00
Crafty.c 'Card',
required: '2D, Canvas, Mouse, Tween'
init: ->
@attr {
w: 1 * CONF.card.w
h: 1 * CONF.card.h
tapped: false
}
@origin 'center'
return
remove: ->
Crafty.log 'Card was removed!'
return
place: (px, py) ->
@tween {
x: px
y: py
}, CONF.anim.time, CONF.anim.func
events:
Tap: (newState) ->
@tapped = !!newState
_rotation = @baseRot + 90 * @tapped
@tween {
rotation: _rotation
}, CONF.anim.time, CONF.anim.func
return
ToggleTap: ->
@trigger 'Tap', !@tapped
return
MouseOver: ->
@z_old = @_z
@z = 1
return
MouseOut: ->
@z = @z_old
delete @z_old
return
Crafty.c 'EnemyCard',
required: 'Card'
init: ->
@baseRot = 180
@rotation = @baseRot
return
Crafty.c 'AllyCard',
required: 'Card, Draggable'
init: ->
@baseRot = 0
@rotation = @baseRot
return
events:
DoubleClick: ->
@trigger 'ToggleTap'
return
StopDrag: ->
round100 = (v) ->
Math.round(v / 100) * 100
@place round100(@_x), round100(@_y)
return