Asset Browser initial implementation - Asset updates.

Script execution on certain existing assets, new asset types and some tweaks to the managers.
This commit is contained in:
Areloch 2018-01-28 14:48:02 -06:00
parent ab453d068c
commit 4341428d53
41 changed files with 3173 additions and 96 deletions

View file

@ -82,6 +82,8 @@ void ModuleDefinition::initPersistFields()
// Call parent.
Parent::initPersistFields();
addProtectedField("ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &defaultProtectedSetFn, &defaultProtectedGetFn, "");
/// Module configuration.
addProtectedField( "ModuleId", TypeString, Offset(mModuleId, ModuleDefinition), &setModuleId, &defaultProtectedGetFn, "A unique string Id for the module. It can contain any characters except a comma or semi-colon (the asset scope character)." );
addProtectedField( "VersionId", TypeS32, Offset(mVersionId, ModuleDefinition), &setVersionId, &defaultProtectedGetFn, "The version Id. Breaking changes to a module should use a higher version Id." );

View file

@ -70,7 +70,8 @@ S32 QSORT_CALLBACK moduleDefinitionVersionIdSort( const void* a, const void* b )
ModuleManager::ModuleManager() :
mEnforceDependencies(true),
mEchoInfo(true),
mDatabaseLocks( 0 )
mDatabaseLocks( 0 ),
mIgnoreLoadedGroups(false)
{
// Set module extension.
dStrcpy( mModuleExtension, MODULE_MANAGER_MODULE_DEFINITION_EXTENSION );
@ -1300,6 +1301,106 @@ StringTableEntry ModuleManager::copyModule( ModuleDefinition* pSourceModuleDefin
//-----------------------------------------------------------------------------
bool ModuleManager::renameModule(ModuleDefinition* pSourceModuleDefinition, const char* pNewModuleName)
{
// Sanity!
AssertFatal(pSourceModuleDefinition != NULL, "Cannot copy module using a NULL source module definition.");
AssertFatal(pNewModuleName != NULL, "Cannot rename a module using a NULL module name.");
// Fetch the source module Id.
StringTableEntry sourceModuleId = pSourceModuleDefinition->getModuleId();
// Is the source module definition registered with this module manager?
if (pSourceModuleDefinition->getModuleManager() != this)
{
// No, so warn.
Con::warnf("Module Manager: Cannot rename module Id '%s' as it is not registered with this module manager.", sourceModuleId);
return StringTable->EmptyString();
}
TamlModuleIdUpdateVisitor moduleIdUpdateVisitor;
moduleIdUpdateVisitor.setModuleIdFrom(sourceModuleId);
moduleIdUpdateVisitor.setModuleIdTo(pNewModuleName);
Vector<Platform::FileInfo> files;
const char* pExtension = (const char*)"Taml";
const U32 extensionLength = dStrlen(pExtension);
Vector<StringTableEntry> directories;
StringTableEntry modulePath = pSourceModuleDefinition->getModulePath();
// Find directories.
if (!Platform::dumpDirectories(modulePath, directories, -1))
{
// Warn.
Con::warnf("Module Manager: Cannot rename module Id '%s' in directory '%s' as sub-folder scanning/renaming failed.",
sourceModuleId, modulePath);
return false;
}
// Iterate directories.
for (Vector<StringTableEntry>::iterator basePathItr = directories.begin(); basePathItr != directories.end(); ++basePathItr)
{
// Fetch base path.
StringTableEntry basePath = *basePathItr;
// Find files.
files.clear();
if (!Platform::dumpPath(basePath, files, 0))
{
// Warn.
Con::warnf("Module Manager: Cannot rename module Id '%s' in directory '%s' as sub-folder scanning/renaming failed.",
sourceModuleId, modulePath);
return false;
}
// Iterate files.
for (Vector<Platform::FileInfo>::iterator fileItr = files.begin(); fileItr != files.end(); ++fileItr)
{
// Fetch file info.
Platform::FileInfo* pFileInfo = fileItr;
// Fetch filename.
const char* pFilename = pFileInfo->pFileName;
// Find filename length.
const U32 filenameLength = dStrlen(pFilename);
// Skip if extension is longer than filename.
if (extensionLength >= filenameLength)
continue;
// Skip if extension not found.
if (dStricmp(pFilename + filenameLength - extensionLength, pExtension) != 0)
continue;
char parseFileBuffer[1024];
dSprintf(parseFileBuffer, sizeof(parseFileBuffer), "%s/%s", pFileInfo->pFullPath, pFilename);
// Parse file.
if (!mTaml.parse(parseFileBuffer, moduleIdUpdateVisitor))
{
// Warn.
Con::warnf("Module Manager: Failed to parse file '%s' whilst renaming module Id '%s' in directory '%s'.",
parseFileBuffer, sourceModuleId, modulePath);
return false;
}
}
}
// Info.
if (mEchoInfo)
{
Con::printf("Module Manager: Finished renaming module Id '%s' to '%s'.", sourceModuleId, pNewModuleName);
}
return true;
}
//-----------------------------------------------------------------------------
bool ModuleManager::synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath )
{
// Sanity!
@ -1986,7 +2087,7 @@ bool ModuleManager::registerModule( const char* pModulePath, const char* pModule
}
// Is the module group already loaded?
if ( findGroupLoaded( moduleGroup ) != NULL )
if ( findGroupLoaded( moduleGroup ) != NULL && !mIgnoreLoadedGroups)
{
// Yes, so warn.
Con::warnf( "Module Manager: Found module: '%s' but it is in a module group '%s' which has already been loaded.",

View file

@ -120,6 +120,7 @@ private:
char mModuleExtension[256];
Taml mTaml;
SimSet mNotificationListeners;
bool mIgnoreLoadedGroups;
// Module definition entry.
struct ModuleDefinitionEntry : public typeModuleDefinitionVector
@ -161,6 +162,7 @@ public:
bool scanModules( const char* pPath, const bool rootOnly = false );
/// Module unregister.
bool registerModule(const char* pModulePath, const char* pModuleFile);
bool unregisterModule( const char* pModuleId, const U32 versionId );
/// Module (un)loading.
@ -179,6 +181,9 @@ public:
StringTableEntry copyModule( ModuleDefinition* pSourceModuleDefinition, const char* pTargetModuleId, const char* pTargetPath, const bool useVersionPathing );
bool synchronizeDependencies( ModuleDefinition* pRootModuleDefinition, const char* pTargetDependencyPath );
/// Editing modules
bool renameModule(ModuleDefinition* pSourceModuleDefinition, const char* pNewModuleName);
/// Module updates.
inline bool isModuleMergeAvailable( void ) const { return Platform::isFile( getModuleMergeFilePath() ); }
bool canMergeModules( const char* pMergeSourcePath );
@ -188,10 +193,11 @@ public:
void addListener( SimObject* pListener );
void removeListener( SimObject* pListener );
void setIgnoreLoadedGroups(bool doIgnore) { mIgnoreLoadedGroups = doIgnore; }
private:
void clearDatabase( void );
bool removeModuleDefinition( ModuleDefinition* pModuleDefinition );
bool registerModule( const char* pModulePath, const char* pModuleFile );
void raiseModulePreLoadNotifications( ModuleDefinition* pModuleDefinition );
void raiseModulePostLoadNotifications( ModuleDefinition* pModuleDefinition );

View file

@ -46,6 +46,16 @@ DefineEngineMethod(ModuleManager, scanModules, bool, (const char* pRootPath, boo
//-----------------------------------------------------------------------------
DefineEngineMethod(ModuleManager, registerModule, bool, (const char* pModulePath, const char* pModuleFile), ("", ""),
"Register the specified module.\n"
"@param moduleId The module Id to register.\n"
"@param versionId The version Id to register.\n"
"@return Whether the module was registered or not.\n")
{
// Unregister the module.
return object->registerModule(pModulePath, pModuleFile);
}
DefineEngineMethod(ModuleManager, unregisterModule, bool, (const char* pModuleId, bool versionId), ("", false),
"Unregister the specified module.\n"
"@param moduleId The module Id to unregister.\n"
@ -246,6 +256,30 @@ DefineEngineMethod(ModuleManager, copyModule, String, (const char* sourceModuleD
//-----------------------------------------------------------------------------
DefineEngineMethod(ModuleManager, renameModule, bool, (const char* sourceModuleDefinition, const char* pNewModuleName),
("", ""),
"Rename a module.\n"
"@param sourceModuleDefinition The module definition to rename.\n"
"@param pNewModuleName The new name the module should have.\n"
"@return Weither the rename was successful or not.\n")
{
// Find the source module definition.
ModuleDefinition* pSourceModuleDefinition = dynamic_cast<ModuleDefinition*>(Sim::findObject(sourceModuleDefinition));
// Was the module definition found?
if (pSourceModuleDefinition == NULL)
{
// No, so warn.
Con::warnf("ModuleManager::renameModule() - Could not find source module definition '%s'.", sourceModuleDefinition);
return "";
}
// Copy module.
return object->renameModule(pSourceModuleDefinition, pNewModuleName);
}
//-----------------------------------------------------------------------------
DefineEngineMethod(ModuleManager, synchronizeDependencies, bool, (const char* rootModuleDefinition, const char* pTargetDependencyFolder), ("", ""),
"Synchronize the module dependencies of a module definition to a target dependency folder.\n"
"@param rootModuleDefinition The module definition used to determine dependencies.\n"
@ -342,3 +376,14 @@ DefineEngineMethod(ModuleManager, removeListener, void, (const char* listenerObj
object->removeListener( pListener );
}
//-----------------------------------------------------------------------------
DefineEngineMethod(ModuleManager, ignoreLoadedGroups, void, (bool doIgnore), (false),
"Sets if the Module Manager should ingore laoded groups.\n"
"@param doIgnore Whether we should or should not ignore loaded groups.\n"
"@return No return value.\n")
{
// Check whether the merge modules can current happen or not.
return object->setIgnoreLoadedGroups(doIgnore);
}