MelkortheCorrupt
D&D Character Creator and Campaign Assistant
b197a8c
raw
history blame
2.82 kB
# components/campaign.py
import gradio as gr
from datetime import datetime
import json
import os
# Placeholder logic; replace with your own AI integration
def generate_campaign_concept(theme, level, players):
return f"**Campaign Theme:** {theme}\n**Starting Level:** {level}\n**Party Size:** {players}\n\nA mysterious prophecy drives the PCs into lost lands..."
def generate_session_content(campaign_summary, session_number):
return f"**Session {session_number} Outline:**\nThe heroes investigate a hidden temple, encounter guardians, and uncover a lost relic."
def save_to_gallery(content_type: str, data: dict, image_path=None):
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
os.makedirs("gallery", exist_ok=True)
filename = f"gallery/{content_type}_{timestamp}.json"
with open(filename, "w") as f:
json.dump({"type": content_type, "data": data, "image": image_path}, f, indent=2)
def campaign_tab():
with gr.TabItem("🎲 Campaign Planner"):
with gr.Row():
with gr.Column():
theme = gr.Dropdown(label="Campaign Theme", choices=["High Fantasy", "Dark Fantasy", "Mystery", "Political Intrigue"], value="High Fantasy")
level = gr.Slider(label="Starting Level", minimum=1, maximum=20, step=1, value=5)
players = gr.Slider(label="Party Size", minimum=1, maximum=8, step=1, value=4)
gen_campaign_btn = gr.Button("🎯 Generate Campaign Concept")
campaign_output = gr.Markdown(label="Campaign Summary")
session_num = gr.Slider(label="Session Number", minimum=1, maximum=20, step=1, value=1)
gen_session_btn = gr.Button("πŸ“ Generate Session Outline")
session_output = gr.Markdown(label="Session Outline")
with gr.Column():
export_campaign = gr.Button("πŸ’Ύ Save Campaign to Gallery")
export_campaign_output = gr.Textbox(label="Export Status")
# Actions
gen_campaign_btn.click(
generate_campaign_concept,
inputs=[theme, level, players],
outputs=[campaign_output]
)
gen_session_btn.click(
generate_session_content,
inputs=[campaign_output, session_num],
outputs=[session_output]
)
export_campaign.click(
lambda th, lv, pl, camp: save_to_gallery(
"campaign",
{
"theme": th,
"level": lv,
"players": pl,
"campaign_summary": camp
}
) or "βœ… Campaign saved!",
inputs=[theme, level, players, campaign_output],
outputs=[export_campaign_output]
)