cleanup locations. make treasure bold. try to add some flair to the images

This commit is contained in:
2025-09-10 22:38:06 -04:00
parent 277a3ba718
commit 799ee18dc2
5 changed files with 228 additions and 22 deletions

View File

@@ -1,11 +1,12 @@
import { callOllama } from "./ollamaClient.js";
// Utility: strip markdown artifacts
// Utility: strip markdown artifacts and clean up extra whitespace
function cleanText(str) {
if (!str) return "";
return str
.replace(/^#+\s*/gm, "")
.replace(/\*\*(.*?)\*\*/g, "$1")
.replace(/[*_`]/g, "")
.replace(/\*\*(.*?)\*\*/g, "$1") // Removes bolding
.replace(/[*_`]/g, "") // Removes other markdown
.replace(/\s+/g, " ")
.trim();
}
@@ -18,7 +19,8 @@ function parseList(raw) {
}
function parseObjects(raw, type = "rooms") {
return raw
let cleanedRaw = raw.replace(/Intermediate Rooms:/i, "").replace(/Climax Room:/i, "").trim();
return cleanedRaw
.split(/\n?\d+[).]\s+/)
.map(entry => cleanText(entry))
.filter(Boolean)
@@ -86,18 +88,18 @@ Output two sections labeled "Description:" and "Hooks & Rumors:". Use a numbered
`Based on the title "${title}", description "${flavor}", and these core concepts:
${coreConcepts}
Generate two key rooms that define the dungeon's narrative arc.
1. **The Entrance/Start Room:** The first room the adventurers will enter. Give it a name and a description that sets the tone and introduces the environmental hazard.
2. **The Climax/Final Room:** The final room where the central conflict will be resolved. Give it a name and a description that includes the primary faction and the central conflict.
Output two numbered lists, labeled "Entrance Room:" and "Climax Room:". Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
1. **Entrance Room:** Give it a name and a description that sets the tone and introduces the environmental hazard.
2. **Climax Room:** Give it a name and a description that includes the primary faction and the central conflict.
Output as two numbered items, plain text only. Do not use bolded headings. Do not include any intro or other text. Only the numbered list. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
undefined, 5, "Step 4: Key Rooms"
);
const [entranceSection, climaxSection] = keyRoomsRaw.split(/Climax Room[:\n]/i);
const entranceRoom = parseObjects(entranceSection.replace(/Entrance Room[:\n]*/i, ""), "rooms")[0];
const climaxRoom = parseObjects(climaxSection || "", "rooms")[0];
const [entranceSection, climaxSection] = keyRoomsRaw.split(/\n?2[).] /); // Split on "2. " to separate the two rooms
const entranceRoom = parseObjects(entranceSection, "rooms")[0];
const climaxRoom = parseObjects(`1. ${climaxSection}`, "rooms")[0]; // Prepend "1. " to make parsing consistent
console.log("Entrance Room:", entranceRoom);
console.log("Climax Room:", climaxRoom);
// Step 5: Main Content (Rooms, Encounters, NPCs, Treasures)
// Step 5: Main Content (Locations, Encounters, NPCs, Treasures)
const mainContentRaw = await callOllama(
`Based on the following dungeon elements and the need for narrative flow:
Title: "${title}"
@@ -108,15 +110,15 @@ Entrance Room: ${JSON.stringify(entranceRoom)}
Climax Room: ${JSON.stringify(climaxRoom)}
Generate the rest of the dungeon's content to fill the space between the entrance and the climax.
- **3 Intermediate Rooms:** Name and a description. Each description must be a maximum of 50 words and contain an environmental feature, a puzzle, or an element that connects to the core concepts or the final room.
- **4 Encounters:** Name and details. At least two encounters must be directly tied to the primary faction.
- **3 NPCs:** Proper name and a trait. One NPC should be a member of the primary faction, one should be a potential ally, and one should be a rival.
- **3 Treasures:** Name and a description that includes a danger or side-effect. Each treasure should be thematically tied to a specific encounter or room.
Output as four separate numbered lists, labeled "Intermediate Rooms:", "Encounters:", "NPCs:", and "Treasures:". Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
- **Strictly 3 Locations:** Each with a name and a short description (max 20 words). The description must be a single sentence. It should contain an environmental feature, a puzzle, or an element that connects to the core concepts or the final room.
- **Strictly 4 Encounters:** Name and details. At least two encounters must be directly tied to the primary faction.
- **Strictly 3 NPCs:** Proper name and a trait. One NPC should be a member of the primary faction, one should be a potential ally, and one should be a rival.
- **Strictly 3 Treasures:** Name and a description that includes a danger or side-effect. Each treasure should be thematically tied to a specific encounter or room.
Output as four separate numbered lists. Label the lists as "Locations:", "Encounters:", "NPCs:", and "Treasures:". Do not use any bolding, preambles, or extra text. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
undefined, 5, "Step 5: Main Content"
);
const [intermediateRoomsSection, encountersSection, npcsSection, treasureSection] = mainContentRaw.split(/Encounters[:\n]|NPCs[:\n]|Treasures?[:\n]/i);
const intermediateRooms = parseObjects(intermediateRoomsSection.replace(/Intermediate Rooms[:\n]*/i, ""), "rooms");
const [intermediateRoomsSection, encountersSection, npcsSection, treasureSection] = mainContentRaw.split(/Encounters:|NPCs:|Treasures?:/i);
const intermediateRooms = parseObjects(intermediateRoomsSection.replace(/Locations:/i, ""), "rooms");
const rooms = [entranceRoom, ...intermediateRooms, climaxRoom];
const encounters = parseObjects(encountersSection || "", "encounters");
const npcs = parseObjects(npcsSection || "", "npcs");

View File

@@ -204,7 +204,11 @@ export function dungeonTemplate(data) {
</tr>`).join("")}
</table>
<h2>Treasure</h2>
<ul>${data.treasure.map(t => `<li>${t}</li>`).join("")}</ul>
<ul>${data.treasure.map(t => {
const [name, ...descParts] = t.split(/[-–—:]/);
const description = descParts.join(" ").trim();
return `<li><b>${name.trim()}</b>: ${description}</li>`;
}).join("")}</ul>
</div>
<div class="col">
<h2>NPCs</h2>

View File

@@ -8,13 +8,24 @@ const __dirname = path.dirname(fileURLToPath(import.meta.url));
const COMFYUI_URL = process.env.COMFYUI_URL || "http://localhost:8188";
// Drawing style prefix
const STYLE_PREFIX = `clean line art, minimalist sketch, concept art sketch, black and white line drawing, lots of white space, sparse shading, very minimal shading, simple black hatching, very low detail, single accent color`;
const STYLE_PREFIX = `clean line art, minimalist sketch, concept art, black and white line drawing, lots of white space, sparse shading, simple black hatching, very low detail`;
const ACCENT_COLORS = ["red", "blue", "yellow", "green", "purple", "orange"];
function selectRandomAccentColor() {
return ACCENT_COLORS[Math.floor(Math.random() * ACCENT_COLORS.length)];
}
async function upscaleImage(inputPath, outputPath, width, height) {
try {
await sharp(inputPath)
.resize(width, height, { kernel: 'lanczos3' })
.sharpen()
.blur(0.3)
.sharpen({
sigma: 1,
flat: 1,
jagged: 2,
})
.png({
compressionLevel: 9,
adaptiveFiltering: true,
@@ -54,7 +65,9 @@ Output:`,
"gemma3n:e4b", 3, "Generate Visual Prompt"
);
return `${STYLE_PREFIX}, ${rawPrompt.trim().replace(/\n/g, " ")}`;
const accentColor = selectRandomAccentColor();
return `${STYLE_PREFIX}, on white paper, monochrome with a single accent of ${accentColor}, ${rawPrompt.trim().replace(/\n/g, " ")}`;
}
// 2. Save image buffer

107
originalworkflow.json Normal file
View File

@@ -0,0 +1,107 @@
{
"3": {
"inputs": {
"seed": 0,
"steps": 20,
"cfg": 8,
"sampler_name": "euler",
"scheduler": "normal",
"denoise": 1,
"model": [
"4",
0
],
"positive": [
"6",
0
],
"negative": [
"7",
0
],
"latent_image": [
"5",
0
]
},
"class_type": "KSampler",
"_meta": {
"title": "KSampler"
}
},
"4": {
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly.safetensors"
},
"class_type": "CheckpointLoaderSimple",
"_meta": {
"title": "Load Checkpoint"
}
},
"5": {
"inputs": {
"width": 512,
"height": 512,
"batch_size": 1
},
"class_type": "EmptyLatentImage",
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"inputs": {
"text": "Prompt",
"clip": [
"4",
1
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"inputs": {
"text": "",
"clip": [
"4",
1
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"inputs": {
"samples": [
"3",
0
],
"vae": [
"4",
2
]
},
"class_type": "VAEDecode",
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"inputs": {
"filename_prefix": "ComfyUI",
"images": [
"8",
0
]
},
"class_type": "SaveImage",
"_meta": {
"title": "Save Image"
}
}
}

80
testworkflow.json Normal file
View File

@@ -0,0 +1,80 @@
{
"3": {
"inputs": {
"seed": "randomize",
"steps": 25,
"cfg": 7,
"sampler_name": "dpmpp_2m_karras",
"scheduler": "normal",
"denoise": 1,
"model": ["4", 0],
"positive": ["6", 0],
"negative": ["7", 0],
"latent_image": ["5", 0]
},
"class_type": "KSampler",
"_meta": {
"title": "KSampler"
}
},
"4": {
"inputs": {
"ckpt_name": "v1-5-pruned-emaonly.safetensors"
},
"class_type": "CheckpointLoaderSimple",
"_meta": {
"title": "Load Checkpoint"
}
},
"5": {
"inputs": {
"width": 512,
"height": 512,
"batch_size": 1
},
"class_type": "EmptyLatentImage",
"_meta": {
"title": "Empty Latent Image"
}
},
"6": {
"inputs": {
"text": "masterpiece, best quality, a dungeons and dragons token, fantasy miniature, digital art, full body portrait of a mighty red dragon",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"inputs": {
"text": "text, watermark, logo, bad anatomy, scrabble, board game, letters, words",
"clip": ["4", 1]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"inputs": {
"samples": ["3", 0],
"vae": ["4", 2]
},
"class_type": "VAEDecode",
"_meta": {
"title": "VAE Decode"
}
},
"9": {
"inputs": {
"filename_prefix": "ComfyUI",
"images": ["8", 0]
},
"class_type": "SaveImage",
"_meta": {
"title": "Save Image"
}
}
}