MUD Dungeon Creation with GPT Assistance - wwestlake/Labyrinth GitHub Wiki
In this project, we are building a tool for owners and admins to easily create and manage various aspects of the MUD (rooms, items, quests, etc.) using an AI assistant (GPT). Owners can write and save themes that can be used to generate content, and GPT will assist in filling out forms based on the user's input and the chosen theme.
The backend is built using .NET 8 Web API with Firebase for authentication and MongoDB for data storage. We will design several endpoints to handle interaction between the frontend and the GPT-powered backend.
The React-based UI will allow the user to create:
- Rooms
- Items
- Quests
- Themes
Each tool has access to GPT through an API to help fill out and complete forms, with the option to retry specific fields or generate entirely new suggestions based on a saved theme.
The architecture is split into three main layers:
-
React UI:
- The user interacts with forms (room, item, quest creation) to input data.
- It communicates with the backend to request GPT assistance, save themes, and submit forms.
- GPT responses will be in a structured format (JSON) to allow easy population of form fields.
-
.NET 8 Web API Backend:
- Handles communication with OpenAI GPT, forwarding user inputs and themes.
- Manages the saving, loading, and application of themes to different requests.
- Handles authentication and data storage with MongoDB.
-
GPT Assistant Logic:
- Dynamically builds prompts based on the type of entity (room, item, quest) and the user’s partially filled data.
- Uses the selected theme to guide GPT’s output to match the dungeon world.
The UI will consist of the following React components:
-
ThemeManager: A component for creating and managing themes.
-
Features:
- Create and save a theme description (e.g., a dark, eerie world).
- Load a saved theme and apply it to form generation requests.
-
Features:
-
EntityForm: A form-based component for creating rooms, items, and quests.
-
Features:
- Dynamically adjust the form based on the selected entity type (room, item, quest).
- Fill out part of the form manually, then ask GPT to complete it.
- Regenerate individual fields with GPT assistance if the result is unsatisfactory.
-
Features:
-
GPTResponseViewer: A section to show GPT suggestions and allow the user to accept or reject the results.
We will design the following API endpoints in the .NET 8 Web API backend. These endpoints will handle session management, GPT interaction, and theme management.
-
POST
/theme/create
- Request:
{ "name": "Dark Dungeon", "description": "This theme is for a dark, eerie world filled with shadows and ancient curses." }
- Response:
{ "themeId": "uuid", "message": "Theme created successfully" }
-
GET
/theme/:themeId
-
Request:
{ themeId }
- Response:
{ "name": "Dark Dungeon", "description": "This theme is for a dark, eerie world..." }
-
Request:
-
POST
/gpt/fillForm
- Request:
{ "themeId": "uuid", "entityType": "room", "partialData": { "description": "A dimly lit cave" } }
- Response:
{ "filledData": { "name": "Forgotten Cavern", "description": "A cave with eerie sounds echoing through the corridors...", "items": ["Skeleton Key", "Ancient Scroll"] } }
-
POST
/gpt/retryField
- Request:
{ "themeId": "uuid", "entityType": "item", "field": "description", "currentData": "A rusty sword" }
- Response:
{ "newDescription": "An ancient sword with glowing runes carved into the blade" }
-
POST
/entity/save
(for rooms, items, or quests)- Request:
{ "entityType": "item", "data": { "name": "Sword of Dawn", "description": "A sword with a shimmering blade that glows in darkness..." } }
- Response:
{ "entityId": "uuid", "message": "Item saved successfully" }
When a user submits partially filled data, the backend constructs a dynamic prompt for GPT based on the theme and entity type.
Theme: Dark Dungeon
User Input: { "description": "A dimly lit cave with echoes of dripping water." }
GPT Task: Based on the theme and user input, generate a complete room description.
This prompt helps GPT to align the generated content with the current dungeon theme.
In React, Axios can be used for API communication. Here’s how the GPT request and form submission would work.
import axios from 'axios';
export const fillFormWithGPT = async (themeId, entityType, partialData) => {
const response = await axios.post('/gpt/fillForm', {
themeId,
entityType,
partialData
});
return response.data;
};
The response from this API will contain the filled form data, which can be used to update the UI.
Below is a general structure for the .NET 8 Web API:
- Install Firebase SDK for .NET and integrate Firebase authentication.
- Apply
[Authorize]
attributes to secure endpoints.
Use MongoDB for storing themes, rooms, items, and quests.
[HttpPost("gpt/fillForm")]
public async Task<IActionResult> FillFormWithGPT([FromBody] GPTFormRequest request)
{
var theme = await _themeService.GetThemeById(request.ThemeId);
var prompt = _promptBuilder.BuildPrompt(request.EntityType, request.PartialData, theme);
var gptResponse = await _gptService.GenerateContent(prompt);
return Ok(new { filledData = gptResponse });
}
public class CodeStore
{
[BsonId]
public ObjectId Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string UserId { get; set; }
public DateTime Created { get; set; }
public DateTime LastModified { get; set; }
public List<CodeFile> CodeFiles { get; set; } = new List<CodeFile>();
public SupportedLanguages Language { get; set; }
}
This example demonstrates how we can store rooms, items, and quests in MongoDB.
-
Create Theme: Owners can create a theme using the
ThemeManager
component. The theme is saved in MongoDB via the backend. - Partially Fill Form: The user partially fills out a form (room, item, quest).
-
Call GPT: A request is sent to GPT through the
/gpt/fillForm
endpoint. - Display GPT Results: The returned data is used to populate the form.
-
Save the Entity: The user can save the generated content to MongoDB through the
/entity/save
endpoint.
- Frontend: React (with Axios for API calls).
- Backend: .NET 8 Web API with Firebase for authentication.
- Database: MongoDB for storing themes, rooms, items, and quests.
- AI Integration: OpenAI GPT API for generating content.
This architecture provides flexibility for admins and owners to interact with GPT dynamically while managing the game’s content creation tools.