-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingViewer.html
More file actions
436 lines (372 loc) · 14.8 KB
/
SettingViewer.html
File metadata and controls
436 lines (372 loc) · 14.8 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>ARK Ascended Config Editor</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
padding: 2rem;
}
textarea {
font-family: monospace;
width: 100%;
min-height: 300px;
resize: vertical;
}
table th, table td {
text-align: center;
vertical-align: middle;
}
.ini-pair {
display: flex;
gap: 1rem;
flex-wrap: wrap;
}
.ini-box {
flex: 1 1 48%;
}
details summary {
cursor: pointer;
}
.dropzone {
border: 2px dashed #ccc;
padding: 0.5rem;
border-radius: 5px;
}
.dropzone.dragover {
background-color: #e6f7ff;
border-color: #007bff;
}
</style>
</head>
<body>
<div class="container">
<h1 class="mb-4">ARK Ascended Config Editor</h1>
<!-- Dual INI Editors with dropdown inside details -->
<details class="dropzone mb-4" id="drop-zone">
<summary><strong>ARK Configuration Files (.ini)</strong></summary>
<!-- Dropdown dynamically populated -->
<div class="mt-3">
<label for="configSelect" class="form-label"><strong>Select Exiting Configuration:</strong></label>
<select id="configSelect" class="form-select" aria-label="Select Exiting Configuration">
<option value="">-- Select configuration --</option>
<!-- options populated by JS -->
</select>
</div>
<div class="ini-pair mt-3">
<div class="ini-box" id="drop-user-settings">
<h6>GameUserSettings.ini</h6>
<textarea id="iniContent1" placeholder="Drop or paste GameUserSettings.ini here..."></textarea>
</div>
<div class="ini-box" id="drop-game-ini">
<h6>Game.ini</h6>
<textarea id="iniContent2" placeholder="Drop or paste Game.ini here..."></textarea>
</div>
</div>
</details>
<button class="btn btn-secondary mb-3" id="copyMarkdownBtn">Copy Tables as Markdown</button>
<div id="results"></div>
</div>
<!-- Toast container -->
<div class="position-fixed top-0 end-0 p-3" style="z-index: 1100">
<div id="errorToast" class="toast align-items-center text-bg-danger border-0" role="alert">
<div class="d-flex">
<div class="toast-body" id="toastMessage">Error message here</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast"
aria-label="Close"></button>
</div>
</div>
</div>
<!-- Formula Warning Modal -->
<div class="modal fade" id="formulaModal" tabindex="-1" aria-labelledby="formulaModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content border-warning">
<div class="modal-header bg-warning text-dark">
<h5 class="modal-title" id="formulaModalLabel">Heads up!</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
The time formulas used here are not final or verified. Results may not match in-game behavior yet.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-warning" data-bs-dismiss="modal">Got it</button>
</div>
</div>
</div>
</div>
<script>
const dinos = [
{name: "Parasaur", baseTame: 300, baseBreed: 1800},
{name: "Argentavis", baseTame: 900, baseBreed: 7200},
{name: "Ankylosaurus", baseTame: 900, baseBreed: 7200},
{name: "T-Rex", baseTame: 1800, baseBreed: 14400},
{name: "Giganotosaurus", baseTame: 3600, baseBreed: 28800}
];
const levels = [1, 50, 100, 150];
function parseMultipliers(iniText) {
const lines = iniText.split(/\r?\n/);
const multipliers = {
TamingSpeedMultiplier: 1,
MatingIntervalMultiplier: 1,
EggHatchSpeedMultiplier: 1,
BabyMatureSpeedMultiplier: 1
};
for (const line of lines) {
for (const key in multipliers) {
if (line.trim().startsWith("#")) {
continue;
}
if (line.trim().startsWith("[")) {
continue;
}
if (line.includes(key)) {
const match = line.match(/=(.+)/);
if (match) {
multipliers[key] = parseFloat(match[1]);
}
}
}
}
return multipliers;
}
function createTable(title, data) {
let html = `<h4 class="mt-4">${title}</h4>`;
html += `<table class="table table-bordered table-striped"><thead><tr><th>Dino</th>`;
levels.forEach(lvl => html += `<th>Lvl ${lvl}</th>`);
html += '</tr></thead><tbody>';
data.forEach(row => {
html += `<tr><td>${row.dino}</td>`;
levels.forEach(lvl => html += `<td>${row.values[lvl]}</td>`);
html += '</tr>';
});
html += '</tbody></table>';
return html;
}
function calculate() {
const ini1 = document.getElementById('iniContent1').value.trim();
const ini2 = document.getElementById('iniContent2').value.trim();
const configText = ini1 + "\n" + ini2;
const m = parseMultipliers(configText);
const tables = {
tamingTime: {
header: "Taming Time",
values: [],
formula: (dino, lvl) => (dino.baseTame + lvl * 2) / m.TamingSpeedMultiplier
},
breadingTime: {
header: "Breeding Time",
values: [],
formula: (dino, lvl) => (dino.baseBreed + lvl * 5) / (m.BabyMatureSpeedMultiplier * m.EggHatchSpeedMultiplier)
},
maturationTime: {
header: "Maturation Time",
values: [],
formula: (dino, lvl) => dino.baseBreed / m.BabyMatureSpeedMultiplier
}
};
dinos.forEach(dino => {
for (const table of Object.values(tables)) {
const row = { dino: dino.name, values: {} };
levels.forEach(lvl => {
row.values[lvl] = formatTime(table.formula(dino, lvl));
});
table.values.push(row);
}
});
let resultHtml = '';
for (const table of Object.values(tables)) {
resultHtml += createTable(table.header, table.values);
}
document.getElementById('results').innerHTML = resultHtml;
}
function formatTime(seconds) {
if (seconds < 1) {
// Show milliseconds with no decimals
return `${Math.round(seconds * 1000)}ms`;
}
if (seconds < 60) {
// Show seconds with no decimals
return `${Math.round(seconds)}s`;
}
const totalMinutes = Math.round(seconds / 60);
if (totalMinutes < 60) {
return `${totalMinutes}m`;
}
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
return minutes > 0 ? `${hours}h ${minutes}m` : `${hours}h`;
}
function handleDrop(zone, textarea) {
zone.addEventListener('dragover', e => {
e.preventDefault();
zone.classList.add('dragover');
});
zone.addEventListener('dragleave', () => {
zone.classList.remove('dragover');
});
zone.addEventListener('drop', e => {
e.preventDefault();
zone.classList.remove('dragover');
// Loop over all dropped files
for (const file of e.dataTransfer.files) {
const reader = new FileReader();
reader.onload = function (e) {
const content = e.target.result;
const fileName = file.name.toLowerCase();
if (fileName === "gameusersettings.ini") {
document.getElementById('iniContent1').value = content;
} else if (fileName === "game.ini") {
document.getElementById('iniContent2').value = content;
} else {
showToast("Unsupported file: " + file.name);
}
};
reader.readAsText(file);
}
});
}
document.getElementById('copyMarkdownBtn').addEventListener('click', () => {
const resultsDiv = document.getElementById('results');
if (!resultsDiv.innerHTML.trim()) {
showToast("No tables to copy!");
return;
}
let markdown = '';
// For each table group: find <h4> title + <table>
const sections = resultsDiv.querySelectorAll('h4');
sections.forEach(header => {
const table = header.nextElementSibling;
if (table && table.tagName === 'TABLE') {
markdown += `### ${header.textContent.trim()}\n\n`;
markdown += tableToMarkdown(table);
markdown += '\n\n';
}
});
// Copy to clipboard
navigator.clipboard.writeText(markdown).then(() => {
showToast("Markdown copied to clipboard!", "success");
}).catch(() => {
showToast("Failed to copy markdown.", "error");
});
});
function tableToMarkdown(table) {
// Get headers and rows as arrays of strings
const headers = Array.from(table.querySelectorAll('thead th')).map(th => th.textContent.trim());
const rows = Array.from(table.querySelectorAll('tbody tr')).map(tr =>
Array.from(tr.querySelectorAll('td')).map(td => td.textContent.trim())
);
// Calculate max width for each column
const colCount = headers.length;
const colWidths = new Array(colCount).fill(0);
// Check header widths
headers.forEach((h, i) => {
if (h.length > colWidths[i]) colWidths[i] = h.length;
});
// Check row widths
rows.forEach(row => {
row.forEach((cell, i) => {
if (cell.length > colWidths[i]) colWidths[i] = cell.length;
});
});
// Helper to pad a cell string with spaces on right
function padCell(str, width) {
return str + ' '.repeat(width - str.length);
}
// Build markdown header line
let md = '| ' + headers.map((h, i) => padCell(h, colWidths[i])).join(' | ') + ' |\n';
// Build separator line
md += '| ' + colWidths.map(w => '-'.repeat(w)).join(' | ') + ' |\n';
// Build each row
rows.forEach(row => {
md += '| ' + row.map((cell, i) => padCell(cell, colWidths[i])).join(' | ') + ' |\n';
});
return md;
}
function showToast(message, style = 'error') {
const toastElement = document.getElementById('errorToast');
const toastMessage = document.getElementById('toastMessage');
// Remove any previous bg color classes
toastElement.classList.remove('text-bg-danger', 'text-bg-success', 'text-bg-info', 'text-bg-warning');
// Add new style class based on input
switch (style.toLowerCase()) {
case 'success':
toastElement.classList.add('text-bg-success');
break;
case 'info':
toastElement.classList.add('text-bg-info');
break;
case 'warning':
toastElement.classList.add('text-bg-warning');
break;
case 'error':
default:
toastElement.classList.add('text-bg-danger');
break;
}
toastMessage.textContent = message;
const toast = new bootstrap.Toast(toastElement);
toast.show();
}
// Populate dropdown dynamically
function populateConfigSelector() {
const select = document.getElementById('configSelect');
const folders = [
"Default",
];
folders.forEach(folder => {
const option = document.createElement('option');
option.value = folder;
option.textContent = folder;
select.appendChild(option);
});
}
// Add new event listener for config dropdown
document.getElementById('configSelect').addEventListener('change', async function() {
const folder = this.value;
if (!folder) {
// Clear textareas when no selection
document.getElementById('iniContent1').value = '';
document.getElementById('iniContent2').value = '';
return;
}
try {
// Fetch both ini files from the folder
const [gusResponse, gameResponse] = await Promise.all([
fetch(`SurvivalAscended/${folder}/GameUserSettings.ini`),
fetch(`SurvivalAscended/${folder}/Game.ini`)
]);
if (!gusResponse.ok || !gameResponse.ok) {
showToast("Failed to load config files.", "error");
return
}
const gusText = await gusResponse.text();
const gameText = await gameResponse.text();
document.getElementById('iniContent1').value = gusText;
document.getElementById('iniContent2').value = gameText;
// Trigger recalculation
document.getElementById('iniContent1').dispatchEvent(new Event('input'));
document.getElementById('iniContent2').dispatchEvent(new Event('input'));
} catch (error) {
showToast(error.message || "Failed to load config files.");
}
});
// Activate drop zones
handleDrop(document.getElementById('drop-user-settings'), 'iniContent1');
handleDrop(document.getElementById('drop-game-ini'), 'iniContent2');
document.getElementById('iniContent1').addEventListener('input', calculate);
document.getElementById('iniContent2').addEventListener('input', calculate);
window.addEventListener('DOMContentLoaded', () => {
calculate();
populateConfigSelector();
const modal = new bootstrap.Modal(document.getElementById('formulaModal'), {
backdrop: 'static',
keyboard: false
});
modal.show();
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>