ping update
This commit is contained in:
parent
22e3dae9be
commit
269e29fcb0
@ -220,6 +220,16 @@ header {
|
|||||||
stroke-width: 4px;
|
stroke-width: 4px;
|
||||||
stroke-dasharray: 121, 242;
|
stroke-dasharray: 121, 242;
|
||||||
animation: saw 2s infinite linear;
|
animation: saw 2s infinite linear;
|
||||||
|
|
||||||
|
transition-property: stroke-color;
|
||||||
|
transition-duration: 0.5s;
|
||||||
|
transition-timing-function: ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ping-text {
|
||||||
|
margin-left: 1em;
|
||||||
|
min-width: 2em;
|
||||||
|
display: inline-block;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes saw {
|
@keyframes saw {
|
||||||
|
|||||||
@ -13,6 +13,9 @@ export const setInstance = value => ({ type: SET_INSTANCE, value });
|
|||||||
export const SET_PLAYER = 'SET_PLAYER';
|
export const SET_PLAYER = 'SET_PLAYER';
|
||||||
export const setPlayer = value => ({ type: SET_PLAYER, value });
|
export const setPlayer = value => ({ type: SET_PLAYER, value });
|
||||||
|
|
||||||
|
export const SET_PING = 'SET_PING';
|
||||||
|
export const setPing = value => ({ type: SET_PING, value });
|
||||||
|
|
||||||
export const SET_GAME = 'SET_GAME';
|
export const SET_GAME = 'SET_GAME';
|
||||||
export const setGame = value => ({ type: SET_GAME, value });
|
export const setGame = value => ({ type: SET_GAME, value });
|
||||||
|
|
||||||
|
|||||||
@ -3,12 +3,20 @@ const preact = require('preact');
|
|||||||
|
|
||||||
const { saw } = require('./shapes');
|
const { saw } = require('./shapes');
|
||||||
|
|
||||||
|
function pingColour(ping) {
|
||||||
|
if (ping < 100) return 'forestgreen';
|
||||||
|
if (ping < 200) return 'yellow';
|
||||||
|
return 'red';
|
||||||
|
}
|
||||||
|
|
||||||
function renderHeader(args) {
|
function renderHeader(args) {
|
||||||
const { account } = args;
|
const { account, ping } = args;
|
||||||
|
|
||||||
const accountStatus = account ?
|
const accountStatus = account ?
|
||||||
(<div className="header-status">
|
(<div className="header-status">
|
||||||
<h1 className="header-username">{account.name}</h1>
|
<h1 className="header-username">{account.name}</h1>
|
||||||
{saw('stat-icon')}
|
{saw(pingColour(ping))}
|
||||||
|
<div className="ping-text">{ping}ms</div>
|
||||||
</div>)
|
</div>)
|
||||||
: '';
|
: '';
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,8 @@ const { connect } = require('preact-redux');
|
|||||||
const Header = require('./header.component');
|
const Header = require('./header.component');
|
||||||
|
|
||||||
const addState = connect(
|
const addState = connect(
|
||||||
({ account }) => {
|
({ account, ping }) => {
|
||||||
return { account };
|
return { account, ping };
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
const toast = require('izitoast');
|
const toast = require('izitoast');
|
||||||
const eachSeries = require('async/eachSeries');
|
const eachSeries = require('async/eachSeries');
|
||||||
const anime = require('animejs').default;
|
const anime = require('animejs').default;
|
||||||
const range = require('lodash/range');
|
|
||||||
|
|
||||||
const actions = require('./actions');
|
const actions = require('./actions');
|
||||||
const { TIMES } = require('./constants');
|
const { TIMES } = require('./constants');
|
||||||
@ -25,9 +24,10 @@ function registerEvents(store) {
|
|||||||
return anime({
|
return anime({
|
||||||
targets: 'img',
|
targets: 'img',
|
||||||
translateX: () => anime.random(-20, 20),
|
translateX: () => anime.random(-20, 20),
|
||||||
translateY: () => anime.random(-20, 20),
|
translateY: () => anime.random(0, 40),
|
||||||
rotate: () => anime.random(-35, 35),
|
rotate: () => anime.random(-35, 35),
|
||||||
duration: () => anime.random(5000, 6000),
|
duration: () => anime.random(5000, 6000),
|
||||||
|
delay: () => anime.random(0, 1000),
|
||||||
direction: 'alternate',
|
direction: 'alternate',
|
||||||
easing: 'linear',
|
easing: 'linear',
|
||||||
loop: true,
|
loop: true,
|
||||||
@ -36,6 +36,10 @@ function registerEvents(store) {
|
|||||||
setInterval(crypAnimations, 5000);
|
setInterval(crypAnimations, 5000);
|
||||||
crypAnimations();
|
crypAnimations();
|
||||||
|
|
||||||
|
function setPing(ping) {
|
||||||
|
store.dispatch(actions.setPing(ping));
|
||||||
|
}
|
||||||
|
|
||||||
function setCryps(cryps) {
|
function setCryps(cryps) {
|
||||||
console.log('EVENT ->', 'cryps', cryps);
|
console.log('EVENT ->', 'cryps', cryps);
|
||||||
}
|
}
|
||||||
@ -287,6 +291,7 @@ function registerEvents(store) {
|
|||||||
setWs,
|
setWs,
|
||||||
setGameList,
|
setGameList,
|
||||||
setZone,
|
setZone,
|
||||||
|
setPing,
|
||||||
setScores,
|
setScores,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,6 +28,7 @@ const store = createStore(
|
|||||||
info: reducers.infoReducer,
|
info: reducers.infoReducer,
|
||||||
instance: reducers.instanceReducer,
|
instance: reducers.instanceReducer,
|
||||||
player: reducers.playerReducer,
|
player: reducers.playerReducer,
|
||||||
|
ping: reducers.pingReducer,
|
||||||
instances: reducers.instancesReducer,
|
instances: reducers.instancesReducer,
|
||||||
reclaiming: reducers.reclaimingReducer,
|
reclaiming: reducers.reclaimingReducer,
|
||||||
selectedCryps: reducers.selectedCrypsReducer,
|
selectedCryps: reducers.selectedCrypsReducer,
|
||||||
|
|||||||
@ -10,6 +10,16 @@ function accountReducer(state = defaultAccount, action) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPing = null;
|
||||||
|
function pingReducer(state = defaultPing, action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case actions.SET_PING:
|
||||||
|
return action.value;
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const defaultActiveSkill = null;
|
const defaultActiveSkill = null;
|
||||||
function activeSkillReducer(state = defaultActiveSkill, action) {
|
function activeSkillReducer(state = defaultActiveSkill, action) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
@ -177,4 +187,5 @@ module.exports = {
|
|||||||
resolutionReducer,
|
resolutionReducer,
|
||||||
wsReducer,
|
wsReducer,
|
||||||
infoReducer,
|
infoReducer,
|
||||||
|
pingReducer,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -28,8 +28,10 @@ function createSocket(events) {
|
|||||||
// -------------
|
// -------------
|
||||||
// Outgoing
|
// Outgoing
|
||||||
// -------------
|
// -------------
|
||||||
|
let ping = Date.now();
|
||||||
function send(msg) {
|
function send(msg) {
|
||||||
console.log('outgoing msg', msg);
|
console.log('outgoing msg', msg);
|
||||||
|
ping = Date.now();
|
||||||
msg.token = account && account.token && account.token;
|
msg.token = account && account.token && account.token;
|
||||||
ws.send(cbor.encode(msg));
|
ws.send(cbor.encode(msg));
|
||||||
}
|
}
|
||||||
@ -281,6 +283,7 @@ function createSocket(events) {
|
|||||||
const { method, params } = res;
|
const { method, params } = res;
|
||||||
|
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
events.setPing(Date.now() - ping);
|
||||||
|
|
||||||
// check for error and split into response type and data
|
// check for error and split into response type and data
|
||||||
if (res.err) return errHandler(res.err);
|
if (res.err) return errHandler(res.err);
|
||||||
|
|||||||
@ -241,6 +241,10 @@ impl Cryp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
|
pub fn spec_add(&mut self, spec: Spec) -> Result<&mut Cryp, Error> {
|
||||||
|
if self.specs.len() >= 6 {
|
||||||
|
return Err(err_msg("maximum specs equipped"));
|
||||||
|
}
|
||||||
|
|
||||||
self.specs.push(spec);
|
self.specs.push(spec);
|
||||||
return Ok(self.calculate_colours());
|
return Ok(self.calculate_colours());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user