Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hackathon: Kingdom royale #46

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions firebase-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ export async function getRoom(room) {
return doc.data();
}

export async function listRooms() {
export async function listRooms(limit = 20, publicRoom = true) {
const db = firebase.firestore();
const docs = await db
.collection(COLLECTION)
.where('public', '==', true)
.where('public', '==', publicRoom)
.orderBy('lastUpdateTime', 'desc')
// TODO: limit to last 7 days instead.
.limit(20)
.limit(limit)
.get();

const rooms = [];
Expand Down
1 change: 1 addition & 0 deletions incrypt.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ <h2>Now Playing</h2>
>, with {{ allPlayers(openRoom) }}
<span>({{ moment(openRoom.lastUpdateTime).fromNow() }})</span>
</p>
<br /><br /><br /><br /><br />
</div>
<div v-else>
<!-- Alert spectators that the game can't be joined. -->
Expand Down
69 changes: 54 additions & 15 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,38 @@
<body class="has-navbar-fixed-top">
<div id="vue">
<navbar ref="navbar" v-model="user"></navbar>
<!-- Notification -->
<div class="modal" :class="{'is-active': alertIsShowing}">
<div class="modal-background" @click="alertIsShowing=false"></div>
<!-- Share Link Notification -->
<div class="modal" :class="{'is-active': showShareModal}">
<div class="modal-background" @click="showShareModal=false"></div>
<div class="modal-content">
<div class="notification">
<label class="is-block mb-2">Invite your friends to play!</label>
<sharelink :link="'https://oneword.games/?room=' + room.name"></sharelink>
<button class="delete" aria-label="close" @click="alertIsShowing=false"></button>
<button class="delete" aria-label="close" @click="showShareModal=false"></button>
</div>
</div>
</div>
<!-- Private Room Notification -->
<div class="modal" :class="{'is-active': showPrivateModal}">
<div class="modal-background" @click="showPrivateModal=false"></div>
<div class="modal-card">
<header class="modal-card-head">
<p class="modal-card-title">Private room</p>
<button class="delete" aria-label="close" @click="showPrivateModal=false"></button>
</header>
<section v-if="" class="modal-card-body">
This room is private. To join, ask your teammates for the room name or link.<br /><br />

To make your own private room, become a supporter!<br />
</section>
<footer class="modal-card-foot">
<button class="button" @click="'TODO: make a showPrivateModal an enum, have an enter box'">
Enter room name
</button>
<button class="button is-warning" @click="referSupporter('private_room_modal')">Become a supporter</button>
</footer>
</div>
</div>
<!-- Home page -->
<div v-if="!room.players" class="container mx-4">
<!-- Announcements -->
Expand Down Expand Up @@ -118,13 +139,20 @@
</template>

<br /><br />
<h2 class="fancy">Open Rooms</h2>
<template v-for="openRoom in allRooms">
<p>
<div v-cloak>
<h2 class="fancy">Private Rooms</h2>
<p v-for="privateRoom in privateRooms">
<a @click="showPrivateModal = true"><b>{{ "Private room" }} with {{ privateRoom.players[0] }}</b></a>
<span v-if="privateRoom.players.length > 1"> and {{ privateRoom.players.length }} others</span>
({{ moment(privateRoom.lastUpdateTime).fromNow() }})
</p>
<h2 class="fancy">Open Rooms</h2>
<p v-for="openRoom in allRooms">
<a @click="room.name = openRoom.name; enterRoom()"><b>{{ openRoom.name }}</b></a
>, with {{ openRoom.players.join(', ') }} ({{ moment(openRoom.lastUpdateTime).fromNow() }})
</p>
</template>
</div>
<br /><br /><br /><br /><br />
</div>
<!-- In game -->
<div v-cloak v-else class="container mx-4">
Expand All @@ -135,7 +163,7 @@ <h1 class="fancy big">{{ room.name }}</h1>
<span class="fancy capitalize">Round {{ room.history.length + 1 }}</span>
<!-- Navigation -->
<span class="buttons are-small">
<button class="button is-dark is-inverted is-outlined" @click="alertIsShowing=true">Invite</button>
<button class="button is-dark is-inverted is-outlined" @click="showShareModal=true">Invite</button>
<button
v-if="room.players.includes(player.name)"
class="button is-dark is-inverted is-outlined"
Expand Down Expand Up @@ -472,6 +500,7 @@ <h2 v-if="room.history.length > 0" class="fancy">History</h2>
data: {
user: {},
allRooms: [],
privateRooms: [],
room: {
name: randomWord('adjectives') + '-' + randomWord('nouns'),
history: [],
Expand All @@ -481,7 +510,8 @@ <h2 v-if="room.history.length > 0" class="fancy">History</h2>
clue: '',
guess: '',
},
alertIsShowing: false,
showShareModal: false,
showPrivateModal: false,
newMod: '',
wordsSaved: false,
},
Expand All @@ -490,7 +520,7 @@ <h2 v-if="room.history.length > 0" class="fancy">History</h2>
this.CATEGORY_ORDER = ['nouns', 'verbs', 'adjectives', 'compounds', 'custom'];
},
async mounted() {
this.allRooms = (await listRooms()).filter((room) => room.players.length > 0);
this.populateHome(); // Begin listing rooms, but don't wait for the result to mount
const parsedUrl = new URL(window.location.href);
const roomName = parsedUrl.searchParams.get('room');
const playerName = parsedUrl.searchParams.get('player');
Expand Down Expand Up @@ -534,6 +564,10 @@ <h2 v-if="room.history.length > 0" class="fancy">History</h2>
moment,
listRooms,
dedupe,
async populateHome() {
this.privateRooms = (await listRooms(5, false)).filter((room) => room.players.length > 0);
this.allRooms = (await listRooms(20, true)).filter((room) => room.players.length > 0);
},
async enterRoom() {
if (!this.player.name) {
this.$refs.navbar.logIn();
Expand Down Expand Up @@ -721,22 +755,27 @@ <h2 v-if="room.history.length > 0" class="fancy">History</h2>
},
});
if (result === 'support') {
firebase.analytics().logEvent('view_promotion', {
source: 'modtools',
});
window.open('./supporter.html', '_blank');
referSupporter('modtools');
}
// Reset UI to non-supporter defaults
this.room.public = true;
this.room.roundsInGame = 13;
}
},
referSupporter,
correct,
isEnd,
score,
},
});

function referSupporter(source) {
firebase.analytics().logEvent('view_promotion', {
source: source,
});
window.open('./supporter.html', '_blank');
}

listenForLogin(vueApp);

// Returns whether a round's guess is correct.
Expand Down
Loading