generated from Anonventions/textgenerator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
496 lines (452 loc) · 18.9 KB
/
index.html
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ItemsAdder Crafting Configurator</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');
body {
font-family: 'Press Start 2P', sans-serif;
margin: 0;
padding: 0;
background: url('https://i.pinimg.com/originals/2d/a3/8e/2da38eeb76f29c28b4909389fe77ecd2.gif') no-repeat center center fixed;
background-size: cover;
color: #dcdcdc;
display: flex;
flex-direction: column;
align-items: center;
min-height: 100vh;
box-sizing: border-box;
padding: 20px;
}
header {
background-color: #333;
color: #00ff00;
text-align: center;
padding: 10px 20px;
border-radius: 8px;
margin-bottom: 20px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
width: 100%;
max-width: 1000px;
}
h1 {
margin: 0;
font-size: 1.5em;
font-family: 'Press Start 2P', sans-serif;
color: #00ff00;
}
.main-content {
display: flex;
gap: 20px;
width: 100%;
max-width: 1000px;
}
.left-column, .right-column {
flex: 1;
background-color: rgba(40, 40, 40, 0.9);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
border-radius: 8px;
padding: 20px;
display: flex;
flex-direction: column;
gap: 20px;
}
h2 {
font-size: 1.2em;
margin-bottom: 10px;
border-bottom: 1px solid #444;
padding-bottom: 5px;
}
.form-group {
position: relative;
margin-bottom: 15px;
}
.form-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
color: #ffffff;
}
.form-group input, .form-group select {
width: 100%;
padding: 8px;
box-sizing: border-box;
border: 1px solid #555;
border-radius: 4px;
background-color: #444;
color: #dcdcdc;
}
.form-group .tooltip {
visibility: hidden;
width: 200px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 5px;
position: absolute;
z-index: 1;
bottom: 125%; /* Position above the input */
left: 50%;
margin-left: -100px; /* Use half of the width to center it */
opacity: 0;
transition: opacity 0.3s;
font-size: 0.8em;
}
.form-group:hover .tooltip {
visibility: visible;
opacity: 1;
}
.grid-container {
display: grid;
grid-template-columns: repeat(3, 60px);
grid-template-rows: repeat(3, 60px);
gap: 3px;
justify-content: center;
margin: 5px 0;
padding: 5px;
background-color: #2b2b2b;
border-radius: 4px;
}
.grid-cell {
width: 60px;
height: 60px;
border: 1px solid #555;
display: flex;
justify-content: center;
align-items: center;
background-color: #3c3c3c;
cursor: pointer;
transition: background-color 0.3s;
font-size: 1em;
font-family: 'Press Start 2P', sans-serif;
color: #fff;
}
.grid-cell:hover {
background-color: #4c4c4c;
}
.ingredients-container {
position: relative;
height: 200px;
overflow-y: auto;
padding: 5px;
border: 1px solid #555;
border-radius: 8px;
background-color: #2b2b2b;
}
.item-list {
display: flex;
flex-direction: column;
gap: 5px;
}
.item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 5px;
border: 1px solid #555;
border-radius: 4px;
background-color: #444;
cursor: grab;
transition: background-color 0.3s, transform 0.3s;
font-size: 0.8em;
position: relative;
}
.item .item-letter {
width: 20px;
height: 20px;
background-color: #555;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
color: #fff;
margin-right: 5px;
}
.item .item-name {
display: none;
position: absolute;
left: 40px;
background-color: #444;
padding: 2px 5px;
border-radius: 4px;
white-space: nowrap;
}
.item:hover .item-name {
display: block;
}
.item:hover {
background-color: #555;
transform: scale(1.05);
}
.btn {
padding: 8px 16px;
border: none;
border-radius: 4px;
background-color: #4CAF50;
color: white;
font-size: 0.8em;
cursor: pointer;
transition: background-color 0.3s;
font-family: 'Press Start 2P', sans-serif;
}
.btn:hover {
background-color: #45a049;
}
#config-output {
background-color: #1e1e1e;
border: 1px solid #444;
padding: 8px;
white-space: pre-wrap;
overflow-x: auto;
max-height: 150px;
color: #f1f1f1;
font-family: 'Courier New', Courier, monospace;
margin-top: 15px;
}
.actions {
margin-top: 15px;
}
</style>
</head>
<body>
<header>
<h1>ItemsAdder Crafting Configurator</h1>
</header>
<div class="main-content">
<div class="left-column">
<section id="config-options">
<h2>Configuration</h2>
<div class="form-group">
<label for="namespace">Namespace:</label>
<input type="text" id="namespace" placeholder="e.g., myitems">
<span class="tooltip">Specify the namespace for the configuration.</span>
</div>
<div class="form-group">
<label for="recipe-key">Recipe Key:</label>
<input type="text" id="recipe-key" placeholder="e.g., item_name">
<span class="tooltip">Unique key for the recipe.</span>
</div>
<div class="form-group">
<label for="enabled">Enabled:</label>
<select id="enabled">
<option value="true">True</option>
<option value="false">False</option>
</select>
<span class="tooltip">Enable or disable the recipe.</span>
</div>
<div id="output-section">
<h2>Generated Config</h2>
<pre id="config-output"></pre>
</div>
<div class="actions">
<button id="generate-config" class="btn">Generate Config</button>
</div>
</section>
</div>
<div class="right-column">
<section id="ingredient-location-section">
<h2>Ingredient Location:</h2>
<div class="form-group">
<input type="text" id="ingredient-location" placeholder="e.g., itemsadder">
<span class="tooltip">Specify the default location for ingredients. If not set, it will be empty.</span>
</div>
</section>
<section id="crafting-section">
<h2>Crafting Grid</h2>
<div class="grid-container">
<div class="grid-cell" data-row="1" data-col="1"></div>
<div class="grid-cell" data-row="1" data-col="2"></div>
<div class="grid-cell" data-row="1" data-col="3"></div>
<div class="grid-cell" data-row="2" data-col="1"></div>
<div class="grid-cell" data-row="2" data-col="2"></div>
<div class="grid-cell" data-row="2" data-col="3"></div>
<div class="grid-cell" data-row="3" data-col="1"></div>
<div class="grid-cell" data-row="3" data-col="2"></div>
<div class="grid-cell" data-row="3" data-col="3"></div>
</div>
</section>
</section>
<section id="items-container">
<h2>Available Items</h2>
<div class="ingredients-container">
<input type="text" id="ingredient-search" placeholder="Search Ingredients..." style="width: 100%; padding: 5px; margin-bottom: 5px;">
<div class="item-list" id="item-list">
<div class="item card" draggable="true" data-item="Example" data-letter="X">
<div class="item-letter">X</div>
<div class="item-name">Example</div>
</div>
</div>
</div>
<div id="add-item">
<h3>Add Ingredient</h3>
<div class="form-group">
<input type="text" id="item-name" placeholder="Ingredient Name [e.g., itemsadder:taco_shell]">
</div>
<div class="form-group">
<input type="text" id="item-letter" maxlength="1" placeholder="A">
</div>
<button id="add-item-button" class="btn">Add Item</button>
</div>
</section>
<section id="upload-section">
<h2>Upload Ingredient JSONs:</h2>
<div class="form-group">
<input type="file" id="json-upload" accept=".json" multiple>
<span class="tooltip">Upload .json files to add ingredients. The filename determines the ingredient name.</span>
</div>
<section id="result-section">
<h2>Result</h2>
<div class="form-group">
<label for="result-amount">Amount:</label>
<input type="number" id="result-amount" value="1" min="1">
<span class="tooltip">Specify the amount of the resulting item.</span>
</div>
</section>
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const gridCells = document.querySelectorAll(".grid-cell");
let draggedItem = null;
// Drag and drop functionality
document.addEventListener("dragstart", (e) => {
if (e.target.classList.contains("item")) {
draggedItem = e.target;
}
});
gridCells.forEach(cell => {
cell.addEventListener("dragover", (e) => {
e.preventDefault();
});
cell.addEventListener("drop", (e) => {
e.preventDefault();
if (draggedItem) {
const letter = draggedItem.getAttribute("data-letter");
cell.textContent = letter;
cell.setAttribute("data-item", draggedItem.getAttribute("data-item"));
cell.setAttribute("data-letter", letter);
}
});
// Allow removing items from the grid by clicking
cell.addEventListener("click", () => {
cell.textContent = "";
cell.removeAttribute("data-item");
cell.removeAttribute("data-letter");
});
});
// Add new item manually
document.getElementById("add-item-button").addEventListener("click", () => {
const itemName = document.getElementById("item-name").value;
const itemLetter = document.getElementById("item-letter").value.toUpperCase();
const location = document.getElementById("ingredient-location").value.trim();
if (itemName && itemLetter) {
const fullItemName = location ? `${location}:${itemName}` : itemName;
addItemToList(fullItemName, itemLetter);
document.getElementById("item-name").value = "";
document.getElementById("item-letter").value = "";
} else {
alert('Please enter both item name and letter.');
}
});
// Handle JSON file upload
document.getElementById("json-upload").addEventListener("change", (event) => {
const files = event.target.files;
const location = document.getElementById("ingredient-location").value.trim();
const usedLetters = new Set();
Array.from(files).forEach(file => {
const reader = new FileReader();
reader.onload = () => {
const fileName = file.name.replace('.json', '');
const itemLetter = generateRandomLetter(usedLetters);
usedLetters.add(itemLetter);
const fullItemName = location ? `${location}:${fileName}` : fileName;
addItemToList(fullItemName, itemLetter);
};
reader.readAsText(file);
});
});
// Add item to list
function addItemToList(itemName, itemLetter) {
const newItem = document.createElement("div");
newItem.classList.add("item", "card");
newItem.setAttribute("draggable", "true");
newItem.setAttribute("data-item", itemName);
newItem.setAttribute("data-letter", itemLetter);
newItem.innerHTML = `<div class="item-letter">${itemLetter}</div><div class="item-name">${itemName}</div>`;
document.getElementById("item-list").appendChild(newItem);
}
// Generate random letter not used in the current ingredient list
function generateRandomLetter(usedLetters) {
const letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let letter;
do {
letter = letters[Math.floor(Math.random() * letters.length)];
} while (usedLetters.has(letter));
return letter;
}
// Generate configuration
document.getElementById("generate-config").addEventListener("click", () => {
const namespace = document.getElementById("namespace").value.trim();
const recipeKey = document.getElementById("recipe-key").value.trim();
const enabled = document.getElementById("enabled").value;
const resultAmount = document.getElementById("result-amount").value;
const location = document.getElementById("ingredient-location").value.trim();
const pattern = [];
const ingredients = {};
for (let row = 1; row <= 3; row++) {
let rowPattern = "";
for (let col = 1; col <= 3; col++) {
const cell = document.querySelector(`.grid-cell[data-row="${row}"][data-col="${col}"]`);
const letter = cell.getAttribute("data-letter");
if (letter) {
rowPattern += letter;
const itemName = cell.getAttribute("data-item");
if (!ingredients[letter]) {
ingredients[letter] = itemName;
}
} else {
rowPattern += "X";
}
}
pattern.push(rowPattern);
}
let resultItem = recipeKey;
if (namespace) {
resultItem = `${namespace}:${recipeKey}`;
} else if (location) {
resultItem = `${location}:${recipeKey}`;
}
const permission = `${location}.${recipeKey}`;
const configParts = [];
if (namespace) {
configParts.push(`info:\n namespace: ${namespace}`);
configParts.push(`recipes:`);
}
configParts.push(` crafting_table:\n ${recipeKey}:\n permission: ${permission}\n enabled: ${enabled}`);
configParts.push(` pattern:\n${pattern.map(line => ` - '${line}'`).join('\n')}`);
configParts.push(` ingredients:\n${Object.entries(ingredients).map(([key, value]) => ` ${key}: ${value}`).join('\n')}`);
configParts.push(` result:\n item: ${resultItem}\n amount: ${resultAmount}`);
const config = configParts.join('\n');
document.getElementById("config-output").textContent = config;
});
// Search functionality
document.getElementById("ingredient-search").addEventListener("input", (e) => {
const searchTerm = e.target.value.toLowerCase();
const items = document.querySelectorAll('.item');
items.forEach(item => {
const itemName = item.getAttribute('data-item').toLowerCase();
if (itemName.includes(searchTerm)) {
item.style.display = 'flex';
} else {
item.style.display = 'none';
}
});
});
});
</script>
</body>
</html>