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

Draft: show initial sentences of goal page #40

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
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
21 changes: 14 additions & 7 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?origin=*&action=query&prop=extracts&exsectionformat=plain&format=json&explaintext&exintro&exsentences=2&titles=" + encodeURIComponent(page)).then((response) => (response.json()));
return Object.values(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 All @@ -222,14 +229,14 @@ async function GetRandomWikipediaArticles(n) {
};

url = url + "?origin=*";
Object.keys(params).forEach(function (key) {
Object.keys(params).forEach(function(key) {
url += "&" + key + "=" + params[key];
});

articles = await fetch(url)
.then((response) => response.json())
.then((json) => json.query.random)
.catch(function (error) {
.catch(function(error) {
console.log(error);
return [{ title: "Gingerbread", title: "League of Legends" }];
});
Expand All @@ -253,14 +260,14 @@ async function SearchForWikipediaTitle(title) {
};

url = url + "?origin=*";
Object.keys(params).forEach(function (key) {
Object.keys(params).forEach(function(key) {
url += "&" + key + "=" + params[key];
});

response = await fetch(url)
.then((response) => response.json())
.then((json) => json)
.catch(function (error) {
.catch(function(error) {
return { error: error };
});

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