Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions wikiweaver-web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@
<div class="text">Start a race from</div>
<input id="start-page-input" class="box text" placeholder="Gingerbread"></input>
<div class="text">to</div>
<input id="goal-page-input" class="box text" placeholder="League of Legends"></input>
<div id="goal-page-container">
<button id="show-goal-text" class="button box" onclick="ToggleGoalSummary()">intro</button>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the button be just un-clickable or completely hidden before the game has started?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can fix a lot of this stuff after the reef.js merge. I think it should just be disabled

<input id="goal-page-input" class="box text" placeholder="League of Legends"></input>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something happened with the width here
image

</div>
<p id="goal-page-summary" hidden="true">
</p>
<div class="flex-horizontal-container" style="margin-top: 0.5rem">
<button id="start-button" class="button box text" onclick="HandleStartGameClicked()">start</button>
<button id="end-button" class="button box text" onclick="HandleEndClicked()">end</button>
Expand Down Expand Up @@ -87,4 +92,4 @@
</div>
</body>

</html>
</html>
5 changes: 5 additions & 0 deletions wikiweaver-web/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ async function init() {
await JoinLobby(code);
}

async function ToggleGoalSummary() {
const elem = document.getElementById("goal-page-summary");
elem.hidden = !elem.hidden;
}

async function HandleStartGameClicked() {
if (!isHost) return;

Expand Down
13 changes: 10 additions & 3 deletions wikiweaver-web/js/networking.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function HandleMessageLobby(msg) {
SetCode(msg.Code);
}

function HandleMessageStart(msg) {
async function HandleMessageStart(msg) {
if (!msg.Success) return;

const elements = {
Expand All @@ -76,13 +76,20 @@ function HandleMessageStart(msg) {
};
EnableElements(elements);

document.getElementById("goal-page-summary").innerText = await GetArticleSummary(msg.GoalPage);
document.getElementById("start-page-input").value = msg.StartPage;
document.getElementById("goal-page-input").value = msg.GoalPage;
StartGame(msg.StartPage, msg.GoalPage);
ResetLeaderboardScores();
StartCountdownTimer(msg.StartTime, msg.Countdown);
}

async function GetArticleSummary(page) {
// TODO: we could limit the number of sentences as a room option for difficulty setting
let data = await fetch("https://en.wikipedia.org/w/api.php?action=query&prop=extracts&exsectionformat=plain&format=json&explaintext&exintro&exsentences=2&titles=" + encodeURIComponent(page)).then((response) => (response.json()));
return data.query.pages[0].extract
}

function HandleMessagePage(msg) {
AddNewPage(msg.Username, msg.Previous, msg.Page, msg.Backmove);
UpdateLeaderboardEntry(msg.Username, msg.Clicks, msg.Pages, msg.FinishTime);
Expand Down Expand Up @@ -169,7 +176,7 @@ async function JoinLobby(code) {
ShowElements(elements);
});

globalThis.socket.addEventListener("message", (event) => {
globalThis.socket.addEventListener("message", async (event) => {
const msg = JSON.parse(event.data);

console.log("recv message:", msg);
Expand Down Expand Up @@ -200,7 +207,7 @@ async function JoinLobby(code) {
break;

case "start":
HandleMessageStart(msg);
await HandleMessageStart(msg);
break;

default:
Expand Down
12 changes: 11 additions & 1 deletion wikiweaver-web/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ img {
overflow-y: auto;
}

#goal-page-container {
display: flex;
flex-direction: row;
gap: 0.5em;
}

#goal-page-input {
flex-grow: 1;
}
Comment on lines +100 to +108
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obviously this needs to be expanded


#maincanvas {
background: var(--maincanvas-background);
min-width: 0;
Expand Down Expand Up @@ -230,4 +240,4 @@ img {

.button:hover {
filter: brightness(85%);
}
}
Loading