0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-07 12:02:44 +00:00

Polishing up the monster card

This commit is contained in:
Scott Tolksdorf
2015-11-14 18:29:51 -05:00
parent 3dee96ad38
commit 3b16e16958
5 changed files with 92 additions and 46 deletions

View File

@@ -40,6 +40,7 @@ var AttackSlot = React.createClass({
if(diceRoll[0] == 20) res = 'Crit!'; if(diceRoll[0] == 20) res = 'Crit!';
} }
this.state.lastRoll[key] = res this.state.lastRoll[key] = res
this.state.lastRoll[key + 'key'] = _.uniqueId(key);
this.setState({ this.setState({
lastRoll : this.state.lastRoll lastRoll : this.state.lastRoll
}) })
@@ -67,8 +68,8 @@ var AttackSlot = React.createClass({
renderNotes : function(){ renderNotes : function(){
var notes = _.omit(this.props, ['name', 'atk', 'dmg', 'uses', 'heal']); var notes = _.omit(this.props, ['name', 'atk', 'dmg', 'uses', 'heal']);
return _.map(notes, function(text, key){ return _.map(notes, function(text, key){
return key + ': ' + text return <div>{key + ': ' + text}</div>
}).join(', '); });
}, },
renderRolls : function(){ renderRolls : function(){
@@ -86,7 +87,7 @@ var AttackSlot = React.createClass({
})} /> })} />
{self.props[type]} {self.props[type]}
</button> </button>
<span>{self.state.lastRoll[type] || ''}</span> <span key={self.state.lastRoll[type+'key']}>{self.state.lastRoll[type] || ''}</span>
</div> </div>
}) })

View File

@@ -12,19 +12,23 @@
width : 40%; width : 40%;
.name{ .name{
font-weight : 800; font-weight : 800;
margin-bottom: 3px;
} }
.notes{ .notes{
font-size : 0.8em; font-size : 0.8em;
} }
.uses{ .uses{
cursor : pointer; cursor : pointer;
//font-size: 0.8em;
//margin-top: 3px;
} }
} }
.rolls{ .rolls{
.roll{ .roll{
margin-bottom : 2px; margin-bottom : 2px;
span{ &>span{
font-weight: 800; font-weight: 800;
.fadeInLeft();
} }
button{ button{
width : 70px; width : 70px;

View File

@@ -32,15 +32,9 @@ var MonsterCard = React.createClass({
getInitialState: function() { getInitialState: function() {
return { return {
//currentHP: this.props.hp,
status : 'normal', status : 'normal',
usedThings : [], usedItems : [],
lastRoll : { },
lastRoll : {
},
mousePos : null, mousePos : null,
tempHP : 0 tempHP : 0
}; };
@@ -82,6 +76,15 @@ var MonsterCard = React.createClass({
}) })
}, },
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(){ renderHPBox : function(){
@@ -100,39 +103,15 @@ var MonsterCard = React.createClass({
}, },
renderStats : function(){ renderStats : function(){
var stats = {
}, 'fa fa-shield' : this.props.ac,
'fa fa-hourglass-2' : this.props.initiative,
rollDice : function(key, notation){
var additive = 0;
var dice = _.reduce([/\+(.*)/, /\-(.*)/], function(r, regexp){
var res = r.match(regexp);
if(res){
additive = res[0]*1;
r = r.replace(res[0], '')
}
return r;
}, notation)
var numDice = dice.split('d')[0];
var die = dice.split('d')[1];
var diceRoll = _.times(numDice, function(){
return _.random(1, die);
});
var res = _.sum(diceRoll) + additive;
if(numDice == 1 && die == 20){
if(diceRoll[0] == 1) res = 'Fail!';
if(diceRoll[0] == 20) res = 'Crit!';
} }
this.state.lastRoll[key] = res return _.map(stats, function(val, icon){
this.setState({ return <span className='stat' key={icon}><i className={icon} /> {val}</span>
lastRoll : this.state.lastRoll
}) })
}, },
renderAttacks : function(){ renderAttacks : function(){
var self = this; var self = this;
return _.map(this.props.attacks, function(attack, name){ return _.map(this.props.attacks, function(attack, name){
@@ -147,9 +126,28 @@ var MonsterCard = React.createClass({
}) })
}, },
renderItems : function(){
var self = this;
var usedItems = this.state.usedItems.slice(0);
return _.map(this.props.items, function(item, index){
var used = _.contains(usedItems, item);
if(used){
usedItems.splice(usedItems.indexOf(item), 1);
}
return <span
key={index}
className={cx({'used' : used})}
onClick={self.addUsed.bind(self, item, used)}>
{item}
</span>
});
},
render : function(){ render : function(){
var self = this; var self = this;
var condition = '' var condition = ''
if(this.props.currentHP + this.state.tempHP > this.props.hp) condition='overhealed'; if(this.props.currentHP + this.state.tempHP > this.props.hp) condition='overhealed';
if(this.props.currentHP + this.state.tempHP <= this.props.hp * 0.5) condition='hurt'; if(this.props.currentHP + this.state.tempHP <= this.props.hp * 0.5) condition='hurt';
@@ -164,7 +162,10 @@ var MonsterCard = React.createClass({
{this.renderHPBox()} {this.renderHPBox()}
<div className='name'>{this.props.name}</div> <div className='info'>
<span className='name'>{this.props.name}</span>
{this.renderStats()}
</div>
<div className='attackContainer'> <div className='attackContainer'>
{this.renderAttacks()} {this.renderAttacks()}
@@ -172,12 +173,23 @@ var MonsterCard = React.createClass({
<div className='spellContainer'> <div className='spellContainer'>
{this.renderSpells()} {this.renderSpells()}
</div> </div>
{this.props.initiative}
<i className='fa fa-times' onClick={this.props.remove} />
<div className='itemContainer'>
{this.renderItems()}
</div>
</div> </div>
); );
} }
}); });
module.exports = MonsterCard; module.exports = MonsterCard;
/*
{this.props.initiative}
<i className='fa fa-times' onClick={this.props.remove} />
*/

View File

@@ -49,6 +49,21 @@
&.dead{ &.dead{
opacity: 0.3; opacity: 0.3;
} }
&>.info{
margin-bottom: 10px;
.name{
font-size: 1.5em;
margin-right: 10px;
}
.stat{
font-size: 0.7em;
margin-right: 5px;
i{
font-size: 0.7em;
}
}
}
.hpBox{ .hpBox{
.noselect(); .noselect();
position : absolute; position : absolute;
@@ -74,4 +89,17 @@
font-weight : 800; font-weight : 800;
} }
} }
.itemContainer{
span{
cursor: pointer;
font-size: 0.7em;
margin-right: 5px;
&.used{
text-decoration: line-through;
}
}
}
} }

View File

@@ -17,6 +17,7 @@ var MonsterManual = {
'goblin' : { 'goblin' : {
"hp" : 40, "hp" : 40,
"mov": 30, "mov": 30,
"ac" : 13,
"attr" : { "attr" : {
"str" : 8, "str" : 8,
"con" : 8, "con" : 8,
@@ -49,7 +50,7 @@ var MonsterManual = {
} }
}, },
"abilities" : ["pack tactics"], "abilities" : ["pack tactics"],
"items" : [] "items" : ['healing_potion', 'healing_potion', 'ring']
} }
} }