1
0
mirror of https://github.com/stolksdorf/homebrewery.git synced 2025-12-24 23:23:36 +00:00

so much progress

This commit is contained in:
Scott Tolksdorf
2016-04-02 17:33:56 -04:00
parent 263257bfb8
commit cb5b63429e
13 changed files with 304 additions and 115 deletions

View File

@@ -2,32 +2,25 @@ var React = require('react');
var _ = require('lodash'); var _ = require('lodash');
var cx = require('classnames'); var cx = require('classnames');
var utils = require('../utils');
var Box = React.createClass({ var Box = React.createClass({
mixins : [utils],
getDefaultProps: function() { getDefaultProps: function() {
return { return {
data : {}, name : 'box',
onChange : function(){}, defaultData : {},
defaultValue : {},
id : 'box', id : '',
title : '',
label : '',
shadow : false,
border : false
}; };
}, },
//Maybe remove
id : function(){
return _.snakeCase(this.props.label) || this.props.id;
},
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(newData){ handleChange : function(newData){
this.props.onChange({ this.updateData(newData);
[this.id()] : _.extend(this.data(), newData)
});
}, },
renderChildren : function(){ renderChildren : function(){
@@ -39,10 +32,21 @@ var Box = React.createClass({
}) })
}) })
}, },
renderTitle : function(){
if(this.props.title) return <h5 className='title'>{this.props.title}</h5>
},
renderLabel : function(){
if(this.props.label) return <h5 className='label'>{this.props.label}</h5>
},
render : function(){ render : function(){
return <div className={cx('box', this.props.className)}> return <div className={cx('box', this.props.className, {
shadow : this.props.shadow,
border : this.props.border
})}>
{this.renderTitle()}
{this.renderChildren()} {this.renderChildren()}
{this.renderLabel()}
</div> </div>
} }
}); });

View File

@@ -1,3 +1,30 @@
.COM{ .box{
position : relative;
padding : 10px;
margin: 10px;
&.border{
border: 1px solid black;
}
&.shadow{
background-color: #ddd;
}
h5{
text-transform: uppercase;
font-size : 0.6em;
text-align: center;
width : 100%;
font-weight: 800;
&.title{
margin-top: -5px;
margin-bottom: 10px;
}
&.label{
margin-bottom: -5px;
margin-top: 10px;
}
}
} }

View File

@@ -1,4 +1,13 @@
module.exports = { module.exports = {
TextInput : require('./textInput/textInput.jsx'), TextInput : require('./textInput/textInput.jsx'),
PlayerInfo : require('./playerInfo/playerInfo.jsx'), PlayerInfo : require('./playerInfo/playerInfo.jsx'),
SkillList : require('./skillList/skillList.jsx'),
Skill : require('./skill/skill.jsx'),
//ShadowBox : require('./shadowBox/shadowBox.jsx'),
//BorderBox : require('./borderBox/borderBox.jsx'),
Box : require('./box/box.jsx')
} }

View File

@@ -3,65 +3,23 @@ var _ = require('lodash');
var cx = require('classnames'); var cx = require('classnames');
var TextInput = require('../textInput/textInput.jsx'); var TextInput = require('../textInput/textInput.jsx');
var Box = require('../box/box.jsx'); var Box = require('../box/box.jsx');
var PlayerInfo = React.createClass({ var PlayerInfo = React.createClass({
getDefaultProps: function() { getDefaultProps: function() {
return { return {
data : {}, title: "player info",
onChange : function(){}, border : true
id : 'playerInfo',
}; };
}, },
/*
id : function(){
return _.snakeCase(this.props.label) || this.props.id;
},
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(newData){
this.props.onChange({
[this.id()] : _.extend(this.data(), newData)
});
},
renderChildren : function(){
return React.Children.map(this.props.children, (child)=>{
return React.cloneElement(child, {
onChange : this.handleChange,
data : this.data()
})
})
},
*/
render : function(){ render : function(){
return <Box className='playerInfo' {...this.props}> return <Box className='playerInfo' {...this.props} >
<TextInput id='name' label="Name" /> <TextInput label="Name" placeholder="name" />
<TextInput id='class' label="Class" /> <TextInput label="Class" />
<TextInput id='race' label="Race" /> <TextInput label="Race" />
{this.props.children} {this.props.children}
</Box> </Box>
} }
/*{this.props.children}*/
/*
render : function(){
return <div className='playerInfo'>
<TextInput id='name' label="Name" onChange={this.handleChange} data={this.data()} />
<TextInput id='class' label="Class" onChange={this.handleChange} data={this.data()} />
<TextInput id='race' label="Race" onChange={this.handleChange} data={this.data()} />
{this.renderChildren()}
</div>
}
*/
}); });
module.exports = PlayerInfo; module.exports = PlayerInfo;

View File

@@ -0,0 +1,64 @@
var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
var utils = require('../utils');
var Skill = React.createClass({
getDefaultProps: function() {
return {
name : 'skill',
defaultData : {
prof : false,
expert : false,
val : ''
},
id : '',
label : '',
sublabel : '',
showExpert : false
};
},
id : utils.id,
data : utils.data,
updateData : utils.updateData,
handleToggleProf : function(){
this.updateData({
prof : !this.data().prof
})
},
handleToggleExpert : function(){
this.updateData({
expert : !this.data().expert
})
},
handleValChange : function(e){
console.log('yo');
this.updateData({
val : e.target.value
})
},
renderExpert : function(){
if(this.props.showExpert){
return <input type="radio" className='expertToggle' onChange={this.handleToggleExpert} checked={this.data().expert} />
}
},
render : function(){
return <div className='skill'>
{this.renderExpert()}
<input type="radio" className='skillToggle' onChange={this.handleToggleProf} checked={this.data().prof} />
<input type='text' onChange={this.handleValChange} value={this.data().val} />
<label>
{this.props.label}
<small>{this.props.sublabel}</small>
</label>
</div>
}
});
module.exports = Skill;

View File

@@ -0,0 +1,35 @@
.skill{
position : relative;
padding-left : 15px;
input[type="radio"]{
margin : 0px;
}
.expertToggle{
position : absolute;
top : 1px;
left : 0px;
}
input[type="text"]{
width : 25px;
margin-left : 10px;
background-color : transparent;
text-align : center;
border : none;
border-bottom : 1px solid black;
outline : none;
&:focus{
background-color : #ddd;
}
}
label{
margin-left : 10px;
font-size : 0.8em;
small{
margin-left : 5px;
font-size : 0.8em;
color : #999;
text-transform : uppercase;
}
}
}

View File

@@ -0,0 +1,61 @@
var React = require('react');
var _ = require('lodash');
var cx = require('classnames');
var Skill = require('../skill/skill.jsx');
var Box = require('../box/box.jsx');
var skill_list = [
{name : 'Acrobatics', stat : 'Dex'},
{name : 'Animal Handling', stat : 'Wis'},
{name : 'Arcana', stat : 'Int'},
{name : 'Athletics', stat : 'Str'},
{name : 'Deception', stat : 'Cha'},
{name : 'History', stat : 'Int'},
{name : 'Insight', stat : 'Wis'},
{name : 'Intimidation', stat : 'Cha'},
{name : 'Investigation', stat : 'Int'},
{name : 'Medicine', stat : 'Wis'},
{name : 'Nature', stat : 'Int'},
{name : 'Perception', stat : 'Wis'},
{name : 'Performance', stat : 'Cha'},
{name : 'Persuasion', stat : 'Cha'},
{name : 'Religion', stat : 'Int'},
{name : 'Sleight of Hand', stat : 'Dex'},
{name : 'Stealth', stat : 'Dex'},
{name : 'Survival', stat : 'Wis'}
]
var SkillList = React.createClass({
getDefaultProps: function() {
return {
name : 'skills',
//title : 'Skills',
shadow : true,
border : false,
showExpert : false
};
},
renderSkills : function(){
return _.map(skill_list, (skill)=>{
return <Skill
label={skill.name}
sublabel={'(' + skill.stat + ')'}
showExpert={this.props.showExpert} />
})
},
render : function(){
return <Box className='skillList' {...this.props}>
{this.renderSkills()}
{this.props.children}
</Box>
}
});
module.exports = SkillList;

View File

@@ -0,0 +1,3 @@
.COM{
}

View File

@@ -2,42 +2,41 @@ var React = require('react');
var _ = require('lodash'); var _ = require('lodash');
var cx = require('classnames'); var cx = require('classnames');
var utils = require('../utils');
var TextInput = React.createClass({ var TextInput = React.createClass({
getDefaultProps: function() { getDefaultProps: function() {
return { return {
data : {}, name : 'text',
defaultValue : '', defaultData : '',
onChange : function(){},
id : '',
id : 'textInput',
label : '', label : '',
}; };
}, },
id : function(){ id : utils.id,
return _.snakeCase(this.props.label) || this.props.id; data : utils.data,
}, updateData : utils.updateData,
data : function(){
return this.props.data[this.id()] || this.props.defaultValue;
},
handleChange : function(e){ handleChange : function(e){
this.props.onChange({ this.updateData(e.target.value);
[this.id()] : e.target.value
});
}, },
renderLabel : function(){ renderLabel : function(){
if(!this.props.label) return; if(this.props.label) return <label htmlFor={this.id()}>{this.props.label}</label>
return <label htmlFor={this.id()}>{this.props.label}</label>
}, },
render : function(){ render : function(){
return <div className='textInput'> return <div className='textInput'>
{this.renderLabel()} {this.renderLabel()}
<input id={this.id()} type='text' onChange={this.handleChange} value={this.data()} /> <input
id={this.id()}
type='text'
onChange={this.handleChange}
value={this.data()}
placeholder={this.props.placeholder}
/>
</div> </div>
} }
}); });

View File

@@ -0,0 +1,29 @@
var _ = require('lodash');
module.exports = {
id : function(){
if(this.props.id) return this.props.id;
if(this.props.label) return _.snakeCase(this.props.label);
if(this.props.title) return _.snakeCase(this.props.title);
return this.props.name;
},
data : function(){
if(!this.id()) return this.props.data || this.props.defaultData;
if(this.props.data && this.props.data[this.id()]) return this.props.data[this.id()];
return this.props.defaultData;
},
updateData : function(val){
if(typeof this.props.onChange !== 'function') throw "No onChange handler set";
if(_.isObject(val)){
this.props.onChange({
[this.id()] : _.extend({}, this.data(), val)
});
}else{
this.props.onChange({
[this.id()] : val
});
}
}
}

View File

@@ -16,22 +16,14 @@ var SheetRenderer = React.createClass({
}; };
}, },
/*
augmentProps : function(props, key){
return _.extend({}, props, {
key : key,
data : this.props.characterData,
onChange :
})
},
*/
renderElement : function(node, key){ renderElement : function(node, key){
if(!node.tag) return null;
if(!Parts[node.tag]) throw 'Could Not Find Element: ' + node.tag
return React.createElement( return React.createElement(
(Parts[node.tag] ? Parts[node.tag] : node.tag), Parts[node.tag],
{key : key, ...node.props}, {key : key, ...node.props},
//this.augmentProps(node.props, key),
...this.renderChildren(node.children)) ...this.renderChildren(node.children))
}, },
renderChildren : function(nodes){ renderChildren : function(nodes){
@@ -44,7 +36,6 @@ var SheetRenderer = React.createClass({
try{ try{
var nodes = jsx2json(this.props.code); var nodes = jsx2json(this.props.code);
nodes = _.map(nodes, (node)=>{ nodes = _.map(nodes, (node)=>{
node.props.data = this.props.characterData; node.props.data = this.props.characterData;
node.props.onChange = (newData)=>{ node.props.onChange = (newData)=>{

View File

@@ -42,7 +42,7 @@ var SplatSheet = React.createClass({
handeCharacterChange : function(data){ handeCharacterChange : function(data){
this.setState({ this.setState({
characterData : data, characterData : JSON.parse(JSON.stringify(data)),
}); });
localStorage.setItem(SPLATSHEET_CHARACTER, JSON.stringify(data)); localStorage.setItem(SPLATSHEET_CHARACTER, JSON.stringify(data));
}, },

View File

@@ -49,10 +49,18 @@ var tokenizer = function(input){
current--; current--;
} }
else if(LETTERS.test(char)){ else if(LETTERS.test(char)){
tokens.push({ var word = getToken(LETTERS);
type : 'word', if(word == 'true' || word == 'false'){
value : getToken(LETTERS) tokens.push({
}); type : 'boolean',
value : word == 'true'
});
}else{
tokens.push({
type : 'word',
value : word
});
}
current--; current--;
} }
else if(char == "'"){ else if(char == "'"){
@@ -123,24 +131,25 @@ var parser = function(tokens){
var last = null; var last = null;
while(current < tokens.length && token.type != 'endTag' && token.type != 'closeTag'){ while(current < tokens.length && token.type != 'endTag' && token.type != 'closeTag'){
if(!key && token.type == 'word'){ if(last && token.type == 'word'){
props[last] = true;
last = token.value;
}else if(!key && token.type == 'word'){
last = token.value; last = token.value;
}else if(last && token.type == 'equals'){ }else if(last && token.type == 'equals'){
key = last; key = last;
last = null; last = null;
}else if(key && (token.type == 'number' || token.type == 'text')){ }else if(key && (token.type == 'number' || token.type == 'text' || token.type == 'boolean')){
props[key] = token.value; props[key] = token.value;
key = null; key = null;
last = null; last = null;
token = tokens[++current];
continue;
}else if(last && token.type == 'word'){
props[last] = true;
}else{ }else{
throw "Invalid property value: " + key + '=' + token.value; throw "Invalid property value: " + key + '=' + token.value;
} }
token = tokens[++current]; token = tokens[++current];
} }
if(last) props[last] = true;
return props; return props;
} }
@@ -177,20 +186,20 @@ var parser = function(tokens){
} }
/*
/*
var test1 = ` var test1 = `
<div test="hey there champ" more_cool=shoobydo size=0> <div test="hey there champ" more_cool=false size=0>
<span> <span>
Hey there! Hey there!
<a>so fucking cool </span> </a> <a>so fucking cool </a>
</span> </span>
let's go party let's go party
<a href='neato' /> <a href='neato' />
</div> </div>
` `
var test2 = "<div>Hey there!</div>" var test2 = "<div cool=0 same>Hey there!</div>"
var tokens = tokenizer(test1); var tokens = tokenizer(test1);