Add tokens to import success check
This commit is contained in:
parent
fde9c41145
commit
262785c65e
@ -193,7 +193,7 @@ function ImportExportModal({
|
|||||||
// Mapping of old asset ids to new asset ids
|
// Mapping of old asset ids to new asset ids
|
||||||
let newAssetIds: Record<string, string> = {};
|
let newAssetIds: Record<string, string> = {};
|
||||||
// Mapping of old asset ids to old maps
|
// Mapping of old asset ids to old maps
|
||||||
let oldAssetIds: Record<string, { mapName: string, assetType: string }> = {};
|
let oldAssetIds: Record<string, { itemName: string, item: "map" | "token", assetType: string }> = {};
|
||||||
|
|
||||||
// Mapping of old maps ids to new map ids
|
// Mapping of old maps ids to new map ids
|
||||||
let newMapIds: Record<string, string> = {};
|
let newMapIds: Record<string, string> = {};
|
||||||
@ -201,21 +201,31 @@ function ImportExportModal({
|
|||||||
let newTokens: Token[] = [];
|
let newTokens: Token[] = [];
|
||||||
if (checkedTokens.length > 0) {
|
if (checkedTokens.length > 0) {
|
||||||
const tokenIds = checkedTokens.map((token) => token.id);
|
const tokenIds = checkedTokens.map((token) => token.id);
|
||||||
const tokensToAdd = await importDB.table("tokens").bulkGet(tokenIds);
|
const tokensToAdd: Token[] = await importDB.table("tokens").bulkGet(tokenIds);
|
||||||
for (let token of tokensToAdd) {
|
for (let token of tokensToAdd) {
|
||||||
|
if (token.name === "Vorkhal") {
|
||||||
|
console.log("found")
|
||||||
|
}
|
||||||
|
if (token) {
|
||||||
// Generate new ids
|
// Generate new ids
|
||||||
const newId = uuid();
|
const newId = uuid();
|
||||||
newTokenIds[token.id] = newId;
|
newTokenIds[token.id] = newId;
|
||||||
|
|
||||||
if (token.type === "default") {
|
if (token.type === "default") {
|
||||||
|
if (userId) {
|
||||||
newTokens.push({ ...token, id: newId, owner: userId });
|
newTokens.push({ ...token, id: newId, owner: userId });
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
const newFileId = uuid();
|
const newFileId = uuid();
|
||||||
const newThumbnailId = uuid();
|
const newThumbnailId = uuid();
|
||||||
newAssetIds[token.file] = newFileId;
|
newAssetIds[token.file] = newFileId;
|
||||||
newAssetIds[token.thumbnail] = newThumbnailId;
|
newAssetIds[token.thumbnail] = newThumbnailId;
|
||||||
|
|
||||||
|
oldAssetIds[token.file] = { itemName: token.name, item: "token", assetType: "file" };
|
||||||
|
oldAssetIds[token.thumbnail] = { itemName: token.name, item: "token", assetType: "thumbnail" };
|
||||||
|
|
||||||
// Change ids and owner
|
// Change ids and owner
|
||||||
|
if (userId) {
|
||||||
newTokens.push({
|
newTokens.push({
|
||||||
...token,
|
...token,
|
||||||
id: newId,
|
id: newId,
|
||||||
@ -226,6 +236,8 @@ function ImportExportModal({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let newMaps: Map[] = [];
|
let newMaps: Map[] = [];
|
||||||
let newStates: MapState[] = [];
|
let newStates: MapState[] = [];
|
||||||
@ -260,14 +272,14 @@ function ImportExportModal({
|
|||||||
newAssetIds[map.file] = newFileId;
|
newAssetIds[map.file] = newFileId;
|
||||||
newAssetIds[map.thumbnail] = newThumbnailId;
|
newAssetIds[map.thumbnail] = newThumbnailId;
|
||||||
|
|
||||||
oldAssetIds[map.file] = { mapName: map.name, assetType: "file" };
|
oldAssetIds[map.file] = { itemName: map.name, item: "map", assetType: "file" };
|
||||||
oldAssetIds[map.thumbnail] = { mapName: map.name, assetType: "thumbnail" };
|
oldAssetIds[map.thumbnail] = { itemName: map.name, item: "map", assetType: "thumbnail" };
|
||||||
|
|
||||||
const newResolutionIds: Record<string, string> = {};
|
const newResolutionIds: Record<string, string> = {};
|
||||||
for (let res of Object.keys(map.resolutions)) {
|
for (let res of Object.keys(map.resolutions)) {
|
||||||
newResolutionIds[res] = uuid();
|
newResolutionIds[res] = uuid();
|
||||||
newAssetIds[map.resolutions[res]] = newResolutionIds[res];
|
newAssetIds[map.resolutions[res]] = newResolutionIds[res];
|
||||||
oldAssetIds[map.resolutions[res]] = { mapName: map.name, assetType: "resolution" };
|
oldAssetIds[map.resolutions[res]] = { itemName: map.name, item: "map", assetType: "resolution" };
|
||||||
}
|
}
|
||||||
// Change ids and owner
|
// Change ids and owner
|
||||||
newMaps.push({
|
newMaps.push({
|
||||||
@ -301,18 +313,25 @@ function ImportExportModal({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const unprocessed = Object.keys(newAssetIds).filter(item => processedAssetIds.indexOf(item) < 0);
|
const unprocessedAssets = Object.keys(newAssetIds).filter(item => processedAssetIds.indexOf(item) < 0);
|
||||||
const unprocessedMaps: string[] = []
|
let unprocessedMaps = 0
|
||||||
if (unprocessed.length > 0) {
|
let unprocessedTokens = 0
|
||||||
for (let item of unprocessed) {
|
if (unprocessedAssets.length > 0) {
|
||||||
let unprocessedMapAsset = oldAssetIds[item]
|
const unprocessedItems: string[] = []
|
||||||
|
for (let item of unprocessedAssets) {
|
||||||
|
let unprocessedItem = oldAssetIds[item]
|
||||||
|
|
||||||
if (!unprocessedMaps.includes(unprocessedMapAsset.mapName)) {
|
if (!unprocessedItems.includes(unprocessedItem.itemName)) {
|
||||||
unprocessedMaps.push(unprocessedMapAsset.mapName)
|
unprocessedItems.push(unprocessedItem.itemName)
|
||||||
|
if (unprocessedItem.item === "map") {
|
||||||
|
unprocessedMaps += 1
|
||||||
|
} else if (unprocessedItem.item === "token") {
|
||||||
|
unprocessedTokens += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
addWarningToast("Could not import ", unprocessedMaps)
|
addWarningToast("Could not import item(s)", unprocessedItems)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add map groups with new ids
|
// Add map groups with new ids
|
||||||
@ -389,8 +408,9 @@ function ImportExportModal({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
const totalImportedMaps = checkedMaps.length - unprocessedMaps.length
|
const totalImportedMaps = checkedMaps.length - unprocessedMaps
|
||||||
addSuccessToast("Imported", totalImportedMaps, checkedTokens.length);
|
const totalImportedTokens = checkedTokens.length - unprocessedTokens
|
||||||
|
addSuccessToast("Imported", totalImportedMaps, totalImportedTokens);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
if (e instanceof MissingAssetError) {
|
if (e instanceof MissingAssetError) {
|
||||||
|
Loading…
Reference in New Issue
Block a user