-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dfb23d6
commit 2ae7910
Showing
4 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.main-gameplay { | ||
display: flex; | ||
flex-direction: column; | ||
height: 100vh; | ||
} | ||
|
||
.conversation-area { | ||
flex-grow: 1; | ||
overflow-y: auto; | ||
padding: 10px; | ||
background-color: #f5f5f5; | ||
} | ||
|
||
.message { | ||
margin-bottom: 10px; | ||
padding: 5px 10px; | ||
border-radius: 5px; | ||
} | ||
|
||
.message.player { | ||
color: blue; | ||
background-color: #e5e5ff; | ||
} | ||
|
||
.message.dm { | ||
color: green; | ||
background-color: #e5ffe5; | ||
} | ||
|
||
.input-area { | ||
display: flex; | ||
} | ||
|
||
.input-area input { | ||
flex-grow: 1; | ||
padding: 10px; | ||
margin-right: 10px; | ||
border: 1px solid #ccc; | ||
border-radius: 5px; | ||
} | ||
|
||
.input-area button { | ||
padding: 10px; | ||
border: none; | ||
border-radius: 5px; | ||
background-color: #4caf50; | ||
color: white; | ||
cursor: pointer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
import './MainGameplayPage.css'; // assuming you have corresponding CSS file | ||
|
||
const MainGameplayPage = () => { | ||
const [inputMessage, setInputMessage] = useState(''); | ||
const [conversation, setConversation] = useState([]); | ||
const endOfMessagesRef = useRef(null); | ||
|
||
const scrollToBottom = () => { | ||
endOfMessagesRef.current?.scrollIntoView({ behavior: "smooth" }); | ||
}; | ||
|
||
useEffect(scrollToBottom, [conversation]); // scroll to bottom when conversation updates | ||
|
||
const handleInputChange = (event) => { | ||
setInputMessage(event.target.value); | ||
}; | ||
|
||
const handleSubmit = () => { | ||
if (!inputMessage.trim()) return; // prevent empty messages | ||
|
||
// Here, you would typically send the message to your backend or GPT API | ||
// and then receive a response to add to the conversation. | ||
// For demonstration, we'll just add the message directly to our conversation log: | ||
const newMessage = { text: inputMessage, sender: 'player' }; | ||
setConversation([...conversation, newMessage]); | ||
|
||
// Simulate a DM response | ||
setTimeout(() => { | ||
const dmResponse = { text: `You said: "${inputMessage}"`, sender: 'dm' }; | ||
setConversation(prev => [...prev, dmResponse]); | ||
}, 1000); | ||
|
||
setInputMessage(''); // clear the input after sending | ||
}; | ||
|
||
const handleKeyPress = (event) => { | ||
if (event.key === 'Enter') { | ||
handleSubmit(); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className="main-gameplay"> | ||
<div className="conversation-area"> | ||
{conversation.map((message, index) => ( | ||
<div key={index} className={`message ${message.sender}`}> | ||
<span>{message.text}</span> | ||
</div> | ||
))} | ||
<div ref={endOfMessagesRef} /> | ||
</div> | ||
|
||
<div className="input-area"> | ||
<input | ||
type="text" | ||
value={inputMessage} | ||
onChange={handleInputChange} | ||
onKeyPress={handleKeyPress} | ||
placeholder="Type your message..." | ||
/> | ||
<button onClick={handleSubmit}>Send</button> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default MainGameplayPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters