feat: start talking to caesar
This commit is contained in:
parent
f19d1f37d7
commit
5f2442284c
|
@ -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."}
|
||||||
|
]
|
|
@ -7,13 +7,12 @@
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<div id="header">
|
<div id="header">
|
||||||
<h1>Hester Gomez</h1>
|
<h1 id="header-title">NAME</h1>
|
||||||
<p class="delay">(Earth, <span id="delay-text"></span>)</p>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul id="messages"></ul>
|
<ul id="messages"></ul>
|
||||||
|
|
||||||
<p id="typing-indicator">Hester is typing...</p>
|
<p id="typing-indicator">NAME is typing...</p>
|
||||||
|
|
||||||
<div id="textbox">
|
<div id="textbox">
|
||||||
<input id="textbox-input" class="rounded-rectangle" type="text" disabled></input>
|
<input id="textbox-input" class="rounded-rectangle" type="text" disabled></input>
|
||||||
|
|
49
main.js
49
main.js
|
@ -17,15 +17,25 @@ class Conversation {
|
||||||
}
|
}
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
setTimeout(() => {
|
document.title = this.contactName;
|
||||||
this.messageIdx = 0;
|
document.getElementById("header-title").innerHTML = this.contactName;
|
||||||
this.pings = 1;
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
const data = this.messageData[this.messageIdx];
|
||||||
|
const message = new ReceivedMessage(data);
|
||||||
|
this.messages.push(message);
|
||||||
|
this.onMessageReceived(message);
|
||||||
|
}, 3623);
|
||||||
|
}
|
||||||
|
|
||||||
const data = this.messageData[this.messageIdx];
|
|
||||||
const message = new ReceivedMessage(data);
|
|
||||||
this.messages.push(message);
|
|
||||||
this.onMessageReceived(message);
|
|
||||||
}, 3623);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
peekNextMessageData() {
|
peekNextMessageData() {
|
||||||
|
@ -269,7 +279,7 @@ class SentMessage {
|
||||||
|
|
||||||
function setTypingIndicator(isTyping) {
|
function setTypingIndicator(isTyping) {
|
||||||
document.getElementById("typing-indicator").innerHTML = isTyping
|
document.getElementById("typing-indicator").innerHTML = isTyping
|
||||||
? "Hester is typing..."
|
? `${conversation.contactName} is typing...`
|
||||||
: "";
|
: "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,18 +333,6 @@ function pressSendButton() {
|
||||||
conversation.sendMessage();
|
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) {
|
function onMessageReceived(message) {
|
||||||
updateChat(message);
|
updateChat(message);
|
||||||
setTypingIndicator(false);
|
setTypingIndicator(false);
|
||||||
|
@ -345,15 +343,10 @@ function onMessageSent(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function init(messageData) {
|
function init(messageData) {
|
||||||
conversation = new Conversation(messageData, "Hester Gomez", onMessageReceived, onMessageSent);
|
conversation = new Conversation(messageData, "Caesar", onMessageReceived, onMessageSent);
|
||||||
conversation.start();
|
conversation.start();
|
||||||
|
|
||||||
document.title = conversation.contactName;
|
|
||||||
|
|
||||||
updateLightLag(0);
|
|
||||||
startLightLagUpdateLoop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch("hester.json")
|
fetch("caesar.json")
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(json => init(json));
|
.then(json => init(json));
|
||||||
|
|
Loading…
Reference in New Issue