| const Personagene = require('../models/personagene'); |
|
|
| class ComicStoryGenerator { |
| constructor() { |
| this.personagene = new Personagene(); |
| } |
|
|
| async createComicStory(theme = 'adventure') { |
| |
| const mainCharacter = await this.personagene.createRandomPersonagene(); |
| |
| |
| const storyElements = this._generateStoryElements(theme, mainCharacter); |
| |
| |
| const panels = await this._createComicPanels(storyElements, mainCharacter); |
| |
| return { |
| title: storyElements.title, |
| theme: theme, |
| mainCharacter: mainCharacter, |
| panels: panels, |
| createdAt: new Date().toISOString(), |
| }; |
| } |
|
|
| _generateStoryElements(theme, character) { |
| const themes = { |
| adventure: { |
| title: "The Quest for the Lost Artifact", |
| plot: `Following a mysterious map, ${character.characteristics.appearance} must journey to a forgotten temple`, |
| conflict: "Guardian spirits protect the artifact", |
| resolution: "Through wisdom and courage, the artifact is claimed" |
| }, |
| mystery: { |
| title: "The Enigma of the Shadow Realm", |
| plot: `${character.characteristics.appearance} investigates strange occurrences in their town`, |
| conflict: "A dark cult is opening portals to another dimension", |
| resolution: "The portals are sealed, saving the town" |
| }, |
| romance: { |
| title: "Love Beyond the Stars", |
| plot: `${character.characteristics.appearance} meets a mysterious stranger`, |
| conflict: "They come from different worlds with opposing destinies", |
| resolution: "Love conquers all, and they find a way to be together" |
| } |
| }; |
|
|
| return themes[theme] || themes.adventure; |
| } |
|
|
| async _createComicPanels(storyElements, mainCharacter) { |
| const panelPrompts = [ |
| `Wide establishing shot of the world where "${storyElements.title}" takes place, fantasy landscape, cinematic view`, |
| `Close-up portrait of the main character: ${mainCharacter.characteristics.appearance}, ${mainCharacter.characteristics.clothing}`, |
| `Action scene: ${storyElements.plot}, dramatic moment, high tension`, |
| `Climactic scene: ${storyElements.conflict}, intense emotions, magical effects`, |
| `Resolution scene: ${storyElements.resolution}, peaceful atmosphere, character growth` |
| ]; |
|
|
| const panels = []; |
| |
| for (let i = 0; i < panelPrompts.length; i++) { |
| |
| |
| panels.push({ |
| id: i + 1, |
| prompt: panelPrompts[i], |
| |
| image: `panel_${i + 1}_placeholder.jpg`, |
| description: `Panel ${i + 1} of the comic story` |
| }); |
| } |
| |
| return panels; |
| } |
|
|
| async createCustomComicStory(characteristics, theme) { |
| |
| const customCharacter = await this.personagene.createPersonagene(characteristics); |
| |
| |
| const story = await this.createComicStory(theme); |
| |
| |
| story.mainCharacter = customCharacter; |
| |
| return story; |
| } |
| } |
|
|
| module.exports = ComicStoryGenerator; |
|
|