Added RPG
This commit is contained in:
@@ -53,6 +53,52 @@ export function createImagePromptBlock(promptText) {
|
||||
return block;
|
||||
}
|
||||
|
||||
function renderChoices(wrapper, choices) {
|
||||
if (!choices || !choices.length) return;
|
||||
const row = document.createElement('div');
|
||||
row.className = 'choice-row';
|
||||
for (const c of choices) {
|
||||
const btn = document.createElement('button');
|
||||
btn.type = 'button';
|
||||
btn.className = 'choice-btn';
|
||||
btn.textContent = c.label;
|
||||
btn.addEventListener('click', () => {
|
||||
dom.inputEl.value = c.label;
|
||||
dom.inputEl.focus();
|
||||
});
|
||||
row.appendChild(btn);
|
||||
}
|
||||
wrapper.appendChild(row);
|
||||
}
|
||||
|
||||
function renderResolution(wrapper, resolution) {
|
||||
if (!resolution?.text) return;
|
||||
const block = document.createElement('div');
|
||||
block.className = 'resolution-block';
|
||||
block.innerHTML = `
|
||||
<div class="resolution-title">Resolution (d20=${resolution.roll}, ${resolution.outcome})</div>
|
||||
<div class="resolution-text"></div>
|
||||
`;
|
||||
block.querySelector('.resolution-text').textContent = resolution.text;
|
||||
wrapper.appendChild(block);
|
||||
}
|
||||
|
||||
function renderDebugBlocks(wrapper, blocks) {
|
||||
if (!blocks || !blocks.length) return;
|
||||
for (const b of blocks) {
|
||||
if (!b?.text) continue;
|
||||
if (b.type === 'global_plot') {
|
||||
addMessage('assistant', `--- Global plot ---\n${b.text}\n---`);
|
||||
} else if (b.type === 'facts') {
|
||||
addMessage('assistant', b.text);
|
||||
} else if (b.type === 'status_quo') {
|
||||
addMessage('assistant', b.text);
|
||||
} else {
|
||||
addMessage('assistant', b.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function generateImageViaA1111(promptText, block) {
|
||||
block.parentElement.querySelector('.chat-image')?.remove();
|
||||
block.parentElement.querySelector('.image-error')?.remove();
|
||||
@@ -238,6 +284,16 @@ export async function sendMessage() {
|
||||
err.textContent = '🖼 ' + data.image_error;
|
||||
bubble.parentElement.appendChild(err);
|
||||
}
|
||||
if (data.choices && bubble) {
|
||||
renderChoices(bubble.parentElement, data.choices);
|
||||
}
|
||||
if (data.resolution && bubble) {
|
||||
// show resolution under the last user message (best-effort: attach near assistant response)
|
||||
renderResolution(bubble.parentElement, data.resolution);
|
||||
}
|
||||
if (data.debug) {
|
||||
renderDebugBlocks(bubble?.parentElement || dom.messagesEl, data.debug);
|
||||
}
|
||||
const { loadSessions } = await import('./sessions.js');
|
||||
loadSessions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user