-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgame-theme.html
More file actions
66 lines (58 loc) · 2.74 KB
/
Copy pathgame-theme.html
File metadata and controls
66 lines (58 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ADnDI - Game Theme</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
<h1>Game Theme</h1>
<div class="form-group">
<label for="customTheme">Write your own context (theme) for this game:</label>
<textarea id="customTheme" rows="5" placeholder="Describe the adventure setting, main conflict, or theme..."></textarea>
</div>
<div class="actions">
<button id="generateTheme" class="btn-primary" disabled>Generate created context</button>
<button id="useDefaultTheme" class="btn-secondary">Use random default context</button>
</div>
</div>
<script>
document.getElementById('customTheme').addEventListener('input', (e) => {
document.getElementById('generateTheme').disabled = e.target.value.trim() === '';
});
document.getElementById('generateTheme').addEventListener('click', () => {
const theme = document.getElementById('customTheme').value.trim();
localStorage.setItem('adndiTheme', theme);
localStorage.setItem('adndiThemeType', 'custom');
window.location.href = 'game.html';
});
document.getElementById('useDefaultTheme').addEventListener('click', async () => {
try {
// Generate a random default theme
const response = await fetch('http://localhost:3000/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: "hackathon/qwen3",
messages: [{
role: "user",
content: "Generate a random D&D adventure theme in one sentence. Just provide the theme description."
}],
temperature: 0.9
})
});
const data = await response.json();
const theme = data.choices?.[0]?.message?.content || "A mysterious dungeon full of treasures and dangers";
localStorage.setItem('adndiTheme', theme);
localStorage.setItem('adndiThemeType', 'default');
window.location.href = 'game.html';
} catch (error) {
console.error('Error generating default theme:', error);
alert('Failed to generate default theme. Please try again.');
}
});
</script>
</body>
</html>