MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / importAllMetaEdits

Function importAllMetaEdits

src/back/MetaEdit.ts:90–349  ·  view source on GitHub ↗
(fullMetaEditsFolderPath: string, openDialog: ShowMessageBoxFunc, state: BackState)

Source from the content-addressed store, hash-verified

88 * @param state Back State
89 */
90export async function importAllMetaEdits(fullMetaEditsFolderPath: string, openDialog: ShowMessageBoxFunc, state: BackState): Promise<ImportMetaEditResult> {
91 const errors: Error[] = [];
92
93 // Load all meta edit files
94 const files: LoadedMetaEditFile[] = [];
95 try {
96 const filenames = await fs.promises.readdir(fullMetaEditsFolderPath);
97
98 for (const filename of filenames) {
99 try {
100 const fullFilename = path.join(fullMetaEditsFolderPath, filename);
101
102 const stats = await fs.promises.stat(fullFilename);
103
104 const raw = await readJsonFile(fullFilename);
105 const parsed = parseMetaEdit(raw);
106
107 files.push({
108 filename: filename,
109 mtime: stats.mtimeMs,
110 content: parsed,
111 });
112 } catch (error: any) { errors.push(error); }
113 }
114 } catch (error: any) { errors.push(error); }
115
116 // Abort if any file failed to load
117 if (errors.length > 0) {
118 return {
119 aborted: true,
120 errors: errors,
121 };
122 }
123
124 // Order meta edits
125 files.sort((a, b) => a.mtime - b.mtime); // Oldest first
126
127 // Combine edits from all meta edits
128 const combinedMetas: CombinedMetaRecord = {};
129 for (const file of files) {
130 for (const meta of file.content.metas) {
131 let combined = combinedMetas[meta.id];
132 if (!combined) {
133 combined = combinedMetas[meta.id] = {};
134 }
135
136 const keys = Object.keys(meta) as (keyof typeof meta)[];
137 for (const key of keys) {
138 if (key !== 'id') { // (ID is for identification, not to be modified)
139 // TODO: Fix values typing later
140 let values: any = combined[key];
141 if (!values) {
142 values = combined[key] = [];
143 }
144
145 const metaValue = meta[key];
146 const isDuplicate = values.some((val: MetaChangeBase<keyof MetaEditMetaMap>) => (
147 (val.value === metaValue) ||

Callers 1

registerRequestCallbacksFunction · 0.90

Calls 9

readJsonFileFunction · 0.90
shallowStrictEqualsFunction · 0.90
stringifyMetaValueFunction · 0.90
awaitDialogFunction · 0.90
copyErrorFunction · 0.90
parseMetaEditFunction · 0.85
paranoidSetGamePropertyFunction · 0.85
pushMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected