rename constructs

This commit is contained in:
Mashy 2019-07-16 15:39:30 +10:00
parent 7081ec8d76
commit a4e92d496e
8 changed files with 89 additions and 30 deletions

View File

@ -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 setCombiner = value => ({ type: 'SET_COMBINER', value: Array.from(value) });
export const setConstructEditId = value => ({ type: 'SET_CONSTRUCT_EDIT_ID', value }); export const setConstructEditId = value => ({ type: 'SET_CONSTRUCT_EDIT_ID', value });
export const setConstructs = value => ({ type: 'SET_CONSTRUCTS', 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 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 });

View File

@ -14,6 +14,7 @@ const addState = connect(
const { const {
ws, ws,
constructs, constructs,
constructRename,
team, team,
instanceList, instanceList,
account, account,
@ -35,25 +36,47 @@ const addState = connect(
return ws.sendInstanceList(); return ws.sendInstanceList();
} }
function selectConstruct(id) { function sendConstructAvatarReroll(id) {
if (!mtxActive) return false; if (!mtxActive) return false;
console.log('using', mtxActive, 'on', id); 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 { return {
account, account,
constructs, constructs,
instanceList,
mtxActive,
constructRename,
team, team,
sendConstructRename,
sendInstanceJoin, sendInstanceJoin,
sendInstanceState, sendInstanceState,
sendInstanceList, sendInstanceList,
instanceList, sendConstructAvatarReroll,
mtxActive,
selectConstruct
}; };
}, },
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) { function List(args) {
@ -61,13 +84,16 @@ function List(args) {
account, account,
team, team,
constructs, constructs,
constructRename,
clearMtxRename,
setConstructRename,
sendConstructRename,
sendInstanceState, sendInstanceState,
sendInstanceJoin, sendInstanceJoin,
sendInstanceList, sendInstanceList,
instanceList, instanceList,
mtxActive, mtxActive,
selectConstruct, sendConstructAvatarReroll,
} = args; } = args;
function listElements() { function listElements() {
@ -115,16 +141,40 @@ function List(args) {
const constructPanels = constructs const constructPanels = constructs
.filter(c => team.includes(c.id)) .filter(c => team.includes(c.id))
.sort(idSort) .sort(idSort)
.map(construct => .map(construct => {
<div const constructName = constructRename === construct.id
key={construct.id} ? <input id='renameInput' type="text" style="text-align: center" placeholder={construct.name}></input>
style={ mtxActive ? { cursor: 'pointer' } : {}} : <h2>{construct.name}</h2>;
onClick={() => selectConstruct(construct.id)}
class="menu-construct" > const confirm = constructRename === construct.id
<ConstructAvatar construct={construct} /> ? <button onClick={() => sendConstructRename(construct.id, document.getElementById('renameInput').value)}>
<h2>{construct.name}</h2> Confirm
</div> </button>
); : false;
const cancel = constructRename === construct.id
? <button onClick={() => clearMtxRename()}>
Cancel
</button>
: false;
return (
<div
key={construct.id}
style={ mtxActive ? { cursor: 'pointer' } : {}}
onClick={() => {
if (!mtxActive) return false;
if (mtxActive === 'Rename') return setConstructRename(construct.id);
sendConstructAvatarReroll(construct.id);
}}
class="menu-construct" >
<ConstructAvatar construct={construct} />
{constructName}
{confirm}
{cancel}
</div>
);
});
return ( return (
<main class="menu-instances"> <main class="menu-instances">

View File

@ -120,6 +120,10 @@ function registerEvents(store) {
store.dispatch(actions.setCombiner([null, null, null])); store.dispatch(actions.setCombiner([null, null, null]));
} }
function clearConstructRename() {
store.dispatch(actions.setConstructRename(null));
}
function clearMtxActive() { function clearMtxActive() {
store.dispatch(actions.setMtxActive(null)); store.dispatch(actions.setMtxActive(null));
} }
@ -223,6 +227,7 @@ function registerEvents(store) {
return { return {
clearCombiner, clearCombiner,
clearConstructRename,
clearInfo, clearInfo,
clearInstance, clearInstance,
clearMtxActive, clearMtxActive,

View File

@ -19,6 +19,7 @@ module.exports = {
combiner: createReducer([null, null, null], 'SET_COMBINER'), combiner: createReducer([null, null, null], 'SET_COMBINER'),
constructs: createReducer([], 'SET_CONSTRUCTS'), constructs: createReducer([], 'SET_CONSTRUCTS'),
constructEditId: createReducer(null, 'SET_CONSTRUCT_EDIT_ID'), constructEditId: createReducer(null, 'SET_CONSTRUCT_EDIT_ID'),
constructRename: createReducer(null, 'SET_CONSTRUCT_RENAME'),
game: createReducer(null, 'SET_GAME'), game: createReducer(null, 'SET_GAME'),
info: createReducer(null, 'SET_INFO'), info: createReducer(null, 'SET_INFO'),
instance: createReducer(null, 'SET_INSTANCE'), instance: createReducer(null, 'SET_INSTANCE'),

View File

@ -97,7 +97,7 @@ function createSocket(events) {
function sendGameSkill(gameId, constructId, targetConstructId, skill) { function sendGameSkill(gameId, constructId, targetConstructId, skill) {
send(['GameSkill', 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); events.setActiveSkill(null);
} }
@ -119,9 +119,12 @@ function createSocket(events) {
send(['InstanceReady', { instance_id: instanceId }]); send(['InstanceReady', { instance_id: instanceId }]);
} }
function sendMtxApply(constructId, mtx) { function sendMtxApply(constructId, mtx, name) {
send(['MtxConstructApply', { construct_id: constructId, mtx }]); send(['MtxConstructApply', { construct_id: constructId, mtx, name }]);
// events.clearMtxActive(); if (mtx === 'Rename') {
events.clearMtxActive();
events.clearConstructRename();
}
} }
function sendMtxBuy(mtx) { function sendMtxBuy(mtx) {

View File

@ -9,7 +9,6 @@ use failure::err_msg;
use skill::{Skill, Cast, Immunity, Disable, Event}; use skill::{Skill, Cast, Immunity, Disable, Event};
use effect::{Cooldown, Effect, Colour}; use effect::{Cooldown, Effect, Colour};
use names::{name};
use spec::{Spec}; use spec::{Spec};
use item::{Item}; use item::{Item};
use img; use img;
@ -252,8 +251,8 @@ impl Construct {
self self
} }
pub fn new_name(self) -> Construct { pub fn new_name(self, name: String) -> Construct {
self.named(&name()) self.named(&name)
} }
pub fn learn(mut self, s: Skill) -> Construct { pub fn learn(mut self, s: Skill) -> Construct {

View File

@ -68,14 +68,14 @@ pub struct Mtx {
variant: MtxVariant, variant: MtxVariant,
} }
pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, construct_id: Uuid) -> Result<Vec<Construct>, Error> { pub fn apply(tx: &mut Transaction, account: &Account, variant: MtxVariant, construct_id: Uuid, name: String) -> Result<Vec<Construct>, Error> {
let mtx = select(tx, variant, account.id)?; let mtx = select(tx, variant, account.id)?;
let mut construct = construct_select(tx, construct_id, account.id)?; let mut construct = construct_select(tx, construct_id, account.id)?;
account::debit(tx, account.id, 1)?; account::debit(tx, account.id, 1)?;
construct = match mtx.variant { construct = match mtx.variant {
MtxVariant::Rename => construct.new_name(), MtxVariant::Rename => construct.new_name(name),
_ => construct.new_img(), _ => construct.new_img(),
}; };
match mtx.variant { match mtx.variant {

View File

@ -42,7 +42,7 @@ enum RpcRequest {
ItemInfo {}, ItemInfo {},
DevResolve { a: Uuid, b: Uuid, skill: Skill }, 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 }, MtxAccountApply { mtx: mtx::MtxVariant },
MtxBuy { mtx: mtx::MtxVariant }, MtxBuy { mtx: mtx::MtxVariant },
@ -149,8 +149,8 @@ pub fn receive(data: Vec<u8>, db: &Db, _client: &mut WebSocket<TcpStream>, begin
Ok(RpcResult::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)), Ok(RpcResult::InstanceState(vbox_unequip(&mut tx, account, instance_id, construct_id, target)?)),
RpcRequest::MtxConstructApply { mtx, construct_id } => RpcRequest::MtxConstructApply { mtx, construct_id, name } =>
Ok(RpcResult::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id)?)), Ok(RpcResult::AccountConstructs(mtx::apply(&mut tx, account, mtx, construct_id, name)?)),
RpcRequest::MtxBuy { mtx } => RpcRequest::MtxBuy { mtx } =>
Ok(RpcResult::AccountShop(mtx::buy(&mut tx, account, mtx)?)), Ok(RpcResult::AccountShop(mtx::buy(&mut tx, account, mtx)?)),