Map uuid support

This commit is contained in:
2025-06-05 10:37:01 +02:00
parent c5b0afbd52
commit 2b957b971f
+9 -4
View File
@@ -1,6 +1,7 @@
const csv = require("fast-csv"); const csv = require("fast-csv");
const fs = require("fs"); const fs = require("fs");
const path = require("path"); const path = require("path");
const uuid = require("uuid");
const map_conf = require("../config/map.conf"); const map_conf = require("../config/map.conf");
const logger = require("./logger.util"); const logger = require("./logger.util");
@@ -24,7 +25,7 @@ async function addMap(filename, meta, throttle, motor) {
const throttle_values = Object.values(throttle); const throttle_values = Object.values(throttle);
const current_values = Object.values(motor["0"]); const current_values = Object.values(motor["0"]);
const brake_values = Object.values(motor["1"]); const brake_values = Object.values(motor["1"]);
for (let i = 0; i <= map_conf.steps; i++) { for (let i = 0; i <= map_conf.steps; i++) {
map[i] = [current_values[i], brake_values[i], throttle_values[i]]; map[i] = [current_values[i], brake_values[i], throttle_values[i]];
} }
@@ -45,6 +46,10 @@ async function updateMap(filename, meta, throttle, motor) {
try { try {
await csv.writeToString(map).then(data => total += data); await csv.writeToString(map).then(data => total += data);
fs.writeFileSync(`app/storage/${filename}`, total); fs.writeFileSync(`app/storage/${filename}`, total);
fs.renameSync(`app/storage/${filename}`, `app/storage/map_${uuid.v4()}.csv`)
if (fs.existsSync("app/storage/selected")) {
fs.unlinkSync("app/storage/selected");
}
} catch (error) { } catch (error) {
throw new Error(error); throw new Error(error);
} }
@@ -151,14 +156,14 @@ async function getAvailableMaps() {
try { try {
var files = fs.readdirSync("app/storage"); var files = fs.readdirSync("app/storage");
for (const file of files) { for (const file of files) {
if (path.extname(file) == ".csv") { if (path.extname(file) == ".csv") {
available_maps[file] = {}; available_maps[file] = {};
try { try {
let meta = await parseMap(file, 1); let meta = await parseMap(file, 1);
if (meta && meta.length) { if (meta && meta.length) {
for (const m of meta) { for (const m of meta) {
available_maps[file][m.slice(0, m.indexOf(":")).toLowerCase()] = m.slice(m.indexOf(":") + 1) available_maps[file][m.slice(0, m.indexOf(":")).toLowerCase()] = m.slice(m.indexOf(":") + 1)