web interface holy FUCK

This commit is contained in:
Jill 2023-11-18 02:55:39 +03:00
parent eb1dd27d6b
commit 3da36de9f6
Signed by: oat
GPG Key ID: 33489AA58A955108
7 changed files with 394 additions and 4 deletions

View File

@ -23,7 +23,7 @@ export default {
if (sub === 'create') {
interaction.reply({
ephemeral: true,
content: `To create a recipe, go here: ${interaction.client.config.siteURL}/create-recipe/\nOnce done, click the button below and paste the resulting string in.`
content: `To create a recipe, go here: ${interaction.client.config.siteURL}/create-recipe/?guild=${interaction.guildId}\nOnce done, click the button below and paste the resulting string in.`
});
}
}

View File

@ -1,10 +1,28 @@
import express from 'express';
import * as log from './lib/log';
import { CustomItem, db } from './lib/db';
import { defaultItems } from './lib/rpg/items';
export async function startServer(port: number) {
const app = express();
app.use(express.static('static/'));
app.get('/api/items', async (req, res) => {
const guildID = req.query.guild;
let customItems : Partial<CustomItem>[];
if (guildID) {
customItems = await db<CustomItem>('customItems')
.select('emoji', 'name', 'id', 'description')
.where('guild', guildID)
.limit(25);
} else {
customItems = [];
}
res.json([...defaultItems, ...customItems]);
});
app.listen(port, () => log.info(`web interface listening on ${port}`));
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

View File

@ -1 +1,58 @@
hi
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>jillo</title>
<meta name="theme-color" content="light dark">
<link href="/style.css" rel="stylesheet">
<link rel="shortcut icon" href="/favicon.ico">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Balsamiq+Sans&display=swap" rel="stylesheet">
<script src="/create-recipe/script.js"></script>
</head>
<body>
<div id="content">
<div class="header">
<div class="bg"></div>
<div class="left">
<a href="/">jillo</a>
</div>
<div class="links">
<a href="https://discord.com/oauth2/authorize?client_id=898850107892596776&scope=bot" target="_blank" rel="noopener">invite</a>
&middot;
<a href="https://git.oat.zone/dark-firepit/jillo-bot" target="_blank" rel="noopener">repo</a>
<img src="/assets/jillo_small.png">
</div>
</div>
<h1>Recipe Creator</h1>
<div class="items">
loading available items...
</div>
<p class="note">Drag items from above into the below lists:</p>
<h2>Inputs <span class="subtitle">Ingredients necessary to create the outputs</span></h2>
<div class="item-list" data-type="inputs">
</div>
<h2>Requirements <span class="subtitle">Unlike inputs, these are not consumed, but are necessary</span></h2>
<div class="item-list" data-type="requirements">
</div>
<h2>Outputs <span class="subtitle">The result of the recipe</span></h2>
<div class="item-list" data-type="outputs">
</div>
<p class="note">Drag an item out of the list in order to remove it</p>
<h1>Recipe string</h1>
<pre id="recipe-string"></pre>
Copy-paste this into Jillo to create your recipe
</div>
</body>
</html>

View File

@ -0,0 +1,145 @@
let resolveLoaded;
const loaded = new Promise(resolve => resolveLoaded = resolve);
function e(unsafeText) {
let div = document.createElement('div');
div.innerText = unsafeText;
return div.innerHTML;
}
/**
* @type {import('../../src/lib/rpg/items').Item | null}
*/
let draggedItem = null;
/**
* @type {Record<string, import('../../src/lib/rpg/items').Items[]>}
*/
let itemLists = {};
function listToString(list) {
return list.map(stack => `${stack.item.id},${stack.quantity}`).join(';');
}
function updateString() {
document.querySelector('#recipe-string').innerText = [
listToString(itemLists['inputs'] || []),
listToString(itemLists['requirements'] || []),
listToString(itemLists['outputs'] || []),
].join('|');
}
/**
* @param {import('../../src/lib/rpg/items').Item} item
*/
function renderItem(item) {
const i = document.createElement('div');
i.innerHTML = `
<div class="icon">
${e(item.emoji)}
</div>
<div class="right">
<div class="name">${e(item.name)}</div>
<div class="description">${item.description ? e(item.description) : '<i>No description</i>'}</div>
</div>
`;
i.classList.add('item');
i.draggable = true;
i.addEventListener('dragstart', event => {
draggedItem = item;
event.target.classList.add('dragging');
});
i.addEventListener('dragend', event => {
draggedItem = null;
event.target.classList.remove('dragging');
});
return i;
}
function renderItemStack(item, quantity, type) {
const i = document.createElement('div');
i.innerHTML = `
<div class="icon">
${e(item.emoji)}
</div>
<div class="right">
x<b>${quantity}</b>
</div>
`;
i.classList.add('itemstack');
i.draggable = true;
i.addEventListener('dragstart', event => {
event.target.classList.add('dragging');
});
i.addEventListener('dragend', event => {
event.target.classList.remove('dragging');
itemLists[type] = itemLists[type] || [];
const items = itemLists[type];
const stackIdx = items.findIndex(n => n.item.id === item.id);
if (stackIdx !== -1) items.splice(stackIdx, 1);
document.querySelector(`.item-list[data-type="${type}"]`).replaceWith(renderItemList(items, type));
updateString();
});
return i;
}
function renderItemList(items, type) {
const i = document.createElement('div');
i.textContent = '';
items.forEach(itemStack => {
i.appendChild(renderItemStack(itemStack.item, itemStack.quantity, type));
});
i.dataset.type = type;
i.classList.add('item-list');
// prevent default to allow drop
i.addEventListener('dragover', (event) => event.preventDefault(), false);
i.addEventListener('dragenter', event => draggedItem && event.target.classList.add('dropping'));
i.addEventListener('dragleave', event => draggedItem && event.target.classList.remove('dropping'));
i.addEventListener('drop', (event) => {
event.preventDefault();
event.target.classList.remove('dropping');
if (!draggedItem) return;
itemLists[type] = itemLists[type] || [];
const items = itemLists[type];
const itemStack = items.find(v => v.item.id === draggedItem.id);
if (!itemStack) {
items.push({
item: draggedItem,
quantity: 1
});
} else {
itemStack.quantity = itemStack.quantity + 1;
}
updateString();
draggedItem = null;
event.target.replaceWith(renderItemList(items, type));
});
return i;
}
Promise.all([
fetch(`/api/items${document.location.search}`)
.then(res => res.json()),
loaded
]).then(items => {
const itemsContainer = document.querySelector('.items');
itemsContainer.textContent = '';
items[0].forEach(item =>
itemsContainer.appendChild(renderItem(item))
);
document.querySelectorAll('.item-list').forEach(elem => {
const type = elem.dataset.type;
elem.replaceWith(renderItemList([], type));
});
updateString();
});
document.addEventListener('DOMContentLoaded', () => resolveLoaded());

BIN
static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -11,10 +11,9 @@ body {
font-family: 'Balsamiq Sans', sans-serif;
font-weight: 300;
width: 100%;
min-height: 100vh;
text-underline-offset: 3px;
font-size: 16px;
color-scheme: dark;
color-scheme: light dark;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
@ -23,13 +22,19 @@ body {
:root {
--text-color: #111;
--text-color-light: #444;
--background-color: #fefefd;
--background-color-dark: #fafafb;
--background-color-dark-2: #f8f8f9;
}
@media (prefers-color-scheme: dark) {
:root {
--text-color: #eee;
--text-color-light: #aaa;
--background-color: #111110;
--background-color-dark: #151514;
--background-color-dark-2: #171718;
}
}
@ -77,4 +82,169 @@ a:hover {
@keyframes popup {
0% { transform: scale(0) rotate(40deg) }
100% { transform: scale(1) rotate(0deg) }
}
#content {
max-width: 1000px;
width: 100%;
margin: auto;
margin-bottom: 6rem;
}
.header {
height: 3rem;
display: flex;
align-items: stretch;
padding: 0rem 1rem;
flex-direction: row;
text-shadow: 2px 2px 2px #000000;
margin-bottom: 2rem;
}
.header .bg {
position: absolute;
left: 0%;
right: 0%;
height: 3rem;
background: linear-gradient(#444, #222);
z-index: -1;
border-bottom: 2px ridge #aaa;
}
.header .left {
font-size: 1.5rem;
flex: 1 1 0px;
display: flex;
align-items: center;
}
.header .left a {
text-decoration: none !important;
color: #fff;
}
.header .links {
flex: 0 0 auto;
text-align: right;
display: flex;
flex-direction: row;
align-items: center;
gap: 0.25rem;
}
.header .links img {
display: block;
width: auto;
height: 100%;
}
.items {
max-width: 500px;
padding: 1em;
height: 200px;
overflow: auto;
background: linear-gradient(var(--background-color-dark), var(--background-color-dark-2));
border-radius: 1em;
display: flex;
flex-direction: column;
}
.item {
display: flex;
flex-direction: row;
height: 3rem;
gap: 0.5rem;
outline: 0px solid rgba(255, 255, 255, 0.0);
transition: outline 0.1s;
padding: 0.5rem;
border-radius: 2rem;
cursor: grab;
}
.item:hover {
outline: 1px solid var(--text-color-light);
}
.item.dragging {
outline: 2px dashed var(--text-color-light);
transition: none;
background-color: var(--background-color);
}
.item .icon {
flex: 0 0 auto;
font-size: 1rem;
line-height: 1;
background-color: rgba(199, 199, 199, 0.25);
border-radius: 4rem;
display: flex;
align-items: center;
justify-content: center;
aspect-ratio: 1 / 1;
user-select: none;
}
.item .right {
flex: 1 1 0px;
display: flex;
flex-direction: column;
line-height: 1;
}
.item .right, .item .right > * {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
.item .right .description {
font-size: 75%;
color: var(--text-color-light);
}
.item-list {
min-height: 2rem;
display: flex;
flex-direction: row;
flex-wrap: wrap;
}
.item-list.dropping::after {
display: flex;
align-items: center;
justify-content: center;
content: '+';
height: 1.5rem;
width: 1.5rem;
outline: 2px dashed var(--text-color-light);
border-radius: 2rem;
padding: 0.5rem;
margin: 0.25rem;
}
.itemstack {
display: flex;
align-items: center;
height: 1.5rem;
line-height: 1;
padding: 0.5rem;
margin: 0.25rem;
outline: 1px solid var(--text-color-light);
background-color: var(--background-color-dark);
border-radius: 2rem;
gap: 0.5rem;
}
.itemstack.dragging {
outline: 2px dashed var(--text-color-light);
transition: none;
background-color: var(--background-color);
}
.subtitle {
color: var(--text-color-light);
font-size: 1rem;
font-weight: normal;
margin-left: 0.5rem;
}
.subtitle::before {
content: '·';
margin-right: 0.5rem;
}
pre {
background: linear-gradient(var(--background-color-dark), var(--background-color-dark-2));
overflow: auto;
word-break: normal;
padding: 0.5rem;
}
.note {
font-style: italic;
color: var(--text-color-light);
}