feat: start talking to caesar

This commit is contained in:
Cat Flynn 2024-10-02 01:13:37 +01:00
parent f19d1f37d7
commit 5f2442284c
3 changed files with 27 additions and 31 deletions

4
caesar.json Normal file
View File

@ -0,0 +1,4 @@
[
{ "character": 0, "text": "Sire! Forgive my informal message. We must speak."},
{ "character": 1, "text": "What is the meaning of this? What is so urgent it cannot wait for our usual meeting? Speak plainly and get to the pooint. I have more important matters to attend to than deciphering vague missives."}
]

View File

@ -7,13 +7,12 @@
<body>
<div id="header">
<h1>Hester Gomez</h1>
<p class="delay">(Earth, <span id="delay-text"></span>)</p>
<h1 id="header-title">NAME</h1>
</div>
<ul id="messages"></ul>
<p id="typing-indicator">Hester is typing...</p>
<p id="typing-indicator">NAME is typing...</p>
<div id="textbox">
<input id="textbox-input" class="rounded-rectangle" type="text" disabled></input>

33
main.js
View File

@ -17,6 +17,14 @@ class Conversation {
}
start() {
document.title = this.contactName;
document.getElementById("header-title").innerHTML = this.contactName;
// if the first message comes from the other party,
const firstMessage = this.messageData[0];
const firstMessageIsOurs = firstMessage.character == 0;
if (firstMessageIsOurs) {
} else {
setTimeout(() => {
this.messageIdx = 0;
this.pings = 1;
@ -28,6 +36,8 @@ class Conversation {
}, 3623);
}
}
peekNextMessageData() {
return this.messageData[this.messageIdx + 1];
}
@ -269,7 +279,7 @@ class SentMessage {
function setTypingIndicator(isTyping) {
document.getElementById("typing-indicator").innerHTML = isTyping
? "Hester is typing..."
? `${conversation.contactName} is typing...`
: "";
}
@ -323,18 +333,6 @@ function pressSendButton() {
conversation.sendMessage();
}
function updateLightLag() {
const lag = conversation.getLightLag();
const text = lag.toFixed(5) + " seconds";
document.getElementById("delay-text").innerHTML = text;
}
function startLightLagUpdateLoop() {
setInterval(() => {
updateLightLag();
}, 1000);
}
function onMessageReceived(message) {
updateChat(message);
setTypingIndicator(false);
@ -345,15 +343,10 @@ function onMessageSent(message) {
}
function init(messageData) {
conversation = new Conversation(messageData, "Hester Gomez", onMessageReceived, onMessageSent);
conversation = new Conversation(messageData, "Caesar", onMessageReceived, onMessageSent);
conversation.start();
document.title = conversation.contactName;
updateLightLag(0);
startLightLagUpdateLoop();
}
fetch("hester.json")
fetch("caesar.json")
.then(response => response.json())
.then(json => init(json));