mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-12 10:15:33 +02:00
Merge
This commit is contained in:
parent
f457a89c8e
commit
669144ccc1
2 changed files with 78 additions and 11 deletions
|
@ -4,6 +4,7 @@ import http from 'http';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import settings, { updateSettings } from '../../settings.js';
|
import settings, { updateSettings } from '../../settings.js';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
// Module-level variables
|
// Module-level variables
|
||||||
let io;
|
let io;
|
||||||
|
@ -132,11 +133,24 @@ export function createMindServer(port = 8080) {
|
||||||
|
|
||||||
socket.on('get-settings', (callback) => {
|
socket.on('get-settings', (callback) => {
|
||||||
callback(settings);
|
callback(settings);
|
||||||
})
|
});
|
||||||
|
|
||||||
socket.on('update-settings', (newSettings) => {
|
socket.on('update-settings', (newSettings) => {
|
||||||
updateSettings(newSettings);
|
updateSettings(newSettings);
|
||||||
})
|
});
|
||||||
|
|
||||||
|
socket.on('get-profile-dir', (callback) => {
|
||||||
|
const profileDir = path.join(__dirname, '../../profiles/');
|
||||||
|
fs.readdir(profileDir, (err, files) => {
|
||||||
|
if (err) {
|
||||||
|
console.error("Could not list the profiles.", err);
|
||||||
|
callback([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
const fileNames = files.filter(file => file.endsWith('.json')).map(file => './profiles/' + file);
|
||||||
|
callback(fileNames);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(port, 'localhost', () => {
|
server.listen(port, 'localhost', () => {
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Mindcraft</title>
|
<title>Mindcraft</title>
|
||||||
<script src="/socket.io/socket.io.js"></script>
|
<script src="/socket.io/socket.io.js"></script>
|
||||||
<link rel="stylesheet" type="text/css" href="/styles.css">
|
<link rel="stylesheet" type="text/css" href="/styles.css">
|
||||||
|
<meta viewport="width=device-width, initial-scale=1.0">
|
||||||
|
<meta charset="UTF-8">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Mindcraft</h1>
|
<h1>Mindcraft</h1>
|
||||||
|
@ -181,6 +183,14 @@
|
||||||
socket.emit('send-message', agentName, message)
|
socket.emit('send-message', agentName, message)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let pathProfiles;
|
||||||
|
function getProfilesFromPath() {
|
||||||
|
socket.emit('get-profile-dir', (response) => {
|
||||||
|
pathProfiles = response;
|
||||||
|
console.log(response);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function toggleSettings() {
|
function toggleSettings() {
|
||||||
document.getElementById("settingsContainer").style.display = document.getElementById("settingsContainer").style.display === "none" ? "block" : "none";
|
document.getElementById("settingsContainer").style.display = document.getElementById("settingsContainer").style.display === "none" ? "block" : "none";
|
||||||
document.getElementById("settingsToggler").innerText = document.getElementById("settingsToggler").innerText === "Show Settings" ? "Hide Settings" : "Show Settings";
|
document.getElementById("settingsToggler").innerText = document.getElementById("settingsToggler").innerText === "Show Settings" ? "Hide Settings" : "Show Settings";
|
||||||
|
@ -200,11 +210,37 @@
|
||||||
socket.emit('update-settings', newSettings);
|
socket.emit('update-settings', newSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateListItem(listId, listContent) {
|
function updateListItem(listId, listContent, enabled = true, clear = true) {
|
||||||
document.getElementById(listId).innerHTML = "";
|
if (clear) {
|
||||||
listContent.forEach(element => {
|
document.getElementById(listId).innerHTML = "";
|
||||||
addProfileItem(listId, element);
|
listContent.forEach(element => {
|
||||||
});
|
addProfileItem(listId, element, enabled);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const list = document.getElementById(listId);
|
||||||
|
const existingItemsDivs = document.querySelectorAll(`#${listId} .list-item`);
|
||||||
|
let existingItems = Array.from(existingItemsDivs)
|
||||||
|
.map(item => item.querySelector('input[type="text"]').value);
|
||||||
|
listContent.forEach(element => {
|
||||||
|
if (existingItems.includes(element)) {
|
||||||
|
const item = Array.from(list.querySelectorAll('.list-item'))
|
||||||
|
.find(item => item.querySelector('input[type="text"]').value === element);
|
||||||
|
if (item) {
|
||||||
|
console.log(`Setting this to ${enabled}: `)
|
||||||
|
const checkbox = item.querySelector('input[type="checkbox"]');
|
||||||
|
console.log(checkbox)
|
||||||
|
console.log(checkbox.checked)
|
||||||
|
checkbox.checked = enabled;
|
||||||
|
console.log("After: ")
|
||||||
|
console.log(checkbox.checked)
|
||||||
|
} else {
|
||||||
|
addProfileItem(listId, element, enabled);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
addProfileItem(listId, element, enabled);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateBooleanRadio(radioName, value) {
|
function updateBooleanRadio(radioName, value) {
|
||||||
|
@ -240,9 +276,21 @@
|
||||||
updateBooleanRadio("mcChatBotMessages", settings["chat_bot_messages"]);
|
updateBooleanRadio("mcChatBotMessages", settings["chat_bot_messages"]);
|
||||||
|
|
||||||
// array/list fields
|
// array/list fields
|
||||||
updateListItem("mcProfileList", settings["profiles"]);
|
|
||||||
updateListItem("mcBlockedActions", settings["blocked_actions"]);
|
updateListItem("mcBlockedActions", settings["blocked_actions"]);
|
||||||
updateListItem("mcOnlyChatWith", settings["only_chat_with"]);
|
updateListItem("mcOnlyChatWith", settings["only_chat_with"]);
|
||||||
|
|
||||||
|
// handling profiles is special
|
||||||
|
updateListItem("mcProfileList", settings["profiles"]);
|
||||||
|
pathProfiles = undefined;
|
||||||
|
getProfilesFromPath();
|
||||||
|
const intervalId = setInterval(() => {
|
||||||
|
if (pathProfiles !== undefined) {
|
||||||
|
clearInterval(intervalId);
|
||||||
|
updateListItem("mcProfileList", pathProfiles, enabled=false);
|
||||||
|
}
|
||||||
|
}, 50);
|
||||||
|
updateListItem("mcProfileList", settings["profiles"], enabled=true, clear = false);
|
||||||
|
console.log(`updated with ${settings["profiles"]}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNewSettings() {
|
function getNewSettings() {
|
||||||
|
@ -276,7 +324,7 @@
|
||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addProfileItem(listName, itemNameArg) {
|
function addProfileItem(listName, itemNameArg, enabled) {
|
||||||
const itemDiv = document.createElement('div');
|
const itemDiv = document.createElement('div');
|
||||||
itemDiv.className = 'list-item';
|
itemDiv.className = 'list-item';
|
||||||
|
|
||||||
|
@ -287,7 +335,12 @@
|
||||||
|
|
||||||
const itemCheckbox = document.createElement('input');
|
const itemCheckbox = document.createElement('input');
|
||||||
itemCheckbox.type = 'checkbox';
|
itemCheckbox.type = 'checkbox';
|
||||||
itemCheckbox.checked = true;
|
itemCheckbox.checked = enabled;
|
||||||
|
if (itemCheckbox.checked) {
|
||||||
|
itemName.classList.remove('not-selected');
|
||||||
|
} else {
|
||||||
|
itemName.classList.add('not-selected');
|
||||||
|
}
|
||||||
itemCheckbox.onchange = function() {
|
itemCheckbox.onchange = function() {
|
||||||
if (itemCheckbox.checked) {
|
if (itemCheckbox.checked) {
|
||||||
itemName.classList.remove('not-selected');
|
itemName.classList.remove('not-selected');
|
||||||
|
|
Loading…
Add table
Reference in a new issue