File size: 2,776 Bytes
4450790
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
import { cB as defineStore, r as ref, q as computed } from "./index-CoOvI8ZH.js";
const useServerConfigStore = defineStore("serverConfig", () => {
  const serverConfigById = ref({});
  const serverConfigs = computed(() => {
    return Object.values(serverConfigById.value);
  });
  const modifiedConfigs = computed(
    () => {
      return serverConfigs.value.filter((config) => {
        return config.initialValue !== config.value;
      });
    }
  );
  const revertChanges = /* @__PURE__ */ __name(() => {
    for (const config of modifiedConfigs.value) {
      config.value = config.initialValue;
    }
  }, "revertChanges");
  const serverConfigsByCategory = computed(() => {
    return serverConfigs.value.reduce(
      (acc, config) => {
        const category = config.category?.[0] ?? "General";
        acc[category] = acc[category] || [];
        acc[category].push(config);
        return acc;
      },
      {}
    );
  });
  const serverConfigValues = computed(() => {
    return Object.fromEntries(
      serverConfigs.value.map((config) => {
        return [
          config.id,
          config.value === config.defaultValue || config.value === null || config.value === void 0 ? void 0 : config.value
        ];
      })
    );
  });
  const launchArgs = computed(() => {
    const args = Object.assign(
      {},
      ...serverConfigs.value.map((config) => {
        if (config.value === config.defaultValue || config.value === null || config.value === void 0) {
          return {};
        }
        return config.getValue ? config.getValue(config.value) : { [config.id]: config.value };
      })
    );
    return Object.fromEntries(
      Object.entries(args).map(([key, value]) => {
        if (value === true) {
          return [key, ""];
        }
        return [key, value.toString()];
      })
    );
  });
  const commandLineArgs = computed(() => {
    return Object.entries(launchArgs.value).map(([key, value]) => [`--${key}`, value]).flat().filter((arg) => arg !== "").join(" ");
  });
  function loadServerConfig(configs, values) {
    for (const config of configs) {
      const value = values[config.id] ?? config.defaultValue;
      serverConfigById.value[config.id] = {
        ...config,
        value,
        initialValue: value
      };
    }
  }
  __name(loadServerConfig, "loadServerConfig");
  return {
    serverConfigById,
    serverConfigs,
    modifiedConfigs,
    serverConfigsByCategory,
    serverConfigValues,
    launchArgs,
    commandLineArgs,
    revertChanges,
    loadServerConfig
  };
});
export {
  useServerConfigStore as u
};
//# sourceMappingURL=serverConfigStore-cctR8PGG.js.map