diff --git a/client/src/components/team.jsx b/client/src/components/team.jsx index d357a0bb..056a18dc 100644 --- a/client/src/components/team.jsx +++ b/client/src/components/team.jsx @@ -64,7 +64,7 @@ function Team(args) { return setTeam(team); } - const constructPanels = constructs.sort(idSort).map(construct => { + const constructPanels = constructs.map(construct => { const colour = team.indexOf(construct.id); const selected = colour > -1; diff --git a/client/src/events.jsx b/client/src/events.jsx index 4c4aeed0..d15c5f19 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -34,6 +34,13 @@ function registerEvents(store) { setNav('list'); } + function setNewConstruct(construct) { + const { constructs } = store.getState(); + constructs.push(construct); + store.dispatch(actions.setConstructs(constructs)); + } + + function setInstanceList(list) { store.dispatch(actions.setInstanceList(list)); } @@ -226,6 +233,7 @@ function registerEvents(store) { setActiveItem, setActiveSkill, setConstructList, + setNewConstruct, setGame, setInstance, setInstanceList, diff --git a/client/src/socket.jsx b/client/src/socket.jsx index 580121a4..7c62dc12 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -46,6 +46,10 @@ function createSocket(events) { send(['AccountInstances', {}]); } + function sendConstructSpawn() { + send(['MtxConstructBuy', {}]); + } + function sendGameState(id) { send(['GameState', { id }]); } @@ -150,6 +154,10 @@ function createSocket(events) { events.setConstructList(constructs); } + function onConstructSpawn(construct) { + events.setNewConstruct(construct); + } + function onGameState(game) { events.setGame(game); } @@ -183,6 +191,7 @@ function createSocket(events) { AccountConstructs: onAccountConstructs, AccountInstances: onAccountInstances, AccountShop: onAccountShop, + ConstructSpawn: onConstructSpawn, GameState: onGameState, InstanceState: onInstanceState, ItemInfo: onItemInfo, @@ -272,6 +281,7 @@ function createSocket(events) { return { sendAccountConstructs, sendAccountInstances, + sendConstructSpawn, sendGameState, sendGameReady, sendGameSkill, diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 76a610d5..8022e24f 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -8,7 +8,7 @@ use failure::Error; use failure::err_msg; use pg::{Db}; -use construct::{Construct}; +use construct::{Construct, construct_spawn}; use game::{Game, game_state, game_skill, game_ready}; use account::{Account, account_constructs, account_instances}; use skill::{Skill, dev_resolve, Resolutions}; @@ -16,6 +16,9 @@ use instance::{Instance, instance_state, instance_list, instance_new, instance_r use vbox::{vbox_accept, vbox_apply, vbox_discard, vbox_combine, vbox_reclaim, vbox_unequip}; use item::{Item, ItemInfoCtr, item_info}; +use names::{name as generate_name}; + + use mtx; #[derive(Debug,Clone,Serialize,Deserialize)] @@ -27,6 +30,7 @@ pub enum RpcMessage { GameState(Game), ItemInfo(ItemInfoCtr), + ConstructSpawn(Construct), OpenInstances(Vec), InstanceState(Instance), @@ -44,6 +48,7 @@ enum RpcRequest { DevResolve { a: Uuid, b: Uuid, skill: Skill }, MtxConstructApply { mtx: mtx::MtxVariant, construct_id: Uuid, name: String }, + MtxConstructBuy { }, MtxAccountApply { mtx: mtx::MtxVariant }, MtxBuy { mtx: mtx::MtxVariant }, @@ -148,6 +153,8 @@ pub fn receive(data: Vec, db: &Db, begin: Instant, account: &Option RpcRequest::VboxUnequip { instance_id, construct_id, target } => Ok(RpcMessage::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)), + RpcRequest::MtxConstructBuy { } => + Ok(RpcMessage::ConstructSpawn(construct_spawn(&mut tx, account.id, generate_name())?)), RpcRequest::MtxConstructApply { mtx, construct_id, name } => Ok(RpcMessage::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id, name)?)),