diff --git a/client/src/components/instance.create.form.jsx b/client/src/components/instance.create.form.jsx new file mode 100644 index 00000000..2045fa82 --- /dev/null +++ b/client/src/components/instance.create.form.jsx @@ -0,0 +1,87 @@ +const preact = require('preact'); +const { connect } = require('preact-redux'); +const { Component } = require('preact'); + +const addState = connect( + function receiveState(state) { + const { ws, selectedCryps } = state; + + function sendInstanceNew(sCryps, name, players) { + if (sCryps.length) { + return ws.sendInstanceNew(sCryps, name, players); + } + return false; + } + + return { + sendInstanceNew, + selectedCryps, + }; + } +); + +class InstanceCreateForm extends Component { + constructor(props) { + super(props); + + this.state = { players: 1, name: '' }; + + const { sendInstanceNew, selectedCryps } = props; + + this.sendInstanceNew = sendInstanceNew.bind(this); + + this.nameChange = this.nameChange.bind(this); + this.playersChange = this.playersChange.bind(this); + this.handleSubmit = this.handleSubmit.bind(this); + } + + playersChange(event) { + this.setState({ players: Number(event.target.value) }); + } + + nameChange(event) { + this.setState({ name: event.target.value }); + } + + handleSubmit(event) { + event.preventDefault(); + this.sendInstanceNew(this.props.selectedCryps, this.state.name, this.state.players); + this.setState({ name: '', players: 2 }); + } + + render() { + return ( +
+
+
+
+ + + + + +
+
+ ); + } +} + +module.exports = addState(InstanceCreateForm); diff --git a/server/src/instance.rs b/server/src/instance.rs index f0e83098..e3dc14ce 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -138,6 +138,10 @@ impl Instance { .position(|p| p.id == player_id) .ok_or(err_msg("player_id not found"))?; + if self.players[i].cryps.iter().all(|c| c.skills.len() == 0) { + return Err(err_msg("your cryps have no skills")); + } + self.players[i].set_ready(true); if self.phase == InstancePhase::Lobby && self.can_start() {