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 setGame = value => ({ type: 'SET_GAME', value });
|
||||||
export const setInfo = value => ({ type: 'SET_INFO', value });
|
export const setInfo = value => ({ type: 'SET_INFO', value });
|
||||||
export const setInstance = value => ({ type: 'SET_INSTANCE', 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 setInstances = value => ({ type: 'SET_INSTANCES', value });
|
||||||
export const setItemEquip = value => ({ type: 'SET_ITEM_EQUIP', value });
|
export const setItemEquip = value => ({ type: 'SET_ITEM_EQUIP', value });
|
||||||
export const setItemInfo = value => ({ type: 'SET_ITEM_INFO', 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 { stringSort } = require('./../utils');
|
||||||
const { ConstructAvatar } = require('./construct');
|
const { ConstructAvatar } = require('./construct');
|
||||||
const actions = require('./../actions');
|
const actions = require('./../actions');
|
||||||
const InstanceCreateForm = require('./instance.create.buttons');
|
const JoinButtons = require('./join.buttons');
|
||||||
const Inventory = require('./inventory');
|
const Inventory = require('./inventory');
|
||||||
|
|
||||||
const idSort = stringSort('id');
|
const idSort = stringSort('id');
|
||||||
@ -16,19 +16,11 @@ const addState = connect(
|
|||||||
constructs,
|
constructs,
|
||||||
constructRename,
|
constructRename,
|
||||||
team,
|
team,
|
||||||
instanceList,
|
|
||||||
mtxActive,
|
mtxActive,
|
||||||
} = state;
|
} = state;
|
||||||
|
|
||||||
function sendInstanceJoin(instance) {
|
function sendInstancePractice() {
|
||||||
if (team.length) {
|
return ws.sendInstancePractice();
|
||||||
return ws.sendInstanceJoin(instance.id, team);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function sendInstanceList() {
|
|
||||||
return ws.sendInstanceList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendConstructAvatarReroll(id) {
|
function sendConstructAvatarReroll(id) {
|
||||||
@ -42,13 +34,11 @@ const addState = connect(
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
constructs,
|
constructs,
|
||||||
instanceList,
|
|
||||||
mtxActive,
|
mtxActive,
|
||||||
constructRename,
|
constructRename,
|
||||||
team,
|
team,
|
||||||
sendConstructRename,
|
sendConstructRename,
|
||||||
sendInstanceJoin,
|
sendInstancePractice,
|
||||||
sendInstanceList,
|
|
||||||
sendConstructAvatarReroll,
|
sendConstructAvatarReroll,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -79,51 +69,10 @@ function List(args) {
|
|||||||
clearMtxRename,
|
clearMtxRename,
|
||||||
setConstructRename,
|
setConstructRename,
|
||||||
sendConstructRename,
|
sendConstructRename,
|
||||||
sendInstanceJoin,
|
|
||||||
sendInstanceList,
|
|
||||||
instanceList,
|
|
||||||
mtxActive,
|
mtxActive,
|
||||||
sendConstructAvatarReroll,
|
sendConstructAvatarReroll,
|
||||||
} = args;
|
} = 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
|
const constructPanels = constructs
|
||||||
.filter(c => team.includes(c.id))
|
.filter(c => team.includes(c.id))
|
||||||
.sort(idSort)
|
.sort(idSort)
|
||||||
@ -167,7 +116,7 @@ function List(args) {
|
|||||||
{constructPanels}
|
{constructPanels}
|
||||||
</div>
|
</div>
|
||||||
<Inventory />
|
<Inventory />
|
||||||
{listElements()}
|
<JoinButtons />
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,10 +20,6 @@ const addState = connect(
|
|||||||
return ws.sendInstanceState(instance.id);
|
return ws.sendInstanceState(instance.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceList() {
|
|
||||||
return ws.sendInstanceList();
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
account,
|
account,
|
||||||
instances,
|
instances,
|
||||||
@ -31,18 +27,9 @@ const addState = connect(
|
|||||||
game,
|
game,
|
||||||
ping,
|
ping,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
sendInstanceList,
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
function receiveDispatch(dispatch) {
|
function receiveDispatch(dispatch) {
|
||||||
function setTestGame(id) {
|
|
||||||
return dispatch(actions.setGame(testGame(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setTestInstance(id) {
|
|
||||||
return dispatch(actions.setInstance(testInstance(id)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setNav(place) {
|
function setNav(place) {
|
||||||
dispatch(actions.setGame(null));
|
dispatch(actions.setGame(null));
|
||||||
dispatch(actions.setInstance(null));
|
dispatch(actions.setInstance(null));
|
||||||
@ -63,8 +50,6 @@ const addState = connect(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setTestGame,
|
|
||||||
setTestInstance,
|
|
||||||
setNav,
|
setNav,
|
||||||
hideNav,
|
hideNav,
|
||||||
};
|
};
|
||||||
@ -79,18 +64,12 @@ function Nav(args) {
|
|||||||
team,
|
team,
|
||||||
|
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
sendInstanceList,
|
|
||||||
|
|
||||||
setTestGame,
|
|
||||||
setTestInstance,
|
|
||||||
setNav,
|
setNav,
|
||||||
hideNav,
|
hideNav,
|
||||||
} = args;
|
} = args;
|
||||||
|
|
||||||
function navTo(p) {
|
function navTo(p) {
|
||||||
if (p === 'list') {
|
|
||||||
sendInstanceList();
|
|
||||||
}
|
|
||||||
return setNav(p);
|
return setNav(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -40,11 +40,6 @@ function registerEvents(store) {
|
|||||||
store.dispatch(actions.setConstructs(constructs));
|
store.dispatch(actions.setConstructs(constructs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function setInstanceList(list) {
|
|
||||||
store.dispatch(actions.setInstanceList(list));
|
|
||||||
}
|
|
||||||
|
|
||||||
function setWs(ws) {
|
function setWs(ws) {
|
||||||
store.dispatch(actions.setWs(ws));
|
store.dispatch(actions.setWs(ws));
|
||||||
}
|
}
|
||||||
@ -236,7 +231,6 @@ function registerEvents(store) {
|
|||||||
setNewConstruct,
|
setNewConstruct,
|
||||||
setGame,
|
setGame,
|
||||||
setInstance,
|
setInstance,
|
||||||
setInstanceList,
|
|
||||||
setItemInfo,
|
setItemInfo,
|
||||||
setPing,
|
setPing,
|
||||||
setShop,
|
setShop,
|
||||||
|
|||||||
@ -31,7 +31,6 @@ module.exports = {
|
|||||||
info: createReducer(null, 'SET_INFO'),
|
info: createReducer(null, 'SET_INFO'),
|
||||||
instance: createReducer(null, 'SET_INSTANCE'),
|
instance: createReducer(null, 'SET_INSTANCE'),
|
||||||
instances: createReducer([], 'SET_INSTANCES'),
|
instances: createReducer([], 'SET_INSTANCES'),
|
||||||
instanceList: createReducer([], 'SET_INSTANCE_LIST'),
|
|
||||||
itemEquip: createReducer(null, 'SET_ITEM_EQUIP'),
|
itemEquip: createReducer(null, 'SET_ITEM_EQUIP'),
|
||||||
itemInfo: createReducer({ combos: [], items: [] }, 'SET_ITEM_INFO'),
|
itemInfo: createReducer({ combos: [], items: [] }, 'SET_ITEM_INFO'),
|
||||||
itemUnequip: createReducer([], 'SET_ITEM_UNEQUIP'),
|
itemUnequip: createReducer([], 'SET_ITEM_UNEQUIP'),
|
||||||
|
|||||||
@ -58,9 +58,6 @@ function createSocket(events) {
|
|||||||
send(['InstanceState', { instance_id: instanceId }]);
|
send(['InstanceState', { instance_id: instanceId }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceList() {
|
|
||||||
send(['InstanceList', {}]); }
|
|
||||||
|
|
||||||
function sendVboxAccept(instanceId, group, index) {
|
function sendVboxAccept(instanceId, group, index) {
|
||||||
send(['VboxAccept', { instance_id: instanceId, group, index }]);
|
send(['VboxAccept', { instance_id: instanceId, group, index }]);
|
||||||
events.clearInstance();
|
events.clearInstance();
|
||||||
@ -107,12 +104,8 @@ function createSocket(events) {
|
|||||||
events.setActiveSkill(null);
|
events.setActiveSkill(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceJoin(instanceId, constructs) {
|
function sendInstancePractice() {
|
||||||
send(['InstanceJoin', { instance_id: instanceId, construct_ids: constructs }]);
|
send(['InstancePractice', {}]);
|
||||||
}
|
|
||||||
|
|
||||||
function sendInstanceNew(constructs, name, pve) {
|
|
||||||
send(['InstanceLobby', { construct_ids: constructs, name, pve }]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendInstanceReady(instanceId) {
|
function sendInstanceReady(instanceId) {
|
||||||
@ -165,10 +158,6 @@ function createSocket(events) {
|
|||||||
events.setInstance(instance);
|
events.setInstance(instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onOpenInstances(list) {
|
|
||||||
events.setInstanceList(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onItemInfo(info) {
|
function onItemInfo(info) {
|
||||||
events.setItemInfo(info);
|
events.setItemInfo(info);
|
||||||
}
|
}
|
||||||
@ -194,7 +183,6 @@ function createSocket(events) {
|
|||||||
GameState: onGameState,
|
GameState: onGameState,
|
||||||
InstanceState: onInstanceState,
|
InstanceState: onInstanceState,
|
||||||
ItemInfo: onItemInfo,
|
ItemInfo: onItemInfo,
|
||||||
OpenInstances: onOpenInstances,
|
|
||||||
Pong: onPong,
|
Pong: onPong,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -280,25 +268,29 @@ function createSocket(events) {
|
|||||||
return {
|
return {
|
||||||
sendAccountConstructs,
|
sendAccountConstructs,
|
||||||
sendAccountInstances,
|
sendAccountInstances,
|
||||||
|
|
||||||
sendGameState,
|
sendGameState,
|
||||||
sendGameReady,
|
sendGameReady,
|
||||||
sendGameSkill,
|
sendGameSkill,
|
||||||
sendGameTarget,
|
sendGameTarget,
|
||||||
sendInstanceJoin,
|
|
||||||
sendInstanceList,
|
|
||||||
sendInstanceReady,
|
sendInstanceReady,
|
||||||
sendInstanceNew,
|
sendInstancePractice,
|
||||||
sendInstanceState,
|
sendInstanceState,
|
||||||
|
|
||||||
sendVboxAccept,
|
sendVboxAccept,
|
||||||
sendVboxApply,
|
sendVboxApply,
|
||||||
sendVboxReclaim,
|
sendVboxReclaim,
|
||||||
sendVboxCombine,
|
sendVboxCombine,
|
||||||
sendVboxDiscard,
|
sendVboxDiscard,
|
||||||
sendVboxUnequip,
|
sendVboxUnequip,
|
||||||
|
|
||||||
sendItemInfo,
|
sendItemInfo,
|
||||||
|
|
||||||
sendMtxApply,
|
sendMtxApply,
|
||||||
sendMtxBuy,
|
sendMtxBuy,
|
||||||
sendMtxConstructSpawn,
|
sendMtxConstructSpawn,
|
||||||
|
|
||||||
connect,
|
connect,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -301,7 +301,8 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
|||||||
SELECT data
|
SELECT data
|
||||||
FROM constructs
|
FROM constructs
|
||||||
WHERE account = $1
|
WHERE account = $1
|
||||||
AND team = true;
|
AND team = true
|
||||||
|
LIMIT 3;
|
||||||
";
|
";
|
||||||
|
|
||||||
let result = tx
|
let result = tx
|
||||||
@ -328,6 +329,38 @@ pub fn account_team(tx: &mut Transaction, account: &Account) -> Result<Vec<Const
|
|||||||
return Ok(constructs);
|
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> {
|
pub fn account_instances(tx: &mut Transaction, account: &Account) -> Result<Vec<Instance>, Error> {
|
||||||
let query = "
|
let query = "
|
||||||
SELECT data, id
|
SELECT data, id
|
||||||
|
|||||||
@ -498,7 +498,7 @@ pub fn instance_create(tx: &mut Transaction, instance: Instance) -> Result<Insta
|
|||||||
|
|
||||||
let query = "
|
let query = "
|
||||||
INSERT INTO instances (id, data)
|
INSERT INTO instances (id, data)
|
||||||
VALUES ($1, $2, $3)
|
VALUES ($1, $2)
|
||||||
RETURNING id;
|
RETURNING id;
|
||||||
";
|
";
|
||||||
|
|
||||||
@ -575,11 +575,10 @@ pub fn instance_delete(tx: &mut Transaction, id: Uuid) -> Result<(), Error> {
|
|||||||
return Ok(());
|
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 = "
|
let query = "
|
||||||
SELECT data, id
|
SELECT data, id
|
||||||
FROM instances
|
FROM instances
|
||||||
WHERE open = true
|
|
||||||
AND finished = false;
|
AND finished = false;
|
||||||
";
|
";
|
||||||
|
|
||||||
@ -677,13 +676,16 @@ pub fn instance_practice(tx: &mut Transaction, account: &Account) -> Result<Inst
|
|||||||
.set_name(bot.name.clone())?;
|
.set_name(bot.name.clone())?;
|
||||||
|
|
||||||
let constructs = account::account_team(tx, account)?;
|
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.add_player(bot)?;
|
||||||
instance.player_ready(bot_id)?;
|
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> {
|
// 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
|
// TODO generate nice game names
|
||||||
.set_name("PVP".to_string())?;
|
.set_name("PVP".to_string())?;
|
||||||
|
|
||||||
|
instance = instance_create(tx, instance)?;
|
||||||
|
|
||||||
for account in [a, b].iter() {
|
for account in [a, b].iter() {
|
||||||
let constructs = account::account_team(tx, account)?;
|
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_create(tx, Player::new(account.id, &account.name, constructs), instance.id, account)?;
|
||||||
instance.add_player(player)?;
|
instance.add_player(player)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
instance_create(tx, instance)
|
instance_update(tx, instance)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use rand::prelude::*;
|
use rand::prelude::*;
|
||||||
use rand::{thread_rng};
|
use rand::{thread_rng};
|
||||||
|
|
||||||
const FIRSTS: [&'static str; 36] = [
|
const FIRSTS: [&'static str; 37] = [
|
||||||
"artificial",
|
"artificial",
|
||||||
"ambient",
|
"ambient",
|
||||||
"borean",
|
"borean",
|
||||||
@ -12,6 +12,7 @@ const FIRSTS: [&'static str; 36] = [
|
|||||||
"concave",
|
"concave",
|
||||||
"convex",
|
"convex",
|
||||||
"distorted",
|
"distorted",
|
||||||
|
"deserted",
|
||||||
"emotive",
|
"emotive",
|
||||||
"emotionless",
|
"emotionless",
|
||||||
"fierce",
|
"fierce",
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
use std::net::TcpStream;
|
|
||||||
use std::time::{Instant};
|
use std::time::{Instant};
|
||||||
|
|
||||||
use serde_cbor::{from_slice};
|
use serde_cbor::{from_slice};
|
||||||
@ -11,7 +11,7 @@ use construct::{Construct};
|
|||||||
use game::{Game, game_state, game_skill, game_ready};
|
use game::{Game, game_state, game_skill, game_ready};
|
||||||
use account::{Account, account_constructs};
|
use account::{Account, account_constructs};
|
||||||
use skill::{Skill, dev_resolve, Resolutions};
|
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 vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip};
|
||||||
use item::{Item, ItemInfoCtr, item_info};
|
use item::{Item, ItemInfoCtr, item_info};
|
||||||
|
|
||||||
@ -27,7 +27,6 @@ pub enum RpcMessage {
|
|||||||
GameState(Game),
|
GameState(Game),
|
||||||
ItemInfo(ItemInfoCtr),
|
ItemInfo(ItemInfoCtr),
|
||||||
|
|
||||||
OpenInstances(Vec<Instance>),
|
|
||||||
InstanceState(Instance),
|
InstanceState(Instance),
|
||||||
|
|
||||||
Pong(()),
|
Pong(()),
|
||||||
@ -56,8 +55,6 @@ enum RpcRequest {
|
|||||||
AccountShop {},
|
AccountShop {},
|
||||||
AccountConstructs {},
|
AccountConstructs {},
|
||||||
|
|
||||||
InstanceList {},
|
|
||||||
InstanceLobby { construct_ids: Vec<Uuid>, name: String, pve: bool, password: Option<String> },
|
|
||||||
InstancePvp {},
|
InstancePvp {},
|
||||||
InstancePractice {},
|
InstancePractice {},
|
||||||
InstanceReady { instance_id: Uuid },
|
InstanceReady { instance_id: Uuid },
|
||||||
@ -119,8 +116,6 @@ pub fn receive(data: Vec<u8>, db: &Db, begin: Instant, account: &Option<Account>
|
|||||||
RpcRequest::GameReady { id } =>
|
RpcRequest::GameReady { id } =>
|
||||||
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),
|
Ok(RpcMessage::GameState(game_ready(&mut tx, account, id)?)),
|
||||||
|
|
||||||
RpcRequest::InstanceList {} =>
|
|
||||||
Ok(RpcMessage::OpenInstances(instance_list(&mut tx)?)),
|
|
||||||
// RpcRequest::InstanceQueue {} =>
|
// RpcRequest::InstanceQueue {} =>
|
||||||
// Ok(RpcMessage::QueueState(instance_queue(&mut tx, account)?)),
|
// Ok(RpcMessage::QueueState(instance_queue(&mut tx, account)?)),
|
||||||
RpcRequest::InstancePractice {} =>
|
RpcRequest::InstancePractice {} =>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user