big play rework

This commit is contained in:
ntr 2019-10-23 16:11:04 +11:00
parent 82da5da23e
commit 06b987e877
14 changed files with 2817 additions and 205 deletions

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 5.0 KiB

2557
client/assets/mnni.svg Normal file

File diff suppressed because it is too large Load Diff

After

Width:  |  Height:  |  Size: 94 KiB

View File

@ -50,31 +50,6 @@ aside {
} }
} }
// button.ready:enabled {
// &:hover {
// color: forestgreen;
// border-color: forestgreen;
// }
// &:active, &:focus, &.enabled {
// background: forestgreen;
// color: black;
// border-color: forestgreen;
// }
// }
button.ready:enabled {
color: forestgreen;
border-color: forestgreen;
&:hover {
background: forestgreen;
color: black;
border-color: forestgreen;
}
}
.timer-container { .timer-container {
grid-area: timer; grid-area: timer;
@ -144,12 +119,6 @@ aside {
} }
} }
.play-ctrl {
.controls {
grid-template-rows: 1fr 1fr 1fr 3fr 1fr;
}
}
.abandon:not([disabled]) { .abandon:not([disabled]) {
&:hover { &:hover {
color: @red; color: @red;

View File

@ -439,10 +439,10 @@
font-weight: bold; font-weight: bold;
color: @black; color: @black;
animation: faceoff 4s linear 0s 2 alternate; animation: faceoff 4s ease-in-out 0s 2 alternate;
&.winner { &.winner {
animation: win 2s linear 0s 1; animation: win 2s ease-in-out 0s 1;
} }
} }

View File

@ -109,13 +109,40 @@ section {
letter-spacing: 0.25em; letter-spacing: 0.25em;
text-transform: uppercase; text-transform: uppercase;
display: grid; display: grid;
grid-template-columns: repeat(4, 1fr); // grid-template-columns: repeat(4, 1fr);
grid-template-columns: 1fr 1fr;
grid-gap: 1em; grid-gap: 1em;
flex-flow: row wrap; flex-flow: row wrap;
align-items: flex-end; align-items: flex-end;
button { button {
border-radius: 0.25em; border-radius: 0.25em;
// height: 3em;
} }
&.play {
grid-template-columns: repeat(2, 1fr);
align-items: flex-start;
&.rejoin {
grid-template-columns: 1fr;
}
button.ready:enabled {
color: forestgreen;
border-color: forestgreen;
&:hover {
background: forestgreen;
color: black;
border-color: forestgreen;
}
}
}
}
.panes {
display: grid;
grid-template-columns: repeat(2, 1fr);
} }
figure { figure {
@ -189,9 +216,14 @@ section {
.list { .list {
grid-template-columns: 1fr 1fr; grid-template-columns: 1fr 1fr;
&.play {
grid-template-columns: 1fr;
} }
} }
}
.menu .team { .menu .team {
grid-template-columns: 1fr; grid-template-columns: 1fr;

View File

@ -281,7 +281,7 @@ ul {
} }
li { li {
margin-bottom: 0.5em; margin-bottom: 0;
} }
.logo { .logo {
@ -299,6 +299,10 @@ li {
background-position: center; background-position: center;
} }
.mnni {
background-image: url("./../mnni.svg");
}
.avatar { .avatar {
grid-area: avatar; grid-area: avatar;
object-fit: contain; object-fit: contain;

View File

@ -95,7 +95,7 @@ function Faceoff(props) {
return ( return (
<div class="faceoff-text winner"> <div class="faceoff-text winner">
<div> {winner.name} </div> <div> {winner.name} </div>
<div> win </div> <div> wins </div>
</div> </div>
) )

View File

@ -62,9 +62,9 @@ class Instance extends Component {
if (!instance) return false; if (!instance) return false;
// if (instance.phase !== 'InProgress') { if (instance.phase !== 'InProgress') {
return <Faceoff />; return <Faceoff />;
// } }
function instanceClick(e) { function instanceClick(e) {
e.stopPropagation(); e.stopPropagation();
@ -95,7 +95,6 @@ class Instance extends Component {
bindSwipes() { bindSwipes() {
const instance = document.getElementById('instance'); const instance = document.getElementById('instance');
if (!instance) { if (!instance) {
console.log('no instance, binding in 50');
return setTimeout(this.bindSwipes, 50); return setTimeout(this.bindSwipes, 50);
} }
if (this.h) this.h.destroy(); if (this.h) this.h.destroy();
@ -116,7 +115,6 @@ class Instance extends Component {
setNavInstance((navInstance + 1) % 4); setNavInstance((navInstance + 1) % 4);
}); });
console.log('hammer gestures bound');
return true; return true;
} }
} }

View File

@ -43,11 +43,11 @@ function Controls(args) {
const zero = Date.parse(instance.phase_start); const zero = Date.parse(instance.phase_start);
const now = Date.now(); const now = Date.now();
const end = Date.parse(instance.phase_end); const end = Date.parse(instance.phase_end);
const timerPct = instance.phase_end const timerPct = instance.phase !== 'Finished' && instance.phase_end
? ((now - zero) / (end - zero) * 100) ? ((now - zero) / (end - zero) * 100)
: 100; : 100;
const displayColour = !instance.phase_end const displayColour = !instance.phase_end || instance.phase === 'Finished'
? '#222' ? '#222'
: player.ready : player.ready
? 'forestgreen' ? 'forestgreen'

View File

@ -0,0 +1,63 @@
const { Component } = require('preact');
const preact = require('preact');
// const { connect } = require('preact-redux');
const idleAnimation = require('./anims/idle');
const wiggle = require('./anims/wiggle');
class MnniAvatatr extends Component {
constructor() {
super();
// The animation ids are a check to ensure that animations are not repeated
// When a new account animation is communicated with state it will have a corresponding Id
// which is a count of how many resoluttions have passed
this.animations = [];
this.resetAnimations = this.resetAnimations.bind(this);
}
render() {
const { account, mtxActive } = this.props;
return (
<div
class="img avatar mnni"
id="mnni"
onMouseDown={this.onClick.bind(this)}>
</div>
);
}
onClick() {
if (this.props.mtxActive) {
return this.props.sendMtxAccountApply();
}
return this.animations.push(wiggle('mnni', this.idle));
}
componentDidMount() {
this.idle = idleAnimation('mnni');
return this.animations.push(this.idle);
}
resetAnimations() {
for (let i = this.animations.length - 1; i >= 0; i--) {
this.animations[i].reset();
}
}
componentWillUnmount() {
this.resetAnimations();
}
}
function Mnni(args) {
return (
<div class='player-box top'>
<MnniAvatatr />
<div class="msg">hi!</div>
<div class="name">MNNI</div>
<div class="score">&nbsp;</div>
</div>
);
}
module.exports = Mnni;

View File

@ -1,155 +1,26 @@
const preact = require('preact'); const preact = require('preact');
const { connect } = require('preact-redux'); // const { connect } = require('preact-redux');
const { errorToast, infoToast } = require('../utils');
const AccountBox = require('./account.box'); const AccountBox = require('./account.box');
const Mnni = require('./mnni');
const addState = connect(
function receiveState(state) {
const {
ws,
instances,
invite,
} = state;
function sendInstanceState(id) {
ws.sendInstanceState(id);
}
function sendInstancePractice() {
ws.sendInstancePractice();
}
function sendInstanceQueue() {
ws.sendInstanceQueue();
}
function sendInstanceInvite() {
ws.sendInstanceInvite();
}
return {
instances,
invite,
sendInstanceState,
sendInstanceQueue,
sendInstancePractice,
sendInstanceInvite,
};
}
);
function JoinButtons(args) { function JoinButtons(args) {
const {
instances,
invite,
sendInstanceState,
sendInstanceQueue,
sendInstancePractice,
sendInstanceInvite,
} = args;
const discordBtn = (
<button
class='discord-btn'
onClick={() => window.open('https://discord.gg/YJJgurM') }>
&nbsp;
</button>
);
if (instances.length) {
return ( return (
<aside class='play-ctrl'> <aside class='play-ctrl'>
<div class="timer-container"></div> <div class="timer-container"></div>
<div class="controls"> <div class="controls">
{discordBtn} <div class="instance-ctrl-btns">
<div></div> <button disabled={true}>-</button>
<div></div> </div>
<Mnni />
<AccountBox /> <AccountBox />
<div class="instance-ctrl-btns"> <div class="instance-ctrl-btns">
<button disabled={true} >Chat</button> <button disabled={true} >Chat</button>
<button <button disabled={true}>-</button>
class='pvp ready full'
onClick={() => sendInstanceState(instances[0].id)}
type="submit">
Rejoin
</button>
</div> </div>
</div> </div>
</aside> </aside>
); );
} }
const inviteBtn = () => { module.exports = JoinButtons;
if (!invite) {
return (
<button
class='pvp ready'
onClick={() => sendInstanceInvite()}
type="submit">
Invite
</button>
);
}
function copyClick(e) {
const link = `${document.location.origin}#join=${invite}`;
const textArea = document.createElement('textarea', { id: '#clipboard' });
textArea.value = link;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
infoToast('Invite link copied to clipboard.');
} catch (err) {
console.error('link copy error', err);
errorToast('Invite link copy error.');
}
document.body.removeChild(textArea);
return true;
}
return (
<button
class='pvp ready enabled'
onClick={copyClick}
type="submit">
Copy <p> &#x1F517; </p>
</button>
);
};
return (
<aside class='play-ctrl'>
<div class="timer-container"></div>
<div class="controls">
<button
class='practice ready'
onClick={() => sendInstancePractice()}
type="submit">
Learn
</button>
{inviteBtn()}
{discordBtn}
<AccountBox />
<div class="instance-ctrl-btns">
<button disabled={true} >Chat</button>
<button
class='pvp ready'
onClick={() => sendInstanceQueue()}
type="submit">
PVP
</button>
</div>
</div>
</aside>
);
}
module.exports = addState(JoinButtons);

View File

@ -2,6 +2,7 @@
const preact = require('preact'); const preact = require('preact');
const { connect } = require('preact-redux'); const { connect } = require('preact-redux');
const { errorToast, infoToast } = require('../utils');
const actions = require('./../actions'); const actions = require('./../actions');
const VERSION = process.env.npm_package_version; const VERSION = process.env.npm_package_version;
@ -11,10 +12,35 @@ const addState = connect(
const { const {
ws, ws,
account, account,
instances,
invite,
} = state; } = state;
function sendInstanceState(id) {
ws.sendInstanceState(id);
}
function sendInstancePractice() {
ws.sendInstancePractice();
}
function sendInstanceQueue() {
ws.sendInstanceQueue();
}
function sendInstanceInvite() {
ws.sendInstanceInvite();
}
return { return {
account, account,
instances,
invite,
sendInstanceState,
sendInstanceQueue,
sendInstancePractice,
sendInstanceInvite,
}; };
}, },
@ -36,13 +62,69 @@ const addState = connect(
} }
); );
function Play(args) { function Play(args) {
const { const {
account, account,
instances,
invite,
sendInstanceState,
sendInstanceQueue,
sendInstancePractice,
sendInstanceInvite,
setNav, setNav,
} = args; } = args;
const inviteBtn = () => {
if (!invite) {
return (
<figure>
<button
class='ready'
onClick={() => sendInstanceInvite()}
type="submit">
Invite
</button>
<figcaption>Invite a Friend</figcaption>
</figure>
);
}
function copyClick(e) {
const link = `${document.location.origin}#join=${invite}`;
const textArea = document.createElement('textarea', { id: '#clipboard' });
textArea.value = link;
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
document.execCommand('copy');
infoToast('Invite link copied to clipboard.');
} catch (err) {
console.error('link copy error', err);
errorToast('Invite link copy error.');
}
document.body.removeChild(textArea);
return true;
}
return (
<figure>
<button
class='ready'
onClick={copyClick}
type="submit">
Copy &#x1F517;
</button>
<figcaption>Invite Generated</figcaption>
</figure>
);
};
const subscription = account.subscribed const subscription = account.subscribed
? <button ? <button
class="yellow-btn" class="yellow-btn"
@ -56,23 +138,56 @@ function Play(args) {
Subscribe Subscribe
</button>; </button>;
const list = () => {
if (!instances.length) return (
<div class='list play'>
<figure>
<button
class="ready"
onClick={() => sendInstanceQueue()}>
PVP
</button>
<figcaption>Matchmaking</figcaption>
</figure>
{inviteBtn()}
<figure>
<button
class="ready"
onClick={() => sendInstancePractice()}>
Learn
</button>
<figcaption>Practice MNML</figcaption>
</figure>
<figure>
<button
class='discord-btn'
onClick={() => window.open('https://discord.gg/YJJgurM') }>
&nbsp;
</button>
<figcaption>Join the Community</figcaption>
</figure>
</div>
);
return (
<div class='list play rejoin'>
<figure>
<button
class="ready"
onClick={() => sendInstanceState(instances[0].id)}>
Rejoin
</button>
<figcaption>Resume playing</figcaption>
</figure>
</div>
);
}
return ( return (
<section class="top"> <section class="top">
<div class="news"> <div class="news">
<h2>v{VERSION}</h2> <h1>v{VERSION}</h1>
<p> {list()}
Join our discord server to find opponents and talk to the devs. <br />
Message @ntr or @mashy on discord. Invite link on the right control panel. <br />
We will also give you some credits to try the mtx. <br />
</p>
<p>
If you enjoy the game you can support the development:
<ul>
<li>Invite people to play pvp games and grow the community. </li>
<li><b>Subscribe</b> or purchase <b>credits</b>.</li>
</ul>
glhf
</p>
</div> </div>
<div> <div>
<h1 class="credits">¤ {account.balance}</h1> <h1 class="credits">¤ {account.balance}</h1>
@ -84,15 +199,19 @@ function Play(args) {
role="link"> role="link">
Get Credits Get Credits
</button> </button>
<div id="error-message"></div> </div>
<div>
Join our Discord server to find opponents and talk to the devs. <br />
Message <b>@ntr</b> or <b>@mashy</b> for some credits to get started.<br />
</div> </div>
<br /> <br />
<p> <div>
Click <b>LEARN</b> to practice the game without time controls. <br /> If you enjoy the game you can support the development:
Select <b>INVITE</b> then click <b>COPY LINK</b> to create a game invitation for a friend.<br /> <ul>
Select <b>PVP</b> to queue for a game against other players. <br /> <li>Invite people to play pvp games and grow the community. </li>
</p> <li><b>Subscribe</b> or purchase <b>credits</b>.</li>
<p> If you can't find a match through pvp queue, ask around on discord. </p> </ul>
</div>
</div> </div>
</section> </section>
); );

View File

@ -41,7 +41,7 @@ function Shop(args) {
<b>Subscriptions</b> grant extra benefits: <b>Subscriptions</b> grant extra benefits:
<ul> <ul>
<li>¤150 per month</li> <li>¤150 per month</li>
<li>Account icons</li> <li>Account img</li>
<li>Chat wheel</li> <li>Chat wheel</li>
</ul> </ul>
</p> </p>

View File

@ -259,7 +259,7 @@ function createSocket(events) {
QueueRequested: () => events.notify('pvp queue request received'), QueueRequested: () => events.notify('pvp queue request received'),
QueueJoined: () => events.notify('you have joined the pvp queue'), QueueJoined: () => events.notify('you have joined the pvp queue'),
InviteRequested: () => events.notify('pvp queue request received'), InviteRequested: () => events.notify('pvp invite request received'),
Invite: code => events.setInvite(code), Invite: code => events.setInvite(code),
InstanceChat: chat => events.setInstanceChat(chat), InstanceChat: chat => events.setInstanceChat(chat),
ChatWheel: wheel => events.setChatWheel(wheel), ChatWheel: wheel => events.setChatWheel(wheel),