Fixed crash after generating asset names, added MP2 auto-generated names to the map

This commit is contained in:
Aruki 2017-02-06 15:10:54 -07:00
parent eca833cf89
commit b3a0e52b6f
7 changed files with 66232 additions and 296 deletions

File diff suppressed because it is too large Load Diff

View File

@ -252,6 +252,10 @@ TWideString MakeRelative(const TWideString& rkPath, const TWideString& rkRelativ
for (; PathIter != PathComponents.end(); PathIter++)
Out += *PathIter + L"\\";
// Attempt to detect if this path is a file as opposed to a directory; if so, remove trailing backslash
if (PathComponents.back().Contains(L'.') && !rkPath.EndsWith(L'/') && !rkPath.EndsWith(L'\\'))
Out = Out.ChopBack(1);
return Out;
}

View File

@ -7,6 +7,7 @@
#include "Core/Resource/Script/CScriptLayer.h"
#include <Math/MathUtil.h>
#define PROCESS_PACKAGES 1
#define PROCESS_WORLDS 1
#define PROCESS_AREAS 1
#define PROCESS_MODELS 1
@ -94,9 +95,8 @@ TWideString MakeWorldName(EGame Game, TWideString RawName)
{
RawName = RawName.ChopBack(RawName.Size() - LastUnderscore);
RawName = RawName.ChopFront(FirstUnderscore + 1);
RawName.Remove(L'_');
}
RawName.Remove(L'_');
}
// DKCR - Remove text after second-to-last underscore
@ -116,7 +116,8 @@ void GenerateAssetNames(CGameProject *pProj)
// todo: CAUD/CSMP
CResourceStore *pStore = pProj->ResourceStore();
// Generate names for package named resources first
#if PROCESS_PACKAGES
// Generate names for package named resources
for (u32 iPkg = 0; iPkg < pProj->NumPackages(); iPkg++)
{
CPackage *pPkg = pProj->PackageByIndex(iPkg);
@ -135,6 +136,7 @@ void GenerateAssetNames(CGameProject *pProj)
}
}
}
#endif
#if PROCESS_WORLDS
// Generate world/area names
@ -171,7 +173,7 @@ void GenerateAssetNames(CGameProject *pProj)
{
// Move sky model
CResourceEntry *pSkyEntry = pSkyModel->Entry();
ApplyGeneratedName(pSkyEntry, WorldDir + L"sky\\cooked\\", L"sky");
ApplyGeneratedName(pSkyEntry, WorldDir + L"sky\\cooked\\", WorldName + L"_" + L"sky");
// Move sky textures
for (u32 iSet = 0; iSet < pSkyModel->GetMatSetCount(); iSet++)
@ -484,8 +486,8 @@ void GenerateAssetNames(CGameProject *pProj)
// Generate string names
for (TResourceIterator<eStringTable> It(pStore); It; ++It)
{
if (It->IsNamed()) continue;
CStringTable *pString = (CStringTable*) It->Load();
if (pString->Entry()->IsNamed()) continue;
TWideString String;
for (u32 iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++)
@ -556,7 +558,7 @@ void GenerateAssetNames(CGameProject *pProj)
CTexture *pFontTex = pFont->Texture();
if (pFontTex)
ApplyGeneratedName(pFontTex->Entry(), pFont->Entry()->DirectoryPath(), pFont->Entry()->Name());
ApplyGeneratedName(pFontTex->Entry(), pFont->Entry()->DirectoryPath(), pFont->Entry()->Name() + L"_tex");
}
}
#endif

View File

@ -321,7 +321,7 @@ bool CResourceEntry::Move(const TWideString& rkDir, const TWideString& rkName)
TString NewCookedPath = CookedAssetPath();
TString NewRawPath = RawAssetPath();
Log::Write("MOVING RESOURCE: " + OldCookedPath + " --> " + NewCookedPath);
Log::Write("MOVING RESOURCE: " + FileUtil::MakeRelative(OldCookedPath, mpStore->CookedDir(false)).ToUTF8() + " --> " + FileUtil::MakeRelative(NewCookedPath, mpStore->CookedDir(false)).ToUTF8());
// If the old/new paths are the same then we should have already exited as CanMoveTo() should have returned false
ASSERT(OldCookedPath != NewCookedPath && OldRawPath != NewRawPath);

View File

@ -582,6 +582,9 @@ bool CResourceStore::DeleteResourceEntry(CResourceEntry *pEntry)
mLoadedResources.erase(It);
}
if (pEntry->Directory())
pEntry->Directory()->RemoveChildResource(pEntry);
auto It = mResourceEntries.find(ID);
ASSERT(It != mResourceEntries.end());
mResourceEntries.erase(It);

View File

@ -183,6 +183,16 @@ void CResourceBrowser::RefreshResources()
mpUI->ResourceTableView->setSpan(iDir, 0, 1, 3);
}
void CResourceBrowser::RefreshDirectories()
{
mpDirectoryModel->SetRoot(mpStore->RootDirectory());
// Clear selection. This function is called when directories are created/deleted and our current selection might not be valid anymore
QModelIndex RootIndex = mpDirectoryModel->index(0, 0, QModelIndex());
mpUI->DirectoryTreeView->selectionModel()->setCurrentIndex(RootIndex, QItemSelectionModel::ClearAndSelect);
mpUI->DirectoryTreeView->setExpanded(RootIndex, true);
}
void CResourceBrowser::UpdateDescriptionLabel()
{
QString Desc;
@ -299,12 +309,14 @@ void CResourceBrowser::OnImportPakContentsTxt()
mpStore->ImportNamesFromPakContentsTxt(TO_TSTRING(rkPath), false);
RefreshResources();
RefreshDirectories();
}
void CResourceBrowser::OnGenerateAssetNames()
{
GenerateAssetNames(mpStore->Project());
RefreshResources();
RefreshDirectories();
}
void CResourceBrowser::OnImportNamesFromAssetNameMap()
@ -322,6 +334,7 @@ void CResourceBrowser::OnImportNamesFromAssetNameMap()
mpStore->ConditionalSaveStore();
RefreshResources();
RefreshDirectories();
}
void CResourceBrowser::ExportAssetNames()
@ -358,6 +371,7 @@ void CResourceBrowser::ResetTypeFilter()
void CResourceBrowser::OnFilterTypeBoxTicked(bool Checked)
{
// NOTE: there should only be one CResourceBrowser; if that ever changes for some reason change this to a member
static bool ReentrantGuard = false;
if (ReentrantGuard) return;
ReentrantGuard = true;

View File

@ -54,6 +54,7 @@ public:
public slots:
void RefreshResources();
void RefreshDirectories();
void UpdateDescriptionLabel();
void UpdateStore();
void OnDisplayModeChanged(int Index);