diff --git a/client/src/actions.jsx b/client/src/actions.jsx index 06e644d5..e4f6fb2b 100644 --- a/client/src/actions.jsx +++ b/client/src/actions.jsx @@ -6,6 +6,7 @@ export const setActiveSkill = (constructId, skill) => ({ type: 'SET_ACTIVE_SKILL export const setCombiner = value => ({ type: 'SET_COMBINER', value: Array.from(value) }); export const setConstructEditId = value => ({ type: 'SET_CONSTRUCT_EDIT_ID', value }); export const setConstructs = value => ({ type: 'SET_CONSTRUCTS', value }); +export const setConstructRename = value => ({ type: 'SET_CONSTRUCT_RENAME', value }); export const setGame = value => ({ type: 'SET_GAME', value }); export const setInfo = value => ({ type: 'SET_INFO', value }); export const setInstance = value => ({ type: 'SET_INSTANCE', value }); diff --git a/client/src/components/list.jsx b/client/src/components/list.jsx index 23f166ff..5a4f932d 100644 --- a/client/src/components/list.jsx +++ b/client/src/components/list.jsx @@ -14,6 +14,7 @@ const addState = connect( const { ws, constructs, + constructRename, team, instanceList, account, @@ -35,25 +36,47 @@ const addState = connect( return ws.sendInstanceList(); } - function selectConstruct(id) { + function sendConstructAvatarReroll(id) { if (!mtxActive) return false; console.log('using', mtxActive, 'on', id); - ws.sendMtxApply(id, mtxActive); + return ws.sendMtxApply(id, mtxActive, ''); + } + + function sendConstructRename(id, name) { + ws.sendMtxApply(id, 'Rename', name); } return { account, constructs, + instanceList, + mtxActive, + constructRename, team, + sendConstructRename, sendInstanceJoin, sendInstanceState, sendInstanceList, - instanceList, - - mtxActive, - selectConstruct + sendConstructAvatarReroll, }; }, + + function receiveDispatch(dispatch) { + function setConstructRename(id) { + dispatch(actions.setConstructRename(id)); + } + + function clearMtxRename() { + dispatch(actions.setConstructRename(null)); + dispatch(actions.setMtxActive(null)); + } + + return { + clearMtxRename, + setConstructRename, + }; + } + ); function List(args) { @@ -61,13 +84,16 @@ function List(args) { account, team, constructs, + constructRename, + clearMtxRename, + setConstructRename, + sendConstructRename, sendInstanceState, sendInstanceJoin, sendInstanceList, instanceList, - mtxActive, - selectConstruct, + sendConstructAvatarReroll, } = args; function listElements() { @@ -115,16 +141,40 @@ function List(args) { const constructPanels = constructs .filter(c => team.includes(c.id)) .sort(idSort) - .map(construct => -
selectConstruct(construct.id)} - class="menu-construct" > - -

{construct.name}

-
- ); + .map(construct => { + const constructName = constructRename === construct.id + ? + :

{construct.name}

; + + const confirm = constructRename === construct.id + ? + : false; + + const cancel = constructRename === construct.id + ? + : false; + return ( +
{ + if (!mtxActive) return false; + if (mtxActive === 'Rename') return setConstructRename(construct.id); + sendConstructAvatarReroll(construct.id); + }} + class="menu-construct" > + + {constructName} + {confirm} + {cancel} + +
+ ); + }); return (
diff --git a/client/src/events.jsx b/client/src/events.jsx index e1d771d8..a271a81c 100644 --- a/client/src/events.jsx +++ b/client/src/events.jsx @@ -120,6 +120,10 @@ function registerEvents(store) { store.dispatch(actions.setCombiner([null, null, null])); } + function clearConstructRename() { + store.dispatch(actions.setConstructRename(null)); + } + function clearMtxActive() { store.dispatch(actions.setMtxActive(null)); } @@ -223,6 +227,7 @@ function registerEvents(store) { return { clearCombiner, + clearConstructRename, clearInfo, clearInstance, clearMtxActive, diff --git a/client/src/reducers.jsx b/client/src/reducers.jsx index 161044ce..288fca18 100644 --- a/client/src/reducers.jsx +++ b/client/src/reducers.jsx @@ -19,6 +19,7 @@ module.exports = { combiner: createReducer([null, null, null], 'SET_COMBINER'), constructs: createReducer([], 'SET_CONSTRUCTS'), constructEditId: createReducer(null, 'SET_CONSTRUCT_EDIT_ID'), + constructRename: createReducer(null, 'SET_CONSTRUCT_RENAME'), game: createReducer(null, 'SET_GAME'), info: createReducer(null, 'SET_INFO'), instance: createReducer(null, 'SET_INSTANCE'), diff --git a/client/src/socket.jsx b/client/src/socket.jsx index f79131ea..f89a8e14 100644 --- a/client/src/socket.jsx +++ b/client/src/socket.jsx @@ -97,7 +97,7 @@ function createSocket(events) { function sendGameSkill(gameId, constructId, targetConstructId, skill) { send(['GameSkill', - { game_id: gameId, construct_id: constructId, target_construct_id: targetConstructId, skill, }, + { game_id: gameId, construct_id: constructId, target_construct_id: targetConstructId, skill }, ]); events.setActiveSkill(null); } @@ -119,9 +119,12 @@ function createSocket(events) { send(['InstanceReady', { instance_id: instanceId }]); } - function sendMtxApply(constructId, mtx) { - send(['MtxConstructApply', { construct_id: constructId, mtx }]); - // events.clearMtxActive(); + function sendMtxApply(constructId, mtx, name) { + send(['MtxConstructApply', { construct_id: constructId, mtx, name }]); + if (mtx === 'Rename') { + events.clearMtxActive(); + events.clearConstructRename(); + } } function sendMtxBuy(mtx) { diff --git a/server/src/construct.rs b/server/src/construct.rs index 7c45217b..8c247368 100644 --- a/server/src/construct.rs +++ b/server/src/construct.rs @@ -9,7 +9,6 @@ use failure::err_msg; use skill::{Skill, Cast, Immunity, Disable, Event}; use effect::{Cooldown, Effect, Colour}; -use names::{name}; use spec::{Spec}; use item::{Item}; use img; @@ -252,8 +251,8 @@ impl Construct { self } - pub fn new_name(self) -> Construct { - self.named(&name()) + pub fn new_name(self, name: String) -> Construct { + self.named(&name) } pub fn learn(mut self, s: Skill) -> Construct { diff --git a/server/src/mtx.rs b/server/src/mtx.rs index c33ada61..effd767f 100644 --- a/server/src/mtx.rs +++ b/server/src/mtx.rs @@ -68,14 +68,14 @@ pub struct Mtx { variant: MtxVariant, } -pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, construct_id: Uuid) -> Result, Error> { +pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, construct_id: Uuid, name: String) -> Result, Error> { let mtx = select(tx, variant, account.id)?; let mut construct = construct_select(tx, construct_id, account.id)?; account::debit(tx, account.id, 1)?; construct = match mtx.variant { - MtxVariant::Rename => construct.new_name(), + MtxVariant::Rename => construct.new_name(name), _ => construct.new_img(), }; match mtx.variant { diff --git a/server/src/rpc.rs b/server/src/rpc.rs index 9776e444..d42d4cbb 100644 --- a/server/src/rpc.rs +++ b/server/src/rpc.rs @@ -42,7 +42,7 @@ enum RpcRequest { ItemInfo {}, DevResolve { a: Uuid, b: Uuid, skill: Skill }, - MtxConstructApply { mtx: mtx::MtxVariant, construct_id: Uuid }, + MtxConstructApply { mtx: mtx::MtxVariant, construct_id: Uuid, name: String }, MtxAccountApply { mtx: mtx::MtxVariant }, MtxBuy { mtx: mtx::MtxVariant }, @@ -149,8 +149,8 @@ pub fn receive(data: Vec, db: &Db, _client: &mut WebSocket, begin Ok(RpcResult::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)), - RpcRequest::MtxConstructApply { mtx, construct_id } => - Ok(RpcResult::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id)?)), + RpcRequest::MtxConstructApply { mtx, construct_id, name } => + Ok(RpcResult::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id, name)?)), RpcRequest::MtxBuy { mtx } => Ok(RpcResult::AccountShop(mtx::buy(&mut tx, account, mtx)?)),