Compare commits

...

3 Commits

Author SHA1 Message Date
dc9ec367a0 remove workflows that were test workflows
Some checks failed
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/cron/ci Pipeline failed
2025-09-10 22:38:37 -04:00
799ee18dc2 cleanup locations. make treasure bold. try to add some flair to the images 2025-09-10 22:38:06 -04:00
277a3ba718 improve overall dungeon cohesiveness
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
ci/woodpecker/cron/ci Pipeline was successful
2025-09-08 22:42:42 -04:00
3 changed files with 101 additions and 79 deletions

View File

@@ -1,12 +1,13 @@
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, "") // remove headers
.replace(/\*\*(.*?)\*\*/g, "$1") // remove bold
.replace(/[*_`]/g, "") // remove stray formatting
.replace(/\s+/g, " ") // normalize whitespace
.replace(/^#+\s*/gm, "")
.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)
@@ -53,85 +55,87 @@ Avoid repeating materials or adjectives. Absolutely do not use the words "Obsidi
const title = generatedTitles[Math.floor(Math.random() * generatedTitles.length)];
console.log("Selected title:", title);
// Step 2: Flavor text
const flavorRaw = await callOllama(
`Write a single evocative paragraph describing the location titled "${title}". Absolutely do not use the words "Obsidian" or "Clockwork" anywhere in the paragraph.
Do not include hooks, NPCs, treasure, or instructions. Do not use bullet points or em-dashes. Output plain text only, one paragraph. Maximum 4 sentences.`,
undefined, 5, "Step 2: Flavor"
// Step 2: Core Concepts
const coreConceptsRaw = await callOllama(
`For a dungeon titled "${title}", generate three core concepts: a central conflict, a primary faction, and a major environmental hazard or dynamic element.
Output as a numbered list with bolded headings. Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.
Example:
1. **Central Conflict:** The dungeon's power source is failing, causing reality to warp.
2. **Primary Faction:** A group of rival cultists trying to seize control of the power source.
3. **Dynamic Element:** Zones of temporal distortion that cause random, brief time shifts.`,
undefined, 5, "Step 2: Core Concepts"
);
const flavor = flavorRaw;
console.log("Flavor text:", flavor);
const coreConcepts = coreConceptsRaw;
console.log("Core Concepts:", coreConcepts);
// Step 3: Hooks & Rumors
const hooksRumorsRaw = await callOllama(
`Based only on this location's flavor:
${flavor}
Generate 3 short adventure hooks or rumors (mix them naturally).
Output as a single numbered list, plain text only. Do not use em-dashes.
Maximum 2 sentences per item. No explanations or extra text.`,
undefined, 5, "Step 3: Hooks & Rumors"
// Step 3: Flavor Text & Hooks
const flavorHooksRaw = await callOllama(
`Based on the title "${title}" and these core concepts:
${coreConcepts}
Write a single evocative paragraph describing the location. Maximum 2 sentences. Maximum 100 words. Then, generate 3 short adventure hooks or rumors.
The hooks should reference the central conflict, faction, and dynamic element.
Output two sections labeled "Description:" and "Hooks & Rumors:". Use a numbered list for the hooks. Plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
undefined, 5, "Step 3: Flavor & Hooks"
);
const hooksRumors = parseList(hooksRumorsRaw);
const [flavorSection, hooksSection] = flavorHooksRaw.split(/Hooks & Rumors[:\n]/i);
const flavor = cleanText(flavorSection.replace(/Description[:\n]*/i, ""));
const hooksRumors = parseList(hooksSection || "");
console.log("Flavor Text:", flavor);
console.log("Hooks & Rumors:", hooksRumors);
// Step 4: Rooms & Encounters
const roomsEncountersRaw = await callOllama(
`Using the flavor and these hooks/rumors:
Flavor:
${flavor}
Hooks & Rumors:
${hooksRumors.join("\n")}
Generate 5 rooms (name + short description) and 6 encounters (name + details).
Output two numbered lists, labeled "Rooms:" and "Encounters:". Plain text only. No extra explanation.`,
undefined, 5, "Step 4: Rooms & Encounters"
// Step 4: Key Rooms
const keyRoomsRaw = await callOllama(
`Based on the title "${title}", description "${flavor}", and these core concepts:
${coreConcepts}
Generate two key rooms that define the dungeon's narrative arc.
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 [roomsSection, encountersSection] = roomsEncountersRaw.split(/Encounters[:\n]/i);
const rooms = parseObjects(roomsSection.replace(/Rooms[:\n]*/i, ""), "rooms", 120);
const encounters = parseObjects(encountersSection || "", "encounters", 120);
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 (Locations, Encounters, NPCs, Treasures)
const mainContentRaw = await callOllama(
`Based on the following dungeon elements and the need for narrative flow:
Title: "${title}"
Description: "${flavor}"
Core Concepts:
${coreConcepts}
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.
- **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:|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");
const treasure = parseList(treasureSection || "");
console.log("Rooms:", rooms);
console.log("Encounters:", encounters);
// Step 5: Treasure & NPCs
const treasureNpcsRaw = await callOllama(
`Based only on these rooms and encounters:
${JSON.stringify({ rooms, encounters }, null, 2)}
Generate 3 treasures and 3 NPCs (name + trait, max 2 sentences each).
Each NPC has a proper name, not just a title.
Treasure should sometimes include a danger or side-effect.
Output numbered lists labeled "Treasure:" and "NPCs:". Plain text only, no extra text.`,
undefined, 5, "Step 5: Treasure & NPCs"
);
const [treasureSection, npcsSection] = treasureNpcsRaw.split(/NPCs[:\n]/i);
const treasure = parseList(treasureSection.replace(/Treasures?[:\n]*/i, ""));
const npcs = parseObjects(npcsSection || "", "npcs", 120);
console.log("Treasure:", treasure);
console.log("NPCs:", npcs);
console.log("Treasure:", treasure);
// Step 6: Plot Resolutions
// Step 6: Player Choices and Consequences
const plotResolutionsRaw = await callOllama(
`Based on the following location's flavor and story hooks:
`Based on all of the following elements, suggest 3 possible, non-conflicting story climaxes or plot resolutions for adventurers exploring this location. Each resolution must provide a meaningful choice with a tangible consequence, directly related to the Central Conflict, the Primary Faction, or the NPCs.
Flavor:
${flavor}
Dungeon Elements:
${JSON.stringify({ title, flavor, hooksRumors, rooms, encounters, treasure, npcs, coreConcepts }, null, 2)}
Hooks & Rumors:
${hooksRumors.join("\n")}
Major NPCs / Encounters:
${[...npcs.map(n => n.name), ...encounters.map(e => e.name)].join(", ")}
Suggest 3 possible, non-conflicting story climaxes or plot resolutions for adventurers exploring this location.
These are prompts and ideas for brainstorming the story's ending, not fixed outcomes. Give the players meaningful choices and agency.
Start each item with phrases like "The adventurers could" or "The PCs might" to emphasize their hypothetical nature.
Deepen the narrative texture and allow roleplay and tactical creativity.
Keep each item short (max 2 sentences). Output as a numbered list, plain text only.`,
Start each item with phrases like "The adventurers could" or "The PCs might". Deepen the narrative texture and allow for roleplay and tactical creativity. Keep each item short (max 2 sentences). Output as a numbered list, plain text only. Absolutely do not use the word "Obsidian" or "obsidian" anywhere in the output.`,
undefined, 5, "Step 6: Plot Resolutions"
);
const plotResolutions = parseList(plotResolutionsRaw);

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,14 +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' })
.blur(0.3)
.sharpen()
.sharpen({
sigma: 1,
flat: 1,
jagged: 2,
})
.png({
compressionLevel: 9,
adaptiveFiltering: true,
@@ -38,13 +48,15 @@ async function generateVisualPrompt(flavor) {
Your output must be a simple list of visual tags describing only the most essential elements of the scene. Focus on the core subject and mood.
Rules:
- Describe a sparse scene with a single focal point or area.
- Describe a sparse scene with a single focal point or landscape.
- Use only 3-5 key descriptive phrases or tags.
- The entire output should be very short, 20-50 words maximum.
- Do NOT repeat wording from the input.
- Focus only on visual content, not style, medium, or camera effects.
- Describe only the visual elements of the image. Focus on colors, shapes, textures, and spatial relationships.
- Exclude any references to style, medium, camera effects, sounds, hypothetical scenarios, or physical sensations.
- Avoid describing fine details; focus on large forms and the overall impression.
- Do NOT include phrases like “an image of” or “a scene showing”.
- Do NOT include the word "Obsidian" or "obsidian" at all.
Input:
${flavor}
@@ -53,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
@@ -177,7 +191,7 @@ async function downloadImage(filename, localFilename) {
// 4c. Submit prompt and handle full image pipeline
async function generateImageViaComfyUI(prompt, filename) {
const negativePrompt = `heavy shading, deep blacks, cross-hatching, dark, gritty, shadow-filled, chiaroscuro, scratchy lines, photorealism, hyper-realistic, high detail, 3D render, CGI, polished, smooth shading, detailed textures, noisy, cluttered, blurry, text, logo, signature, watermark, artist name, branding, ugly, deformed, unnatural patterns, perfect curves, repetitive textures`;
const negativePrompt = `heavy shading, deep blacks, dark, gritty, shadow-filled, chiaroscuro, scratchy lines, photorealism, hyper-realistic, high detail, 3D render, CGI, polished, smooth shading, detailed textures, noisy, cluttered, blurry, text, logo, signature, watermark, artist name, branding, ugly, deformed, unnatural patterns, perfect curves, repetitive textures`;
const workflow = buildComfyWorkflow(prompt, negativePrompt);
try {