133 lines
3.6 KiB
JavaScript
133 lines
3.6 KiB
JavaScript
// const { connect } = require('preact-redux');
|
|
const preact = require('preact');
|
|
const { connect } = require('preact-redux');
|
|
const { Elements } = require('react-stripe-elements');
|
|
|
|
const Header = require('./header');
|
|
const Team = require('./team');
|
|
const StripeBtns = require('./stripe.buttons');
|
|
|
|
const actions = require('./../actions');
|
|
|
|
const VERSION = process.env.npm_package_version;
|
|
|
|
const addState = connect(
|
|
function receiveState(state) {
|
|
const {
|
|
ws,
|
|
account,
|
|
shop,
|
|
} = state;
|
|
|
|
function mtxBuy(mtx) {
|
|
return ws.sendMtxBuy(mtx.variant);
|
|
}
|
|
|
|
return {
|
|
account,
|
|
shop,
|
|
mtxBuy,
|
|
};
|
|
},
|
|
|
|
function receiveDispatch(dispatch) {
|
|
function setMtxActive(mtx) {
|
|
dispatch(actions.setConstructRename(null));
|
|
dispatch(actions.setMtxActive(mtx));
|
|
return true;
|
|
}
|
|
|
|
function setNav(place) {
|
|
return dispatch(actions.setNav(place));
|
|
}
|
|
|
|
return {
|
|
setMtxActive,
|
|
setNav,
|
|
};
|
|
}
|
|
);
|
|
|
|
function Play(args) {
|
|
const {
|
|
account,
|
|
shop,
|
|
mtxBuy,
|
|
|
|
setMtxActive,
|
|
setNav,
|
|
} = args;
|
|
|
|
if (!shop) return false;
|
|
|
|
const useMtx = (item, i) => {
|
|
const price = item === 'Rename' ? 5 : 1;
|
|
return (
|
|
<figure key={i} onClick={() => setMtxActive(item)} >
|
|
<figcaption>{item}</figcaption>
|
|
<button disabled={account.balance === 0}>¤{price}</button>
|
|
</figure>
|
|
);
|
|
};
|
|
|
|
const availableMtx = (item, i) => (
|
|
<figure key={i}>
|
|
<figcaption>Enable {item.variant}</figcaption>
|
|
<button onClick={() => mtxBuy(item)} disabled={account.balance < item.credits}>¤{item.credits}</button>
|
|
</figure>
|
|
);
|
|
|
|
const subscription = account.subscribed
|
|
? <button
|
|
class="yellow-btn"
|
|
disabled>
|
|
Subscribed
|
|
</button>
|
|
: <button
|
|
onClick={() => setNav('shop')}
|
|
class="yellow-btn"
|
|
role="link">
|
|
Subscribe
|
|
</button>;
|
|
|
|
return (
|
|
<section class="top">
|
|
<div class="news">
|
|
<h1>v{VERSION}</h1>
|
|
<p>Use the buttons on the right to join an instance.</p>
|
|
<p>
|
|
Select <b>PVP</b> to play against other players.<br />
|
|
Select <b>INVITE</b> then click <b>COPY LINK</b> to generate an instance invitation for a friend.<br />
|
|
Click <b>LEARN</b> to practice the game without time controls.
|
|
</p>
|
|
<p>
|
|
If you enjoy the game please support its development by <b>subscribing</b> or purchasing <b>credits</b>.<br />
|
|
glhf
|
|
</p>
|
|
<p>--ntr & mashy</p>
|
|
</div>
|
|
<div>
|
|
<h1 class="credits">¤ {account.balance}</h1>
|
|
<div class='list'>
|
|
{subscription}
|
|
<button
|
|
onClick={() => setNav('shop')}
|
|
class="yellow-btn"
|
|
role="link">
|
|
Get Credits
|
|
</button>
|
|
<div id="error-message"></div>
|
|
</div>
|
|
<div class='list'>
|
|
{shop.owned.map(useMtx)}
|
|
</div>
|
|
<div class='list'>
|
|
{shop.available.map(availableMtx)}
|
|
</div>
|
|
</div>
|
|
</section>
|
|
);
|
|
}
|
|
|
|
module.exports = addState(Play);
|