Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
24 changes: 22 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
const chatGptMessages = [];
const stageContainer = document.querySelector('.stage-container');

const createStage = (setting, actions) => {
if(!setting || !actions.length) {
return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ignore


const stageTemplate = document.querySelector('#stage-template');
const stage = stageTemplate.content.cloneNode(true);
stage.querySelector('.stage-setting').innerHTML = setting;
stageContainer.append(stage);

const actionsHtml = actions.map((action) => `<button>${action}</button>`).join('');
document.querySelector('.stage-actions').innerHTML = actionsHtml;
const buttons = document.querySelectorAll('.stage-actions button');
buttons.forEach((button) => button.addEventListener(
'click',
() => alert(button.innerText)
))
}

const startGame = async (genre) => {
showErrorMessage(false);
Expand Down Expand Up @@ -33,8 +53,8 @@ const startGame = async (genre) => {
const message = chatResponseJson.choices[0].message;
const content = JSON.parse(message.content);
const {setting, actions} = content;
console.log('SETTING:', setting);
console.log('ACTIONS:', actions);

createStage(setting, actions);
Copy link
Contributor Author

@julesnuggy julesnuggy Jul 13, 2023

Choose a reason for hiding this comment

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

Wrap 57 with if (actions.length) {} to avoid error if ChatGPT decides to game over (which is not yet setup)


showLoadingAnimation(false);
} catch (error) {
Expand Down
18 changes: 18 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ header {
margin-bottom: 32px;
}

.stage-actions {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px;
}

.stage-actions button {
background-color: transparent;
padding: 16px;
font-family: 'Space Grotesk', sans-serif;
font-size: 20px;
text-align: center;
color: white;
border: 2px solid #a1d2ff;
cursor: pointer;
}

.loading {
display: flex;
justify-content: center;
Expand Down