Skip to content

Commit

Permalink
feat: Add Support for Coil Subscription and limit hat selection to su…
Browse files Browse the repository at this point in the history
…bscribets
  • Loading branch information
johnedvard committed Aug 30, 2022
1 parent e11a66e commit c8bed9e
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 14 deletions.
8 changes: 8 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
<button id="bonusBtn">Bonus Content</button>
</div>
<div id="bonus" class="overlay hide">
<div id="coil-subscriber" class="hide">
Thanks for being a Coil subscriber
</div>

<a id="coilBtn" href="https://coil.com/" class="btn">
Subscribe to Coil for more bonus hats
</a>

<img class="close-icon" width="40px" />
<div id="bonus-grid"></div>
</div>
Expand Down
31 changes: 28 additions & 3 deletions src/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import skull from 'data-url:./assets/img/skull.png';
import { emit, on } from 'kontra';
import {
LEVEL_COMPLETE,
MONETIZATION_PROGRESS,
NEAR_TOKENS_ADDED,
NFT_MINT,
RESTART_LEVEL,
START_LEVEL,
START_NEXT_LEVEL,
} from './gameEvents';
import { fetchArcadianHeads } from './arcadianApi';
import { nftTokensBySeries, setSelectedArcadian } from './store';
import { isSubscriber, nftTokensBySeries, setSelectedArcadian } from './store';
import { IPFS_BASE_PATH } from './near/nearConnection';
import { doesOwnNft, getNearLevelId } from './utils';

const overlayIds = ['main', 'bonus', 'levels', 'level-dialog', 'near-levels'];
const levels = 20;
let hasRemovedDisableOnBonusEls = false;
export const initMenu = () => {
addButtonListeners();
listenForGameEvents();
Expand Down Expand Up @@ -94,6 +96,9 @@ const pouplateBonusGrid = (bonusGridEl) => {
bonusEl.setAttribute('width', img.width * 4);
bonusEl.classList.add('bonus-item');
bonusEl.setAttribute('arcadian', res[i].value.id);
if (i > 5 && !isSubscriber) {
bonusEl.classList.add('disabled');
}
const ctx = bonusEl.getContext('2d');
ctx.imageSmoothingEnabled = false;
ctx.scale(8, 8);
Expand All @@ -108,8 +113,12 @@ const pouplateBonusGrid = (bonusGridEl) => {
const listenForBonusGridEvents = (bonusGridEl) => {
bonusGridEl.addEventListener('click', (e) => {
if (e.target.classList.contains('bonus-item')) {
setSelectedArcadian(e.target.getAttribute('arcadian'));
showOverlay('main');
if (!e.target.classList.contains('disabled')) {
setSelectedArcadian(e.target.getAttribute('arcadian'));
showOverlay('main');
} else {
// TODO (johnedvard) tell player to become a subscriber
}
}
});
};
Expand Down Expand Up @@ -195,6 +204,7 @@ const showOverlay = (id) => {
const listenForGameEvents = () => {
on(LEVEL_COMPLETE, onLevelComplete);
on(NEAR_TOKENS_ADDED, onNearTokensAdded);
on(MONETIZATION_PROGRESS, onMonetizationProgress);
};
const onLevelComplete = () => {
showOverlay('level-dialog');
Expand All @@ -207,3 +217,18 @@ const onNearTokensAdded = ({
}) => {
initNearLevels({ nftTokensBySeries, nftTokensForOwner, nftCollections });
};

const onMonetizationProgress = () => {
if (hasRemovedDisableOnBonusEls) return;
const coilSubEl = document.getElementById('coil-subscriber');
const coilBtnEl = document.getElementById('coilBtn');
if (coilBtnEl) coilBtnEl.remove();
if (coilSubEl) coilSubEl.classList.remove('hide');
const bonusItemEls = document.getElementsByClassName('bonus-item');
for (item of bonusItemEls) {
item.classList.remove('disabled');
}
if (bonusItemEls && bonusItemEls.length) {
hasRemovedDisableOnBonusEls = true;
}
};
10 changes: 8 additions & 2 deletions src/monetization.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { emit } from 'kontra';
import { MONETIZATION_PROGRESS } from './gameEvents';
import { setIsSubscriber } from './store';

export const initMonetization = () => {
if (document && document.monetization) {
document.monetization.addEventListener('monetizationprogress', (evt) =>
emit(MONETIZATION_PROGRESS, evt)
handleSubscription(evt)
);
} else {
window.addEventListener('monetizationprogress', (evt) =>
emit(MONETIZATION_PROGRESS, evt)
handleSubscription(evt)
);
}
};
const handleSubscription = (evt) => {
setIsSubscriber();
emit(MONETIZATION_PROGRESS, evt);
};
5 changes: 5 additions & 0 deletions src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let selectedArcadian = {};
export let nftTokensBySeries = [];
export let nftTokensForOwner = [];
export let nftCollections = [];
export let isSubscriber = false;

export const setGameWidth = (width) => {
gameWidth = width;
Expand Down Expand Up @@ -40,3 +41,7 @@ export const setNftTokens = (tokensForOwner, tokensBySeries, collections) => {
nftCollections,
});
};

export const setIsSubscriber = () => {
// isSubscriber = true;
};
38 changes: 29 additions & 9 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ body {
height: 100vh;
margin: 0;
padding: 0;
color: var(--fgc2);
font-family: sans-serif;
}
#container {
position: relative;
Expand Down Expand Up @@ -57,7 +59,8 @@ canvas {
filter: drop-shadow(0 0 12px var(--acc));
}

button {
button,
.btn {
width: 240px;
height: 50px;
margin: 20px 0px 0px 0px;
Expand All @@ -67,6 +70,12 @@ button {
border-radius: 4px;
font-size: large;
font-weight: bolder;
cursor: pointer;
}
button:hover,
.btn:hover {
background-color: var(--bgc2);
color: var(--fgc2);
}
button:disabled {
background-color: lightgray;
Expand All @@ -79,6 +88,17 @@ button:disabled img {
button:hover img {
filter: none;
}
#coil-subscriber {
height: 50px;
}
#coilBtn {
width: 400px;
height: 50px;
text-decoration: none;
display: flex;
justify-content: center;
align-items: center;
}
.overlay {
position: absolute;
width: 100%;
Expand Down Expand Up @@ -110,10 +130,6 @@ button:hover img {
border-radius: 4px;
background-color: var(--fgc2);
}
.level-item:hover {
background-color: var(--bgc2);
color: var(--fgc2);
}
.level-item img {
width: 100%;
height: auto;
Expand Down Expand Up @@ -147,9 +163,7 @@ button:hover img {
#bonus-grid {
row-gap: 0px;
}
#bonus-grid > canvas {
margin-bottom: -60px;
}

#level-dialog {
width: 50%;
height: 50%;
Expand All @@ -161,10 +175,16 @@ button:hover img {
cursor: pointer;
background: none;
border-radius: 4px;
margin-bottom: -60px;
}
.bonus-item:hover {
.bonus-item:hover:not(.disabled) {
transform: scale(1.1);
}
.bonus-item.disabled {
background-color: black;
filter: contrast(0.5);
cursor: not-allowed;
}

#bonus-grid > canvas {
width: 200px;
Expand Down

0 comments on commit c8bed9e

Please sign in to comment.