chat wheelu
This commit is contained in:
parent
189d1023c6
commit
ddca205f0c
@ -12,6 +12,9 @@ export const setAnimText = value => ({ type: 'SET_ANIM_TEXT', value });
|
||||
export const setDemo = value => ({ type: 'SET_DEMO', value });
|
||||
|
||||
export const setChatShow = value => ({ type: 'SET_CHAT_SHOW', value });
|
||||
export const setChatWheel = value => ({ type: 'SET_CHAT_WHEEL', value });
|
||||
export const setInstanceChat = value => ({ type: 'SET_INSTANCE_CHAT', value });
|
||||
|
||||
export const setActiveItem = value => ({ type: 'SET_ACTIVE_VAR', value });
|
||||
export const setActiveSkill = (constructId, skill) => ({ type: 'SET_ACTIVE_SKILL', value: constructId ? { constructId, skill } : null });
|
||||
export const setCombiner = value => ({ type: 'SET_COMBINER', value: Array.from(value) });
|
||||
|
||||
@ -8,18 +8,20 @@ const addState = connect(
|
||||
const {
|
||||
ws,
|
||||
chatShow,
|
||||
chatWheel,
|
||||
instance,
|
||||
} = state;
|
||||
|
||||
function sendChat(i) {
|
||||
// return ws.sendChat(i);
|
||||
function sendInstanceChat(instance, i) {
|
||||
return ws.sendInstanceChat(instance, i);
|
||||
}
|
||||
|
||||
return {
|
||||
instance,
|
||||
chatShow,
|
||||
chatWheel,
|
||||
|
||||
sendChat,
|
||||
sendInstanceChat,
|
||||
};
|
||||
},
|
||||
|
||||
@ -38,31 +40,21 @@ function Chat(args) {
|
||||
const {
|
||||
instance,
|
||||
chatShow,
|
||||
chatWheel,
|
||||
|
||||
sendChat,
|
||||
sendInstanceChat,
|
||||
setChatShow,
|
||||
} = args;
|
||||
|
||||
const chat = [
|
||||
'gl',
|
||||
'hf',
|
||||
'gg',
|
||||
'thx',
|
||||
'nice',
|
||||
'hmm',
|
||||
'ok',
|
||||
'...',
|
||||
];
|
||||
|
||||
function onClick(i) {
|
||||
sendChat(i);
|
||||
sendInstanceChat(instance.id, i);
|
||||
setChatShow(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={`instance-ctrl-btns chat`}>
|
||||
{chat.map((c, i) => <button key={i} onClick={() => onClick(i)} >{c}</button>)}
|
||||
{chatWheel.map((c, i) => <button key={i} onClick={() => onClick(i)} >{c}</button>)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ const addState = connect(
|
||||
const {
|
||||
ws,
|
||||
instance,
|
||||
instanceChat,
|
||||
account,
|
||||
chatShow,
|
||||
} = state;
|
||||
@ -20,6 +21,7 @@ const addState = connect(
|
||||
return {
|
||||
chatShow,
|
||||
instance,
|
||||
instanceChat,
|
||||
account,
|
||||
};
|
||||
},
|
||||
@ -29,6 +31,7 @@ function Controls(args) {
|
||||
const {
|
||||
account,
|
||||
instance,
|
||||
instanceChat,
|
||||
chatShow,
|
||||
} = args;
|
||||
|
||||
@ -65,14 +68,14 @@ function Controls(args) {
|
||||
|
||||
const bottom = chatShow
|
||||
? <Chat />
|
||||
: <PlayerBox player={player} isPlayer={true} />;
|
||||
: <PlayerBox player={player} isPlayer={true} chat={instanceChat && instanceChat[player.id]} />;
|
||||
|
||||
return (
|
||||
<aside>
|
||||
{timer}
|
||||
<div class="controls instance-ctrl">
|
||||
<InstanceCtrlTopBtns />
|
||||
<PlayerBox player={opponent} />
|
||||
<PlayerBox player={opponent} chat={instanceChat && instanceChat[opponent.id]}/>
|
||||
{bottom}
|
||||
<InstanceCtrlBtns />
|
||||
</div>
|
||||
|
||||
@ -56,6 +56,7 @@ function Scoreboard(args) {
|
||||
const {
|
||||
isPlayer,
|
||||
player,
|
||||
chat,
|
||||
} = args;
|
||||
|
||||
const scoreText = () => {
|
||||
@ -73,14 +74,14 @@ function Scoreboard(args) {
|
||||
<div class="score">{scoreText()}</div>
|
||||
<div class="name">{player.name}</div>
|
||||
<Img img={player.img} id={player.id} />
|
||||
<div class="msg"> </div>
|
||||
<div class="msg">{chat || '\u00A0'}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div class={`player-box bottom ${player.ready ? 'ready' : ''}`}>
|
||||
<div class="msg"> </div>
|
||||
<div class="msg">{chat || '\u00A0'}</div>
|
||||
<div class="score">{scoreText()}</div>
|
||||
<div class="name">{player.name}</div>
|
||||
<Img img={player.img} id={player.id} />
|
||||
|
||||
@ -212,6 +212,14 @@ function registerEvents(store) {
|
||||
return store.dispatch(actions.setInstance(v));
|
||||
}
|
||||
|
||||
function setInstanceChat(v) {
|
||||
return store.dispatch(actions.setInstanceChat(v));
|
||||
}
|
||||
|
||||
function setChatWheel(v) {
|
||||
return store.dispatch(actions.setChatWheel(v));
|
||||
}
|
||||
|
||||
function setItemInfo(v) {
|
||||
return store.dispatch(actions.setItemInfo(v));
|
||||
}
|
||||
@ -318,12 +326,14 @@ function registerEvents(store) {
|
||||
setAccountInstances,
|
||||
setActiveItem,
|
||||
setActiveSkill,
|
||||
setChatWheel,
|
||||
setDemo,
|
||||
setConstructList,
|
||||
setNewConstruct,
|
||||
setGame,
|
||||
setEmail,
|
||||
setInstance,
|
||||
setInstanceChat,
|
||||
setItemInfo,
|
||||
setInvite,
|
||||
setPing,
|
||||
|
||||
@ -25,6 +25,8 @@ module.exports = {
|
||||
demo: createReducer(null, 'SET_DEMO'),
|
||||
|
||||
chatShow: createReducer(null, 'SET_CHAT_SHOW'),
|
||||
chatWheel: createReducer([], 'SET_CHAT_WHEEL'),
|
||||
|
||||
combiner: createReducer([], 'SET_COMBINER'),
|
||||
constructs: createReducer([], 'SET_CONSTRUCTS'),
|
||||
constructEditId: createReducer(null, 'SET_CONSTRUCT_EDIT_ID'),
|
||||
@ -34,6 +36,7 @@ module.exports = {
|
||||
invite: createReducer(null, 'SET_INVITE'),
|
||||
info: createReducer(null, 'SET_INFO'),
|
||||
instance: createReducer(null, 'SET_INSTANCE'),
|
||||
instanceChat: createReducer(null, 'SET_INSTANCE_CHAT'),
|
||||
instances: createReducer([], 'SET_INSTANCES'),
|
||||
itemEquip: createReducer(null, 'SET_ITEM_EQUIP'),
|
||||
itemInfo: createReducer({ combos: [], items: [] }, 'SET_ITEM_INFO'),
|
||||
|
||||
@ -67,6 +67,10 @@ function createSocket(events) {
|
||||
send(['InstanceState', { instance_id: instanceId }]);
|
||||
}
|
||||
|
||||
function sendInstanceChat(instanceId, index) {
|
||||
send(['InstanceChat', { instance_id: instanceId, index }]);
|
||||
}
|
||||
|
||||
function sendVboxAccept(instanceId, group, index) {
|
||||
send(['VboxAccept', { instance_id: instanceId, group, index }]);
|
||||
events.clearInstance();
|
||||
@ -253,8 +257,11 @@ function createSocket(events) {
|
||||
QueueJoined: () => events.notify('you have joined the pvp queue'),
|
||||
InviteRequested: () => events.notify('pvp queue request received'),
|
||||
Invite: code => events.setInvite(code),
|
||||
InstanceChat: chat => events.setInstanceChat(chat),
|
||||
ChatWheel: wheel => events.setChatWheel(wheel),
|
||||
Joining: () => events.notify('searching for instance...'),
|
||||
|
||||
Processing: () => true,
|
||||
Error: errHandler,
|
||||
};
|
||||
|
||||
@ -358,6 +365,7 @@ function createSocket(events) {
|
||||
sendInstanceState,
|
||||
sendInstanceInvite,
|
||||
sendInstanceJoin,
|
||||
sendInstanceChat,
|
||||
|
||||
sendVboxAccept,
|
||||
sendVboxApply,
|
||||
|
||||
@ -65,6 +65,19 @@ pub fn select(db: &Db, id: Uuid) -> Result<Account, Error> {
|
||||
Account::try_from(row)
|
||||
}
|
||||
|
||||
pub fn chat_wheel(_db: &Db, _id: Uuid) -> Result<Vec<String>, Error> {
|
||||
return Ok(vec![
|
||||
"gl".to_string(),
|
||||
"hf".to_string(),
|
||||
"gg".to_string(),
|
||||
"thx".to_string(),
|
||||
"nice".to_string(),
|
||||
"hmm".to_string(),
|
||||
"ok".to_string(),
|
||||
"...".to_string(),
|
||||
])
|
||||
}
|
||||
|
||||
pub fn select_name(db: &Db, name: &String) -> Result<Account, Error> {
|
||||
let query = "
|
||||
SELECT id, name, balance, subscribed, img
|
||||
|
||||
@ -58,7 +58,9 @@ pub enum Event {
|
||||
Invite(Id),
|
||||
Join(Id, String),
|
||||
Joined(Id),
|
||||
Chat(Id, Uuid, String)
|
||||
|
||||
Chat(Id, Uuid, String),
|
||||
ChatClear(Id, Uuid),
|
||||
}
|
||||
|
||||
struct WsClient {
|
||||
@ -66,6 +68,7 @@ struct WsClient {
|
||||
account: Option<Uuid>,
|
||||
tx: Sender<RpcMessage>,
|
||||
subs: HashSet<Uuid>,
|
||||
chat: Option<(Uuid, String)>,
|
||||
pvp: bool,
|
||||
invite: Option<String>,
|
||||
}
|
||||
@ -121,7 +124,15 @@ impl Events {
|
||||
None => None,
|
||||
};
|
||||
|
||||
let client = WsClient { id, tx, account: account_id, subs: HashSet::new(), pvp: false, invite: None };
|
||||
let client = WsClient { id,
|
||||
tx,
|
||||
account: account_id,
|
||||
subs: HashSet::new(),
|
||||
pvp: false,
|
||||
invite: None,
|
||||
chat: None,
|
||||
};
|
||||
|
||||
self.clients.insert(id, client);
|
||||
|
||||
info!("clients={:?}", self.clients.len());
|
||||
@ -216,7 +227,7 @@ impl Events {
|
||||
}
|
||||
|
||||
// create the req for the already queued opponent
|
||||
if let Some(opp_req) = match self.clients.iter_mut().find(|(_c_id, c)| c.pvp) {
|
||||
if let Some(opp_req) = match self.clients.iter_mut().find(|(c_id, c)| c.pvp && **c_id != id) {
|
||||
Some((q_id, q)) => {
|
||||
q.pvp = false;
|
||||
Some(PvpRequest { id: *q_id, account: q.account.unwrap(), tx: q.tx.clone() })
|
||||
@ -292,6 +303,52 @@ impl Events {
|
||||
return Ok(());
|
||||
},
|
||||
|
||||
Event::Chat(id, instance, msg) => {
|
||||
// set the chat state of this connection
|
||||
{
|
||||
let c = self.clients.get_mut(&id)
|
||||
.ok_or(format_err!("connection not found id={:?}", id))?;
|
||||
|
||||
if c.chat.is_some() {
|
||||
return Err(err_msg("you must wait"));
|
||||
}
|
||||
|
||||
c.chat = Some((instance, msg));
|
||||
}
|
||||
|
||||
// now collect all listeners of this instance
|
||||
|
||||
let chat_state: HashMap<Uuid, String> = self.clients.iter()
|
||||
.filter(|(_id, c)| c.account.is_some())
|
||||
.filter(|(_id, c)| match c.chat {
|
||||
Some(ref chat) => chat.0 == instance,
|
||||
None => false,
|
||||
})
|
||||
.map(|(_id, c)| (c.account.unwrap(), c.chat.clone().unwrap().1))
|
||||
.collect();
|
||||
|
||||
return self.event(Event::Push(instance, RpcMessage::InstanceChat(chat_state)));
|
||||
},
|
||||
|
||||
Event::ChatClear(id, instance) => {
|
||||
{
|
||||
match self.clients.get_mut(&id) {
|
||||
Some(c) => c.chat = None,
|
||||
None => (),
|
||||
};
|
||||
}
|
||||
|
||||
let chat_state: HashMap<Uuid, String> = self.clients.iter()
|
||||
.filter(|(_id, c)| c.account.is_some())
|
||||
.filter(|(_id, c)| match c.chat {
|
||||
Some(ref chat) => chat.0 == instance,
|
||||
None => false,
|
||||
})
|
||||
.map(|(_id, c)| (c.account.unwrap(), c.chat.clone().unwrap().1))
|
||||
.collect();
|
||||
|
||||
return self.event(Event::Push(instance, RpcMessage::InstanceChat(chat_state)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use std::fs::File;
|
||||
use std::collections::{HashMap};
|
||||
|
||||
use uuid::Uuid;
|
||||
|
||||
@ -31,6 +32,8 @@ enum InstancePhase {
|
||||
Finished,
|
||||
}
|
||||
|
||||
pub type ChatState = HashMap<Uuid, String>;
|
||||
|
||||
#[derive(Debug,Clone,Serialize,Deserialize)]
|
||||
struct Round {
|
||||
game_id: Option<Uuid>,
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
use std::time::{Instant};
|
||||
use std::thread::spawn;
|
||||
use std::thread::{spawn, sleep};
|
||||
use std::time;
|
||||
|
||||
use std::str;
|
||||
|
||||
use uuid::Uuid;
|
||||
@ -21,7 +23,7 @@ use account;
|
||||
use construct::{Construct};
|
||||
use events::{Event};
|
||||
use game::{Game, game_state, game_skill, game_skill_clear, game_ready};
|
||||
use instance::{Instance, instance_state, instance_practice, instance_ready, instance_abandon, demo};
|
||||
use instance::{Instance, ChatState, instance_state, instance_practice, instance_ready, instance_abandon, demo};
|
||||
use item::{Item, ItemInfoCtr, item_info};
|
||||
use mtx;
|
||||
use mail;
|
||||
@ -50,6 +52,8 @@ pub enum RpcMessage {
|
||||
ItemInfo(ItemInfoCtr),
|
||||
|
||||
InstanceState(Instance),
|
||||
InstanceChat(ChatState),
|
||||
ChatWheel(Vec<String>),
|
||||
|
||||
EmailState(Option<Email>),
|
||||
SubscriptionState(Option<Subscription>),
|
||||
@ -66,6 +70,8 @@ pub enum RpcMessage {
|
||||
Invite(String),
|
||||
Joining(()),
|
||||
|
||||
Processing(()),
|
||||
|
||||
Error(String),
|
||||
}
|
||||
|
||||
@ -102,6 +108,7 @@ pub enum RpcRequest {
|
||||
InstanceAbandon { instance_id: Uuid },
|
||||
InstanceReady { instance_id: Uuid },
|
||||
InstanceState { instance_id: Uuid },
|
||||
InstanceChat { instance_id: Uuid, index: usize },
|
||||
|
||||
VboxAccept { instance_id: Uuid, group: usize, index: usize },
|
||||
VboxDiscard { instance_id: Uuid },
|
||||
@ -164,21 +171,22 @@ impl Connection {
|
||||
return Err(err_msg("subscribe to unlock chat"))
|
||||
}
|
||||
|
||||
let chat = vec![
|
||||
"gl",
|
||||
"hf",
|
||||
"gg",
|
||||
"thx",
|
||||
"nice",
|
||||
"hmm",
|
||||
"ok",
|
||||
"...",
|
||||
];
|
||||
let wheel = account::chat_wheel(&db, account.id)?;
|
||||
|
||||
self.events.send(Event::Chat(self.id, instance_id, chat[index]))?;
|
||||
if let Some(c) = wheel.get(index) {
|
||||
self.events.send(Event::Chat(self.id, instance_id, c.to_string()))?;
|
||||
} else {
|
||||
return Err(err_msg("invalid chat index"));
|
||||
}
|
||||
|
||||
// evnts sends to subs
|
||||
Ok(RpcMessage::Joining(()))
|
||||
let events_tx = self.events.clone();
|
||||
let id = self.id;
|
||||
spawn(move || {
|
||||
sleep(time::Duration::from_secs(3));
|
||||
events_tx.send(Event::ChatClear(id, instance_id)).unwrap();
|
||||
});
|
||||
|
||||
Ok(RpcMessage::Processing(()))
|
||||
},
|
||||
_ => {
|
||||
// all good, let's make a tx and process
|
||||
@ -337,6 +345,9 @@ impl Handler for Connection {
|
||||
let team = account::team(&mut tx, &a).unwrap();
|
||||
self.send(RpcMessage::AccountTeam(team)).unwrap();
|
||||
|
||||
let wheel = account::chat_wheel(&db, a.id).unwrap();
|
||||
self.send(RpcMessage::ChatWheel(wheel)).unwrap();
|
||||
|
||||
// tx should do nothing
|
||||
tx.commit().unwrap();
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user