Skip to content

Commit c8bed9e

Browse files
committed
feat: Add Support for Coil Subscription and limit hat selection to subscribets
1 parent e11a66e commit c8bed9e

5 files changed

Lines changed: 78 additions & 14 deletions

File tree

src/index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@
1919
<button id="bonusBtn">Bonus Content</button>
2020
</div>
2121
<div id="bonus" class="overlay hide">
22+
<div id="coil-subscriber" class="hide">
23+
Thanks for being a Coil subscriber
24+
</div>
25+
26+
<a id="coilBtn" href="https://coil.com/" class="btn">
27+
Subscribe to Coil for more bonus hats
28+
</a>
29+
2230
<img class="close-icon" width="40px" />
2331
<div id="bonus-grid"></div>
2432
</div>

src/menu.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ import skull from 'data-url:./assets/img/skull.png';
44
import { emit, on } from 'kontra';
55
import {
66
LEVEL_COMPLETE,
7+
MONETIZATION_PROGRESS,
78
NEAR_TOKENS_ADDED,
89
NFT_MINT,
910
RESTART_LEVEL,
1011
START_LEVEL,
1112
START_NEXT_LEVEL,
1213
} from './gameEvents';
1314
import { fetchArcadianHeads } from './arcadianApi';
14-
import { nftTokensBySeries, setSelectedArcadian } from './store';
15+
import { isSubscriber, nftTokensBySeries, setSelectedArcadian } from './store';
1516
import { IPFS_BASE_PATH } from './near/nearConnection';
1617
import { doesOwnNft, getNearLevelId } from './utils';
1718

1819
const overlayIds = ['main', 'bonus', 'levels', 'level-dialog', 'near-levels'];
1920
const levels = 20;
21+
let hasRemovedDisableOnBonusEls = false;
2022
export const initMenu = () => {
2123
addButtonListeners();
2224
listenForGameEvents();
@@ -94,6 +96,9 @@ const pouplateBonusGrid = (bonusGridEl) => {
9496
bonusEl.setAttribute('width', img.width * 4);
9597
bonusEl.classList.add('bonus-item');
9698
bonusEl.setAttribute('arcadian', res[i].value.id);
99+
if (i > 5 && !isSubscriber) {
100+
bonusEl.classList.add('disabled');
101+
}
97102
const ctx = bonusEl.getContext('2d');
98103
ctx.imageSmoothingEnabled = false;
99104
ctx.scale(8, 8);
@@ -108,8 +113,12 @@ const pouplateBonusGrid = (bonusGridEl) => {
108113
const listenForBonusGridEvents = (bonusGridEl) => {
109114
bonusGridEl.addEventListener('click', (e) => {
110115
if (e.target.classList.contains('bonus-item')) {
111-
setSelectedArcadian(e.target.getAttribute('arcadian'));
112-
showOverlay('main');
116+
if (!e.target.classList.contains('disabled')) {
117+
setSelectedArcadian(e.target.getAttribute('arcadian'));
118+
showOverlay('main');
119+
} else {
120+
// TODO (johnedvard) tell player to become a subscriber
121+
}
113122
}
114123
});
115124
};
@@ -195,6 +204,7 @@ const showOverlay = (id) => {
195204
const listenForGameEvents = () => {
196205
on(LEVEL_COMPLETE, onLevelComplete);
197206
on(NEAR_TOKENS_ADDED, onNearTokensAdded);
207+
on(MONETIZATION_PROGRESS, onMonetizationProgress);
198208
};
199209
const onLevelComplete = () => {
200210
showOverlay('level-dialog');
@@ -207,3 +217,18 @@ const onNearTokensAdded = ({
207217
}) => {
208218
initNearLevels({ nftTokensBySeries, nftTokensForOwner, nftCollections });
209219
};
220+
221+
const onMonetizationProgress = () => {
222+
if (hasRemovedDisableOnBonusEls) return;
223+
const coilSubEl = document.getElementById('coil-subscriber');
224+
const coilBtnEl = document.getElementById('coilBtn');
225+
if (coilBtnEl) coilBtnEl.remove();
226+
if (coilSubEl) coilSubEl.classList.remove('hide');
227+
const bonusItemEls = document.getElementsByClassName('bonus-item');
228+
for (item of bonusItemEls) {
229+
item.classList.remove('disabled');
230+
}
231+
if (bonusItemEls && bonusItemEls.length) {
232+
hasRemovedDisableOnBonusEls = true;
233+
}
234+
};

src/monetization.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
1+
import { emit } from 'kontra';
12
import { MONETIZATION_PROGRESS } from './gameEvents';
3+
import { setIsSubscriber } from './store';
24

35
export const initMonetization = () => {
46
if (document && document.monetization) {
57
document.monetization.addEventListener('monetizationprogress', (evt) =>
6-
emit(MONETIZATION_PROGRESS, evt)
8+
handleSubscription(evt)
79
);
810
} else {
911
window.addEventListener('monetizationprogress', (evt) =>
10-
emit(MONETIZATION_PROGRESS, evt)
12+
handleSubscription(evt)
1113
);
1214
}
1315
};
16+
const handleSubscription = (evt) => {
17+
setIsSubscriber();
18+
emit(MONETIZATION_PROGRESS, evt);
19+
};

src/store.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ let selectedArcadian = {};
88
export let nftTokensBySeries = [];
99
export let nftTokensForOwner = [];
1010
export let nftCollections = [];
11+
export let isSubscriber = false;
1112

1213
export const setGameWidth = (width) => {
1314
gameWidth = width;
@@ -40,3 +41,7 @@ export const setNftTokens = (tokensForOwner, tokensBySeries, collections) => {
4041
nftCollections,
4142
});
4243
};
44+
45+
export const setIsSubscriber = () => {
46+
// isSubscriber = true;
47+
};

src/styles.css

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ body {
1010
height: 100vh;
1111
margin: 0;
1212
padding: 0;
13+
color: var(--fgc2);
14+
font-family: sans-serif;
1315
}
1416
#container {
1517
position: relative;
@@ -57,7 +59,8 @@ canvas {
5759
filter: drop-shadow(0 0 12px var(--acc));
5860
}
5961

60-
button {
62+
button,
63+
.btn {
6164
width: 240px;
6265
height: 50px;
6366
margin: 20px 0px 0px 0px;
@@ -67,6 +70,12 @@ button {
6770
border-radius: 4px;
6871
font-size: large;
6972
font-weight: bolder;
73+
cursor: pointer;
74+
}
75+
button:hover,
76+
.btn:hover {
77+
background-color: var(--bgc2);
78+
color: var(--fgc2);
7079
}
7180
button:disabled {
7281
background-color: lightgray;
@@ -79,6 +88,17 @@ button:disabled img {
7988
button:hover img {
8089
filter: none;
8190
}
91+
#coil-subscriber {
92+
height: 50px;
93+
}
94+
#coilBtn {
95+
width: 400px;
96+
height: 50px;
97+
text-decoration: none;
98+
display: flex;
99+
justify-content: center;
100+
align-items: center;
101+
}
82102
.overlay {
83103
position: absolute;
84104
width: 100%;
@@ -110,10 +130,6 @@ button:hover img {
110130
border-radius: 4px;
111131
background-color: var(--fgc2);
112132
}
113-
.level-item:hover {
114-
background-color: var(--bgc2);
115-
color: var(--fgc2);
116-
}
117133
.level-item img {
118134
width: 100%;
119135
height: auto;
@@ -147,9 +163,7 @@ button:hover img {
147163
#bonus-grid {
148164
row-gap: 0px;
149165
}
150-
#bonus-grid > canvas {
151-
margin-bottom: -60px;
152-
}
166+
153167
#level-dialog {
154168
width: 50%;
155169
height: 50%;
@@ -161,10 +175,16 @@ button:hover img {
161175
cursor: pointer;
162176
background: none;
163177
border-radius: 4px;
178+
margin-bottom: -60px;
164179
}
165-
.bonus-item:hover {
180+
.bonus-item:hover:not(.disabled) {
166181
transform: scale(1.1);
167182
}
183+
.bonus-item.disabled {
184+
background-color: black;
185+
filter: contrast(0.5);
186+
cursor: not-allowed;
187+
}
168188

169189
#bonus-grid > canvas {
170190
width: 200px;

0 commit comments

Comments
 (0)