var React = require('react'); var _ = require('lodash'); var cx = require('classnames'); var RollDice = require('naturalcrit/rollDice'); var AttackSlot = React.createClass({ getDefaultProps: function() { return { name : '', uses : null }; }, getInitialState: function() { return { lastRoll: {}, usedCount : 0 }; }, rollDice : function(key, notation){ var res = RollDice(notation); this.state.lastRoll[key] = res this.state.lastRoll[key + 'key'] = _.uniqueId(key); this.setState({ lastRoll : this.state.lastRoll }) }, renderUses : function(){ var self = this; if(!this.props.uses) return null; return _.times(this.props.uses, function(index){ var atCount = index < self.state.usedCount; return }) }, updateCount : function(used){ this.setState({ usedCount : this.state.usedCount + (used ? -1 : 1) }); }, renderNotes : function(){ var notes = _.omit(this.props, ['name', 'atk', 'dmg', 'uses', 'heal']); return _.map(notes, function(text, key){ return
{key + ': ' + text}
}); }, renderRolls : function(){ var self = this; return _.map(['atk', 'dmg', 'heal'], function(type){ if(!self.props[type]) return null; return
{self.state.lastRoll[type]}
}) }, render : function(){ var self = this; return(
{this.props.name}
{this.renderUses()}
{this.renderNotes()}
{this.renderRolls()}
); } }); module.exports = AttackSlot;