MCPcopy Create free account
hub / github.com/Shazbot/WH3-Mod-Manager / getPackViewData

Function getPackViewData

src/packFileSerializer.ts:835–894  ·  view source on GitHub ↗
(pack: Pack, table?: DBTable | string, getLocs?: boolean)

Source from the content-addressed store, hash-verified

833 return results;
834};
835export const getPackViewData = (pack: Pack, table?: DBTable | string, getLocs?: boolean) => {
836 console.log("getPackViewData:", pack.name, table);
837 const tables = pack.packedFiles.map((packedFile) => packedFile.name);
838 const locFiles: Record<string, PackedFile> = {};
839 if (getLocs) {
840 for (const packedFile of pack.packedFiles) {
841 if (packedFile.name.endsWith(".loc")) {
842 // console.log("found loc pack file", packedFile.name);
843 locFiles[packedFile.name] = packedFile;
844 }
845 }
846 }
847 const result = { packName: pack.name, packPath: pack.path, tables } as PackViewData;
848 result.packedFiles = result.packedFiles || {};
849 let packedFiles: PackedFile[] = [];
850 if (table) {
851 if (typeof table === "string") {
852 packedFiles = pack.packedFiles.filter((packedFile) => packedFile.name == table);
853 } else {
854 packedFiles = pack.packedFiles.filter((packedFile) =>
855 packedFile.name.startsWith(`db\\${table.dbName}\\${table.dbSubname}`),
856 );
857 }
858 }
859 if (getLocs) {
860 packedFiles = packedFiles.concat(Object.values(locFiles));
861 }
862 // console.log("getpackviewdata packedFiles:", packedFiles);
863 for (const packedFile of packedFiles) {
864 const amendedSchemaFields: AmendedSchemaField[] = [];
865 const dbversion = locFiles[packedFile.name] ? LocVersion : getDBVersion(packedFile);
866 if (!dbversion) {
867 console.log("no dbversion for", packedFile.name);
868 return;
869 }
870 const chunkedSchemaIntoRows = chunkSchemaIntoRows(packedFile.schemaFields || [], dbversion);
871 // console.log("chunked into ", chunkedSchemaIntoRows.length);
872 // console.log("num fields in row is ", dbversion.fields.length);
873 // console.log("db types are ", dbversion.fields.map((field) => field.name).join(", "));
874 // console.log("with num chunks of ", chunkedSchemaIntoRows.map((row) => row.length).join(","));
875 for (const chunkedSchemaIntoRow of chunkedSchemaIntoRows) {
876 for (const dbFieldsIndex of dbversion.fields.keys()) {
877 const { name, field_type } = dbversion.fields[dbFieldsIndex];
878 const fields = chunkedSchemaIntoRow[dbFieldsIndex].fields;
879 if (!fields) {
880 console.log("MISSING FIELD ", name);
881 }
882 const resolvedKeyValue = resolveKeyValue(field_type, fields);
883 amendedSchemaFields.push({ name, resolvedKeyValue, ...chunkedSchemaIntoRow[dbFieldsIndex] });
884 // if (chunkedSchemaIntoRow == chunkedSchemaIntoRows[0]) {
885 // console.log("AMENDING ", name, resolvedKeyValue);
886 // }
887 }
888 }
889 packedFile.schemaFields = amendedSchemaFields;
890 packedFile.tableSchema = dbversion;
891 result.packedFiles[packedFile.name] = packedFile;
892 }

Callers 3

getLocsTrieFunction · 0.90
getPackDataFunction · 0.90
createOverwritePackFunction · 0.85

Calls 3

chunkSchemaIntoRowsFunction · 0.85
resolveKeyValueFunction · 0.85
getDBVersionFunction · 0.70

Tested by

no test coverage detected