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 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 });

View File

@ -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 =>
.map(construct => {
const constructName = constructRename === construct.id
? <input id='renameInput' type="text" style="text-align: center" placeholder={construct.name}></input>
: <h2>{construct.name}</h2>;
const confirm = constructRename === construct.id
? <button onClick={() => sendConstructRename(construct.id, document.getElementById('renameInput').value)}>
Confirm
</button>
: false;
const cancel = constructRename === construct.id
? <button onClick={() => clearMtxRename()}>
Cancel
</button>
: false;
return (
<div
key={construct.id}
style={ mtxActive ? { cursor: 'pointer' } : {}}
onClick={() => selectConstruct(construct.id)}
onClick={() => {
if (!mtxActive) return false;
if (mtxActive === 'Rename') return setConstructRename(construct.id);
sendConstructAvatarReroll(construct.id);
}}
class="menu-construct" >
<ConstructAvatar construct={construct} />
<h2>{construct.name}</h2>
{constructName}
{confirm}
{cancel}
</div>
);
});
return (
<main class="menu-instances">

View File

@ -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,

View File

@ -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'),

View File

@ -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) {

View File

@ -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 {

View File

@ -68,14 +68,14 @@ pub struct Mtx {
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 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 {

View File

@ -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<u8>, db: &Db, _client: &mut WebSocket<TcpStream>, 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)?)),