-
-
Notifications
You must be signed in to change notification settings - Fork 601
Expand file tree
/
Copy pathconfig.ts
More file actions
146 lines (140 loc) · 4.27 KB
/
Copy pathconfig.ts
File metadata and controls
146 lines (140 loc) · 4.27 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
import { defineStore } from "pinia";
import type { ConfigResponse, EjsControlsButton } from "@/__generated__";
import api from "@/services/api";
export type Config = ConfigResponse;
type ExclusionTypes =
| "EXCLUDED_PLATFORMS"
| "EXCLUDED_SINGLE_EXT"
| "EXCLUDED_SINGLE_FILES"
| "EXCLUDED_MULTI_FILES"
| "EXCLUDED_MULTI_PARTS_EXT"
| "EXCLUDED_MULTI_PARTS_FILES";
const defaultConfig = {
CONFIG_FILE_MOUNTED: false,
CONFIG_FILE_WRITABLE: false,
CONFIG_FILE_PARSE_ERROR: null,
EXCLUDED_PLATFORMS: [],
EXCLUDED_SINGLE_EXT: [],
EXCLUDED_SINGLE_FILES: [],
EXCLUDED_MULTI_FILES: [],
EXCLUDED_MULTI_PARTS_EXT: [],
EXCLUDED_MULTI_PARTS_FILES: [],
DEFAULT_EXCLUDED_DIRS: [],
DEFAULT_EXCLUDED_FILES: [],
DEFAULT_EXCLUDED_EXTENSIONS: [],
PLATFORMS_BINDING: {},
PLATFORMS_VERSIONS: {},
SKIP_HASH_CALCULATION: false,
EJS_DEBUG: false,
EJS_NETPLAY_ENABLED: false,
EJS_CACHE_LIMIT: null,
EJS_DISABLE_AUTO_UNLOAD: false,
EJS_DISABLE_BATCH_BOOTUP: false,
EJS_NETPLAY_ICE_SERVERS: [],
EJS_SETTINGS: {},
EJS_CONTROLS: {},
SCAN_METADATA_PRIORITY: [],
SCAN_ARTWORK_PRIORITY: [],
SCAN_ARTWORK_PRIORITY_OVERRIDES: {},
SCAN_REGION_PRIORITY: [],
SCAN_LANGUAGE_PRIORITY: [],
SCAN_MEDIA: [],
GAMELIST_MEDIA_THUMBNAIL: "box2d",
GAMELIST_MEDIA_IMAGE: "screenshot",
} as ConfigResponse;
export default defineStore("config", {
state: () => ({
config: { ...defaultConfig },
}),
actions: {
async fetchConfig(): Promise<ConfigResponse> {
try {
const response = await api.get("/config");
this.config = response.data;
return this.config;
} catch (error) {
console.error("Error fetching config: ", error);
return this.config;
}
},
addPlatformBinding(fsSlug: string, slug: string) {
this.config.PLATFORMS_BINDING[fsSlug] = slug;
},
removePlatformBinding(fsSlug: string) {
delete this.config.PLATFORMS_BINDING[fsSlug];
},
addPlatformVersion(fsSlug: string, slug: string) {
this.config.PLATFORMS_VERSIONS[fsSlug] = slug;
},
removePlatformVersion(fsSlug: string) {
delete this.config.PLATFORMS_VERSIONS[fsSlug];
},
addExclusion(exclusionType: ExclusionTypes, exclusionValue: string) {
this.config[exclusionType].push(exclusionValue);
},
removeExclusion(exclusionValue: string, exclusionType: ExclusionTypes) {
const index = this.config[exclusionType].indexOf(exclusionValue);
if (index !== -1) {
this.config[exclusionType].splice(index, 1);
} else {
console.error(
`Value '${exclusionValue}' not found in exclusion type '${exclusionType}'`,
);
}
},
isExclusionType(type: string): type is ExclusionTypes {
return Object.keys(this.config).includes(type);
},
getEJSCoreOptions(core: string | null): Record<string, string | boolean> {
const defaultOptions = this.config.EJS_SETTINGS["default"] || {};
if (!core) return defaultOptions;
return {
...defaultOptions,
...this.config.EJS_SETTINGS[core],
};
},
getEJSControls(
core: string | null,
): Record<number, Record<number, EjsControlsButton>> | null {
const defaultControls = this.config.EJS_CONTROLS["default"];
if (!core) {
if (!defaultControls) return null;
return {
0: defaultControls["_0"] || {},
1: defaultControls["_1"] || {},
2: defaultControls["_2"] || {},
3: defaultControls["_3"] || {},
};
}
const coreControls = this.config.EJS_CONTROLS[core];
if (!coreControls) return null;
if (!defaultControls) {
return {
0: coreControls["_0"] || {},
1: coreControls["_1"] || {},
2: coreControls["_2"] || {},
3: coreControls["_3"] || {},
};
}
return {
0: {
...(defaultControls["_0"] || {}),
...(coreControls["_0"] || {}),
},
1: {
...(defaultControls["_1"] || {}),
...(coreControls["_1"] || {}),
},
2: {
...(defaultControls["_2"] || {}),
...(coreControls["_2"] || {}),
},
3: {
...(defaultControls["_3"] || {}),
...(coreControls["_3"] || {}),
},
};
},
reset() {},
},
});