Chat work

This commit is contained in:
somebody
2022-11-09 20:05:57 -06:00
parent a27fcaf4a5
commit 5952e94283
2 changed files with 31 additions and 8 deletions

View File

@@ -618,7 +618,7 @@ gensettingstf = [
"label": "Chat Style",
"id": "chat_style",
"default": 0,
"tooltip": "How to represent chat messages in the UI",
"tooltip": "How chat messages are shown",
"menu_path": "Interface",
"sub_path": "UI",
"classname": "story",

View File

@@ -5943,9 +5943,6 @@ function deleteChatPromptIfEmpty() {
prompt.remove();
}
// Initial message
//addMessage(null, null, -1);
function computeChatGametext(actionId) {
// TODO: Customizable format?
let lines = [];
@@ -5962,6 +5959,8 @@ function computeChatGametext(actionId) {
}
function updateChatStyle() {
const storyArea = document.getElementById("Selected Text");
if (chat.useV2) {
// Already bubbles, do nothing
if (document.getElementsByClassName("chat-message").length) {
@@ -5969,6 +5968,12 @@ function updateChatStyle() {
return;
}
// Delete normal text
for (const child of storyArea.children) {
child.remove();
}
let addedMessages = 0;
for (const [chunkId, chunk] of Object.entries(actions_data)) {
@@ -5983,11 +5988,29 @@ function updateChatStyle() {
} else {
console.info("TODO: Convert 2 text")
if (!document.getElementsByClassName("chat-message").length) {
console.info("Already text, do nothing")
return;
if (!storyArea.children.length) {
for (const [chunkId, action] of Object.entries(actions_data)) {
let item = document.createElement("span");
item.id = 'Selected Text Chunk '+chunkId;
item.classList.add("rawtext");
item.setAttribute("chunk", chunkId);
//need to find the closest element
next_id = chunkId+1;
if (Math.max.apply(null,Object.keys(actions_data).map(Number)) <= next_id) {
storyArea.append(item);
} else {
storyArea.prepend(item);
}
$(".chat-message").remove();
chunk_element = document.createElement("span");
chunk_element.textContent = action['Selected Text'];
item.append(chunk_element);
item.original_text = action['Selected Text'];
}
}
const jQCM = $(".chat-message");
if (jQCM.length) jQCM.remove();
}
}