remove instance list
This commit is contained in:
parent
66223033b0
commit
9fdda7c52c
@ -17,7 +17,6 @@ export const setConstructRename = value => ({ type: 'SET_CONSTRUCT_RENAME', valu
|
||||
export const setGame = value => ({ type: 'SET_GAME', value });
|
||||
export const setInfo = value => ({ type: 'SET_INFO', value });
|
||||
export const setInstance = value => ({ type: 'SET_INSTANCE', value });
|
||||
export const setInstanceList = value => ({ type: 'SET_INSTANCE_LIST', value });
|
||||
export const setInstances = value => ({ type: 'SET_INSTANCES', value });
|
||||
export const setItemEquip = value => ({ type: 'SET_ITEM_EQUIP', value });
|
||||
export const setItemInfo = value => ({ type: 'SET_ITEM_INFO', value });
|
||||
|
||||
@ -1,46 +0,0 @@
|
||||
const preact = require('preact');
|
||||
const { connect } = require('preact-redux');
|
||||
const { Component } = require('preact');
|
||||
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { ws, team, account } = state;
|
||||
|
||||
function sendInstanceNew(sConstructs, pve) {
|
||||
if (sConstructs.length) {
|
||||
return ws.sendInstanceNew(sConstructs, account.name, pve);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
sendInstanceNew,
|
||||
team,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
function CreateButtons(args) {
|
||||
const { team, sendInstanceNew } = args;
|
||||
const disabled = !team.every(c => c);
|
||||
|
||||
const classes = `create-form ${disabled ? 'disabled' : ''}`;
|
||||
return (
|
||||
<div class={classes}>
|
||||
<button
|
||||
onClick={() => sendInstanceNew(team, true)}
|
||||
disabled={disabled}
|
||||
type="submit">
|
||||
Practice vs CPU
|
||||
</button>
|
||||
<button
|
||||
onClick={() => sendInstanceNew(team, false)}
|
||||
disabled={disabled}
|
||||
type="submit">
|
||||
PVP
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = addState(CreateButtons);
|
||||
@ -1,91 +0,0 @@
|
||||
const preact = require('preact');
|
||||
const { connect } = require('preact-redux');
|
||||
const { Component } = require('preact');
|
||||
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { ws, team } = state;
|
||||
|
||||
function sendInstanceNew(sConstructs, name, pve) {
|
||||
if (sConstructs.length) {
|
||||
return ws.sendInstanceNew(sConstructs, name, pve);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
sendInstanceNew,
|
||||
team,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
class InstanceCreateForm extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
|
||||
this.state = { pve: false, name: '' };
|
||||
|
||||
const { sendInstanceNew } = props;
|
||||
|
||||
this.sendInstanceNew = sendInstanceNew.bind(this);
|
||||
|
||||
this.nameInput = this.nameInput.bind(this);
|
||||
this.pveChange = this.pveChange.bind(this);
|
||||
this.handleSubmit = this.handleSubmit.bind(this);
|
||||
}
|
||||
|
||||
pveChange() {
|
||||
this.setState({ pve: !this.state.pve });
|
||||
}
|
||||
|
||||
nameInput(event) {
|
||||
this.setState({ name: event.target.value });
|
||||
}
|
||||
|
||||
handleSubmit(event) {
|
||||
event.preventDefault();
|
||||
this.sendInstanceNew(this.props.team, this.state.name, this.state.pve);
|
||||
this.setState({ name: '', pve: false });
|
||||
}
|
||||
|
||||
render() {
|
||||
const disabled = !this.props.team.every(c => c);
|
||||
|
||||
const classes = `create-form ${disabled ? 'disabled' : ''}`;
|
||||
return (
|
||||
<div class={classes}>
|
||||
<form>
|
||||
<fieldset>
|
||||
<legend>New Instance</legend>
|
||||
<label>Instance Name</label>
|
||||
<input
|
||||
class="login-input"
|
||||
type="text"
|
||||
disabled={disabled}
|
||||
value={this.state.name}
|
||||
placeholder="game name"
|
||||
onInput={this.nameInput}
|
||||
/>
|
||||
<label htmlFor="pveSelect">Practice Mode - vs CPU, no Time Control</label>
|
||||
<input id="pveSelect"
|
||||
type="checkbox"
|
||||
disabled={disabled}
|
||||
checked={this.state.pve}
|
||||
onChange={this.pveChange}
|
||||
>
|
||||
</input>
|
||||
</fieldset>
|
||||
</form>
|
||||
<button
|
||||
onClick={this.handleSubmit}
|
||||
disabled={disabled}
|
||||
type="submit">
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = addState(InstanceCreateForm);
|
||||
46
client/src/components/join.buttons.jsx
Normal file
46
client/src/components/join.buttons.jsx
Normal file
@ -0,0 +1,46 @@
|
||||
const preact = require('preact');
|
||||
const { connect } = require('preact-redux');
|
||||
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { ws } = state;
|
||||
|
||||
function sendInstancePractice() {
|
||||
ws.sendInstancePractice();
|
||||
}
|
||||
|
||||
function sendInstanceQueue() {
|
||||
ws.sendInstanceQueue();
|
||||
}
|
||||
|
||||
return {
|
||||
sendInstanceQueue,
|
||||
sendInstancePractice,
|
||||
};
|
||||
}
|
||||
);
|
||||
|
||||
function CreateButtons(args) {
|
||||
const {
|
||||
sendInstanceQueue,
|
||||
sendInstancePractice,
|
||||
} = args;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>Join Game</h1>
|
||||
<button
|
||||
onClick={() => sendInstancePractice()}
|
||||
type="submit">
|
||||
Practice vs CPU
|
||||
</button>
|
||||
<button
|
||||
onClick={() => sendInstanceQueue()}
|
||||
type="submit">
|
||||
PVP
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = addState(CreateButtons);
|
||||
@ -4,7 +4,7 @@ const preact = require('preact');
|
||||
const { stringSort } = require('./../utils');
|
||||
const { ConstructAvatar } = require('./construct');
|
||||
const actions = require('./../actions');
|
||||
const InstanceCreateForm = require('./instance.create.buttons');
|
||||
const JoinButtons = require('./join.buttons');
|
||||
const Inventory = require('./inventory');
|
||||
|
||||
const idSort = stringSort('id');
|
||||
@ -16,19 +16,11 @@ const addState = connect(
|
||||
constructs,
|
||||
constructRename,
|
||||
team,
|
||||
instanceList,
|
||||
mtxActive,
|
||||
} = state;
|
||||
|
||||
function sendInstanceJoin(instance) {
|
||||
if (team.length) {
|
||||
return ws.sendInstanceJoin(instance.id, team);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function sendInstanceList() {
|
||||
return ws.sendInstanceList();
|
||||
function sendInstancePractice() {
|
||||
return ws.sendInstancePractice();
|
||||
}
|
||||
|
||||
function sendConstructAvatarReroll(id) {
|
||||
@ -42,13 +34,11 @@ const addState = connect(
|
||||
|
||||
return {
|
||||
constructs,
|
||||
instanceList,
|
||||
mtxActive,
|
||||
constructRename,
|
||||
team,
|
||||
sendConstructRename,
|
||||
sendInstanceJoin,
|
||||
sendInstanceList,
|
||||
sendInstancePractice,
|
||||
sendConstructAvatarReroll,
|
||||
};
|
||||
},
|
||||
@ -79,51 +69,10 @@ function List(args) {
|
||||
clearMtxRename,
|
||||
setConstructRename,
|
||||
sendConstructRename,
|
||||
sendInstanceJoin,
|
||||
sendInstanceList,
|
||||
instanceList,
|
||||
mtxActive,
|
||||
sendConstructAvatarReroll,
|
||||
} = args;
|
||||
|
||||
function listElements() {
|
||||
if (!instanceList) return <div>...</div>;
|
||||
|
||||
const instancePanels = instanceList.map(instance => {
|
||||
function instanceClick() {
|
||||
return sendInstanceJoin(instance);
|
||||
}
|
||||
|
||||
return (
|
||||
<tr key={instance.id}
|
||||
class="right"
|
||||
onClick={instanceClick} >
|
||||
<td>{instance.name}</td>
|
||||
</tr>
|
||||
);
|
||||
});
|
||||
|
||||
return (
|
||||
<div class="menu-instance-list" >
|
||||
<h1>Join Game</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>opponent name</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{instancePanels}
|
||||
<tr class="right" onClick={() => sendInstanceList()}>
|
||||
<td colSpan={3} >↺</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<InstanceCreateForm />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const constructPanels = constructs
|
||||
.filter(c => team.includes(c.id))
|
||||
.sort(idSort)
|
||||
@ -167,7 +116,7 @@ function List(args) {
|
||||
{constructPanels}
|
||||
</div>
|
||||
<Inventory />
|
||||
{listElements()}
|
||||
<JoinButtons />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
@ -20,10 +20,6 @@ const addState = connect(
|
||||
return ws.sendInstanceState(instance.id);
|
||||
}
|
||||
|
||||
function sendInstanceList() {
|
||||
return ws.sendInstanceList();
|
||||
}
|
||||
|
||||
return {
|
||||
account,
|
||||
instances,
|
||||
@ -31,18 +27,9 @@ const addState = connect(
|
||||
game,
|
||||
ping,
|
||||
sendInstanceState,
|
||||
sendInstanceList,
|
||||
};
|
||||
},
|
||||
function receiveDispatch(dispatch) {
|
||||
function setTestGame(id) {
|
||||
return dispatch(actions.setGame(testGame(id)));
|
||||
}
|
||||
|
||||
function setTestInstance(id) {
|
||||
return dispatch(actions.setInstance(testInstance(id)));
|
||||
}
|
||||
|
||||
function setNav(place) {
|
||||
dispatch(actions.setGame(null));
|
||||
dispatch(actions.setInstance(null));
|
||||
@ -63,8 +50,6 @@ const addState = connect(
|
||||
}
|
||||
|
||||
return {
|
||||
setTestGame,
|
||||
setTestInstance,
|
||||
setNav,
|
||||
hideNav,
|
||||
};
|
||||
@ -79,18 +64,12 @@ function Nav(args) {
|
||||
team,
|
||||
|
||||
sendInstanceState,
|
||||
sendInstanceList,
|
||||
|
||||
setTestGame,
|
||||
setTestInstance,
|
||||
setNav,
|
||||
hideNav,
|
||||
} = args;
|
||||
|
||||
function navTo(p) {
|
||||
if (p === 'list') {
|
||||
sendInstanceList();
|
||||
}
|
||||
return setNav(p);
|
||||
}
|
||||
|
||||
|
||||
@ -40,11 +40,6 @@ function registerEvents(store) {
|
||||
store.dispatch(actions.setConstructs(constructs));
|
||||
}
|
||||
|
||||
|
||||
function setInstanceList(list) {
|
||||
store.dispatch(actions.setInstanceList(list));
|
||||
}
|
||||
|
||||
function setWs(ws) {
|
||||
store.dispatch(actions.setWs(ws));
|
||||
}
|
||||
@ -236,7 +231,6 @@ function registerEvents(store) {
|
||||
setNewConstruct,
|
||||
setGame,
|
||||
setInstance,
|
||||
setInstanceList,
|
||||
setItemInfo,
|
||||
setPing,
|
||||
setShop,
|
||||
|
||||
@ -31,7 +31,6 @@ module.exports = {
|
||||
info: createReducer(null, 'SET_INFO'),
|
||||
instance: createReducer(null, 'SET_INSTANCE'),
|
||||
instances: createReducer([], 'SET_INSTANCES'),
|
||||
instanceList: createReducer([], 'SET_INSTANCE_LIST'),
|
||||
itemEquip: createReducer(null, 'SET_ITEM_EQUIP'),
|
||||
itemInfo: createReducer({ combos: [], items: [] }, 'SET_ITEM_INFO'),
|
||||
itemUnequip: createReducer([], 'SET_ITEM_UNEQUIP'),
|
||||
|
||||
@ -58,9 +58,6 @@ function createSocket(events) {
|
||||
send(['InstanceState', { instance_id: instanceId }]);
|
||||
}
|
||||
|
||||
function sendInstanceList() {
|
||||
send(['InstanceList', {}]); }
|
||||
|
||||
function sendVboxAccept(instanceId, group, index) {
|
||||
send(['VboxAccept', { instance_id: instanceId, group, index }]);
|
||||
events.clearInstance();
|
||||
@ -107,12 +104,8 @@ function createSocket(events) {
|
||||
events.setActiveSkill(null);
|
||||
}
|
||||
|
||||
function sendInstanceJoin(instanceId, constructs) {
|
||||
send(['InstanceJoin', { instance_id: instanceId, construct_ids: constructs }]);
|
||||
}
|
||||
|
||||
function sendInstanceNew(constructs, name, pve) {
|
||||
send(['InstanceLobby', { construct_ids: constructs, name, pve }]);
|
||||
function sendInstancePractice() {
|
||||
send(['InstancePractice', {}]);
|
||||
}
|
||||
|
||||
function sendInstanceReady(instanceId) {
|
||||
@ -165,10 +158,6 @@ function createSocket(events) {
|
||||
events.setInstance(instance);
|
||||
}
|
||||
|
||||
function onOpenInstances(list) {
|
||||
events.setInstanceList(list);
|
||||
}
|
||||
|
||||
function onItemInfo(info) {
|
||||
events.setItemInfo(info);
|
||||
}
|
||||
@ -194,7 +183,6 @@ function createSocket(events) {
|
||||
GameState: onGameState,
|
||||
InstanceState: onInstanceState,
|
||||
ItemInfo: onItemInfo,
|
||||
OpenInstances: onOpenInstances,
|
||||
Pong: onPong,
|
||||
};
|
||||
|
||||
@ -280,25 +268,29 @@ function createSocket(events) {
|
||||
return {
|
||||
sendAccountConstructs,
|
||||
sendAccountInstances,
|
||||
|
||||
sendGameState,
|
||||
sendGameReady,
|
||||
sendGameSkill,
|
||||
sendGameTarget,
|
||||
sendInstanceJoin,
|
||||
sendInstanceList,
|
||||
|
||||
sendInstanceReady,
|
||||
sendInstanceNew,
|
||||
sendInstancePractice,
|
||||
sendInstanceState,
|
||||
|
||||
sendVboxAccept,
|
||||
sendVboxApply,
|
||||
sendVboxReclaim,
|
||||
sendVboxCombine,
|
||||
sendVboxDiscard,
|
||||
sendVboxUnequip,
|
||||
|
||||
sendItemInfo,
|
||||
|
||||
sendMtxApply,
|
||||
sendMtxBuy,
|
||||
sendMtxConstructSpawn,
|
||||
|
||||
connect,
|
||||
};
|
||||
}
|
||||
|
||||
@ -301,7 +301,8 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
||||
SELECT data
|
||||
FROM constructs
|
||||
WHERE account = $1
|
||||
AND team = true;
|
||||
AND team = true
|
||||
LIMIT 3;
|
||||
";
|
||||
|
||||
let result = tx
|
||||
@ -328,6 +329,38 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
||||
return Ok(constructs);
|
||||
}
|
||||
|
||||
pub fn account_set_team(tx: &mut Transaction, account: &Account, ids: Vec<Uuid>) -> Result<Vec<Construct>, Error> {
|
||||
let query = "
|
||||
UPDATE constructs
|
||||
SET team = false
|
||||
WHERE account = $1;
|
||||
";
|
||||
|
||||
let updated = tx
|
||||
.execute(query, &[&account.id, &ids])?;
|
||||
|
||||
if updated > 3 {
|
||||
warn!("team members >3 account={:?} count={:?}", account, updated);
|
||||
}
|
||||
|
||||
let query = "
|
||||
UPDATE constructs
|
||||
SET team = true
|
||||
WHERE account = $1
|
||||
AND id in $2
|
||||
RETURNING data;
|
||||
";
|
||||
|
||||
let updated = tx
|
||||
.execute(query, &[&account.id, &ids])?;
|
||||
|
||||
if updated != 3 {
|
||||
return Err(format_err!("could not create team of 3 account={:?} updated={:?}", account, updated));
|
||||
}
|
||||
|
||||
account_team(tx, account)
|
||||
}
|
||||
|
||||
pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
|
||||
@ -498,7 +498,7 @@ pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Insta
|
||||
|
||||
let query = "
|
||||
INSERT INTO instances (id, data)
|
||||
VALUES ($1, $2, $3)
|
||||
VALUES ($1, $2)
|
||||
RETURNING id;
|
||||
";
|
||||
|
||||
@ -575,11 +575,10 @@ pub fn instance_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
pub fn instance_list(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
pub fn _instance_list(tx: &mut Transaction) -> Result<Vec<Instance>, Error> {
|
||||
let query = "
|
||||
SELECT data, id
|
||||
FROM instances
|
||||
WHERE open = true
|
||||
AND finished = false;
|
||||
";
|
||||
|
||||
@ -677,13 +676,16 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
|
||||
.set_name(bot.name.clone())?;
|
||||
|
||||
let constructs = account::account_team(tx, account)?;
|
||||
let player = player_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
|
||||
let player = Player::new(account.id, &account.name, constructs);
|
||||
|
||||
instance.add_player(player)?;
|
||||
instance.add_player(player.clone())?;
|
||||
instance.add_player(bot)?;
|
||||
instance.player_ready(bot_id)?;
|
||||
|
||||
instance_create(tx, instance)
|
||||
instance = instance_create(tx, instance)?;
|
||||
player_create(tx, player, instance.id, account)?;
|
||||
|
||||
Ok(instance)
|
||||
}
|
||||
|
||||
// pub fn instance_queue(tx: &mut Transaction, a: &Account, b: &Account) -> Result<Instance, Error> {
|
||||
@ -694,13 +696,15 @@ pub fn instance_pvp(tx: &mut Transaction, a: &Account, b: &Account) -> Result<In
|
||||
// TODO generate nice game names
|
||||
.set_name("PVP".to_string())?;
|
||||
|
||||
instance = instance_create(tx, instance)?;
|
||||
|
||||
for account in [a, b].iter() {
|
||||
let constructs = account::account_team(tx, account)?;
|
||||
let player = player_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
|
||||
instance.add_player(player)?;
|
||||
}
|
||||
|
||||
instance_create(tx, instance)
|
||||
instance_update(tx, instance)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
use rand::prelude::*;
|
||||
use rand::{thread_rng};
|
||||
|
||||
const FIRSTS: [&'static str; 36] = [
|
||||
const FIRSTS: [&'static str; 37] = [
|
||||
"artificial",
|
||||
"ambient",
|
||||
"borean",
|
||||
@ -12,6 +12,7 @@ const FIRSTS: [&'static str; 36] = [
|
||||
"concave",
|
||||
"convex",
|
||||
"distorted",
|
||||
"deserted",
|
||||
"emotive",
|
||||
"emotionless",
|
||||
"fierce",
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use std::net::TcpStream;
|
||||
|
||||
use std::time::{Instant};
|
||||
|
||||
use serde_cbor::{from_slice};
|
||||
@ -11,7 +11,7 @@ use construct::{Construct};
|
||||
use game::{Game, game_state, game_skill, game_ready};
|
||||
use account::{Account, account_constructs};
|
||||
use skill::{Skill, dev_resolve, Resolutions};
|
||||
use instance::{Instance, instance_state, instance_list, instance_practice, instance_ready, instance_pvp};
|
||||
use instance::{Instance, instance_state, instance_practice, instance_ready, instance_pvp};
|
||||
use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
|
||||
@ -27,7 +27,6 @@ pub enum RpcMessage {
|
||||
GameState(Game),
|
||||
ItemInfo(ItemInfoCtr),
|
||||
|
||||
OpenInstances(Vec<Instance>),
|
||||
InstanceState(Instance),
|
||||
|
||||
Pong(()),
|
||||
@ -56,8 +55,6 @@ enum RpcRequest {
|
||||
AccountShop {},
|
||||
AccountConstructs {},
|
||||
|
||||
InstanceList {},
|
||||
InstanceLobby { construct_ids: Vec<Uuid>, name: String, pve: bool, password: Option<String> },
|
||||
InstancePvp {},
|
||||
InstancePractice {},
|
||||
InstanceReady { instance_id: Uuid },
|
||||
@ -119,8 +116,6 @@ pub fn receive(data: Vec<u8>, db: &Db, begin: Instant, account: &Option<Account>
|
||||
RpcRequest::GameReady { id } =>
|
||||
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),
|
||||
|
||||
RpcRequest::InstanceList {} =>
|
||||
Ok(RpcMessage::OpenInstances(instance_list(&mut tx)?)),
|
||||
// RpcRequest::InstanceQueue {} =>
|
||||
// Ok(RpcMessage::QueueState(instance_queue(&mut tx, account)?)),
|
||||
RpcRequest::InstancePractice {} =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user