var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); var AttackSlot = require('./attackSlot/attackSlot.jsx'); var MonsterCard = React.createClass({ getDefaultProps: function() { return { name : '', hp : 1, currentHP : 1, ac: 1, move : 30, attr : { str : 8, con : 8, dex : 8, int : 8, wis : 8, cha : 8 }, attacks : {}, spells : {}, abilities : [], items : [], updateHP : function(){}, remove : function(){}, }; }, getInitialState: function() { return { status : 'normal', usedItems : [], lastRoll : { }, mousePos : null, tempHP : 0 }; }, componentDidMount: function() { window.addEventListener('mousemove', this.handleMouseDrag); window.addEventListener('mouseup', this.handleMouseUp); }, handleMouseDown : function(e){ this.setState({ mousePos : { x : e.pageX, y : e.pageY, } }); e.stopPropagation() e.preventDefault() }, handleMouseUp : function(e){ if(!this.state.mousePos) return; this.props.updateHP(this.props.currentHP + this.state.tempHP); this.setState({ mousePos : null, tempHP : 0 }); }, handleMouseDrag : function(e){ if (!this.state.mousePos) return; var distance = Math.sqrt(Math.pow(e.pageX - this.state.mousePos.x, 2) + Math.pow(e.pageY - this.state.mousePos.y, 2)); var mult = (e.pageY > this.state.mousePos.y ? -1 : 1) this.setState({ tempHP : Math.floor(distance * mult/25) }) }, addUsed : function(item, shouldRemove){ if(!shouldRemove) this.state.usedItems.push(item); if(shouldRemove) this.state.usedItems.splice(this.state.usedItems.indexOf(item), 1); this.setState({ usedItems : this.state.usedItems }); }, renderHPBox : function(){ var self = this; var tempHP if(this.state.tempHP){ var sign = (this.state.tempHP > 0 ? '+' : ''); tempHP = {['(',sign,this.state.tempHP,')'].join('')} } return