Merge branch 'development' of https://github.com/TorqueGameEngines/Torque3D into aiSubsystem

This commit is contained in:
AzaezelX 2025-05-03 15:25:36 -05:00
commit 4ba93dafc3
48 changed files with 2382 additions and 3705 deletions

View file

@ -24,7 +24,7 @@ IMPLEMENT_CALLBACK(SubScene, onUnloaded, void, (), (),
"@brief Called when a subScene has been unloaded and has game mode implications.\n\n"); "@brief Called when a subScene has been unloaded and has game mode implications.\n\n");
SubScene::SubScene() : SubScene::SubScene() :
mLevelAssetId(StringTable->EmptyString()), mSubSceneAssetId(StringTable->EmptyString()),
mGameModesNames(StringTable->EmptyString()), mGameModesNames(StringTable->EmptyString()),
mScopeDistance(-1), mScopeDistance(-1),
mLoaded(false), mLoaded(false),
@ -67,7 +67,7 @@ void SubScene::initPersistFields()
{ {
addGroup("SubScene"); addGroup("SubScene");
addField("isGlobalLayer", TypeBool, Offset(mGlobalLayer, SubScene), ""); addField("isGlobalLayer", TypeBool, Offset(mGlobalLayer, SubScene), "");
INITPERSISTFIELD_LEVELASSET(Level, SubScene, "The level asset to load."); INITPERSISTFIELD_SUBSCENEASSET(SubScene, SubScene, "The subscene asset to load.");
addField("tickPeriodMS", TypeS32, Offset(mTickPeriodMS, SubScene), "evaluation rate (ms)"); addField("tickPeriodMS", TypeS32, Offset(mTickPeriodMS, SubScene), "evaluation rate (ms)");
addField("gameModes", TypeGameModeList, Offset(mGameModesNames, SubScene), "The game modes that this subscene is associated with."); addField("gameModes", TypeGameModeList, Offset(mGameModesNames, SubScene), "The game modes that this subscene is associated with.");
endGroup("SubScene"); endGroup("SubScene");
@ -265,13 +265,13 @@ void SubScene::processTick(const Move* move)
void SubScene::_onFileChanged(const Torque::Path& path) void SubScene::_onFileChanged(const Torque::Path& path)
{ {
if(mLevelAsset.isNull() || Torque::Path(mLevelAsset->getLevelPath()) != path) if(mSubSceneAsset.isNull() || Torque::Path(mSubSceneAsset->getLevelPath()) != path)
return; return;
if (mSaving) if (mSaving)
return; return;
AssertFatal(path == mLevelAsset->getLevelPath(), "Prefab::_onFileChanged - path does not match filename."); AssertFatal(path == mSubSceneAsset->getLevelPath(), "SubScene::_onFileChanged - path does not match filename.");
_closeFile(false); _closeFile(false);
_loadFile(false); _loadFile(false);
@ -307,9 +307,9 @@ void SubScene::_closeFile(bool removeFileNotify)
_removeContents(SimGroupIterator(this)); _removeContents(SimGroupIterator(this));
if (removeFileNotify && mLevelAsset.notNull() && mLevelAsset->getLevelPath() != StringTable->EmptyString()) if (removeFileNotify && mSubSceneAsset.notNull() && mSubSceneAsset->getLevelPath() != StringTable->EmptyString())
{ {
Torque::FS::RemoveChangeNotification(mLevelAsset->getLevelPath(), this, &SubScene::_onFileChanged); Torque::FS::RemoveChangeNotification(mSubSceneAsset->getLevelPath(), this, &SubScene::_onFileChanged);
} }
mGameModesList.clear(); mGameModesList.clear();
@ -319,18 +319,18 @@ void SubScene::_loadFile(bool addFileNotify)
{ {
AssertFatal(isServerObject(), "Trying to load a SubScene file on the client is bad!"); AssertFatal(isServerObject(), "Trying to load a SubScene file on the client is bad!");
if(mLevelAsset.isNull() || mLevelAsset->getLevelPath() == StringTable->EmptyString()) if(mSubSceneAsset.isNull() || mSubSceneAsset->getLevelPath() == StringTable->EmptyString())
return; return;
String evalCmd = String::ToString("exec(\"%s\");", mLevelAsset->getLevelPath()); String evalCmd = String::ToString("exec(\"%s\");", mSubSceneAsset->getLevelPath());
String instantGroup = Con::getVariable("InstantGroup"); String instantGroup = Con::getVariable("InstantGroup");
Con::setIntVariable("InstantGroup", this->getId()); Con::setIntVariable("InstantGroup", this->getId());
Con::evaluate((const char*)evalCmd.c_str(), false, mLevelAsset->getLevelPath()); Con::evaluate((const char*)evalCmd.c_str(), false, mSubSceneAsset->getLevelPath());
Con::setVariable("InstantGroup", instantGroup.c_str()); Con::setVariable("InstantGroup", instantGroup.c_str());
if (addFileNotify) if (addFileNotify)
Torque::FS::AddChangeNotification(mLevelAsset->getLevelPath(), this, &SubScene::_onFileChanged); Torque::FS::AddChangeNotification(mSubSceneAsset->getLevelPath(), this, &SubScene::_onFileChanged);
} }
void SubScene::load() void SubScene::load()
@ -432,7 +432,7 @@ bool SubScene::save()
if (size() == 0 || !isLoaded()) if (size() == 0 || !isLoaded())
return false; return false;
if (mLevelAsset.isNull()) if (mSubSceneAsset.isNull())
return false; return false;
if (mSaving) if (mSaving)
@ -446,7 +446,7 @@ bool SubScene::save()
PersistenceManager prMger; PersistenceManager prMger;
StringTableEntry levelPath = mLevelAsset->getLevelPath(); StringTableEntry levelPath = mSubSceneAsset->getLevelPath();
FileStream fs; FileStream fs;
fs.open(levelPath, Torque::FS::File::Write); fs.open(levelPath, Torque::FS::File::Write);
@ -460,7 +460,7 @@ bool SubScene::save()
{ {
if ((*itr)->isMethod("onSaving")) if ((*itr)->isMethod("onSaving"))
{ {
Con::executef((*itr), "onSaving", mLevelAssetId); Con::executef((*itr), "onSaving", mSubSceneAssetId);
} }
if (childObj->getGroup() == this) if (childObj->getGroup() == this)
@ -481,14 +481,14 @@ bool SubScene::save()
bool saveSuccess = false; bool saveSuccess = false;
//Get the level asset //Get the level asset
if (mLevelAsset.isNull()) if (mSubSceneAsset.isNull())
return saveSuccess; return saveSuccess;
//update the gamemode list as well //update the gamemode list as well
mLevelAsset->setDataField(StringTable->insert("gameModesNames"), NULL, StringTable->insert(mGameModesNames)); mSubSceneAsset->setDataField(StringTable->insert("gameModesNames"), NULL, StringTable->insert(mGameModesNames));
//Finally, save //Finally, save
saveSuccess = mLevelAsset->saveAsset(); saveSuccess = mSubSceneAsset->saveAsset();
mSaving = false; mSaving = false;

View file

@ -5,8 +5,8 @@
#ifndef SCENE_GROUP_H #ifndef SCENE_GROUP_H
#include "SceneGroup.h" #include "SceneGroup.h"
#endif #endif
#ifndef LEVEL_ASSET_H #ifndef SUBSCENE_ASSET_H
#include "assets/LevelAsset.h" #include "assets/SubSceneAsset.h"
#endif #endif
class GameMode; class GameMode;
@ -21,13 +21,13 @@ public:
NextFreeMask = Parent::NextFreeMask << 0 NextFreeMask = Parent::NextFreeMask << 0
}; };
void onLevelChanged() {} void onSubSceneChanged() {}
protected: protected:
static bool smTransformChildren; static bool smTransformChildren;
private: private:
DECLARE_LEVELASSET(SubScene, Level, onLevelChanged); DECLARE_SUBSCENEASSET(SubScene, SubScene, onSubSceneChanged);
StringTableEntry mGameModesNames; StringTableEntry mGameModesNames;
Vector<GameMode*> mGameModesList; Vector<GameMode*> mGameModesList;
@ -61,7 +61,7 @@ public:
static void initPersistFields(); static void initPersistFields();
static void consoleInit(); static void consoleInit();
StringTableEntry getTypeHint() const override { return (getLevelAsset()) ? getLevelAsset()->getAssetName() : StringTable->EmptyString(); } StringTableEntry getTypeHint() const override { return (getSubSceneAsset()) ? getSubSceneAsset()->getAssetName() : StringTable->EmptyString(); }
// SimObject // SimObject
bool onAdd() override; bool onAdd() override;
@ -122,6 +122,6 @@ public:
DECLARE_CALLBACK(void, onLoaded, ()); DECLARE_CALLBACK(void, onLoaded, ());
DECLARE_CALLBACK(void, onUnloaded, ()); DECLARE_CALLBACK(void, onUnloaded, ());
DECLARE_ASSET_SETGET(SubScene, Level); DECLARE_ASSET_SETGET(SubScene, SubScene);
}; };
#endif #endif

View file

@ -178,3 +178,17 @@ void CppAsset::onAssetRefresh(void)
mHeaderPath = getOwned() ? expandAssetFilePath(mHeaderFile) : mHeaderPath; mHeaderPath = getOwned() ? expandAssetFilePath(mHeaderFile) : mHeaderPath;
} }
DefineEngineMethod(CppAsset, getCodePath, const char*, (), ,
"Gets the code file filepath of this asset.\n"
"@return File path of the code file.")
{
return object->getCppFilePath();
}
DefineEngineMethod(CppAsset, getHeaderPath, const char*, (), ,
"Gets the header file filepath of this asset.\n"
"@return File path of the header file.")
{
return object->getHeaderFilePath();
}

View file

@ -66,6 +66,9 @@ public:
void setHeaderFile(const char* pHeaderFile); void setHeaderFile(const char* pHeaderFile);
inline StringTableEntry getHeaderFile(void) const { return mHeaderFile; }; inline StringTableEntry getHeaderFile(void) const { return mHeaderFile; };
inline StringTableEntry getCppFilePath(void) const { return mCodePath; };
inline StringTableEntry getHeaderFilePath(void) const { return mHeaderPath; };
protected: protected:
void initializeAsset(void) override; void initializeAsset(void) override;
void onAssetRefresh(void) override; void onAssetRefresh(void) override;
@ -73,9 +76,6 @@ protected:
static bool setCppFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setCppFile(data); return false; } static bool setCppFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setCppFile(data); return false; }
static const char* getCppFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getCppFile(); } static const char* getCppFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getCppFile(); }
inline StringTableEntry getCppFilePath(void) const { return mCodePath; };
inline StringTableEntry getHeaderFilePath(void) const { return mHeaderPath; };
static bool setHeaderFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setHeaderFile(data); return false; } static bool setHeaderFile(void *obj, const char *index, const char *data) { static_cast<CppAsset*>(obj)->setHeaderFile(data); return false; }
static const char* getHeaderFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getHeaderFile(); } static const char* getHeaderFile(void* obj, const char* data) { return static_cast<CppAsset*>(obj)->getHeaderFile(); }
}; };

View file

@ -101,7 +101,7 @@ ConsoleSetType(TypeLevelAssetId)
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false) LevelAsset::LevelAsset() : AssetBase()
{ {
mLevelName = StringTable->EmptyString(); mLevelName = StringTable->EmptyString();
mLevelFile = StringTable->EmptyString(); mLevelFile = StringTable->EmptyString();
@ -117,7 +117,6 @@ LevelAsset::LevelAsset() : AssetBase(), mIsSubLevel(false)
mNavmeshPath = StringTable->EmptyString(); mNavmeshPath = StringTable->EmptyString();
mGameModesNames = StringTable->EmptyString(); mGameModesNames = StringTable->EmptyString();
mMainLevelAsset = StringTable->EmptyString();
mEditorFile = StringTable->EmptyString(); mEditorFile = StringTable->EmptyString();
mBakedSceneFile = StringTable->EmptyString(); mBakedSceneFile = StringTable->EmptyString();
@ -158,7 +157,6 @@ void LevelAsset::initPersistFields()
addProtectedField("BakedSceneFile", TypeAssetLooseFilePath, Offset(mBakedSceneFile, LevelAsset), addProtectedField("BakedSceneFile", TypeAssetLooseFilePath, Offset(mBakedSceneFile, LevelAsset),
&setBakedSceneFile, &getBakedSceneFile, "Path to the level file with the objects generated as part of the baking process"); &setBakedSceneFile, &getBakedSceneFile, "Path to the level file with the objects generated as part of the baking process");
addField("isSubScene", TypeBool, Offset(mIsSubLevel, LevelAsset), "Is this a sublevel to another Scene");
addField("gameModesNames", TypeString, Offset(mGameModesNames, LevelAsset), "Name of the Game Mode to be used with this level"); addField("gameModesNames", TypeString, Offset(mGameModesNames, LevelAsset), "Name of the Game Mode to be used with this level");
} }
@ -481,15 +479,8 @@ GuiControl* GuiInspectorTypeLevelAssetPtr::constructEditControl()
// Create "Open in Editor" button // Create "Open in Editor" button
mEditButton = new GuiBitmapButtonCtrl(); mEditButton = new GuiBitmapButtonCtrl();
String setSubSceneValue = "$createLevelAssetIsSubScene = \"\";"; dSprintf(szBuffer, sizeof(szBuffer), "$createAndAssignField = %s; AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"createAndAssignLevelAsset\");",
if(dynamic_cast<SubScene*>(mInspector->getInspectObject()) != NULL) getIdString());
{
setSubSceneValue = "$createLevelAssetIsSubScene = true;";
}
dSprintf(szBuffer, sizeof(szBuffer), "$createAndAssignField = %s; %s AssetBrowser.setupCreateNewAsset(\"LevelAsset\", AssetBrowser.selectedModule, \"createAndAssignLevelAsset\");",
getIdString(),
setSubSceneValue.c_str());
mEditButton->setField("Command", szBuffer); mEditButton->setField("Command", szBuffer);
char bitmapName[512] = "ToolsModule:iconAdd_image"; char bitmapName[512] = "ToolsModule:iconAdd_image";

View file

@ -66,9 +66,6 @@ class LevelAsset : public AssetBase
StringTableEntry mEditorFile; StringTableEntry mEditorFile;
StringTableEntry mBakedSceneFile; StringTableEntry mBakedSceneFile;
bool mIsSubLevel;
StringTableEntry mMainLevelAsset;
StringTableEntry mGameModesNames; StringTableEntry mGameModesNames;
Vector<AssetBase*> mAssetDependencies; Vector<AssetBase*> mAssetDependencies;

View file

@ -0,0 +1,166 @@
#include "SubSceneAsset.h"
#include "T3D/SubScene.h"
IMPLEMENT_CONOBJECT(SubSceneAsset);
ConsoleType(SubSceneAssetPtr, TypeSubSceneAssetPtr, const char*, "")
//-----------------------------------------------------------------------------
ConsoleGetType(TypeSubSceneAssetPtr)
{
// Fetch asset Id.
return *((const char**)(dptr));
}
//-----------------------------------------------------------------------------
ConsoleSetType(TypeSubSceneAssetPtr)
{
// Was a single argument specified?
if (argc == 1)
{
// Yes, so fetch field value.
*((const char**)dptr) = StringTable->insert(argv[0]);
return;
}
// Warn.
Con::warnf("(TypeSubSceneAssetPtr) - Cannot set multiple args to a single asset.");
}
//-----------------------------------------------------------------------------
ConsoleType(assetIdString, TypeSubSceneAssetId, const char*, "")
ConsoleGetType(TypeSubSceneAssetId)
{
// Fetch asset Id.
return *((const char**)(dptr));
}
ConsoleSetType(TypeSubSceneAssetId)
{
// Was a single argument specified?
if (argc == 1)
{
*((const char**)dptr) = StringTable->insert(argv[0]);
return;
}
// Warn.
Con::warnf("(TypeSubSceneAssetId) - Cannot set multiple args to a single asset.");
}
SubSceneAsset::SubSceneAsset() : LevelAsset()
{
}
SubSceneAsset::~SubSceneAsset()
{
}
void SubSceneAsset::initPersistFields()
{
docsURL;
Parent::initPersistFields();
}
//-----------------------------------------------------------------------------
// GuiInspectorTypeAssetId
//-----------------------------------------------------------------------------
IMPLEMENT_CONOBJECT(GuiInspectorTypeSubSceneAssetPtr);
ConsoleDocClass(GuiInspectorTypeSubSceneAssetPtr,
"@brief Inspector field type for Shapes\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeSubSceneAssetPtr::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeSubSceneAssetPtr)->setInspectorFieldType("GuiInspectorTypeSubSceneAssetPtr");
}
GuiControl* GuiInspectorTypeSubSceneAssetPtr::constructEditControl()
{
// Create base filename edit controls
GuiControl* retCtrl = Parent::constructEditControl();
if (retCtrl == NULL)
return retCtrl;
// Change filespec
char szBuffer[512];
dSprintf(szBuffer, sizeof(szBuffer), "AssetBrowser.showDialog(\"SubSceneAsset\", \"AssetBrowser.changeAsset\", %s, \"\");",
getIdString());
mBrowseButton->setField("Command", szBuffer);
setDataField(StringTable->insert("targetObject"), NULL, mInspector->getInspectObject()->getIdString());
// Create "Open in Editor" button
mEditButton = new GuiBitmapButtonCtrl();
dSprintf(szBuffer, sizeof(szBuffer), "$createAndAssignField = %s; AssetBrowser.setupCreateNewAsset(\"SubSceneAsset\", AssetBrowser.selectedModule);",
getIdString());
mEditButton->setField("Command", szBuffer);
char bitmapName[512] = "ToolsModule:iconAdd_image";
mEditButton->setBitmap(StringTable->insert(bitmapName));
mEditButton->setDataField(StringTable->insert("Profile"), NULL, "GuiButtonProfile");
mEditButton->setDataField(StringTable->insert("tooltipprofile"), NULL, "GuiToolTipProfile");
mEditButton->setDataField(StringTable->insert("hovertime"), NULL, "1000");
mEditButton->setDataField(StringTable->insert("tooltip"), NULL, "Test play this sound");
mEditButton->registerObject();
addObject(mEditButton);
return retCtrl;
}
bool GuiInspectorTypeSubSceneAssetPtr::updateRects()
{
S32 dividerPos, dividerMargin;
mInspector->getDivider(dividerPos, dividerMargin);
Point2I fieldExtent = getExtent();
Point2I fieldPos = getPosition();
mCaptionRect.set(0, 0, fieldExtent.x - dividerPos - dividerMargin, fieldExtent.y);
mEditCtrlRect.set(fieldExtent.x - dividerPos + dividerMargin, 1, dividerPos - dividerMargin - 34, fieldExtent.y);
bool resized = mEdit->resize(mEditCtrlRect.point, mEditCtrlRect.extent);
if (mBrowseButton != NULL)
{
mBrowseRect.set(fieldExtent.x - 32, 2, 14, fieldExtent.y - 4);
resized |= mBrowseButton->resize(mBrowseRect.point, mBrowseRect.extent);
}
if (mEditButton != NULL)
{
RectI shapeEdRect(fieldExtent.x - 16, 2, 14, fieldExtent.y - 4);
resized |= mEditButton->resize(shapeEdRect.point, shapeEdRect.extent);
}
return resized;
}
IMPLEMENT_CONOBJECT(GuiInspectorTypeSubSceneAssetId);
ConsoleDocClass(GuiInspectorTypeSubSceneAssetId,
"@brief Inspector field type for SubScene\n\n"
"Editor use only.\n\n"
"@internal"
);
void GuiInspectorTypeSubSceneAssetId::consoleInit()
{
Parent::consoleInit();
ConsoleBaseType::getType(TypeSubSceneAssetId)->setInspectorFieldType("GuiInspectorTypeSubSceneAssetId");
}

View file

@ -0,0 +1,113 @@
#pragma once
#ifndef SUBSCENE_ASSET_H
#define SUBSCENE_ASSET_H
#ifndef LEVEL_ASSET_H
#include "LevelAsset.h"
#endif
#ifndef _ASSET_DEFINITION_H_
#include "assets/assetDefinition.h"
#endif
#ifndef _GUI_INSPECTOR_TYPES_H_
#include "gui/editor/guiInspectorTypes.h"
#endif
class SubSceneAsset : public LevelAsset
{
typedef LevelAsset Parent;
public:
SubSceneAsset();
virtual ~SubSceneAsset();
/// Engine.
static void initPersistFields();
/// Declare Console Object.
DECLARE_CONOBJECT(SubSceneAsset);
};
#ifdef TORQUE_TOOLS
class GuiInspectorTypeSubSceneAssetPtr : public GuiInspectorTypeFileName
{
typedef GuiInspectorTypeFileName Parent;
public:
GuiBitmapButtonCtrl* mEditButton;
DECLARE_CONOBJECT(GuiInspectorTypeSubSceneAssetPtr);
static void consoleInit();
GuiControl* constructEditControl() override;
bool updateRects() override;
};
class GuiInspectorTypeSubSceneAssetId : public GuiInspectorTypeSubSceneAssetPtr
{
typedef GuiInspectorTypeSubSceneAssetPtr Parent;
public:
DECLARE_CONOBJECT(GuiInspectorTypeSubSceneAssetId);
static void consoleInit();
};
#endif
DefineConsoleType(TypeSubSceneAssetPtr, SubSceneAsset)
DefineConsoleType(TypeSubSceneAssetId, String)
#pragma region Singular Asset Macros
//Singular assets
/// <Summary>
/// Declares an SubScene asset
/// This establishes the assetId, asset and legacy filepath fields, along with supplemental getter and setter functions
/// </Summary>
#define DECLARE_SUBSCENEASSET(className, name, changeFunc) public: \
StringTableEntry m##name##AssetId;\
AssetPtr<SubSceneAsset> m##name##Asset;\
public: \
const AssetPtr<SubSceneAsset> & get##name##Asset() const { return m##name##Asset; }\
void set##name##Asset(const AssetPtr<SubSceneAsset> &_in) { m##name##Asset = _in;}\
\
bool _set##name(StringTableEntry _in)\
{\
if(m##name##AssetId != _in)\
{\
if (m##name##Asset.notNull())\
{\
m##name##Asset->getChangedSignal().remove(this, &className::changeFunc);\
}\
if (_in == NULL || _in == StringTable->EmptyString())\
{\
m##name##AssetId = StringTable->EmptyString();\
m##name##Asset = NULL;\
return true;\
}\
if (AssetDatabase.isDeclaredAsset(_in))\
{\
m##name##AssetId = _in;\
m##name##Asset = _in;\
return true;\
}\
}\
\
if(get##name() == StringTable->EmptyString())\
return true;\
\
return false;\
}\
\
const StringTableEntry get##name() const\
{\
return m##name##AssetId;\
}\
bool name##Valid() {return (get##name() != StringTable->EmptyString() && m##name##Asset->getStatus() == AssetBase::Ok); }
#define INITPERSISTFIELD_SUBSCENEASSET(name, consoleClass, docs) \
addProtectedField(assetText(name, Asset), TypeSubSceneAssetId, Offset(m##name##AssetId, consoleClass), _set##name##Data, &defaultProtectedGetFn, assetDoc(name, asset docs.));
#pragma endregion
#endif // SUBSCENE_ASSET_H

View file

@ -1563,6 +1563,53 @@ bool AssetManager::restoreAssetTags( void )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const char* AssetManager::getAssetLooseFiles(const char* pAssetId)
{
// Debug Profiling.
PROFILE_SCOPE(AssetManager_getAssetLooseFIles);
// Sanity!
AssertFatal(pAssetId != NULL, "Cannot look up NULL asset Id.");
// Find asset.
AssetDefinition* pAssetDefinition = findAsset(pAssetId);
// Did we find the asset?
if (pAssetDefinition == NULL)
{
// No, so warn.
Con::warnf("Asset Manager: Failed to find asset Id '%s' as it does not exist.", pAssetId);
return String::EmptyString;
}
// Info.
if (mEchoInfo)
{
Con::printSeparator();
Con::printf("Asset Manager: Started getting loose files of Asset Id '%s'...", pAssetId);
}
String looseFileList = "";
Vector<StringTableEntry>& assetLooseFiles = pAssetDefinition->mAssetLooseFiles;
for (Vector<StringTableEntry>::iterator looseFileItr = assetLooseFiles.begin(); looseFileItr != assetLooseFiles.end(); ++looseFileItr)
{
// Fetch loose file.
StringTableEntry looseFile = *looseFileItr;
looseFileList += looseFile;
if (looseFileItr != assetLooseFiles.end())
looseFileList += "\t";
}
char* ret = Con::getReturnBuffer(1024);
dSprintf(ret, 1024, "%s", looseFileList.c_str());
return ret;
}
//-----------------------------------------------------------------------------
S32 QSORT_CALLBACK descendingAssetDefinitionLoadCount(const void* a, const void* b) S32 QSORT_CALLBACK descendingAssetDefinitionLoadCount(const void* a, const void* b)
{ {
// Debug Profiling. // Debug Profiling.

View file

@ -341,6 +341,9 @@ public:
bool restoreAssetTags( void ); bool restoreAssetTags( void );
inline AssetTagsManifest* getAssetTags( void ) const { return mAssetTagsManifest; } inline AssetTagsManifest* getAssetTags( void ) const { return mAssetTagsManifest; }
/// Loose File management
const char* getAssetLooseFiles(const char* pAssetId);
/// Info. /// Info.
inline U32 getDeclaredAssetCount( void ) const { return (U32)mDeclaredAssets.size(); } inline U32 getDeclaredAssetCount( void ) const { return (U32)mDeclaredAssets.size(); }
inline U32 getReferencedAssetCount( void ) const { return (U32)mReferencedAssets.size(); } inline U32 getReferencedAssetCount( void ) const { return (U32)mReferencedAssets.size(); }

View file

@ -432,6 +432,20 @@ DefineEngineMethod(AssetManager, getAssetTags, S32, (), ,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
DefineEngineMethod(AssetManager, getAssetLooseFiles, const char*, (const char* assetId), (""),
"Finds the specified asset Id and gets a list of its loose files.\n"
"@param assetId The selected asset Id.\n"
"@return A tab-delinated list of loose files associated to the assetId.\n")
{
// Fetch asset Id.
const char* pAssetId = assetId;
// Delete asset.
return object->getAssetLooseFiles(pAssetId);
}
//-----------------------------------------------------------------------------
DefineEngineMethod(AssetManager, findAllAssets, S32, (const char* assetQuery, bool ignoreInternal, bool ignorePrivate), ("", true, true), DefineEngineMethod(AssetManager, findAllAssets, S32, (const char* assetQuery, bool ignoreInternal, bool ignorePrivate), ("", true, true),
"Performs an asset query searching for all assets optionally ignoring internal assets.\n" "Performs an asset query searching for all assets optionally ignoring internal assets.\n"
"@param assetQuery The asset query object that will be populated with the results.\n" "@param assetQuery The asset query object that will be populated with the results.\n"

View file

@ -102,7 +102,15 @@ DefineEngineFunction( isObject, bool, (const char * objectName), ,"isObject(obje
if (!String::compare(objectName, "0") || !String::compare(objectName, "")) if (!String::compare(objectName, "0") || !String::compare(objectName, ""))
return false; return false;
else else
return (Sim::findObject(objectName) != NULL); {
SimObject* obj= Sim::findObject(objectName);
if (obj)
{
if (!obj->isProperlyAdded() || obj->isRemoved())
obj = NULL;
}
return obj != NULL;
}
} }
ConsoleDocFragment _spawnObject1( ConsoleDocFragment _spawnObject1(

View file

@ -3296,6 +3296,9 @@ DefineEngineMethod( SimObject, getGroup, SimGroup*, (),,
DefineEngineMethod( SimObject, delete, void, (),, DefineEngineMethod( SimObject, delete, void, (),,
"Delete and remove the object." ) "Delete and remove the object." )
{ {
if (!object->isProperlyAdded() || object->isRemoved())
return;
object->deleteObject(); object->deleteObject();
} }

View file

@ -230,7 +230,7 @@ void PopupMenu::enableItem(S32 pos, bool enable)
void PopupMenu::checkItem(S32 pos, bool checked) void PopupMenu::checkItem(S32 pos, bool checked)
{ {
if (mMenuItems.empty() || mMenuItems.size() < pos || pos < 0) if (mMenuItems.empty() || mMenuItems.size() <= pos || pos < 0)
return; return;
if (checked && mMenuItems[pos].mCheckGroup != -1 && mRadioSelection) if (checked && mMenuItems[pos].mCheckGroup != -1 && mRadioSelection)

View file

@ -27,30 +27,9 @@ function initializeAssetBrowser()
$AssetBrowser::collectionSetsFile = "tools/assetBrowser/searchCollectionSets.xml"; $AssetBrowser::collectionSetsFile = "tools/assetBrowser/searchCollectionSets.xml";
$AssetBrowser::currentImportConfig = ""; $AssetBrowser::currentImportConfig = "";
if(!isObject(AssetFilterTypeList)) if(!isObject(ABAssetTypesList))
{ new ArrayObject(ABAssetTypesList){};
new ArrayObject(AssetFilterTypeList);
AssetFilterTypeList.add("All");
AssetFilterTypeList.add("ComponentAsset");
AssetFilterTypeList.add("CppAsset");
AssetFilterTypeList.add("CubemapAsset");
AssetFilterTypeList.add("GameObjectAsset");
AssetFilterTypeList.add("GUIAsset");
AssetFilterTypeList.add("ImageAsset");
AssetFilterTypeList.add("LevelAsset");
AssetFilterTypeList.add("MaterialAsset");
AssetFilterTypeList.add("ParticleAsset");
AssetFilterTypeList.add("PostFXAsset");
AssetFilterTypeList.add("ScriptAsset");
AssetFilterTypeList.add("ShapeAsset");
AssetFilterTypeList.add("ShapeAnimationAsset");
AssetFilterTypeList.add("SoundAsset");
AssetFilterTypeList.add("StateMachineAsset");
AssetFilterTypeList.add("TerrainAsset");
AssetFilterTypeList.add("TerrainMaterialAsset");
}
exec("./scripts/profiles." @ $TorqueScriptFileExtension); exec("./scripts/profiles." @ $TorqueScriptFileExtension);
exec("./guis/assetBrowser.gui"); exec("./guis/assetBrowser.gui");
@ -90,19 +69,19 @@ function initializeAssetBrowser()
exec("./scripts/utils." @ $TorqueScriptFileExtension); exec("./scripts/utils." @ $TorqueScriptFileExtension);
//Processing for the different asset types //Processing for the different asset types
exec("./scripts/assetTypes/component." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/genericAsset." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/cpp." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/cpp." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/gameObject." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/gui." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/gui." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/image." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/image." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/level." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/level." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/subScene." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/material." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/material." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/postFX." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/postFX." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/script." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/script." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/shape." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/shape." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/shapeAnimation." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/shapeAnimation." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/sound." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/sound." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/stateMachine." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/cubemap." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/cubemap." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/folder." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/folder." @ $TorqueScriptFileExtension);
exec("./scripts/assetTypes/terrain." @ $TorqueScriptFileExtension); exec("./scripts/assetTypes/terrain." @ $TorqueScriptFileExtension);

View file

@ -1,86 +0,0 @@
//Builds the preview data of the asset for the Asset Browser
function AssetBrowser::build_AssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = "";
%previewData.doubleClickCommand = "";
%previewData.previewImage = "tools/assetBrowser/art/gameObjectIcon";
%previewData.assetFriendlyName = %assetDef.gameObjectName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.gameObjectName;
}
//Some last-step setup for the creation of the new asset before we do the actual making
//This is generally intended to just set up any type-specific fields for creation
function AssetBrowser::setupCreateNew_Asset(%this)
{
}
//Performs the actual creation of the asset, including loose file copy or generation
function AssetBrowser::create_Asset(%this)
{
}
//This is a pre-process step to prepare the asset item for import
function AssetBrowser::prepareImport_Asset(%this, %assetItem)
{
}
//Performs the action of actually importing the asset item
function AssetBrowser::import_Asset(%this, %assetDef)
{
}
//Editing the asset
function AssetBrowser::edit_Asset(%this, %assetDef)
{
}
//Duplicates the asset
function AssetBrowser::duplicate_Asset(%this, %assetDef, %targetModule)
{
}
//Renames the asset
function AssetBrowser::rename_Asset(%this, %assetDef, %newAssetName)
{
}
//Deletes the asset
function AssetBrowser::delete_Asset(%this, %assetDef)
{
}
//Moves the asset to a new path/module
function AssetBrowser::move_Asset(%this, %assetDef, %destinationFolder)
{
}
//Drag and drop action onto a GUI control
function AssetBrowser::dragAndDrop_Asset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
}
//Even for when
function AssetBrowser::on_AssetEditorDropped(%this, %assetDef, %position)
{
}
//Clicking of the button for the asset type inspector field
function GuiInspectorType_AssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
}
//Drag and droppin onto the asset type inspector field
function GuiInspectorType_AssetPtr::onControlDropped( %this, %payload, %position )
{
}

View file

@ -1,143 +0,0 @@
function AssetBrowser::createComponentAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%tamlpath = %modulePath @ "/components/" @ %assetName @ ".asset.taml";
%scriptPath = %modulePath @ "/components/" @ %assetName @ "." @ $TorqueScriptFileExtension;
%asset = new ComponentAsset()
{
AssetName = %assetName;
versionId = 1;
componentName = %assetName;
componentClass = AssetBrowser.newAssetSettings.parentClass;
friendlyName = AssetBrowser.newAssetSettings.friendlyName;
componentType = AssetBrowser.newAssetSettings.componentGroup;
description = AssetBrowser.newAssetSettings.description;
scriptFile = %assetName @ "." @ $TorqueScriptFileExtension;
};
TamlWrite(%asset, %tamlpath);
%file = new FileObject();
%templateFile = new FileObject();
%templateCodeFilePath = %this.templateFilesPath @ "componentFile." @ $TorqueScriptFileExtension @ ".template";
if(%file.openForWrite(%scriptPath) && %templateFile.openForRead(%templateCodeFilePath))
{
while( !%templateFile.isEOF() )
{
%line = %templateFile.readline();
%line = strreplace( %line, "@@", %assetName );
%file.writeline(%line);
echo(%line);
}
%file.close();
%templateFile.close();
}
else
{
%file.close();
%templateFile.close();
warnf("CreateComponentAsset - Something went wrong and we couldn't write the Component script file!");
}
Canvas.popDialog(AssetBrowser_newComponentAsset);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh();
return %tamlpath;
}
function AssetBrowser::editComponentAsset(%this, %assetDef)
{
%scriptFile = %assetDef.scriptFile;
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
function AssetBrowser::duplicateComponentAsset(%this, %assetId)
{
}
function AssetBrowser::renameComponentAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//rename the file to match
%path = filePath(%assetPath);
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%assetDef.componentName = %newName;
%assetDef.scriptFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %originalName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
}
//not used
function AssetBrowser::importComponentAsset(%this, %assetId)
{
}
function AssetBrowser::buildComponentAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:componentIcon_image";
%previewData.assetFriendlyName = %assetDef.friendlyName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}

View file

@ -1,44 +1,21 @@
function AssetBrowser::buildCppPreview(%this, %assetDef, %previewData) AssetBrowser::registerAssetType("CppAsset", "C++ Assets", "");
{ AssetBrowser::registerFileType("CPPFileType", "C++ Files", ".cpp;.h;.c", false);
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.codeFilePath;
%previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:cppIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}
function AssetBrowser::buildCppAssetPreview(%this, %assetDef, %previewData) function CppAsset::onCreateNew()
{ {
%previewData.assetName = %assetDef.assetName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%previewData.assetPath = %assetDef.codeFilePath;
%previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:cppIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.assetName;
}
function AssetBrowser::createCppAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
//%tamlpath = %assetPath @ %assetName @ ".asset.taml"; %tamlpath = %assetPath @ %assetName @ ".asset.taml";
%codePath = %assetPath @ %assetName @ ".cpp"; %codePath = %assetPath @ %assetName @ ".cpp";
%headerPath = %assetPath @ %assetName @ ".h"; %headerPath = %assetPath @ %assetName @ ".h";
//Do the work here //Do the work here
/*%assetType = AssetBrowser.newAssetSettings.assetType; //%assetType = $CurrentAssetBrowser.newAssetSettings.assetType;
%asset = new CppAsset() %asset = new CppAsset()
{ {
@ -48,7 +25,7 @@ function AssetBrowser::createCppAsset(%this)
headerFile = %headerPath; headerFile = %headerPath;
}; };
TamlWrite(%asset, %tamlpath);*/ TamlWrite(%asset, %tamlpath);
%tamlpath = %assetPath @ %assetName @ ".asset.taml"; %tamlpath = %assetPath @ %assetName @ ".asset.taml";
@ -67,28 +44,28 @@ function AssetBrowser::createCppAsset(%this)
if($AssetBrowser::newAssetTypeOverride $= "StaticClass") if($AssetBrowser::newAssetTypeOverride $= "StaticClass")
{ {
%cppTemplateCodeFilePath = %this.templateFilesPath @ "CppStaticClassFile.cpp.template"; %cppTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppStaticClassFile.cpp.template";
%cppTemplateHeaderFilePath = %this.templateFilesPath @ "CppStaticClassFile.h.template"; %cppTemplateHeaderFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppStaticClassFile.h.template";
} }
else if($AssetBrowser::newAssetTypeOverride $= "ScriptClass") else if($AssetBrowser::newAssetTypeOverride $= "ScriptClass")
{ {
%cppTemplateCodeFilePath = %this.templateFilesPath @ "CppScriptClassFile.cpp.template"; %cppTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppScriptClassFile.cpp.template";
%cppTemplateHeaderFilePath = %this.templateFilesPath @ "CppScriptClassFile.h.template"; %cppTemplateHeaderFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppScriptClassFile.h.template";
} }
else if($AssetBrowser::newAssetTypeOverride $= "AssetTypeCppClass") else if($AssetBrowser::newAssetTypeOverride $= "AssetTypeCppClass")
{ {
%cppTemplateCodeFilePath = %this.templateFilesPath @ "CppAssetTypeClassFile.cpp.template"; %cppTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppAssetTypeClassFile.cpp.template";
%cppTemplateHeaderFilePath = %this.templateFilesPath @ "CppAssetTypeClassFile.h.template"; %cppTemplateHeaderFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppAssetTypeClassFile.h.template";
} }
else if($AssetBrowser::newAssetTypeOverride $= "RenderCppClass") else if($AssetBrowser::newAssetTypeOverride $= "RenderCppClass")
{ {
%cppTemplateCodeFilePath = %this.templateFilesPath @ "CppRenderClassFile.cpp.template"; %cppTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppRenderClassFile.cpp.template";
%cppTemplateHeaderFilePath = %this.templateFilesPath @ "CppRenderClassFile.h.template"; %cppTemplateHeaderFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppRenderClassFile.h.template";
} }
else if($AssetBrowser::newAssetTypeOverride $= "SceneObjectCppClass") else if($AssetBrowser::newAssetTypeOverride $= "SceneObjectCppClass")
{ {
%cppTemplateCodeFilePath = %this.templateFilesPath @ "CppSceneObjectClassFile.cpp.template"; %cppTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppSceneObjectClassFile.cpp.template";
%cppTemplateHeaderFilePath = %this.templateFilesPath @ "CppSceneObjectClassFile.h.template"; %cppTemplateHeaderFilePath = $CurrentAssetBrowser.templateFilesPath @ "CppSceneObjectClassFile.h.template";
} }
$AssetBrowser::newAssetTypeOverride = ""; $AssetBrowser::newAssetTypeOverride = "";
@ -101,7 +78,6 @@ function AssetBrowser::createCppAsset(%this)
%line = strreplace( %line, "@", %assetName ); %line = strreplace( %line, "@", %assetName );
%file.writeline(%line); %file.writeline(%line);
//echo(%line);
} }
%file.close(); %file.close();
@ -134,7 +110,7 @@ function AssetBrowser::createCppAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ header file!"); warn("CreateNewCppAsset - Something went wrong and we couldn't write the C++ header file!");
} }
//Last, check that we have a C++ Module definition. If not, make one so anything important can be initialized on startup there //Last, check that we have a C++ Module definition. If not, make one so anything important can be initialized on startup there
@ -144,7 +120,7 @@ function AssetBrowser::createCppAsset(%this)
%file = new FileObject(); %file = new FileObject();
%templateFile = new FileObject(); %templateFile = new FileObject();
if(%file.openForWrite(%cppModuleFilePath) && %templateFile.openForRead(%this.templateFilesPath @ "CppModuleFile.cpp")) if(%file.openForWrite(%cppModuleFilePath) && %templateFile.openForRead($CurrentAssetBrowser.templateFilesPath @ "CppModuleFile.cpp"))
{ {
while( !%templateFile.isEOF() ) while( !%templateFile.isEOF() )
{ {
@ -163,57 +139,133 @@ function AssetBrowser::createCppAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreateNewCppAsset - Something went wrong and we couldn't write the C++ module file!"); warn("CreateNewCppAsset - Something went wrong and we couldn't write the C++ module file!");
} }
} }
return ""; return "";
} }
function AssetBrowser::editCppAsset(%this, %assetDef) function CppAsset::buildBrowserElement(%this, %previewData)
{ {
%previewData.assetName = %this.assetName;
%previewData.assetPath = %this.codeFilePath;
//%previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:cppIcon_image";
%previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %this.description;
%previewData.tooltip = %this.assetName;
} }
//Renames the asset function CppAsset::onEditCodeFile(%this, %filePath)
function AssetBrowser::renameCppAsset(%this, %assetDef, %newAssetName)
{ {
%newCodeLooseFilename = renameAssetLooseFile(%assetDef.codefile, %newAssetName); if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.getCodeFile() @ "\\\"\");");
if(!%newCodeLooseFilename $= "") else
return; warn("CppAsset::onEditCodeFile() - systemCommand function disabled in this build. Unable to launch application to edit file.");
%newHeaderLooseFilename = renameAssetLooseFile(%assetDef.headerFile, %newAssetName);
if(!%newHeaderLooseFilename $= "")
return;
%assetDef.codefile = %newCodeLooseFilename;
%assetDef.headerFile = %newHeaderLooseFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
} }
//Deletes the asset function CppAsset::onEditHeaderFile(%this, %filePath)
function AssetBrowser::deleteCppAsset(%this, %assetDef)
{ {
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true); if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.getHeaderFile() @ "\\\"\");");
else
warn("CppAsset::onEditHeaderFile() - systemCommand function disabled in this build. Unable to launch application to edit file.");
} }
//Moves the asset to a new path/module function CppAsset::onShowActionMenu(%this)
function AssetBrowser::moveCppAsset(%this, %assetDef, %destination)
{ {
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId()); GenericAsset::onShowActionMenu(%this);
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination); if( !isObject( EditCPPFilesSubmenuPopup ) )
{
if(%newAssetPath $= "") new PopupMenu( EditCPPFilesSubmenuPopup )
return false; {
superClass = "MenuBuilder";
class = "EditorWorldMenu";
moveAssetLooseFile(%assetDef.codeFile, %destination); jumpFileName = "";
moveAssetLooseFile(%assetDef.headerFile, %destination); jumpLineNumber = "";
};
}
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId()); //Regen the menu so we're fully up and current with options and references
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath); EditCPPFilesSubmenuPopup.clearItems();
EditCPPFilesSubmenuPopup.item[ 0 ] = "Code file" TAB "" TAB %this @ ".onEditCodeFile();";
EditCPPFilesSubmenuPopup.item[ 1 ] = "Header file" TAB "" TAB %this @ ".onEditHeaderFile();";
EditCPPFilesSubmenuPopup.reloadItems();
EditAssetPopup.item[ 0 ] = "Edit C++ Files" TAB EditCPPFilesSubmenuPopup;
EditAssetPopup.reloadItems();
EditAssetPopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditAssetPopup;
} }
//==============================================================================
function CPPFileType::buildBrowserElement(%filePath, %previewData)
{
%previewData.assetName = fileName(%filePath);
%previewData.assetPath = %filePath;
//%previewData.doubleClickCommand = "echo(\"Not yet implemented to edit C++ files from the editor\");";//"EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:cppIcon_image";
%previewData.assetFriendlyName = %previewData.assetName;
%previewData.assetDesc = %filePath;
%previewData.tooltip = %filePath;
}
function CPPFileType::onEdit(%filePath)
{
if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %filePath @ "\\\"\");");
else
warn("CPPFileType::onEdit() - systemCommand function disabled in this build. Unable to launch application to edit file.");
}
function CPPFileType::onShowActionMenu(%filePath)
{
if( !isObject( EditCPPFileTypePopup ) )
{
new PopupMenu( EditCPPFileTypePopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
//Regen the menu so we're fully up and current with options and references
EditCPPFileTypePopup.clearItems();
EditCPPFileTypePopup.item[ 0 ] = "Edit C++ File" TAB "" TAB $CurrentAssetBrowser @ ".editAsset();";
EditCPPFileTypePopup.item[ 1 ] = "Rename File" TAB "" TAB $CurrentAssetBrowser @ ".renameAsset();";
EditCPPFileTypePopup.item[ 2 ] = "-";
EditCPPFileTypePopup.item[ 3 ] = "Duplicate File" TAB "" TAB $CurrentAssetBrowser @ ".duplicateAsset();";
EditCPPFileTypePopup.item[ 4 ] = "-";
EditCPPFileTypePopup.item[ 5 ] = "Open File Location" TAB "" TAB $CurrentAssetBrowser @ ".openFileLocation();";
EditCPPFileTypePopup.item[ 6 ] = "-";
EditCPPFileTypePopup.item[ 7 ] = "Delete File" TAB "" TAB $CurrentAssetBrowser @ ".deleteAsset();";
EditCPPFileTypePopup.objectData = %filePath;
EditCPPFileTypePopup.objectType = "CPPFileType";
EditCPPFileTypePopup.reloadItems();
EditCPPFileTypePopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditCPPFileTypePopup;
}
function CPPFileType::onEditProperties(%this, %inspector)
{
}

View file

@ -1,9 +1,11 @@
function AssetBrowser::createCubemapAsset(%this) AssetBrowser::registerAssetType("CubemapAsset", "Cubemaps");
function CubemapAsset::onCreateNew()
{ {
Canvas.pushDialog(CubemapEditor); Canvas.pushDialog(CubemapEditor);
return; return;
%moduleName = AssetBrowser.newAssetSettings.moduleName; /*%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = AssetBrowser.newAssetSettings.assetName;
@ -30,57 +32,13 @@ function AssetBrowser::createCubemapAsset(%this)
AssetBrowser.refresh(); AssetBrowser.refresh();
return %tamlpath; return %tamlpath;*/
} }
function AssetBrowser::editCubemapAsset(%this, %assetDef) function CubemapAsset::onEdit(%this)
{ {
%this.hideDialog(); %this.hideDialog();
CubemapEditor.openCubemapAsset(%assetDef); CubemapEditor.openCubemapAsset(%this);
}
//Renames the asset
function AssetBrowser::renameCubemapAsset(%this, %assetDef, %newAssetName)
{
/*%newCodeLooseFilename = renameAssetLooseFile(%assetDef.codefile, %newAssetName);
if(!%newCodeLooseFilename $= "")
return;
%newHeaderLooseFilename = renameAssetLooseFile(%assetDef.headerFile, %newAssetName);
if(!%newHeaderLooseFilename $= "")
return;
%assetDef.codefile = %newCodeLooseFilename;
%assetDef.headerFile = %newHeaderLooseFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);*/
}
//Deletes the asset
function AssetBrowser::deleteCubemapAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveCubemapAsset(%this, %assetDef, %destination)
{
/*%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.codeFile, %destination);
moveAssetLooseFile(%assetDef.headerFile, %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);*/
} }
function GuiInspectorTypeCubemapAssetPtr::onControlDropped( %this, %payload, %position ) function GuiInspectorTypeCubemapAssetPtr::onControlDropped( %this, %payload, %position )

View file

@ -1,54 +1,29 @@
function AssetBrowser::createNewDatablock(%this) AssetBrowser::registerObjectType("DatablockObjectType", "Datablock Objects", "GameBaseData");
{
AssetBrowser_newFolderNameTxt.text = "NewFolder";
Canvas.pushDialog(AssetBrowser_newFolder);
}
function AssetBrowser::doCreateNewDatablock(%this) function DatablockObjectType::onEdit(%this, %className)
{ {
%newFolderName = AssetBrowser_newFolderNameTxt.getText(); if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset")
if(%newFolderName $= "")
%newFolderName = "NewFolder";
%newFolderIdx = "";
%matched = true;
%newFolderPath = "";
while(%matched == true)
{ {
%newFolderPath = AssetBrowser.dirHandler.currentAddress @ "/" @ %newFolderName @ %newFolderIdx; $CurrentAssetBrowser.hideDialog();
if(!isDirectory(%newFolderPath))
{ DatablockEditorPlugin.openDatablock(%this);
%matched = false;
}
else
{
%newFolderIdx++;
}
} }
else
//make a dummy file {
%file = new FileObject(); %this.onWorldEditorDropped();
%file.openForWrite(%newFolderPath @ "/test"); }
%file.close();
fileDelete(%newFolderPath @ "/test");
//refresh the directory
AssetBrowser.loadDirectories();
%this.navigateTo(%newFolderPath);
} }
function AssetBrowser::buildDatablockPreview(%this, %assetDef, %previewData) function DatablockObjectType::buildBrowserElement(%this, %className, %previewData)
{ {
%previewData.assetName = %assetDef; echo("DatablockObjectType::buildBrowserElement() - " @ %this @ ", " @ %previewData);
%previewData.assetPath = ""; %previewData.assetName = %this.getName();
%previewData.assetPath = %this.getFileName();
%previewData.previewImage = "ToolsModule:datablockIcon_image"; %previewData.previewImage = "ToolsModule:datablockIcon_image";
//Lets see if we have a icon for specifically for this datablock type //Lets see if we have a icon for specifically for this datablock type
%dataClass = %assetDef.getClassName(); %dataClass = %this.getClassName();
%dataClass = strreplace(%dataClass, "Data", ""); %dataClass = strreplace(%dataClass, "Data", "");
%previewImage = "tools/classIcons/" @ %dataClass @ ".png"; %previewImage = "tools/classIcons/" @ %dataClass @ ".png";
@ -58,27 +33,42 @@ function AssetBrowser::buildDatablockPreview(%this, %assetDef, %previewData)
} }
//%previewData.assetFriendlyName = %assetDef.assetName; //%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef; %previewData.assetDesc = %this;
%previewData.tooltip = "\nDatablock Name: " @ %assetDef @ %previewData.tooltip = "\nDatablock Name: " @ %previewData.assetName @
"\nDatablock Type: " @ %assetDef.getClassName() @ "\nDatablock Type: " @ %dataClass @
"\nDefinition Path: " @ %assetDef.getFilename(); "\nDefinition Path: " @ %previewData.assetPath;
}
function DatablockObjectType::onShowActionMenu(%this, %className)
{
if( !isObject( EditDatablockObjectTypePopup ) )
{
new PopupMenu( EditDatablockObjectTypePopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
if(%this.selectMode) EditDatablockObjectTypePopup.objectData = %this;
{ EditDatablockObjectTypePopup.objectType = "DatablockObjectType";
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
} //Regen the menu so we're fully up and current with options and references
else EditDatablockObjectTypePopup.clearItems();
{
if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset") EditDatablockObjectTypePopup.item[ 0 ] = "Edit Datablock" TAB "" TAB $CurrentAssetBrowser @ ".editAsset();";
{ EditDatablockObjectTypePopup.item[ 1 ] = "-";
%previewData.doubleClickCommand = "DatablockEditorPlugin.openDatablock( "@%assetDef@" );"; EditDatablockObjectTypePopup.item[ 2 ] = "Open Datablock Location" TAB "" TAB $CurrentAssetBrowser @ ".openFolderLocation(" @ %this.getFilename() @ ");";
}
else EditDatablockObjectTypePopup.reloadItems();
{
%previewData.doubleClickCommand = "AssetBrowser.onDatablockEditorDropped( "@%assetDef@" );"; EditDatablockObjectTypePopup.showPopup(Canvas);
}
} $CurrentAssetBrowser.popupMenu = EditDatablockObjectTypePopup;
} }
function spawnDatablockObject(%datablock) function spawnDatablockObject(%datablock)
@ -92,96 +82,8 @@ function spawnDatablockObject(%datablock)
return eval(%createCmd);//eval("showImportDialog( \"" @ %shapePath @ "\", \"" @ %createCmd @ "\" );"); return eval(%createCmd);//eval("showImportDialog( \"" @ %shapePath @ "\", \"" @ %createCmd @ "\" );");
} }
function AssetBrowser::renameDatablock(%this, %folderPath, %newFolderName) function DatablockObjectType::onWorldEditorDropped(%this, %position)
{ {
%fullPath = makeFullPath(%folderPath); %newObj = spawnDatablockObject(%this);
%newFullPath = makeFullPath(%folderPath); %newObj.position = %position;
%fullPath = strreplace(%fullPath, "//", "/");
%count = getTokenCount(%fullPath, "/");
%basePath = getTokens(%fullPath, "/", 0, %count-2);
%oldName = getToken(%fullPath, "/", %count-1);
//We need to ensure that no files are 'active' while we try and clean up behind ourselves with the delete action
//so, we nix any assets active for the module, do the delete action on the old folder, and then re-acquire our assets.
//This will have the added benefit of updating paths for asset items
%module = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress);
%moduleId = %module.ModuleId;
AssetDatabase.removeDeclaredAssets(%moduleId);
%copiedSuccess = %this.dirHandler.copyDatablock(%fullPath, %basePath @ "/" @ %newFolderName);
%this.dirHandler.deleteDatablock(%fullPath);
%this.loadDirectories();
AssetDatabase.addModuleDeclaredAssets(%moduleId);
}
function AssetBrowser::moveDatablock(%this, %folderPath, %newFolderPath)
{
%fullPath = makeFullPath(%folderPath);
%newFullPath = makeFullPath(%newFolderPath);
%fullPath = strreplace(%fullPath, "//", "/");
%newFullPath = strreplace(%newFullPath, "//", "/");
%count = getTokenCount(%fullPath, "/");
%basePath = getTokens(%fullPath, "/", 0, %count-2);
%oldName = getToken(%fullPath, "/", %count-1);
%copiedSuccess = %this.dirHandler.copyDatablock(%fullPath, %newFullPath);
%this.dirHandler.deleteDatablock(%fullPath);
%this.loadDirectories();
//thrash the modules and reload them
%oldModule = %this.dirHandler.getModuleFromAddress(%folderPath);
%newModule = %this.dirHandler.getModuleFromAddress(%newFolderPath);
//if we didn't move modules, then we don't need to do anything other than refresh the assets within it
if(%oldModule == %newModule)
{
//only do a refresh to update asset loose file paths
AssetDatabase.refreshAllAssets();
}
else
{
//they're different moduels now, so we gotta unload/reload both
ModuleDatabase.unloadExplicit(%oldModule.getModuleId());
ModuleDatabase.loadExplicit(%oldModule.getModuleId());
ModuleDatabase.unloadExplicit(%newModule.getModuleId());
ModuleDatabase.loadExplicit(%newModule.getModuleId());
}
}
function AssetBrowser::deleteDatablock(%this, %folderPath)
{
%this.dirHandler.deleteDatablock(%folderPath);
%this.refresh();
}
function AssetBrowser::onDatablockEditorDropped(%this, %assetDef, %position)
{
%targetPosition = EWorldEditor.unproject(%position SPC 1);
%camPos = LocalClientConnection.camera.getPosition();
%rayResult = containerRayCast(%camPos, %targetPosition, -1);
%pos = ObjectCreator.getCreateObjectPosition();
if(%rayResult != 0)
{
%pos = getWords(%rayResult, 1, 3);
}
else
{
%pos = "0 0 0";
}
%newObj = spawnDatablockObject(%assetDef);
%newObj.position = %pos;
} }

View file

@ -1,4 +1,6 @@
function AssetBrowser::createNewFolder(%this) AssetBrowser::registerFileType("FolderObjectType", "Folder", "/", false);
function FolderObjectType::setupCreateNew()
{ {
AssetBrowser_newFolderNameTxt.text = "NewFolder"; AssetBrowser_newFolderNameTxt.text = "NewFolder";
Canvas.pushDialog(AssetBrowser_newFolder, 99, true); Canvas.pushDialog(AssetBrowser_newFolder, 99, true);
@ -6,7 +8,7 @@ function AssetBrowser::createNewFolder(%this)
AssetBrowser_newFolderNameTxt.selectAllText(); AssetBrowser_newFolderNameTxt.selectAllText();
} }
function AssetBrowser::doCreateNewFolder(%this) function FolderObjectType::onCreateNew()
{ {
%newFolderName = AssetBrowser_newFolderNameTxt.getText(); %newFolderName = AssetBrowser_newFolderNameTxt.getText();
@ -19,7 +21,7 @@ function AssetBrowser::doCreateNewFolder(%this)
} }
else else
{ {
%currentAddressPath = AssetBrowser.dirHandler.currentAddress; %currentAddressPath = $CurrentAssetBrowser.dirHandler.currentAddress;
} }
%newFolderIdx = ""; %newFolderIdx = "";
@ -46,29 +48,65 @@ function AssetBrowser::doCreateNewFolder(%this)
fileDelete(%newFolderPath @ "/test"); fileDelete(%newFolderPath @ "/test");
//refresh the directory //refresh the directory
AssetBrowser.loadDirectories(); $CurrentAssetBrowser.loadDirectories();
%this.navigateTo(%newFolderPath); $CurrentAssetBrowser.navigateTo(%newFolderPath);
//On the off chance we're trying to select a path, we'll update the select path window too //On the off chance we're trying to select a path, we'll update the select path window too
if(SelectAssetPath.isAwake()) if(SelectAssetPath.isAwake())
SelectAssetPath.showDialog(%newFolderPath, SelectAssetPath.callback); SelectAssetPath.showDialog(%newFolderPath, SelectAssetPath.callback);
} }
function AssetBrowser::buildFolderPreview(%this, %assetDef, %previewData) function FolderObjectType::buildBrowserElement(%folderPath, %previewData)
{ {
%previewData.assetName = %assetDef.assetName; %folderName = fileBase(%folderPath);
%previewData.assetPath = %assetDef.dirPath;
%previewData.assetName = %folderName;
%previewData.assetPath = %folderPath;
%previewData.previewImage = "ToolsModule:FolderIcon_image"; %previewData.previewImage = "ToolsModule:FolderIcon_image";
//%previewData.assetFriendlyName = %assetDef.assetName; //%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = "Folder";
%previewData.tooltip = %assetDef.dirPath; %previewData.tooltip = %folderPath;
%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %assetDef.dirPath @ "/" @ %assetDef.assetName @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName %previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %folderPath @"\");"; //browseTo %this.dirPath / %this.assetName
} }
function AssetBrowser::renameFolder(%this, %folderPath, %newFolderName) function FolderObjectType::onShowActionMenu(%folderPath)
{
if( !isObject( EditFolderTypePopup ) )
{
new PopupMenu( EditFolderTypePopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
EditFolderTypePopup.objectData = %folderPath;
EditFolderTypePopup.objectType = "FolderObjectType";
//Regen the menu so we're fully up and current with options and references
EditFolderTypePopup.clearItems();
EditFolderTypePopup.item[ 0 ] = "Rename Folder" TAB "" TAB $CurrentAssetBrowser @ ".renameAsset();";
EditFolderTypePopup.item[ 1 ] = "Duplicate Folder" TAB "" TAB $CurrentAssetBrowser @ ".duplicateAsset();";
EditFolderTypePopup.item[ 2 ] = "-";
EditFolderTypePopup.item[ 3 ] = "Open Folder Location" TAB "" TAB $CurrentAssetBrowser @ ".openFolderLocation(" @ %folderPath @ ");";
EditFolderTypePopup.item[ 4 ] = "-";
EditFolderTypePopup.item[ 5 ] = "Delete Folder" TAB "" TAB $CurrentAssetBrowser @ ".deleteAsset();";
EditFolderTypePopup.reloadItems();
EditFolderTypePopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditFolderTypePopup;
}
function FolderObjectType::onRename(%folderPath, %newFolderName)
{ {
%fullPath = makeFullPath(%folderPath); %fullPath = makeFullPath(%folderPath);
%newFullPath = makeFullPath(%folderPath); %newFullPath = makeFullPath(%folderPath);
@ -83,23 +121,40 @@ function AssetBrowser::renameFolder(%this, %folderPath, %newFolderName)
//so, we nix any assets active for the module, do the delete action on the old folder, and then re-acquire our assets. //so, we nix any assets active for the module, do the delete action on the old folder, and then re-acquire our assets.
//This will have the added benefit of updating paths for asset items //This will have the added benefit of updating paths for asset items
%module = AssetBrowser.dirHandler.getModuleFromAddress(AssetBrowser.dirHandler.currentAddress); %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress($CurrentAssetBrowser.dirHandler.currentAddress);
%moduleId = %module.ModuleId; %moduleId = %module.ModuleId;
AssetDatabase.removeDeclaredAssets(%moduleId); $CurrentAssetBrowser.removeDeclaredAssets(%moduleId);
%copiedSuccess = %this.dirHandler.copyFolder(%fullPath, %basePath @ "/" @ %newFolderName); %copiedSuccess = $CurrentAssetBrowser.dirHandler.copyFolder(%fullPath, %basePath @ "/" @ %newFolderName);
%this.dirHandler.deleteFolder(%fullPath); $CurrentAssetBrowser.dirHandler.deleteFolder(%fullPath);
%this.loadDirectories(); $CurrentAssetBrowser.loadDirectories();
AssetDatabase.addModuleDeclaredAssets(%moduleId); $CurrentAssetBrowser.addModuleDeclaredAssets(%moduleId);
} }
function AssetBrowser::moveFolder(%this, %folderPath, %newFolderPath) function FolderObjectType::onDelete(%folderPath)
{
$CurrentAssetBrowser.dirHandler.deleteFolder(%folderPath);
$CurrentAssetBrowser.refresh();
}
function FolderObjectType::onWorldEditorDropped(%folderPath, %position)
{
//We do nothing with this as we don't process entire folders for spawning
}
function FolderObjectType::onGuiEditorDropped(%folderPath, %position)
{
//We do nothing with this as we don't process entire folders for spawning
}
function FolderObjectType::onMovePath(%folderPath, %destinationPath)
{ {
%fullPath = makeFullPath(%folderPath); %fullPath = makeFullPath(%folderPath);
%newFullPath = makeFullPath(%newFolderPath); %newFullPath = makeFullPath(%destinationPath);
%fullPath = strreplace(%fullPath, "//", "/"); %fullPath = strreplace(%fullPath, "//", "/");
%newFullPath = strreplace(%newFullPath, "//", "/"); %newFullPath = strreplace(%newFullPath, "//", "/");
@ -108,14 +163,20 @@ function AssetBrowser::moveFolder(%this, %folderPath, %newFolderPath)
%basePath = getTokens(%fullPath, "/", 0, %count-2); %basePath = getTokens(%fullPath, "/", 0, %count-2);
%oldName = getToken(%fullPath, "/", %count-1); %oldName = getToken(%fullPath, "/", %count-1);
%copiedSuccess = %this.dirHandler.copyFolder(%fullPath, %newFullPath); %copiedSuccess = $CurrentAssetBrowser.dirHandler.copyFolder(%fullPath, %newFullPath);
%this.dirHandler.deleteFolder(%fullPath); $CurrentAssetBrowser.dirHandler.deleteFolder(%fullPath);
%this.loadDirectories(); $CurrentAssetBrowser.loadDirectories();
}
function FolderObjectType::onMoveModule(%folderPath, %destinationPath)
{
//Same logic as a regular folder move
FolderObjectType::onMovePath(%folderPath, %destinationPath);
//thrash the modules and reload them //thrash the modules and reload them
%oldModule = %this.dirHandler.getModuleFromAddress(%folderPath); %oldModule = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(%folderPath);
%newModule = %this.dirHandler.getModuleFromAddress(%newFolderPath); %newModule = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(%destinationPath);
//if we didn't move modules, then we don't need to do anything other than refresh the assets within it //if we didn't move modules, then we don't need to do anything other than refresh the assets within it
if(%oldModule == %newModule) if(%oldModule == %newModule)
@ -132,11 +193,4 @@ function AssetBrowser::moveFolder(%this, %folderPath, %newFolderPath)
ModuleDatabase.unloadExplicit(%newModule.getModuleId()); ModuleDatabase.unloadExplicit(%newModule.getModuleId());
ModuleDatabase.loadExplicit(%newModule.getModuleId()); ModuleDatabase.loadExplicit(%newModule.getModuleId());
} }
}
function AssetBrowser::deleteFolder(%this, %folderPath)
{
%this.dirHandler.deleteFolder(%folderPath);
%this.refresh();
} }

View file

@ -1,285 +0,0 @@
function AssetBrowser::createGameObjectAsset(%this)
{
GameObjectCreatorObjectName.text = "";
%activeSelection = EWorldEditor.getActiveSelection();
if( %activeSelection.getCount() == 0 )
return;
GameObjectCreator.selectedEntity = %activeSelection.getObject( 0 );
Canvas.pushDialog(GameObjectCreator);
}
function AssetBrowser::editGameObjectAsset(%this, %assetDef)
{
//We have no dedicated GO editor for now, so just defer to the script editing aspect
%this.editGameObjectAssetScript(%assetDef);
}
function AssetBrowser::editGameObjectAssetScript(%this, %assetDef)
{
%scriptFile = %assetDef.scriptFile;
if(%scriptFile !$= "")
EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0);
}
function AssetBrowser::applyInstanceToGameObject(%this, %assetDef)
{
%obj = EditGameObjectAssetPopup.object;
//TODO add proper validation against the original GO asset
%obj.dirtyGameObject = true;
TamlWrite(%obj, %assetDef.TAMLFilePath);
}
function AssetBrowser::duplicateGameObjectAsset(%this, %assetDef, %targetModule)
{
//Check if we have a target module, if not we need to select one
if(%targetModule $= "")
{
error("AssetBrowser::duplicateGameObjectAsset - No target module selected!");
return;
}
%assetId = %assetDef.getAssetId();
%assetName = AssetDatabase.getAssetName(%assetId);
//First step, copy the files
%modulePath = "data/" @ %targetModule @ "/gameObjects/";
if(!isDirectory(%modulePath))
createPath(%modulePath);
%assetFile = AssetDatabase.getAssetFilePath(%assetId);
%scriptFile = %assetDef.scriptFile;
%gameObjectFile = %assetDef.TAMLFile;
echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule);
%tamlPath = %modulePath @ fileName(%assetFile);
pathCopy(%assetFile, %tamlPath);
pathCopy(%scriptFile, %modulePath @ fileName(%scriptFile));
pathCopy(%gameObjectFile, %modulePath @ fileName(%gameObjectFile));
echo("AssetBrowser::duplicateGameObjectAsset - duplicated!");
//Register the asset
%moduleDef = ModuleDatabase.findModule(%targetModule, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath);
//Refresh the browser
AssetBrowser.refresh();
//Rename it for convenience
AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName);
}
//not used
function AssetBrowser::importGameObjectAsset(%this, %assetId)
{
}
function AssetBrowser::dragAndDropGameObjectAsset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
if(%dropTarget.getId() == EWorldEditor.getId())
{
if(isObject(%assetDef))
{
%gameObject = %assetDef.createObject();
getScene(0).add(%gameObject);
%pos = ObjectCreator.getCreateObjectPosition(); //LocalClientConnection.camera.position;
%gameObject.position = %pos;
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%gameObject);
}
else
{
error("WorldEditor::onControlDropped - unable to create GameObject");
}
}
}
function AssetBrowser::onGameObjectAssetEditorDropped(%this, %assetDef, %position)
{
//echo("DROPPED A SHAPE ON THE EDITOR WINDOW!");
%targetPosition = EWorldEditor.unproject(%position SPC 1);
%camPos = LocalClientConnection.camera.getPosition();
%rayResult = containerRayCast(%camPos, %targetPosition, -1);
%pos = ObjectCreator.getCreateObjectPosition();
if(%rayResult != 0)
{
%pos = getWords(%rayResult, 1, 3);
}
%gameObject = %assetDef.createObject();
getScene(0).add(%gameObject);
%gameObject.position = %pos;
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%gameObject);
EWorldEditor.isDirty = true;
}
function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%oldScriptFilePath = %assetDef.scriptFile;
%scriptFilePath = filePath(%assetDef.scriptFile);
%scriptExt = fileExt(%assetDef.scriptFile);
%oldGOFilePath = %assetDef.TAMLFile;
%filepath = AssetDatabase.getAssetFilePath(%assetDef.getAssetId());
%path = makeRelativePath(filePath(%filepath));
%newScriptFileName = %path @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%newGOFile = %path @ "/" @ %newName @ ".taml";
%assetDef.gameObjectName = %newName;
%assetDef.scriptFile = %newScriptFileName;
%assetDef.TAMLFile = %newGOFile;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%filepath);
//Quick check, if we duplicated the asset to a new module, the old path may not line up so we'll want to update that to be relevent
if(filePath(%oldScriptFilePath) !$= %path)
{
%oldFileBase = fileName(%oldScriptFilePath);
%oldScriptFilePath = %path @ "/" @ %oldFileBase;
}
%scriptFileCopySuccess = pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
if(!%scriptFileCopySuccess)
error("AssetBrowser::renameGameObjectAsset - unable to copy scriptFile");
if(filePath(%oldGOFilePath) !$= %path)
{
%oldFileBase = fileName(%oldGOFilePath);
%oldGOFilePath = %path @ "/" @ %oldFileBase;
}
%goFileCopySuccess = pathCopy(%oldGOFilePath, %newGOFile);
fileDelete(%oldGOFilePath);
if(!%scriptFileCopySuccess)
error("AssetBrowser::renameGameObjectAsset - unable to copy gameObject");
//Go through our scriptfile and replace the old namespace with the new
%editedFileContents = "";
%file = new FileObject();
if ( %file.openForRead( %newScriptFileName ) )
{
while ( !%file.isEOF() )
{
%line = %file.readLine();
%line = trim( %line );
%editedFileContents = %editedFileContents @ strreplace(%line, %originalName, %newName) @ "\n";
}
%file.close();
}
if(%editedFileContents !$= "")
{
%file.openForWrite(%newScriptFileName);
%file.writeline(%editedFileContents);
%file.close();
}
exec(%newScriptFileName);
%gameObj = TAMLRead(%newGOFile);
%gameObj.className = %newName;
%gameObj.GameObject = %assetDef.getAssetId();
TAMLWrite(%gameObj, %newGOFile);
}
//Deletes the asset
function AssetBrowser::deleteGameObjectAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveGameObjectAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.scriptFile, %destination);
moveAssetLooseFile(%assetDef.TAMLFile, %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildGameObjectAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "EditorOpenFileInTorsion( "@%previewData.assetPath@", 0 );";
%previewData.previewImage = "ToolsModule:gameObjectIcon_image";
%previewData.assetFriendlyName = %assetDef.gameObjectName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.gameObjectName @ "\nDefinition Path: " @ %assetDef.getFilename();
}
function GuiInspectorTypeGameObjectAssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
EditGameObjectAssetPopup.object = %obj;
%assetId = %obj.getFieldValue(%fieldName);
if(%assetId !$= "")
{
EditGameObjectAssetPopup.assetId = %assetId;
EditGameObjectAssetPopup.showPopup(Canvas);
}
else
{
//We've gotta be trying to create a GameObject, so kick that off
AssetBrowser.createGameObjectAsset();
}
}

View file

@ -0,0 +1,351 @@
//This function registers the asset type, associated file extensions and human-readable name with the Asset Browser
//This is primarily so there's an easy hook-in point for the 'type' namespace, as well as registration for AB
//filter modes and file scanning
AssetBrowser::registerAssetType("GenericAsset", "", "", false);
//This function is called when we want to have adjustable field information for a new asset
//This could be a secondary name or description, a 'preview image' or anything else beyond
//just the basic AssetName and AssetDescription files
function GenericAsset::setupCreateNew()
{
echo("GenericAsset::setupCreateNew()");
}
//This is called when we actually finally decide to create the new asset itself
//We create the asset definition, supplemental files, save everything to disk and
//then register with the AssetDatabase so it's available for use
function GenericAsset::onCreateNew()
{
echo("GenericAsset::onCreateNew()");
}
//This us called when we are creating a 'card' in the AssetBrowser for viewing
//when navigating. It packs whatever relevent information such as the preview image
//into the %previewData object that the AssetBrowser then uses to actually display
function GenericAsset::buildBrowserElement(%this, %previewData)
{
%previewData.assetName = %this.assetName;
%previewData.assetPath = %this.getFileName();
%previewData.doubleClickCommand = "";
%previewData.previewImage = "ToolsModule:genericAssetIcon_image";
%previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %this.assetName @ "\nDefinition Path: " @ %previewData.assetPath;
}
//This is called when we specifically need to special-handle generation of a preview image
//Such as rendering a shape or material to a cached image file, rather than simply using a
//basic image to represent the type in the AssetBrowser
function GenericAsset::generatePreviewImage(%this, %previewButton, %forceRegenerate)
{
}
//Called when we rename the asset. The place we would change the asset definition name
//as well as update the name for any associated files
function GenericAsset::onRename(%this, %newAssetName)
{
%assetPath = makeFullPath($CurrentAssetBrowser.getAssetFilePath(%this.getAssetId()));
%assetFilepath = filePath(%assetPath);
%assetFileExt = fileExt(%assetPath);
%newAssetPath = %assetFilepath @ "/" @ %newAssetName @ ".asset.taml";
%copiedSuccess = pathCopy(%assetPath, %newAssetPath);
if(!%copiedSuccess)
return "";
replaceInFile(%newAssetPath, %this.assetName, %newAssetName);
%looseFilesList = AssetDatabase.getAssetLooseFiles(%this.getAssetId());
for(%i=0; %i < getFieldCount(%looseFilesList); %i++)
{
%looseFile = getField(%looseFilesList, %i);
if(!isFile(%looseFile))
{
errorf("GenericAsset::onMovePath() - could not find loose file: " @ %looseFile);
continue;
}
%newLooseFileName = strReplace(fileName(%looseFile), %this.assetName, %newAssetName);
%looseFileExt = fileExt(%looseFile);
echo("GenericAsset::onRename() - renamed loose file from: " @ %looseFile @ " to: " @ %assetPath @ "/" @ %newLooseFileName @ %looseFileExt);
%looseFileNewPath = %assetPath @ "/" @ %newLooseFileName @ %looseFileExt;
%copiedSuccess = pathCopy(%looseFile, %looseFileNewPath);
if(!%copiedSuccess)
{
errorf("GenericAsset::onDuplicate() - failed to duplicate loose file: " @ %looseFile);
}
else
{
fileDelete(%looseFile);
replaceInFile(%looseFileNewPath, %this.assetName, %newAssetName);
}
}
%module = getModuleFromAddress(%newAssetPath);
//Add with the new file
$CurrentAssetBrowser.addDeclaredAsset(%module, %newAssetPath);
GenericAsset::onDelete(%this);
return %newAssetPath;
}
//Called when duplicating the asset. A copy is made, and then we perform a rename action
//on the copy to ensure there's no name conflicts
function GenericAsset::onDuplicate(%this, %newAssetName)
{
%assetPath = makeFullPath($CurrentAssetBrowser.getAssetFilePath(%this.getAssetId()));
%assetFilepath = filePath(%assetPath);
%assetFileExt = fileExt(%assetPath);
%newAssetPath = %assetFilepath @ "/" @ %newAssetName @ ".asset.taml";
%copiedSuccess = pathCopy(%assetPath, %newAssetPath);
if(!%copiedSuccess)
return "";
replaceInFile(%newAssetPath, %this.assetName, %newAssetName);
%looseFilesList = AssetDatabase.getAssetLooseFiles(%this.getAssetId());
for(%i=0; %i < getFieldCount(%looseFilesList); %i++)
{
%looseFile = getField(%looseFilesList, %i);
if(!isFile(%looseFile))
{
errorf("GenericAsset::onMovePath() - could not find loose file: " @ %looseFile);
continue;
}
%newLooseFileName = strReplace(fileName(%looseFile), %this.assetName, %newAssetName);
%looseFileExt = fileExt(%looseFile);
echo("GenericAsset::onDuplicate() - renamed loose file from: " @ %looseFile @ " to: " @ %assetPath @ "/" @ %newLooseFileName @ %looseFileExt);
%looseFileNewPath = %assetPath @ "/" @ %newLooseFileName @ %looseFileExt;
%copiedSuccess = pathCopy(%looseFile, %looseFileNewPath);
if(!%copiedSuccess)
{
errorf("GenericAsset::onDuplicate() - failed to duplicate loose file: " @ %looseFile);
}
else
{
replaceInFile(%looseFileNewPath, %this.assetName, %newAssetName);
}
}
%module = getModuleFromAddress(%newAssetPath);
//Add with the new file
$CurrentAssetBrowser.addDeclaredAsset(%module, %newAssetPath);
$CurrentAssetBrowser.refresh();
return %newAssetPath;
}
//Called when the asset is deleted. This would be where and associated files
//are also removed from the system
function GenericAsset::onDelete(%this)
{
AssetDatabase.deleteAsset(%this.getAssetId(), true);
$CurrentAssetBrowser.refresh();
}
//Called when the asset is moved from one file path to another. Associated files would be
//likewise moved
function GenericAsset::onMovePath(%this, %destinationPath)
{
%assetPath = makeFullPath($CurrentAssetBrowser.getAssetFilePath(%this.getAssetId()));
moveAssetFile(%this, %destinationPath);
%looseFilesList = AssetDatabase.getAssetLooseFiles(%this.getAssetId());
for(%i=0; %i < getFieldCount(%looseFilesList); %i++)
{
%looseFile = getField(%looseFilesList, %i);
moveAssetLooseFile(%looseFile, %destinationPath);
}
AssetDatabase.refreshAsset(%this.getAssetId());
$CurrentAssetBrowser.refresh();
}
function GenericAsset::onMoveModule(%this, %destinationPath)
{
%assetPath = makeFullPath($CurrentAssetBrowser.getAssetFilePath(%this.getAssetId()));
%newAssetPath = moveAssetFile(%this, %destinationPath);
%looseFilesList = AssetDatabase.getAssetLooseFiles(%this.getAssetId());
for(%i=0; %i < getFieldCount(%looseFilesList); %i++)
{
%looseFile = getField(%looseFilesList, %i);
moveAssetLooseFile(%looseFile, %destinationPath);
}
%targetModule = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(%destinationPath);
AssetDatabase.removeDeclaredAsset(%this.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
$CurrentAssetBrowser.refresh();
}
//Called when there is an InspectorType field for this AssetType and a Asset preview
//has been dragged and dropped from the AssetBrowser onto this field in the inspector
//Generally this would see the field assigned with the dropped asset's ID
/*function GuiInspectorType<AssetType>Ptr::onControlDropped(%this, %payload, %position)
{
}*/
//Called when the asset is edited. This can either open the asset in the respective
//editor(MaterialAsset opens MaterialEd, etc) or performs some other action, such as loading
//a LevelAsset in the editor or possibly opening an associated file in a system program for editing
function GenericAsset::onEdit(%this)
{
echo("GenericAsset::onEdit() - " @ %this);
}
//Called when the asset's Preview has been right-clicked to do a context popup menu
//Allows for special-menu population per-type if desired, as not all assets will or should
//offer the same 'actions' for editing and management
function GenericAsset::onShowActionMenu(%this)
{
if( !isObject( EditAssetPopup ) )
{
new PopupMenu( EditAssetPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
//Regen the menu so we're fully up and current with options and references
EditAssetPopup.clearItems();
EditAssetPopup.item[ 0 ] = "Edit Asset" TAB "" TAB $CurrentAssetBrowser @ ".editAsset();";
EditAssetPopup.item[ 1 ] = "Rename Asset" TAB "" TAB $CurrentAssetBrowser @ ".renameAsset();";
EditAssetPopup.item[ 2 ] = "Reload Asset" TAB "" TAB $CurrentAssetBrowser @ ".refreshAsset();";
EditAssetPopup.item[ 3 ] = "Asset Properties" TAB "" TAB $CurrentAssetBrowser @ ".editAssetInfo();";
EditAssetPopup.item[ 4 ] = "-";
EditAssetPopup.item[ 5 ] = "Duplicate Asset" TAB "" TAB $CurrentAssetBrowser @ ".duplicateAsset();";
EditAssetPopup.item[ 6 ] = "-";
EditAssetPopup.item[ 7 ] = "Regenerate Preview Image" TAB "" TAB $CurrentAssetBrowser @ ".regeneratePreviewImage();";
EditAssetPopup.item[ 8 ] = "-";
EditAssetPopup.item[ 9 ] = "Re-Import Asset" TAB "" TAB $CurrentAssetBrowser @ ".reImportAsset();";
EditAssetPopup.item[ 10 ] = "-";
EditAssetPopup.item[ 11 ] = "Open File Location" TAB "" TAB $CurrentAssetBrowser @ ".openFileLocation();";
EditAssetPopup.item[ 12 ] = "-";
EditAssetPopup.item[ 13 ] = "Delete Asset" TAB "" TAB $CurrentAssetBrowser @ ".deleteAsset();";
%assetId = %this.getAssetId();
%assetType = AssetDatabase.getAssetType(%assetId);
EditAssetPopup.objectData = %assetId;
EditAssetPopup.objectType = %assetType;
EditAssetPopup.reloadItems();
EditAssetPopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditAssetPopup;
}
//Called when editing the asset's properties, generally presented via an inspector
//This function allows for special type handling if just inspecting the Type's object
//is insufficient
function GenericAsset::onEditProperties(%this)
{
Canvas.pushDialog(AssetBrowser_editAsset);
AssetBrowser_editAssetWindow.text = "Asset Properties - " @ %this.getAssetId();
AssetEditInspector.tempAsset = %this.deepClone();
AssetEditInspector.inspect(AssetEditInspector.tempAsset);
AssetBrowser_editAsset.editedObjectData = %this.getAssetId();
AssetBrowser_editAsset.editedObject = AssetEditInspector.tempAsset;
AssetBrowser_editAsset.editedObjectType = AssetDatabase.getAssetType(%this.getAssetId());
//remove some of the groups we don't need:
for(%i=0; %i < AssetEditInspector.getCount(); %i++)
{
%caption = AssetEditInspector.getObject(%i).caption;
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
AssetEditInspector.remove(AssetEditInspector.getObject(%i));
%i--;
}
}
}
//Called when the AssetType has it's properties saved from the onEditProperties process
function GenericAsset::onSaveProperties(%this)
{
%assetId = %this.getAssetId();
%file = AssetDatabase.getAssetFilePath(%assetId);
%success = TamlWrite(AssetBrowser_editAsset.editedObject, %file);
AssetDatabase.releaseAsset(%assetId);
$CurrentAssetBrowser.reloadAsset(%assetId);
$CurrentAssetBrowser.refresh();
%this.refreshAsset();
}
//Called when the asset's Preview has been dragged and dropped into the world editor
//This would usually spawn an associated instance, or a scene object that can utilize the
//asset in question(ie, Dropping a SoundAsset spawns a SoundEmitter)
function GenericAsset::onWorldEditorDropped(%this, %position)
{
echo("GenericAsset::onWorldEditorDropped() - " @ %this @ ", " @ %position);
}
//Called when the asset's Preview has been dragged and dropped into the GUI editor
//This would usually spawn an associated instance, or a gui object that can utilize the
//asset in question(ie, Dropping a SoundAsset spawns a guiAudioCtrl)
function GenericAsset::onGuiEditorDropped(%this, %position)
{
echo("GenericAsset::onGuiEditorDropped() - " @ %this @ ", " @ %position);
}
//An example case of handling other specialized editors, such as dropping a Datablock
//Preview into the DatablockEditor. This would be very case-by-case
/*function GenericAsset::on<Editor>EditorDropped()
{
}*/
//Called when the asset has been detected as having had files on the system changed. Allows
//for automatically responding to those changes, such as re-execing script files
function GenericAsset::onChanged(%this)
{
echo("GenericAsset::onChanged() - " @ %this);
}
function GenericAsset::onStatusChanged(%this, %newStstus)
{
echo("GenericAsset::onStatusChanged() - " @ %this @ ", " @ %newStstus);
}

View file

@ -1,9 +1,12 @@
function AssetBrowser::createGUIAsset(%this) AssetBrowser::registerFileType("GUIFileType", "GUI Files", ".gui;.gui.dso", false);
AssetBrowser::registerAssetType("GUIAsset", "GUIs");
function GUIAsset::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
@ -24,7 +27,7 @@ function AssetBrowser::createGUIAsset(%this)
%file = new FileObject(); %file = new FileObject();
%templateFile = new FileObject(); %templateFile = new FileObject();
%guiTemplateCodeFilePath = %this.templateFilesPath @ "guiFile.gui.template"; %guiTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "guiFile.gui.template";
if(%file.openForWrite(%guipath) && %templateFile.openForRead(%guiTemplateCodeFilePath)) if(%file.openForWrite(%guipath) && %templateFile.openForRead(%guiTemplateCodeFilePath))
{ {
@ -45,10 +48,10 @@ function AssetBrowser::createGUIAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreateGUIAsset - Something went wrong and we couldn't write the GUI file!"); warn("GUIAsset::onCreateNew() - Something went wrong and we couldn't write the GUI file!");
} }
%scriptTemplateCodeFilePath = %this.templateFilesPath @ "guiFile." @ $TorqueScriptFileExtension @ ".template"; %scriptTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "guiFile." @ $TorqueScriptFileExtension @ ".template";
if(%file.openForWrite(%scriptPath) && %templateFile.openForRead(%scriptTemplateCodeFilePath)) if(%file.openForWrite(%scriptPath) && %templateFile.openForRead(%scriptTemplateCodeFilePath))
{ {
@ -69,7 +72,7 @@ function AssetBrowser::createGUIAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreateGUIAsset - Something went wrong and we couldn't write the GUI script file!"); warn("GUIAsset::onCreateNew() - Something went wrong and we couldn't write the GUI script file!");
} }
//load the gui //load the gui
@ -79,31 +82,17 @@ function AssetBrowser::createGUIAsset(%this)
%moduleDef = ModuleDatabase.findModule(%moduleName, 1); %moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh(); $CurrentAssetBrowser.refresh();
return %tamlpath; return %tamlpath;
} }
function AssetBrowser::inspectImportingGUIAsset(%this, %assetItem) function GUIAsset::onEdit(%this)
{ {
AssetImportCtrl-->NewAssetsInspector.startGroup("GUI"); if(!isObject(%this.assetName))
AssetImportCtrl-->NewAssetsInspector.addField("GUIFile", "GUI File Path", "filename", "Intended usage case of this image. Used to map to material slots and set up texture profiles.", "",
"", %assetItem);
//Make this a callback so that if it's set we can callback to a validator function
//This function(and others for other asset types) would check if the loosefile audit window is open, and if it is, remove the file from the list
AssetImportCtrl-->NewAssetsInspector.addField("ScriptFile", "Script File Path", "filename", "Intended usage case of this image. Used to map to material slots and set up texture profiles.", "",
"", %assetItem);
AssetImportCtrl-->NewAssetsInspector.endGroup();
}
function AssetBrowser::editGUIAsset(%this, %assetDef)
{
if(!isObject(%assetDef.assetName))
{ {
exec(%assetDef.GUIFilePath); exec(%this.GUIFilePath);
exec(%assetDef.mScriptFilePath); exec(%this.mScriptFilePath);
} }
if( EditorIsActive() && !GuiEditor.toggleIntoEditorGui ) if( EditorIsActive() && !GuiEditor.toggleIntoEditorGui )
@ -112,63 +101,20 @@ function AssetBrowser::editGUIAsset(%this, %assetDef)
if( !$InGuiEditor && !GuiEditorIsActive() ) if( !$InGuiEditor && !GuiEditorIsActive() )
GuiEditor.open(); GuiEditor.open();
GuiEditContent(%assetDef.assetName); GuiEditContent(%this.assetName);
} }
//Renames the asset function GUIAsset::buildBrowserElement(%this, %previewData)
function AssetBrowser::renameGUIAsset(%this, %assetDef, %newAssetName)
{ {
%newScriptLooseFilename = renameAssetLooseFile(%assetDef.scriptFile, %newAssetName); %previewData.assetName = %this.assetName;
%previewData.assetPath = %this.getGUIPath();
if(!%newScriptLooseFilename $= "")
return;
%newGUILooseFilename = renameAssetLooseFile(%assetDef.guiFile, %newAssetName);
if(!%newGUILooseFilename $= "")
return;
%assetDef.scriptFile = %newScriptLooseFilename;
%assetDef.guiFile = %newGUILooseFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
}
//Deletes the asset
function AssetBrowser::deleteGUIAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveGUIAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getGUIPath(), %destination);
moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildGUIAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.GUIFilePath;
%previewData.doubleClickCommand = ""; %previewData.doubleClickCommand = "";
%previewData.previewImage = "ToolsModule:guiIcon_image"; %previewData.previewImage = "ToolsModule:guiIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\nDefinition Path: " @ %assetDef.getScriptPath(); %previewData.tooltip = "Asset Name: " @ %this.assetName @
} "\nGUI Path: " @ %this.getGUIPath() @
"\nScript Path: " @ %this.getScriptPath();
}

View file

@ -1,208 +1,33 @@
function AssetBrowser::prepareImportImageAsset(%this, %assetItem) AssetBrowser::registerAssetType("ImageAsset", "Images");
{
if((getAssetImportConfigValue("Images/GenerateMaterialOnImport", "1") == 1 && %assetItem.parentAssetItem $= "") || %assetItem.parentAssetItem !$= "")
{
//First, see if this already has a suffix of some sort based on our import config logic. Many content pipeline tools like substance automatically appends them
%foundSuffixType = parseImageSuffixes(%assetItem);
if(%foundSuffixType $= "")
{
%noSuffixName = %assetItem.AssetName;
}
else
{
%suffixPos = strpos(strlwr(%assetItem.AssetName), strlwr(%assetItem.ImageType), 0);
%noSuffixName = getSubStr(%assetItem.AssetName, 0, %suffixPos);
}
//Check if our material already exists
//First, lets double-check that we don't already have an
%materialAsset = ImportAssetWindow.findImportingAssetByName(%noSuffixName);
%cratedNewMaterial = false;
//Sanity catch in the case we have some naming convention shenanigans in play
if(%materialAsset != 0 && %materialAsset.assetType !$= "MaterialAsset")
%materialAsset = 0;
if(%materialAsset == 0)
{
%filePath = %assetItem.filePath;
if(%filePath !$= "")
%materialAsset = AssetBrowser.addImportingAsset("MaterialAsset", "", "", %noSuffixName);
//%materialAsset.filePath = filePath(%assetItem.filePath) @ "/" @ %noSuffixName;
ImportAssetItems.add(%materialAsset);
%cratedNewMaterial = true;
}
if(isObject(%materialAsset))
{
if(%assetItem.parentAssetItem !$= "")
{
%parentIndex = %assetItem.parentAssetItem.childAssetItems.getIndexFromKey(%assetItem);
%assetItem.parentAssetItem.childAssetItems.erase(%parentIndex);
}
else
{
//if we didn't have a parent until now, we're going to pull from it from our ImportAssetItems list
%itemIndex = ImportAssetItems.getIndexFromKey(%assetItem);
ImportAssetItems.erase(%itemIndex);
}
//Establish parentage
%materialAsset.childAssetItems.add(%assetItem);
%assetItem.parentAssetItem = %materialAsset;
ImportAssetWindow.assetHeirarchyChanged = true;
}
//Lets do some cleverness here. If we're generating a material we can parse like assets being imported(similar file names) but different suffixes
//if we find these, we'll just populate into the original's material
//If we need to append the diffuse suffix and indeed didn't find a suffix on the name, do that here
if(%foundSuffixType $= "")
{
if(getAssetImportConfigValue("Images/UseDiffuseSuffixOnOriginImg", "1") == 1)
{
if(%foundSuffixType $= "")
{
%diffuseToken = getToken(getAssetImportConfigValue("Images/DiffuseTypeSuffixes", ""), ",", 0);
%assetItem.AssetName = %assetItem.AssetName @ %diffuseToken;
}
}
else
{
//We need to ensure that our image asset doesn't match the same name as the material asset, so if we're not trying to force the diffuse suffix
//we'll give it a generic one
if(%materialAsset.assetName $= %assetItem.assetName)
{
%assetItem.AssetName = %assetItem.AssetName @ "_image";
}
}
%foundSuffixType = "diffuse";
}
if(%foundSuffixType !$= "")
{
//otherwise, if we have some sort of suffix, we'll want to figure out if we've already got an existing material, and should append to it
if(getAssetImportConfigValue("Materials/PopulateMaterialMaps", "1") == 1)
{
if(%foundSuffixType $= "diffuse")
%assetItem.ImageType = "Albedo";
else if(%foundSuffixType $= "normal")
%assetItem.ImageType = "Normal";
else if(%foundSuffixType $= "metalness")
%assetItem.ImageType = "metalness";
else if(%foundSuffixType $= "roughness")
%assetItem.ImageType = "roughness";
else if(%foundSuffixType $= "specular")
%assetItem.ImageType = "specular";
else if(%foundSuffixType $= "AO")
%assetItem.ImageType = "AO";
else if(%foundSuffixType $= "composite")
%assetItem.ImageType = "composite";
}
}
//If we JUST created this material, we need to do a process pass on it to do any other setup for it
/*if(%cratedNewMaterial)
{
AssetBrowser.prepareImportMaterialAsset(%materialAsset);
}*/
}
%assetItem.processed = true; function ImageAsset::buildBrowserElement(%this, %previewData)
refreshImportAssetWindow();
}
function AssetBrowser::inspectImportingImageAsset(%this, %assetItem)
{
AssetImportCtrl-->NewAssetsInspector.startGroup("Image");
AssetImportCtrl-->NewAssetsInspector.addField("ImageType", "Image Type", "list", "Intended usage case of this image. Used to map to material slots and set up texture profiles.", "GUI",
"Albedo,Normal,Composite,Roughness,AO,Metalness,Glow,GUI,Particle,Decal", %assetItem);
AssetImportCtrl-->NewAssetsInspector.endGroup();
}
function AssetBrowser::importImageAsset(%this, %assetItem)
{
%moduleName = AssetImportTargetModule.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%assetFullPath = %assetPath @ "/" @ fileName(%filePath);
%newAsset = new ImageAsset()
{
assetName = %assetName;
versionId = 1;
imageFile = fileName(%filePath);
imageType = %assetItem.imageType;
};
//No point in indicating the original path data if it was imported in-place
if(!startsWith(makeFullPath(%filePath), getMainDotCsDir()))
{
%newAsset.originalFilePath = %filePath;
}
%assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ "/" @ %assetName @ ".asset.taml");
//and copy the file into the relevent directory
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
{
error("Unable to import asset: " @ %filePath);
return;
}
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ "/" @ %assetName @ ".asset.taml");
else
AssetDatabase.refreshAsset(%assetId);
}
function AssetBrowser::buildImageAssetPreview(%this, %assetDef, %previewData)
{ {
//%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getImagePath()))); //%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getImagePath())));
%previewData.previewImage = "ToolsModule:genericAssetIcon_image"; %previewData.previewImage = "ToolsModule:genericAssetIcon_image";
%previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.previewLoaded = false; //this marks it for loading progressively later
%previewData.assetName = %assetDef.assetName; %previewData.assetName = %this.assetName;
%previewData.assetPath = %assetDef.scriptFile; %previewData.assetPath = %this.scriptFile;
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
//image info //image info
//%info = %assetDef.getImageInfo(); //%info = %assetDef.getImageInfo();
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\n" @ %previewData.tooltip = "Asset Name: " @ %this.assetName @ "\n" @
"Asset Type: Image Asset\n" @ "Asset Type: Image Asset\n" @
"Asset Definition ID: " @ %assetDef @ "\n" @ "Asset Definition ID: " @ %this @ "\n" @
"Image Type: " @ %assetDef.imageType @ "\n" @ "Image Type: " @ %this.imageType @ "\n" @
/* "Format: " @ getWord(%info, 0) @ "\n" @ /* "Format: " @ getWord(%info, 0) @ "\n" @
"Height: " @ getWord(%info, 1) @ "\n" @ "Height: " @ getWord(%info, 1) @ "\n" @
"Width: " @ getWord(%info, 2) @ "\n" @ "Width: " @ getWord(%info, 2) @ "\n" @
"Depth: " @ getWord(%info, 3) @ "\n" @ */ "Depth: " @ getWord(%info, 3) @ "\n" @ */
"Image File path: " @ %assetDef.getImagePath(); "Image File path: " @ %this.getImagePath();
} }
function AssetBrowser::generateImageAssetPreviewImage(%this, %previewButton, %forceRegenerate) function ImageAsset::generatePreviewImage(%this, %previewButton, %forceRegenerate)
{ {
if(%forceRegenerate $= "") if(%forceRegenerate $= "")
%forceRegenerate = false; %forceRegenerate = false;
@ -211,24 +36,20 @@ function AssetBrowser::generateImageAssetPreviewImage(%this, %previewButton, %fo
if(!IsDirectory(%previewPath)) if(!IsDirectory(%previewPath))
{ {
%this.dirHandler.createFolder(%previewPath); $CurrentAssetBrowser.dirHandler.createFolder(%previewPath);
} }
%assetId = %previewButton.moduleName @ ":" @ %previewButton.assetName; %previewFilePath = %previewPath @ %this.assetName @ "_Preview.png";
if(!isFile(%previewFilePath) || (compareFileTimes(%this.getImagePath(), %previewFilePath) == 1))
%assetDef = AssetDatabase.acquireAsset(%assetId);
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.png";
if(!isFile(%previewFilePath) || (compareFileTimes(%assetDef.getImagePath(), %previewFilePath) == 1))
{ {
%generatePreview = true; %generatePreview = true;
} }
%previewAssetName = %previewButton.moduleName @ "_" @ %assetDef.assetName @ "_PreviewImage"; %previewAssetName = %previewButton.moduleName @ "_" @ %this.assetName @ "_PreviewImage";
if(%generatePreview || %forceRegenerate) if(%generatePreview || %forceRegenerate)
{ {
%success = saveScaledImage(%assetDef.getImagePath(), %previewFilePath, EditorSettings.value("Assets/Browser/PreviewImageSize")); %success = saveScaledImage(%this.getImagePath(), %previewFilePath, EditorSettings.value("Assets/Browser/PreviewImageSize"));
if(%success) if(%success)
{ {
@ -252,81 +73,42 @@ function AssetBrowser::generateImageAssetPreviewImage(%this, %previewButton, %fo
if(!%success) if(!%success)
{ {
return false; //failed to register the preview image for some reason? return false; //failed to register the preview image for some reason?
}
}
%previewButton.bitmapAsset = %previewAssetName;
return true;
} }
} }
else
%previewButton.bitmapAsset = %previewAssetName; {
return true; //just map the existing one then
if(AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName))
{
%previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName;
return true;
} }
} }
else
{
//just map the existing one then
if(AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName))
{
%previewButton.bitmapAsset = "ToolsModule:" @ %previewAssetName;
return true;
}
}
return false; return false;
} }
//Renames the asset function ImageAsset::onShowActionMenu(%this)
function AssetBrowser::renameImageAsset(%this, %assetDef, %newAssetName)
{ {
%newFilename = renameAssetLooseFile(%assetDef.getImagePath(), %newAssetName); GenericAsset::onShowActionMenu(%this);
if(!%newFilename $= "")
return;
%assetDef.imageFile = %newFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
} }
//Duplicates the asset function ImageAsset::onEditProperties(%this)
function AssetBrowser::duplicateImageAsset(%this, %assetDef, %newAssetName)
{ {
%duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName); GenericAsset::onEditProperties(%this);
%newFilename = duplicateAssetLooseFile(%assetDef.imageFile, %newAssetName);
if(!%newFilename $= "")
return;
%module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset);
%dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName);
%dupAssetDef.imageFile = fileName(%newFilename);
%dupAssetDef.saveAsset();
} }
//Deletes the asset //Called when the AssetType has it's properties saved from the onEditProperties process
function AssetBrowser::deleteImageAsset(%this, %assetDef) function ImageAsset::onSaveProperties(%this)
{ {
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true); GenericAsset::onSaveProperties(%this);
} }
//Moves the asset to a new path/module
function AssetBrowser::moveImageAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getImagePath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position ) function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %position )
{ {
Canvas.popDialog(EditorDragAndDropLayer); Canvas.popDialog(EditorDragAndDropLayer);
@ -346,176 +128,4 @@ function GuiInspectorTypeImageAssetPtr::onControlDropped( %this, %payload, %posi
} }
EWorldEditor.isDirty = true; EWorldEditor.isDirty = true;
}
function parseImageSuffixes(%assetItem)
{
//diffuse
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/DiffuseTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/DiffuseTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "diffuse";
}
}
//normal
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/NormalTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/NormalTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "normal";
}
}
//roughness
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/RoughnessTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/RoughnessTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "roughness";
}
}
//Ambient Occlusion
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/AOTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/AOTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "AO";
}
}
//metalness
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/MetalnessTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/MetalnessTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "metalness";
}
}
//composite
%suffixCount = getTokenCount(getAssetImportConfigValue("Images/CompositeTypeSuffixes", ""), ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(getAssetImportConfigValue("Images/CompositeTypeSuffixes", ""), ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.ImageType = %suffixToken;
return "composite";
}
}
//specular
/*%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %assetItem.AssetName))
{
%assetItem.imageSuffixType = %suffixToken;
return "specular";
}
}*/
return "";
}
function parseImagePathSuffixes(%filePath)
{
//diffuse
%diffuseSuffixes = getAssetImportConfigValue("Images/DiffuseTypeSuffixes", "");
%suffixCount = getTokenCount(%diffuseSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(%diffuseSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "diffuse";
}
}
//normal
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.NormalTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "normal";
}
}
//roughness
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.RoughnessTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "roughness";
}
}
//Ambient Occlusion
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.AOTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "AO";
}
}
//metalness
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.MetalnessTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "metalness";
}
}
//composite
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.CompositeTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "composite";
}
}
//specular
%suffixCount = getTokenCount(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;");
for(%sfx = 0; %sfx < %suffixCount; %sfx++)
{
%suffixToken = getToken(ImportAssetWindow.activeImportConfig.SpecularTypeSuffixes, ",;", %sfx);
if(strIsMatchExpr("*"@%suffixToken, %filePath))
{
return "specular";
}
}
return "";
} }

View file

@ -1,30 +1,20 @@
function AssetBrowser::setupCreateNewLevelAsset(%this) AssetBrowser::registerAssetType("LevelAsset", "Levels");
function LevelAsset::setupCreateNew()
{ {
NewAssetPropertiesInspector.startGroup("Level"); NewAssetPropertiesInspector.startGroup("Level");
NewAssetPropertiesInspector.addField("LevelName", "Level Name", "String", "Human-readable name of new level", "", "", %this.newAssetSettings); NewAssetPropertiesInspector.addField("LevelName", "Level Name", "String", "Human-readable name of new level", "", "", $CurrentAssetBrowser.newAssetSettings);
NewAssetPropertiesInspector.addField("levelPreviewImage", "Level Preview Image", "Image", "Preview Image for the level", "", "", %this.newAssetSettings); NewAssetPropertiesInspector.addField("levelPreviewImage", "Level Preview Image", "Image", "Preview Image for the level", "", "", $CurrentAssetBrowser.newAssetSettings);
//If we forcefully set it elsewhere, adhere
if($createLevelAssetIsSubScene == true)
%this.newAssetSettings.isSubScene = true;
else
%this.newAssetSettings.isSubScene = false;
NewAssetPropertiesInspector.addField("isSubScene", "Is SubScene", "bool", "Is this levelAsset intended as a subScene", %this.newAssetSettings.isSubScene, "", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup(); NewAssetPropertiesInspector.endGroup();
} }
function AssetImporter::importLevelAsset(%this, %assetItem) function LevelAsset::onCreateNew(%this)
{ {
} %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
function AssetBrowser::createLevelAsset(%this)
{
%moduleName = AssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
@ -43,10 +33,10 @@ function AssetBrowser::createLevelAsset(%this)
PostFXPresetFile = %assetName @ ".postfxpreset." @ $TorqueScriptFileExtension; PostFXPresetFile = %assetName @ ".postfxpreset." @ $TorqueScriptFileExtension;
ForestFile = %assetName @ ".forest"; ForestFile = %assetName @ ".forest";
NavmeshFile = %assetName @ ".nav"; NavmeshFile = %assetName @ ".nav";
LevelName = AssetBrowser.newAssetSettings.levelName; LevelName = $CurrentAssetBrowser.newAssetSettings.levelName;
AssetDescription = AssetBrowser.newAssetSettings.description; AssetDescription = $CurrentAssetBrowser.newAssetSettings.description;
PreviewImage = AssetBrowser.newAssetSettings.levelPreviewImage; PreviewImage = $CurrentAssetBrowser.newAssetSettings.levelPreviewImage;
isSubScene = AssetBrowser.newAssetSettings.isSubScene; isSubScene = $CurrentAssetBrowser.newAssetSettings.isSubScene;
}; };
TamlWrite(%asset, %tamlpath); TamlWrite(%asset, %tamlpath);
@ -90,219 +80,42 @@ function AssetBrowser::createLevelAsset(%this)
if(!%addSuccess) if(!%addSuccess)
{ {
error("AssetBrowser::createLevelAsset() - failed to add declared asset: " @ %tamlpath @ " for module: " @ %moduleDef); error("LevelAsset::onCreateNew() - failed to add declared asset: " @ %tamlpath @ " for module: " @ %moduleDef);
} }
AssetBrowser.refresh(); $CurrentAssetBrowser.refresh();
if(%addSuccess && isObject($createAndAssignField))
{
$createAndAssignField.apply(%moduleName @ ":" @ %assetName);
$createAndAssignField = "";
}
return %tamlpath; return %tamlpath;
} }
//============================================================================== function LevelAsset::onEdit(%this)
//SubScene derivative
//==============================================================================
function AssetBrowser::setupCreateNewSubScene(%this)
{ {
%this.newAssetSettings.isSubScene = true; schedule( 1, 0, "EditorOpenMission", %this);
%this.newAssetSettings.assetType = "LevelAsset";
} }
//============================================================================== function LevelAsset::buildBrowserElement(%this, %previewData)
function AssetBrowser::editLevelAsset(%this, %assetDef)
{ {
echo("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); %previewData.assetName = %this.assetName;
echo(%assetDef @ ".isSubScene = " @ %assetDef.isSubScene); %previewData.assetPath = %this.getLevelPath();
if(!%assetDef.isSubScene) %previewData.doubleClickCommand = "schedule( 1, 0, \"EditorOpenMission\", "@%this@");";
schedule( 1, 0, "EditorOpenMission", %assetDef);
}
//Renames the asset
function AssetBrowser::renameLevelAsset(%this, %assetDef, %newAssetName)
{
%newFilename = renameAssetLooseFile(%assetDef.LevelFile, %newAssetName);
if(!%newFilename $= "") %levelPreviewImage = %this.PreviewImage;
return;
//TODO the other loose files
%assetDef.LevelFile = %newFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
}
//Duplicates the asset
function AssetBrowser::duplicateLevelAsset(%this, %assetDef, %newAssetName)
{
%duplicatedAsset = duplicateAssetFile(%assetDef, %newAssetName);
%newFilename = duplicateAssetLooseFile(%assetDef.LevelFile, %newAssetName);
if(!%newFilename $= "")
return;
%module = AssetBrowser.dirHandler.getModuleFromAddress(%duplicatedAsset);
%dupAssetDef = AssetDatabase.acquireAsset(%module.ModuleId @ ":" @ %newAssetName);
%dupAssetDef.LevelFile = fileName(%newFilename);
%dupAssetDef.saveAsset();
}
//Deletes the asset
function AssetBrowser::deleteLevelAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveLevelAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getLevelPath(), %destination);
moveAssetLooseFile(%assetDef.getPreviewImagePath(), %destination);
moveAssetLooseFile(%assetDef.getPostFXPresetPath(), %destination);
moveAssetLooseFile(%assetDef.getDecalsPath(), %destination);
moveAssetLooseFile(%assetDef.getForestPath(), %destination);
moveAssetLooseFile(%assetDef.getNavmeshPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildLevelAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.getLevelPath();
if(%this.selectMode || %assetDef.isSubScene)
{
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
}
else
{
%previewData.doubleClickCommand = "schedule( 1, 0, \"EditorOpenMission\", "@%assetDef@");";
}
%levelPreviewImage = %assetDef.PreviewImage;
if(isFile(%levelPreviewImage)) if(isFile(%levelPreviewImage))
%previewData.previewImage = %levelPreviewImage; %previewData.previewImage = %levelPreviewImage;
else else
%previewData.previewImage = "ToolsModule:levelIcon_image"; %previewData.previewImage = "ToolsModule:levelIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\n" @ %previewData.tooltip = "Asset Name: " @ %this.assetName @ "\n" @
"Asset Type: Level Asset\n" @ "Asset Type: Level Asset\n" @
"Asset Definition ID: " @ %assetDef @ "\n" @ "Asset Definition ID: " @ %this @ "\n" @
"Level File path: " @ %assetDef.getLevelPath(); "Level File path: " @ %this.getLevelPath();
}
function createAndAssignLevelAsset(%moduleName, %assetName)
{
if(AssetDatabase.isDeclaredAsset(%moduleName))
$createAndAssignField.apply(%moduleName);
else
$createAndAssignField.apply(%moduleName @ ":" @ %assetName);
}
function EWorldEditor::createSelectedAsSubScene( %this, %object )
{
//create new level asset here
AssetBrowser.setupCreateNewAsset("SubScene", AssetBrowser.selectedModule, "finishCreateSelectedAsSubScene");
%this.contextActionObject = %object;
}
function finishCreateSelectedAsSubScene(%assetId)
{
echo("finishCreateSelectedAsSubScene");
%subScene = new SubScene() {
levelAsset = %assetId;
};
%levelAssetDef = AssetDatabase.acquireAsset(%assetId);
%levelFilePath = %levelAssetDef.getLevelPath();
//write out to file
EWorldEditor.contextActionObject.save(%levelFilePath);
AssetDatabase.releaseAsset(%assetId);
getRootScene().add(%subScene);
EWorldEditor.contextActionObject.delete();
%subScene.load();
%subScene.recalculateBounds();
%scalar = $SubScene::createScalar;
if(%scalar $= "")
%scalar = 1.5;
//pad for loading boundary
%subScene.scale = VectorScale(%subScene.scale, %scalar);
}
function GuiInspectorTypeLevelAssetPtr::onControlDropped( %this, %payload, %position )
{
Canvas.popDialog(EditorDragAndDropLayer);
// Make sure this is a color swatch drag operation.
if( !%payload.parentGroup.isInNamespaceHierarchy( "AssetPreviewControlType_AssetDrop" ) )
return;
%assetType = %payload.assetType;
%module = %payload.moduleName;
%assetName = %payload.assetName;
if(%assetType $= "LevelAsset")
{
%cmd = %this @ ".apply(\""@ %module @ ":" @ %assetName @ "\");";
eval(%cmd);
}
EWorldEditor.isDirty = true;
}
function AssetBrowser::onLevelAssetEditorDropped(%this, %assetDef, %position)
{
%assetId = %assetDef.getAssetId();
if(!%assetDef.isSubScene)
{
errorf("Cannot drag-and-drop LevelAsset into WorldEditor");
return;
}
%newSubScene = new SubScene()
{
position = %position;
levelAsset = %assetId;
};
getScene(0).add(%newSubScene);
%newSubScene.load();
%newSubScene.recalculateBounds();
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%newSubScene);
EWorldEditor.dropSelection();
EWorldEditor.isDirty = true;
MECreateUndoAction::submit(%newSubScene );
} }

View file

@ -1,14 +1,17 @@
function AssetBrowser::buildLooseFilePreview(%this, %assetDef, %previewData) AssetBrowser::registerFileType("NonAssetLooseFile", "Loose Files", "-");
function NonAssetLooseFile::buildBrowserElement(%filePath, %previewData)
{ {
%fullPath = %assetDef.dirPath @ "/" @ %assetDef.assetName; %fileName = fileName(%filePath);
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %fullPath; %previewData.assetName = %fileName;
%previewData.assetPath = %filePath;
%previewData.previewImage = "ToolsModule:looseFileIcon_image"; %previewData.previewImage = "ToolsModule:looseFileIcon_image";
//%previewData.assetFriendlyName = %assetDef.assetName; //%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %filePath;
%previewData.tooltip = %fullPath; %previewData.tooltip = %filePath;
//%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %assetDef.dirPath @ "/" @ %assetDef.assetName @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName //%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %assetDef.dirPath @ "/" @ %assetDef.assetName @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName
%previewData.doubleClickCommand = "AssetBrowser.autoImportFile(\"" @ %fullPath @ "\");"; //%previewData.doubleClickCommand = "AssetBrowser.autoImportFile(\"" @ %fullPath @ "\");";
} }

View file

@ -1,4 +1,6 @@
function AssetBrowser::createMaterialAsset(%this) AssetBrowser::registerAssetType("MaterialAsset", "Materials");
function MaterialAsset::createMaterialAsset(%this)
{ {
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = AssetBrowser.newAssetSettings.assetName;
@ -33,15 +35,15 @@ function AssetBrowser::createMaterialAsset(%this)
return %tamlpath; return %tamlpath;
} }
function AssetBrowser::editMaterialAsset(%this, %assetDef) function MaterialAsset::onEdit(%this)
{ {
%assetDef.materialDefinitionName.reload(); %this.materialDefinitionName.reload();
EditorGui.setEditor(MaterialEditorPlugin); EditorGui.setEditor(MaterialEditorPlugin);
MaterialEditorGui.currentMaterialAsset = %assetDef.getAssetId(); MaterialEditorGui.currentMaterialAsset = %this.getAssetId();
MaterialEditorGui.currentMaterial = %assetDef.materialDefinitionName; MaterialEditorGui.currentMaterial = %this.materialDefinitionName;
MaterialEditorGui.setActiveMaterial( %assetDef.materialDefinitionName ); MaterialEditorGui.setActiveMaterial( %this.materialDefinitionName );
AssetBrowser.hideDialog(); AssetBrowser.hideDialog();
} }
@ -60,451 +62,82 @@ function AssetBrowser::renameMaterialAsset(%this, %assetDef, %newAssetName)
renameAssetFile(%assetDef, %newAssetName); renameAssetFile(%assetDef, %newAssetName);
} }
//Deletes the asset function MaterialAsset::buildBrowserElement(%this, %previewData)
function AssetBrowser::deleteMaterialAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveMaterialAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::prepareImportMaterialAsset(%this, %assetItem)
{
ImportActivityLog.add("Preparing Material for Import: " @ %assetItem.assetName);
//Iterate over to find appropriate images for
//Fetch just the fileBase name
%fileDir = filePath(%assetItem.filePath);
%fileName = fileBase(%assetItem.filePath);
%fileExt = fileExt(%assetItem.filePath);
%assetItem.generatedAsset = true;
//Check if we need to filter this material out or not
if(getAssetImportConfigValue("Materials/IgnoreMaterials", "") !$= "")
{
%ignoredMatNamesCount = getTokenCount(getAssetImportConfigValue("Materials/IgnoreMaterials", ""), ",;");
for(%i=0; %i < %ignoredMatNamesCount; %i++)
{
%ignoreName = getToken(getAssetImportConfigValue("Materials/IgnoreMaterials", ""), ",;", %i);
if(strIsMatchExpr(%ignoreName, %fileName))
{
//We fit the bill, ignore this material and skip it
%assetItem.skip = true;
ImportActivityLog.add(%assetItem.assetName @ " has been ignored due to config Materials/IgnoreMaterials settings");
return;
}
}
}
if(getAssetImportConfigValue("Materials/PopulateMaterialMaps", "1") == 1)
{
ImportActivityLog.add("Attempting to Auto-Populate Material Maps");
for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
{
%childAssetItem = %assetItem.childAssetItems.getKey(%i);
if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == true || %childAssetItem.assetType !$= "ImageAsset")
return;
if(%childAssetItem.imageType $= "Albedo")
{
%assetItem.diffuseImageAsset = %childAssetItem;
}
}
/*%materialItemId = ImportAssetTree.findItemByObjectId(%assetItem);
if(%assetItem.diffuseImageAsset $= "")
{
%diffuseTypeSuffixes = getAssetImportConfigValue("Images/DiffuseTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %diffuseTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Diffuse Map Image Asset via file: " @ %targetFilePath);
%diffuseAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.diffuseImageAsset = %diffuseAsset;
}
}
//Now, iterate over our comma-delimited suffixes to see if we have any matches. We'll use the first match in each case, if any.
if(%assetItem.normalImageAsset $= "")
{
%normalTypeSuffixes = getAssetImportConfigValue("Images/NormalTypeSuffixes", "");
//First, normal map
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %normalTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Normal Map Image Asset via file: " @ %targetFilePath);
%normalAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.normalImageAsset = %normalAsset;
}
}
if(%assetItem.metalImageAsset $= "")
{
%metalnessTypeSuffixes = getAssetImportConfigValue("Images/MetalnessTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %metalnessTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Metalness Map Image Asset via file: " @ %targetFilePath);
%metalAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.metalImageAsset = %metalAsset;
}
}
if(%assetItem.roughnessImageAsset $= "")
{
%roughnessTypeSuffixes = getAssetImportConfigValue("Images/RoughnessTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %roughnessTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Roughness Map Image Asset via file: " @ %targetFilePath);
%roughnessAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.roughnessImageAsset = %roughnessAsset;
}
}
if(%assetItem.smoothnessImageAsset $= "")
{
%smoothnessTypeSuffixes = getAssetImportConfigValue("Images/SmoothnessTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %smoothnessTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Smoothness Map Image Asset via file: " @ %targetFilePath);
%smoothnessAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.SmoothnessImageAsset = %smoothnessAsset;
}
}
if(%assetItem.AOImageAsset $= "")
{
%aoTypeSuffixes = getAssetImportConfigValue("Images/AOTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %aoTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated AO Map Image Asset via file: " @ %targetFilePath);
%AOAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.AOImageAsset = %AOAsset;
}
}
if(%assetItem.compositeImageAsset $= "")
{
%compositeTypeSuffixes = getAssetImportConfigValue("Images/CompositeTypeSuffixes", "");
%targetFilePath = %this.findMaterialMapFileWSuffix(%fileDir, %fileName, %fileExt, %compositeTypeSuffixes);
if(%targetFilePath !$= "")
{
ImportActivityLog.add("Auto-Populated Composite Map Image Asset via file: " @ %targetFilePath);
%compositeAsset = AssetBrowser.addImportingAsset("ImageAsset", %targetFilePath, %assetItem);
%assetItem.compositeImageAsset = %compositeAsset;
}
}
//If after the above we didn't find any, check to see if we should be generating one
if(%assetItem.compositeImageAsset $= "" &&
(%assetItem.roughnessImageAsset !$= "" || %assetItem.AOImageAsset !$= "" || %assetItem.metalnessImageAsset !$= "") &&
getAssetImportConfigValue("Materials/CreateComposites", "1") == 1)
{
%assetItem.roughnessImageAsset.skip = true;
%assetItem.AOImageAsset.skip = true;
%assetItem.metalnessImageAsset.skip = true;
%compositeAssetPath = AssetBrowser.dirHandler.currentAddress @ "/";
%saveAsPath = %compositeAssetPath @ "/" @ %assetItem.assetName @ "_composite.png";
ImportActivityLog.add("Auto-Generated Composite Map from ORM maps");
%compositeAsset = AssetBrowser.addImportingAsset("ImageAsset", "", %assetItem, %assetItem.assetName @ "_composite");
%compositeAsset.generatedAsset = true;
%compositeAsset.filePath = %saveAsPath;
%assetItem.compositeImageAsset = %compositeAsset;
}*/
}
%assetItem.processed = true;
refreshImportAssetWindow();
}
function AssetBrowser::findMaterialMapFileWSuffix(%this, %fileDir, %filename, %fileExt, %suffixesList)
{
%listCount = getTokenCount(%suffixesList, ",;");
%foundFile = 0;
%filePath = "";
for(%i=0; %i < %listCount; %i++)
{
%entryText = getToken(%suffixesList, ",;", %i);
if(%fileExt $= "")
{
%filePath = findFirstFile(%fileDir @ "/" @ %filename @ %entryText @ ".*");
%foundFile = isFile(%filePath);
}
else
{
%filePath = %fileDir @ "/" @ %filename @ %entryText @ %fileExt;
%foundFile = isFile(%filePath);
}
if(%foundFile)
{
return %filePath;
}
}
return "";
}
function AssetBrowser::importMaterialAsset(%this, %assetItem)
{
%moduleName = AssetImportTargetModule.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%tamlpath = %assetPath @ %assetName @ ".asset.taml";
%sgfPath = %assetPath @ %assetName @ ".sgf";
%scriptPath = %assetPath @ %assetName @ "." @ $TorqueScriptFileExtension;
%newAsset = new MaterialAsset()
{
assetName = %assetName;
versionId = 1;
shaderGraph = %sgfPath;
scriptFile = %assetName @ "." @ $TorqueScriptFileExtension;
materialDefinitionName = %assetName;
};
//No point in indicating the original path data if it was imported in-place
%mainPath = getMainDotCsDir();
if(!startsWith(makeFullPath(%filePath), getMainDotCsDir()))
{
%newAsset.originalFilePath = %filePath;
}
//check dependencies
%dependencySlotId = 0;
for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
{
%childAssetItem = %assetItem.childAssetItems.getKey(%i);
if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == false)
continue;
%depAssetType = %childAssetItem.assetType;
if(%depAssetType $= "ImageAsset")
{
%matSet = "%newAsset.imageMap"@%dependencySlotId@"=\"@asset="@%moduleName@":"@%childAssetItem.assetName@"\";";
eval(%matSet);
%dependencySlotId++;
}
}
%assetImportSuccessful = TamlWrite(%newAsset, %tamlpath);
//if we're set to save a composite image, we do that first
if(getAssetImportConfigValue("Materials/CreateComposites", "1") == 1)
{
//don't save a composite if we've already got one bound
if(%assetItem.compositeImageAsset !$= "" && %assetItem.compositeImageAsset.generatedAsset)
{
if(%assetItem.roughnessImageAsset !$= "" || %assetItem.AOImageAsset !$= "" || %assetItem.metalnessImageAsset !$= "")
{
%channelKey = "0 1 2 3";
saveCompositeTexture(%assetItem.AOImageAsset.filePath,
%assetItem.roughnessImageAsset.filePath,
%assetItem.metalnessImageAsset.filePath,"",
%channelKey,
%assetItem.compositeImageAsset.filePath);
%compositeAssetId = %moduleName @ ":" @ assetItem.compositeImageAsset.assetName;
AssetDatabase.refreshAsset(%compositeAssetId);
}
}
}
%file = new FileObject();
if(%file.openForWrite(%scriptPath))
{
%file.writeline("//--- OBJECT WRITE BEGIN ---");
%file.writeline("singleton Material(" @ %assetName @ ") {");
//TODO: pass along the shape's target material for this just to be sure
%file.writeLine(" mapTo = \"" @ %assetName @ "\";");
//now we re-iterate back over our child items so we can map them correctly
for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
{
%childAssetItem = %assetItem.childAssetItems.getKey(%i);
if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == false)
continue;
if(%childAssetItem.assetType $= "ImageAsset")
{
%mapFieldName = "";
if(%childAssetItem.imageType $= "Albedo")
%mapFieldName = "DiffuseMap";
else if(%childAssetItem.imageType $= "Normal")
%mapFieldName = "NormalMap";
else if(%childAssetItem.imageType $= "Metalness")
%mapFieldName = "MetalMap";
else if(%childAssetItem.imageType $= "Roughness")
%mapFieldName = "RoughnessMap";
else if(%childAssetItem.imageType $= "AO")
%mapFieldName = "AOMap";
else if(%childAssetItem.imageType $= "Composite")
%mapFieldName = "ORMConfigMap";
%path = fileName(%childAssetItem.filePath);
%file.writeline(" "@ %mapFieldName @ "[0] = \"" @ %path @"\";");
%file.writeline(" "@ %mapFieldName @ "Asset[0] = \"" @ %moduleName @ ":" @ %childAssetItem.assetName @"\";");
}
}
%file.writeline("};");
%file.writeline("//--- OBJECT WRITE END ---");
%file.close();
}
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
else
AssetDatabase.refreshAsset(%assetId);
}
function AssetBrowser::buildMaterialAssetPreview(%this, %assetDef, %previewData, %forcePreviewRegenerate)
{ {
%previewData.previewImage = "ToolsModule:genericAssetIcon_image"; %previewData.previewImage = "ToolsModule:genericAssetIcon_image";
%previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.previewLoaded = false; //this marks it for loading progressively later
%previewData.assetName = %assetDef.assetName; %previewData.assetName = %this.assetName;
%previewData.assetPath = %assetDef.scriptFile; %previewData.assetPath = %this.scriptFile;
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
if(%this.selectMode) if(%this.selectMode)
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".selectAsset( " @ $CurrentAssetBrowser @ ".selectedAsset );";
else else
%previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@%this@" );";
%definitionPath = %assetDef.getScriptPath(); %definitionPath = %this.getScriptPath();
if(%definitionPath $= "") if(%definitionPath $= "")
%definitionPath = %assetDef.getFilename(); %definitionPath = %this.getFilename();
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ %previewData.tooltip = "Asset Name: " @ %this.assetName @
"\nAsset Type: Material Asset" @ "\nAsset Type: Material Asset" @
"\nAsset Definition ID: " @ %assetDef @ "\nAsset Definition ID: " @ %this @
"\nDefinition Path: " @ %definitionPath; "\nDefinition Path: " @ %definitionPath;
if(!%this.selectMode) if(!$CurrentAssetBrowser.selectMode)
{ {
%previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@%this@" );";
} }
} }
function AssetBrowser::generateMaterialAssetPreviewImage(%this, %previewButton, %forceRegenerate) function MaterialAsset::generatePreviewImage(%this, %previewButton, %forceRegenerate)
{ {
if(%forceRegenerate $= "") if(%forceRegenerate $= "")
%forceRegenerate = false; %forceRegenerate = false;
%assetId = %previewButton.moduleName @ ":" @ %previewButton.assetName; %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%this.getAssetId()))));
%assetDef = AssetDatabase.acquireAsset(%assetId);
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%assetDef.getAssetId()))));
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/"; %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
if(!IsDirectory(%previewPath)) if(!IsDirectory(%previewPath))
{ {
%this.dirHandler.createFolder(%previewPath); $CurrentAssetBrowser.dirHandler.createFolder(%previewPath);
} }
%generatePreview = false; %generatePreview = false;
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.dds"; %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds";
if(!isFile(%previewFilePath)) if(!isFile(%previewFilePath))
{ {
%generatePreview = true; %generatePreview = true;
} }
else else
{ {
if(isObject(%assetDef.materialDefinitionName)) if(isObject(%this.materialDefinitionName))
{ {
if(compareFileTimes(%assetDef.materialDefinitionName.getDiffuseMap(0), %previewFilePath) == 1 || if(compareFileTimes(%this.materialDefinitionName.getDiffuseMap(0), %previewFilePath) == 1 ||
compareFileTimes(%assetDef.materialDefinitionName.getFilename(), %previewFilePath) == 1) compareFileTimes(%this.materialDefinitionName.getFilename(), %previewFilePath) == 1)
%generatePreview = true; %generatePreview = true;
} }
} }
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage"; %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage";
if(%generatePreview || %forceRegenerate) if(%generatePreview || %forceRegenerate)
{ {
if(isObject(%assetDef.materialDefinitionName)) if(isObject(%this.materialDefinitionName))
{ {
//real fast, we'll be 100% sure that the image resource we need is loaded //real fast, we'll be 100% sure that the image resource we need is loaded
%diffuseMapAssetId = %assetDef.materialDefinitionName.getDiffuseMapAsset(0); %diffuseMapAssetId = %this.materialDefinitionName.getDiffuseMapAsset(0);
if(AssetDatabase.isDeclaredAsset(%diffuseMapAssetId)) if(AssetDatabase.isDeclaredAsset(%diffuseMapAssetId))
{ {
%diffuseMapAsset = AssetDatabase.acquireAsset(%diffuseMapAssetId); %diffuseMapAsset = AssetDatabase.acquireAsset(%diffuseMapAssetId);
AssetDatabase.releaseAsset(%diffuseMapAssetId); AssetDatabase.releaseAsset(%diffuseMapAssetId);
} }
%previewShapeDef = AssetDatabase.acquireAsset("ToolsModule:previewSphereShape"); %previewShapeDef = AssetDatabase.acquireAsset("ToolsModule:previewSphereShape");
%generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, %assetDef.materialDefinitionName); %generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, %this.materialDefinitionName);
pathCopy(%generatedFilePath, %previewFilePath, false); pathCopy(%generatedFilePath, %previewFilePath, false);
fileDelete(%generatedFilePath); fileDelete(%generatedFilePath);
@ -548,7 +181,7 @@ function AssetBrowser::generateMaterialAssetPreviewImage(%this, %previewButton,
return false; return false;
} }
function AssetBrowser::onMaterialAssetEditorDropped(%this, %assetDef, %position) function MaterialAsset::onWorldEditorDropped(%this, %position)
{ {
//echo("DROPPED A SHAPE ON THE EDITOR WINDOW!"); //echo("DROPPED A SHAPE ON THE EDITOR WINDOW!");
//first, see if we hit a static shape //first, see if we hit a static shape
@ -558,26 +191,24 @@ function AssetBrowser::onMaterialAssetEditorDropped(%this, %assetDef, %position)
%camPos = LocalClientConnection.camera.getPosition(); %camPos = LocalClientConnection.camera.getPosition();
%rayResult = materialRayCast(%camPos, %targetPosition, -1, 0, false); %rayResult = materialRayCast(%camPos, %targetPosition, -1, 0, false);
%validTarget = false;
if(%rayResult != 0) if(%rayResult != 0)
{ {
%obj = getWord(%rayResult, 0); %obj = getWord(%rayResult, 0);
if(%obj.isMemberOfClass("TSStatic")) if(%obj.isMemberOfClass("TSStatic"))
{ {
//oh, cool a valid target! //oh, cool a valid target!
%obj.materialSlot0 = %assetDef.getAssetId(); %obj.materialSlot0 = %this.getAssetId();
echo("MaterialSlot0 set to " @ %assetDef.getAssetId()); //echo("MaterialSlot0 set to " @ %this.getAssetId());
} }
else if(%obj.isField("materialAsset")) else if(%obj.isField("materialAsset"))
{ {
%obj.materialAsset = %assetDef.getAssetId(); %obj.materialAsset = %this.getAssetId();
echo("materialAsset set to " @ %assetDef.getAssetId()); //echo("materialAsset set to " @ %this.getAssetId());
} }
%obj.inspectPostApply(); %obj.inspectPostApply();
EWorldEditor.isDirty = true;
} }
EWorldEditor.isDirty = true;
} }
function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position ) function GuiInspectorTypeMaterialAssetPtr::onControlDropped( %this, %payload, %position )

View file

@ -1,8 +1,10 @@
function AssetBrowser::createPostEffectAsset(%this) AssetBrowser::registerAssetType("PostEffectAsset", "Post Effects");
function PostEffectAsset::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
%tamlpath = %assetPath @ %assetName @ ".asset.taml"; %tamlpath = %assetPath @ %assetName @ ".asset.taml";
@ -27,7 +29,7 @@ function AssetBrowser::createPostEffectAsset(%this)
%file = new FileObject(); %file = new FileObject();
%templateFile = new FileObject(); %templateFile = new FileObject();
%postFXTemplateCodeFilePath = %this.templateFilesPath @ "postFXFile." @ $TorqueScriptFileExtension @ ".template"; %postFXTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "postFXFile." @ $TorqueScriptFileExtension @ ".template";
if(%file.openForWrite(%scriptPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath)) if(%file.openForWrite(%scriptPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath))
{ {
@ -37,7 +39,7 @@ function AssetBrowser::createPostEffectAsset(%this)
%line = strreplace( %line, "@@", %assetName ); %line = strreplace( %line, "@@", %assetName );
%file.writeline(%line); %file.writeline(%line);
echo(%line); //echo(%line);
} }
%file.close(); %file.close();
@ -48,11 +50,11 @@ function AssetBrowser::createPostEffectAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreatePostFXAsset - Something went wrong and we couldn't write the PostFX script file!"); warn("PostEffectAsset::onCreateNew() - Something went wrong and we couldn't write the PostFX script file!");
} }
//hlsl shader //hlsl shader
%postFXTemplateCodeFilePath = %this.templateFilesPath @ "postFXFileP.hlsl.template"; %postFXTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "postFXFileP.hlsl.template";
if(%file.openForWrite(%hlslPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath)) if(%file.openForWrite(%hlslPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath))
{ {
@ -62,7 +64,7 @@ function AssetBrowser::createPostEffectAsset(%this)
%line = strreplace( %line, "@@", %assetName ); %line = strreplace( %line, "@@", %assetName );
%file.writeline(%line); %file.writeline(%line);
echo(%line); //echo(%line);
} }
%file.close(); %file.close();
@ -73,11 +75,11 @@ function AssetBrowser::createPostEffectAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreatePostFXAsset - Something went wrong and we couldn't write the PostFX hlsl file!"); warn("PostEffectAsset::onCreateNew() - Something went wrong and we couldn't write the PostFX hlsl file!");
} }
//glsl shader //glsl shader
%postFXTemplateCodeFilePath = %this.templateFilesPath @ "postFXFileP.glsl.template"; %postFXTemplateCodeFilePath = $CurrentAssetBrowser.templateFilesPath @ "postFXFileP.glsl.template";
if(%file.openForWrite(%glslPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath)) if(%file.openForWrite(%glslPath) && %templateFile.openForRead(%postFXTemplateCodeFilePath))
{ {
@ -87,7 +89,7 @@ function AssetBrowser::createPostEffectAsset(%this)
%line = strreplace( %line, "@@", %assetName ); %line = strreplace( %line, "@@", %assetName );
%file.writeline(%line); %file.writeline(%line);
echo(%line); //echo(%line);
} }
%file.close(); %file.close();
@ -98,72 +100,80 @@ function AssetBrowser::createPostEffectAsset(%this)
%file.close(); %file.close();
%templateFile.close(); %templateFile.close();
warnf("CreatePostFXAsset - Something went wrong and we couldn't write the PostFX glsl file!"); warn("PostEffectAsset::onCreateNew() - Something went wrong and we couldn't write the PostFX glsl file!");
} }
return %tamlpath; return %tamlpath;
} }
//Renames the asset function PostEffectAsset::buildBrowserElement(%this, %previewData)
function AssetBrowser::renamePostEffectAsset(%this, %assetDef, %newAssetName)
{ {
%newScriptFilename = renameAssetLooseFile(%assetDef.scriptPath, %newAssetName); %previewData.assetName = %this.assetName;
%previewData.assetPath = %this.scriptFilePath;
if(!%newScriptFilename $= "")
return;
%newHLSLFilename = renameAssetLooseFile(%assetDef.hlslShader, %newAssetName);
if(!%newHLSLFilename $= "")
return;
%newGLSLFilename = renameAssetLooseFile(%assetDef.glslShader, %newAssetName);
if(!%newGLSLFilename $= "")
return;
%assetDef.scriptPath = %newScriptFilename;
%assetDef.hlslShader = %newHLSLFilename;
%assetDef.glslShader = %newGLSLFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
}
//Deletes the asset
function AssetBrowser::deletePostEffectAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::movePostEffectAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
moveAssetLooseFile(%assetDef.getHLSLShaderPath(), %destination);
moveAssetLooseFile(%assetDef.getGLSLShaderPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildPostEffectAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFilePath;
%previewData.doubleClickCommand = ""; %previewData.doubleClickCommand = "";
%previewData.previewImage = "ToolsModule:postEffectIcon_image"; %previewData.previewImage = "ToolsModule:postEffectIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\nDefinition Path: " @ %assetDef.getFilename(); %previewData.tooltip = "Asset Name: " @ %this.assetName @
"\nDefinition Path: " @ %this.getFilename();
}
function PostEffectAsset::onShowActionMenu(%this)
{
GenericAsset::onShowActionMenu(%this);
if( !isObject( EditPostFXAssetSubmenuPopup ) )
{
new PopupMenu( EditPostFXAssetSubmenuPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
//Regen the menu so we're fully up and current with options and references
EditPostFXAssetSubmenuPopup.clearItems();
EditPostFXAssetSubmenuPopup.item[ 0 ] = "Script file" TAB "" TAB %this @ ".onEditScriptFile();";
EditPostFXAssetSubmenuPopup.item[ 1 ] = "HLSL file" TAB "" TAB %this @ ".onEditHLSLFile();";
EditPostFXAssetSubmenuPopup.item[ 2 ] = "GLSL file" TAB "" TAB %this @ ".onEditHLSLFile();";
EditPostFXAssetSubmenuPopup.reloadItems();
EditAssetPopup.item[ 0 ] = "Edit PostFX Asset Files" TAB EditPostFXAssetSubmenuPopup;
EditAssetPopup.reloadItems();
EditAssetPopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditAssetPopup;
}
function PostEffectAsset::onEditScriptFile(%this)
{
if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.getScriptPath() @ "\\\"\");");
else
warn("PostEffectAsset::onEditScriptFile() - systemCommand function disabled in this build. Unable to launch application to edit file.");
}
function PostEffectAsset::onEditHLSLFile(%this)
{
if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.getHLSLShaderPath() @ "\\\"\");");
else
warn("PostEffectAsset::onEditHLSLFile() - systemCommand function disabled in this build. Unable to launch application to edit file.");
}
function PostEffectAsset::onEditGLSLFile(%this)
{
if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.getGLSLShaderPath() @ "\\\"\");");
else
warn("PostEffectAsset::onEditGLSLFile() - systemCommand function disabled in this build. Unable to launch application to edit file.");
} }

View file

@ -1,9 +1,11 @@
function AssetBrowser::createPrefab(%this) AssetBrowser::registerFileType("PrefabFileType", "Prefabs", ".prefab");
function PrefabFileType::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
@ -13,46 +15,32 @@ function AssetBrowser::createPrefab(%this)
EWorldEditor.makeSelectionPrefab( %prefabFilePath ); EWorldEditor.makeSelectionPrefab( %prefabFilePath );
EditorTree.buildVisibleTree( true ); EditorTree.buildVisibleTree( true );
$CurrentAssetBrowser.refresh();
} }
function AssetBrowser::buildPrefabPreview(%this, %assetDef, %previewData) function PrefabFileType::buildBrowserElement(%filePath, %previewData)
{ {
%fullPath = %assetDef.dirPath @ "/" @ %assetDef.assetName; %previewData.assetName = fileName(%filePath);
%previewData.assetName = %assetDef.assetName; %previewData.assetPath = %filePath;
%previewData.assetPath = %fullPath;
echo("PrefabFileType::buildBrowserElement() - name, path: " @ %previewData.assetName @ ", " @ %filePath);
%previewData.previewImage = "ToolsModule:prefabIcon_image"; %previewData.previewImage = "ToolsModule:prefabIcon_image";
//%previewData.assetFriendlyName = %assetDef.assetName; //%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %filePath;
%previewData.tooltip = %fullPath; %previewData.tooltip = %filePath;
//%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %assetDef.dirPath @ "/" @ %assetDef.assetName @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName //%previewData.doubleClickCommand = "AssetBrowser.schedule(10, \"navigateTo\",\""@ %assetDef.dirPath @ "/" @ %assetDef.assetName @"\");";//browseTo %assetDef.dirPath / %assetDef.assetName
%previewData.doubleClickCommand = "AssetBrowser.autoImportFile(\"" @ %fullPath @ "\");"; %previewData.doubleClickCommand = "AssetBrowser.autoImportFile(\"" @ %filePath @ "\");";
} }
function AssetBrowser::onPrefabEditorDropped(%this, %assetDef, %position) function PrefabFileType::onWorldEditorDropped(%filePath, %position)
{ {
//echo("DROPPED A SHAPE ON THE EDITOR WINDOW!");
%targetPosition = EWorldEditor.unproject(%position SPC 1);
%camPos = LocalClientConnection.camera.getPosition();
%rayResult = containerRayCast(%camPos, %targetPosition, -1);
%pos = ObjectCreator.getCreateObjectPosition();
if(%rayResult != 0)
{
%pos = getWords(%rayResult, 1, 3);
}
else
{
%pos = "0 0 0";
}
%newPrefab = new Prefab() %newPrefab = new Prefab()
{ {
position = %pos; position = %position;
fileName = %assetDef; fileName = %filePath;
}; };
getScene(0).add(%newPrefab); getScene(0).add(%newPrefab);

View file

@ -1,9 +1,12 @@
function AssetBrowser::createScriptAsset(%this) AssetBrowser::registerFileType("ScriptFileType", "Script Files", ".tscript;.cs;.dso;.tscript.dso;.cs.dso", false);
AssetBrowser::registerAssetType("ScriptAsset", "Scripts");
function ScriptAsset::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
@ -32,97 +35,122 @@ function AssetBrowser::createScriptAsset(%this)
return %tamlpath; return %tamlpath;
} }
function AssetBrowser::editScriptAsset(%this, %assetDef) function ScriptAsset::onEdit(%this)
{ {
%scriptFile = %assetDef.scriptFile; %scriptFile = %this.scriptFile;
//EditorOpenFileInTorsion(makeFullPath(%scriptFile), 0); if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %this.fileName @ "\\\"\");");
else
warn("ScriptAsset::onEdit() - systemCommand function disabled in this build. Unable to launch application to edit file.");
} }
function AssetBrowser::duplicateScriptAsset(%this, %assetDef, %targetModule) function ScriptAsset::buildBrowserElement(%this, %previewData)
{ {
} %previewData.assetName = %this.assetName;
%previewData.assetPath = %this.fileName;
function AssetBrowser::importScriptAsset(%this, %assetId)
{
}
function AssetBrowser::onScriptAssetEditorDropped(%this, %assetDef, %position)
{
}
//Renames the asset
function AssetBrowser::renameScriptAsset(%this, %assetDef, %newAssetName)
{
%newFilename = renameAssetLooseFile(%assetDef.scriptFile, %newAssetName);
if(!%newFilename $= "") if(%this.isServerSide)
return;
%assetDef.scriptFile = %newFilename;
%assetDef.saveAsset();
renameAssetFile(%assetDef, %newAssetName);
}
//Deletes the asset
function AssetBrowser::deleteScriptAsset(%this, %assetDef)
{
AssetDatabase.deleteAsset(%assetDef.getAssetId(), true);
}
//Moves the asset to a new path/module
function AssetBrowser::moveScriptAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildScriptAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
//%previewData.doubleClickCommand = "EditorOpenFileInTorsion( \""@%previewData.assetPath@"\", 0 );";
if(%assetDef.isServerSide)
%previewData.previewImage = "ToolsModule:serverScriptIcon_image"; %previewData.previewImage = "ToolsModule:serverScriptIcon_image";
else else
%previewData.previewImage = "ToolsModule:clientScriptIcon_image"; %previewData.previewImage = "ToolsModule:clientScriptIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.fileName;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\nDefinition Path: " @ %assetDef.getFilename(); %previewData.tooltip = "Script Asset: " @ %this.getAssetId() @ "\n" @
} "File path: " @ %this.fileName;
function AssetBrowser::buildTScriptPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
//%previewData.doubleClickCommand = "EditorOpenFileInTorsion( \""@%previewData.assetPath@"\", 0 );";
if(%assetDef.isServerSide)
%previewData.previewImage = "ToolsModule:serverScriptIcon_image";
else
%previewData.previewImage = "ToolsModule:clientScriptIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\nDefinition Path: " @ %assetDef.getFilename();
} }
function GuiInspectorTypeScriptAssetPtr::onClick( %this, %fieldName ) function GuiInspectorTypeScriptAssetPtr::onClick( %this, %fieldName )
{ {
//Get our data //Get our data
%obj = %this.getInspector().getInspectObject(0); %obj = %this.getInspector().getInspectObject(0);
}
//==============================================================================
// Handling for random script files in the browser
//==============================================================================
function ScriptFileType::buildBrowserElement(%filePath, %previewData)
{
%previewData.assetName = fileName(%filePath);
%previewData.assetPath = %filePath;
%previewData.doubleClickCommand = "systemCommand(\"start \\\"\\\" \\\"" @ %filePath @ "\\\"\");";
/*if(%assetDef.isServerSide)
%previewData.previewImage = "ToolsModule:serverScriptIcon_image";
else
%previewData.previewImage = "ToolsModule:clientScriptIcon_image";*/
%previewData.previewImage = "ToolsModule:clientScriptIcon_image";
%previewData.assetFriendlyName = %previewData.assetName;
%previewData.assetDesc = %filePath;
%previewData.tooltip = "Script File: " @ %filePath;
}
function ScriptAssetType::onEdit(%filePath)
{
if(isFunction("systemCommand"))
eval("systemCommand(\"start \\\"\\\" \\\"" @ %filePath @ "\\\"\");");
else
warn("ScriptAssetType::onEdit() - systemCommand function disabled in this build. Unable to launch application to edit file.");
}
function ScriptFileType::onShowActionMenu(%filePath)
{
if( !isObject( EditScriptFileTypePopup ) )
{
new PopupMenu( EditScriptFileTypePopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
jumpFileName = "";
jumpLineNumber = "";
};
}
//Regen the menu so we're fully up and current with options and references
EditScriptFileTypePopup.clearItems();
EditScriptFileTypePopup.item[ 0 ] = "Edit File" TAB "" TAB $CurrentAssetBrowser @ ".editAsset();";
EditScriptFileTypePopup.item[ 1 ] = "Rename File" TAB "" TAB $CurrentAssetBrowser @ ".renameAsset();";
EditScriptFileTypePopup.item[ 2 ] = "-";
EditScriptFileTypePopup.item[ 3 ] = "Duplicate File" TAB "" TAB $CurrentAssetBrowser @ ".duplicateAsset();";
EditScriptFileTypePopup.item[ 4 ] = "-";
EditScriptFileTypePopup.item[ 5 ] = "Open File Location" TAB "" TAB $CurrentAssetBrowser @ ".openFileLocation();";
EditScriptFileTypePopup.item[ 6 ] = "-";
EditScriptFileTypePopup.item[ 7 ] = "Delete File" TAB "" TAB $CurrentAssetBrowser @ ".deleteAsset();";
EditScriptFileTypePopup.item[ 8 ] = "-";
EditScriptFileTypePopup.item[ 9 ] = "File Properties" TAB "" TAB $CurrentAssetBrowser @ ".editAssetInfo();";
EditScriptFileTypePopup.objectData = %filePath;
EditScriptFileTypePopup.objectType = "ScriptFileType";
EditScriptFileTypePopup.reloadItems();
EditScriptFileTypePopup.showPopup(Canvas);
$CurrentAssetBrowser.popupMenu = EditScriptFileTypePopup;
}
function ScriptFileType::onEditProperties(%filePath)
{
Canvas.pushDialog(AssetBrowser_editAsset);
AssetBrowser_editAssetWindow.text = "Script File Properties - " @ %filePath;
AssetBrowser_editAsset.editedObjectData = %filePath;
//AssetBrowser_editAsset.editedObject = SpecialAssetEditInspector.tempAsset;
AssetBrowser_editAsset.editedObjectType = "ScriptFileType";
AssetEditInspector.startGroup("Script File Properties");
AssetEditInspector.addField("$ScriptFileType::ExecutionMode", "Execution Mode", "list", "How should this script file be executed by the module", "Server", "Client;Server;Shared;None");
AssetEditInspector.addField("$ScriptFileType::ExecutionOverride", "Do Execution Override", "bool", "Should this execution override files that share the same name?", "false");
AssetEditInspector.addField("$ScriptFileType::ExecutionConditions", "Execution Conditional", "command", "Does the execution of this script file have special conditionals?", "");
AssetEditInspector.endGroup("Script File Properties");
}
function ScriptFileType::onSaveProperties(%filePath)
{
//Do voodoo here
} }

View file

@ -1,285 +1,60 @@
function AssetBrowser::createShapeAsset(%this) AssetBrowser::registerAssetType("ShapeAsset", "Shapes");
function ShapeAsset::onEdit(%this)
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset")
%modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%tamlpath = %assetPath @ %assetName @ ".asset.taml";
%shapeFilePath = %assetPath @ %assetName @ ".dae";
%asset = new ShapeAsset()
{ {
AssetName = %assetName; $CurrentAssetBrowser.hideDialog();
versionId = 1; EditorGui.setEditor( ShapeEditorPlugin );
friendlyName = AssetBrowser.newAssetSettings.friendlyName; ShapeEditorPlugin.openShapeAsset(%this);
description = AssetBrowser.newAssetSettings.description;
fileName = %assetName @ ".dae";
};
TamlWrite(%asset, %tamlpath);
Canvas.popDialog(AssetBrowser_newComponentAsset);
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh();
return %tamlpath;
}
function AssetBrowser::editShapeAsset(%this, %assetDef)
{
%this.hideDialog();
EditorGui.setEditor( ShapeEditorPlugin );
ShapeEditorPlugin.openShapeAsset(%assetDef);
}
function AssetBrowser::onShapeAssetChanged(%this, %assetDef)
{
}
function AssetBrowser::deleteShapeAsset(%this, %assetDef)
{
}
function AssetBrowser::moveShapeAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getShapePath(), %destination);
moveAssetLooseFile(%assetDef.getShapeConstructorFilePath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::prepareImportShapeAsset(%this, %assetItem)
{
ImportActivityLog.add("Preparing Shape for Import: " @ %assetItem.assetName);
%fileExt = fileExt(%assetItem.filePath);
if(!isObject(%assetItem.shapeInfo))
{
%shapeInfo = new GuiTreeViewCtrl();
if(%fileExt $= ".dae")
{
enumColladaForImport(%assetItem.filePath, %shapeInfo, false);
}
else if(%fileExt $= ".dts")
{
%shapeInfo.insertItem(0, "Shape", 1);
%shapeInfo.insertItem(0, "Animations", 0);
}
else
{
GetShapeInfo(%assetItem.filePath, %shapeInfo, false);
}
%assetItem.shapeInfo = %shapeInfo;
} }
else
%shapeCount = %assetItem.shapeInfo._meshCount;
%shapeItem = %assetItem.shapeInfo.findItemByName("Meshes");
//%shapeId = ImportAssetTree.findItemByObjectId(%assetItem);
if(getAssetImportConfigValue("Meshes/ImportMesh", "1") == 1 && %shapeCount > 0)
{ {
} %this.onWorldEditorDropped();
%animCount = %assetItem.shapeInfo._animCount;
%animItem = %assetItem.shapeInfo.findItemByName("Animations");
if(getAssetImportConfigValue("Animations/ImportAnimations", "1") == 1 && %animCount > 0)
{
}
%matCount = %assetItem.shapeInfo._materialCount;
%matItem = %assetItem.shapeInfo.findItemByName("Materials");
ImportActivityLog.add(" Shape Info: Mesh Count: " @ %shapeCount @ " | Material Count: " @ %matCount @ " | Anim Count: " @ %animCount);
if(getAssetImportConfigValue("Materials/ImportMaterials", "1") == 1 && %matCount > 0)
{
%materialItem = %assetItem.shapeInfo.getChild(%matItem);
processShapeMaterialInfo(%assetItem, %materialItem);
%materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem);
while(%materialItem != 0)
{
processShapeMaterialInfo(%assetItem, %materialItem);
%materialItem = %assetItem.shapeInfo.getNextSibling(%materialItem);
}
}
}
function AssetBrowser::importShapeAsset(%this, %assetItem)
{
%moduleName = AssetImportTargetModule.getText();
%assetType = %assetItem.AssetType;
%filePath = %assetItem.filePath;
%assetName = %assetItem.assetName;
%assetImportSuccessful = false;
%assetId = %moduleName@":"@%assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%assetFullPath = %assetPath @ fileName(%filePath);
%newAsset = new ShapeAsset()
{
assetName = %assetName;
versionId = 1;
fileName = fileName(%filePath);
isNewShape = true;
};
//No point in indicating the original path data if it was imported in-place
if(!startsWith(makeFullPath(%filePath), getMainDotCsDir()))
{
%newAsset.originalFilePath = %filePath;
}
//check dependencies
%dependencySlotId = 0;
for(%i=0; %i < %assetItem.childAssetItems.count(); %i++)
{
%childAssetItem = %assetItem.childAssetItems.getKey(%i);
if(!isObject(%childAssetItem) || %childAssetItem.skip || %childAssetItem.processed == false)
continue;
%depAssetType = %childAssetItem.assetType;
if(%childAssetItem.assetType $= "MaterialAsset")
{
%matSet = "%newAsset.materialSlot"@%dependencySlotId@"=\"@asset="@%moduleName@":"@%childAssetItem.assetName@"\";";
eval(%matSet);
%dependencySlotId++;
}
else if(%depAssetType $= "AnimationAsset")
{
%matSet = "%newAsset.animationSequence"@%dependencySlotId@"=\"@asset="@%moduleName@":"@%childAssetItem.assetName@"\";";
eval(%matSet);
%dependencySlotId++;
}
}
%assetImportSuccessful = TAMLWrite(%newAsset, %assetPath @ %assetName @ ".asset.taml");
//and copy the file into the relevent directory
if(filePath(%filePath) !$= filePath(%assetFullPath))
{
%doOverwrite = !AssetBrowser.isAssetReImport;
if(!pathCopy(%filePath, %assetFullPath, %doOverwrite))
{
error("Unable to import asset: " @ %filePath);
}
}
%constructor = ShapeEditor.findConstructor( %assetFullPath );
if(!isObject(%constructor))
%constructor = ShapeEditor.createConstructor(%assetFullPath);
//We'll update any relevent bits to the ShapeConstructor here
$TSShapeConstructor::neverImportMat = "";
if(getAssetImportConfigValue("Materials/IgnoreMaterials", "") !$= "")
{
%ignoreMaterialList = getAssetImportConfigValue("Materials/IgnoreMaterials", "");
%ignoredMatNamesCount = getTokenCount(%ignoreMaterialList, ",;");
for(%i=0; %i < %ignoredMatNamesCount; %i++)
{
if(%i==0)
$TSShapeConstructor::neverImportMat = getToken(%ignoreMaterialList, ",;", %i);
else
$TSShapeConstructor::neverImportMat = $TSShapeConstructor::neverImportMat TAB getToken(%ignoreMaterialList, ",;", %i);
}
} }
if(getAssetImportConfigValue("Materials/DoUpAxisOverride", "") $= "1")
%constructor.upAxis = getAssetImportConfigValue("Meshes/UpAxisOverride", "Z_AXIS");
if(getAssetImportConfigValue("Meshes/DoScaleOverride", "0") $= "1")
%constructor.unit = getAssetImportConfigValue("Meshes/ScaleOverride", "1");
else
%constructor.unit = -1;
%constructor.lodType = getAssetImportConfigValue("Meshes/LODType", "0");
//%constructor.singleDetailSize = getAssetImportConfigValue("Meshes/convertLeftHanded", "0");
%constructor.alwaysImport = getAssetImportConfigValue("Meshes/AlwaysImportedNodes", "");
%constructor.neverImport = getAssetImportConfigValue("Meshes/AlwaysIgnoreNodes", "");
%constructor.alwaysImportMesh = getAssetImportConfigValue("Meshes/AlwaysImportMeshes", "");
%constructor.neverImportMesh = getAssetImportConfigValue("Meshes/AlwaysIgnoreMeshes", "");
%constructor.ignoreNodeScale = getAssetImportConfigValue("Meshes/IgnoreNodeScale", "0");
%constructor.adjustCenter = getAssetImportConfigValue("Meshes/AdjustCenter", "0");
%constructor.adjustFloor = getAssetImportConfigValue("Meshes/AdjustFloor", "0");
%constructor.convertLeftHanded = getAssetImportConfigValue("Meshes/convertLeftHanded", "0");
%constructor.calcTangentSpace = getAssetImportConfigValue("Meshes/calcTangentSpace", "0");
%constructor.genUVCoords = getAssetImportConfigValue("Meshes/genUVCoords", "0");
%constructor.flipUVCoords = getAssetImportConfigValue("Meshes/flipUVCoords", "0");
%constructor.findInstances = getAssetImportConfigValue("Meshes/findInstances", "0");
%constructor.limitBoneWeights = getAssetImportConfigValue("Meshes/limitBoneWeights", "0");
%constructor.joinIdenticalVerts = getAssetImportConfigValue("Meshes/joinIdenticalVerts", "0");
%constructor.reverseWindingOrder = getAssetImportConfigValue("Meshes/reverseWindingOrder", "0");
%constructor.invertNormals = getAssetImportConfigValue("Meshes/invertNormals", "0");
%constructor.removeRedundantMats = getAssetImportConfigValue("Meshes/removeRedundantMats", "0");
%constructor.animTiming = getAssetImportConfigValue("Animations/animTiming", "Seconds");
%constructor.animFPS = getAssetImportConfigValue("Animations/animFPS", "2");
%constructor.neverImportMat = $TSShapeConstructor::neverImportMat;
ShapeEditor.saveConstructor( %constructor );
//now, force-load the file if it's collada
/*%fileExt = fileExt(%assetFullPath);
if(isSupportedFormat(getSubStr(%fileExt,1)))
{
%tempShape = new TSStatic()
{
shapeName = %assetFullPath;
};
%tempShape.delete();
}*/
%moduleDef = ModuleDatabase.findModule(%moduleName,1);
if(!AssetBrowser.isAssetReImport)
AssetDatabase.addDeclaredAsset(%moduleDef, %assetPath @ %assetName @ ".asset.taml");
else
AssetDatabase.refreshAsset(%assetId);
} }
function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData, %forcePreviewRegenerate) function ShapeAsset::onShowActionMenu(%assetDef)
{
GenericAsset::onShowActionMenu(%assetDef);
}
function ShapeAsset::onChanged(%this)
{
echo("ShapeAsset::onChanged() - asset " @ %this.assetId @ " has changed!");
}
function ShapeAsset::onDelete(%this)
{
//Special handle the cache preview image
%module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%this.getShapePath())));
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/" @ %this.assetName @ "_Preview.dds";
if(isFile(%previewPath))
{
$CurrentAssetBrowser.dirHandler.deleteFile(%previewPath);
}
//then just let the Generic function handle the rest
GenericAsset::onDelete(%this);
}
function ShapeAsset::buildBrowserElement(%this, %previewData)
{ {
%previewData.previewImage = "ToolsModule:genericAssetIcon_image"; %previewData.previewImage = "ToolsModule:genericAssetIcon_image";
%previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.previewLoaded = false; //this marks it for loading progressively later
%previewData.assetName = %assetDef.assetName; %previewData.assetName = %this.assetName;
%previewData.assetPath = %assetDef.fileName; %previewData.assetPath = %this.fileName;
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\n" @ %previewData.tooltip = "Asset Name: " @ %this.assetName @ "\n" @
"Asset Type: Shape Asset\n" @ "Asset Type: Shape Asset\n" @
"Asset Definition ID: " @ %assetDef @ "\n" @ "Asset Definition ID: " @ %this @ "\n" @
"Shape File path: " @ %assetDef.getShapePath(); "Shape File path: " @ %this.getShapePath();
if(%this.selectMode) /*if(%this.selectMode)
{ {
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );"; %previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );";
} }
@ -293,41 +68,39 @@ function AssetBrowser::buildShapeAssetPreview(%this, %assetDef, %previewData, %f
{ {
%previewData.doubleClickCommand = "AssetBrowser.onShapeAssetEditorDropped( "@%assetDef@" );"; %previewData.doubleClickCommand = "AssetBrowser.onShapeAssetEditorDropped( "@%assetDef@" );";
} }
} }*/
} }
function AssetBrowser::generateShapeAssetPreviewImage(%this, %previewButton, %forceRegenerate) function ShapeAsset::generatePreviewImage(%this, %previewButton, %forceRegenerate)
{ {
if(%forceRegenerate $= "") if(%forceRegenerate $= "")
%forceRegenerate = false; %forceRegenerate = false;
%assetId = %previewButton.moduleName @ ":" @ %previewButton.assetName; %assetId = %this.getAssetId();
%assetDef = AssetDatabase.acquireAsset(%assetId); %module = %previewButton.assetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%this.getShapePath())));
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(%assetDef.getShapePath())));
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/"; %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
if(!IsDirectory(%previewPath)) if(!IsDirectory(%previewPath))
{ {
%this.dirHandler.createFolder(%previewPath); %previewButton.assetBrowser.dirHandler.createFolder(%previewPath);
} }
%generatePreview = false; %generatePreview = false;
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.dds"; %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds";
if(!isFile(%previewFilePath) || (compareFileTimes(%assetDef.getShapePath(), %previewFilePath) == 1)) if(!isFile(%previewFilePath) || (compareFileTimes(%this.getShapePath(), %previewFilePath) == 1))
{ {
%generatePreview = true; %generatePreview = true;
} }
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage"; %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage";
if(%generatePreview || %forceRegenerate) if(%generatePreview || %forceRegenerate)
{ {
//real fast, we'll be 100% sure that the image resource we need is loaded //real fast, we'll be 100% sure that the image resource we need is loaded
%matSlot0AssetId = %assetDef.materialSlot0; %matSlot0AssetId = %this.materialSlot0;
if(AssetDatabase.isDeclaredAsset(%matSlot0AssetId)) if(AssetDatabase.isDeclaredAsset(%matSlot0AssetId))
{ {
%matAsset = AssetDatabase.acquireAsset(%matSlot0AssetId); %matAsset = AssetDatabase.acquireAsset(%matSlot0AssetId);
@ -337,7 +110,7 @@ function AssetBrowser::generateShapeAssetPreviewImage(%this, %previewButton, %fo
//This is slightly hacky, but we're going to utilize the imposter/last detail system //This is slightly hacky, but we're going to utilize the imposter/last detail system
//to generate our previews for us and then clean up the unneeded bits //to generate our previews for us and then clean up the unneeded bits
%filePath = %assetDef.generateCachedPreviewImage(); %filePath = %this.generateCachedPreviewImage();
pathCopy(%filePath, %previewFilePath, false); pathCopy(%filePath, %previewFilePath, false);
fileDelete(%filePath); //cleanup fileDelete(%filePath); //cleanup
@ -380,7 +153,7 @@ function AssetBrowser::generateShapeAssetPreviewImage(%this, %previewButton, %fo
return false; return false;
} }
function AssetBrowser::onShapeAssetEditorDropped(%this, %assetDef, %position) function ShapeAsset::onWorldEditorDropped(%assetDef, %position)
{ {
%assetId = %assetDef.getAssetId(); %assetId = %assetDef.getAssetId();
@ -402,6 +175,11 @@ function AssetBrowser::onShapeAssetEditorDropped(%this, %assetDef, %position)
MECreateUndoAction::submit(%newStatic ); MECreateUndoAction::submit(%newStatic );
} }
function ShapeAsset::onGUIEditorDropped(%assetDef, %position)
{
}
function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position ) function GuiInspectorTypeShapeAssetPtr::onControlDropped( %this, %payload, %position )
{ {
Canvas.popDialog(EditorDragAndDropLayer); Canvas.popDialog(EditorDragAndDropLayer);

View file

@ -1,57 +1,16 @@
function AssetBrowser::createShapeAnimationAsset(%this) AssetBrowser::registerAssetType("ShapeAnimationAsset", "Shape Anims");
{
%dlg = new OpenFileDialog()
{
Filters = "Animation Files(*.dae, *.cached.dts)|*.dae;*.cached.dts";
DefaultPath = $Pref::WorldEditor::LastPath;
DefaultFile = "";
ChangePath = false;
OverwritePrompt = true;
forceRelativePath = false;
//MultipleFiles = true;
};
%ret = %dlg.Execute(); function ShapeAnimationAsset::onEdit(%this)
if ( %ret )
{
$Pref::WorldEditor::LastPath = filePath( %dlg.FileName );
%fullPath = %dlg.FileName;
}
%dlg.delete();
if ( !%ret )
return;
}
function AssetBrowser::editShapeAnimationAsset(%this, %assetDef)
{ {
%this.hideDialog(); $CurrentAssetBrowser.hideDialog();
EditorGui.setEditor( ShapeEditorPlugin ); EditorGui.setEditor( ShapeEditorPlugin );
ShapeEditorPlugin.openShapeAsset(%assetDef); ShapeEditorPlugin.openShapeAsset(%this);
} }
function AssetBrowser::moveShapeAnimationAsset(%this, %assetDef, %destination) function ShapeAnimationAsset::buildBrowserElement(%this, %previewData)
{ {
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId()); %previewData.assetName = %this.animationName;
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination); %previewData.assetPath = %this.scriptFile;
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getAnimationPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildShapeAnimationAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.animationName;
%previewData.assetPath = %assetDef.scriptFile;
//Lotta prepwork //Lotta prepwork
/*%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); " /*%previewData.doubleClickCommand = %assetDef@".materialDefinitionName.reload(); "
@ -66,7 +25,9 @@ function AssetBrowser::buildShapeAnimationAssetPreview(%this, %assetDef, %previe
%previewData.previewImage = "ToolsModule:animationIcon_image"; %previewData.previewImage = "ToolsModule:animationIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef @ "\nShape File path: " @ %assetDef.getShapePath(); %previewData.tooltip = %this.friendlyName @ "\n"
@ %this @ "\nShape File path: "
@ %this.getShapePath();
} }

View file

@ -1,61 +1,50 @@
function AssetBrowser::editSoundAsset(%this, %assetDef) AssetBrowser::registerAssetType("SoundAsset", "Sounds");
function SoundAsset::onEdit(%this)
{ {
if (isObject($PreviewSoundSource)) if (isObject($PreviewSoundSource))
sfxStop($PreviewSoundSource); sfxStop($PreviewSoundSource);
$PreviewSoundSource = %assetDef.playSound(); $PreviewSoundSource = %this.playSound();
} }
function AssetBrowser::onSoundAssetChanged(%this, %assetDef) function SoundAsset::onChanged(%this)
{ {
if (isObject($PreviewSoundSource)) if (isObject($PreviewSoundSource))
sfxStop($PreviewSoundSource); sfxStop($PreviewSoundSource);
} }
function AssetBrowser::moveSoundAsset(%this, %assetDef, %destination) function SoundAsset::buildBrowserElement(%this, %previewData)
{ {
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId()); %previewData.assetName = %this.assetName;
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination); %previewData.assetPath = %this.soundFilePath;
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getSoundPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildSoundAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.soundFilePath;
if(%this.selectMode) if(%this.selectMode)
{ {
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".selectAsset( " @ $CurrentAssetBrowser @ ".selectedAsset );";
} }
else else
{ {
if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset") %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@ %this @" );";
/*if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset")
{ {
%previewData.doubleClickCommand = "AssetBrowser.editAsset( "@%assetDef@" );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".editAsset( "@ %this @" );";
} }
else else
{ {
%previewData.doubleClickCommand = "AssetBrowser.onSoundAssetEditorDropped( "@%assetDef@" );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".onSoundAssetEditorDropped( "@ %this @" );";
} }*/
} }
%previewData.previewImage = "ToolsModule:soundIcon_image"; %previewData.previewImage = "ToolsModule:soundIcon_image";
%previewData.assetFriendlyName = %assetDef.assetName; %previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ "\nDefinition Path: " @ %assetDef.getFilename(); %previewData.tooltip = "Asset Name: " @ %this.assetName @
"\nDefinition Path: " @ %this.getFilename();
} }
function AssetBrowser::onSoundAssetEditorDropped(%this, %assetDef, %position) function SoundAsset::onWorldEditorDropped(%this, %position)
{ {
%targetPosition = EWorldEditor.unproject(%position SPC 1); %targetPosition = EWorldEditor.unproject(%position SPC 1);
%camPos = LocalClientConnection.camera.getPosition(); %camPos = LocalClientConnection.camera.getPosition();
@ -72,14 +61,12 @@ function AssetBrowser::onSoundAssetEditorDropped(%this, %assetDef, %position)
%pos = "0 0 0"; %pos = "0 0 0";
} }
%assetId = %assetDef.getAssetId();
%newSFXEmitter = new SFXEmitter() %newSFXEmitter = new SFXEmitter()
{ {
position = %pos; position = %pos;
soundAsset = %assetDef.getAssetId(); soundAsset = %this.getAssetId();
pitch = %assetDef.pitchAdjust; pitch = %this.pitchAdjust;
volume = %assetDef.volumeAdjust; volume = %this.volumeAdjust;
}; };
getScene(0).add(%newSFXEmitter); getScene(0).add(%newSFXEmitter);
@ -91,15 +78,15 @@ function AssetBrowser::onSoundAssetEditorDropped(%this, %assetDef, %position)
} }
function AssetBrowser::onSoundAssetGUIEditorDropped(%this, %assetDef, %position) function SoundAsset::onGUIEditorDropped(%this, %position)
{ {
%assetId = %assetDef.getAssetId(); %assetId = %this.getAssetId();
%cmd = "new GuiAudioCtrl(){"; %cmd = "new GuiAudioCtrl(){";
%cmd = %cmd @ "SoundAsset =\""@ %assetId @"\";"; %cmd = %cmd @ "SoundAsset =\""@ %assetId @"\";";
%cmd = %cmd @ "position =\""@ %position @"\";"; %cmd = %cmd @ "position =\""@ %position @"\";";
%cmd = %cmd @ "};"; %cmd = %cmd @ "};";
%ctrl = GuiEditCanvas.createObject(%cmd); %ctrl = GuiEditCanvas.createObject(%cmd);
echo(%ctrl SPC "created"); //echo(%ctrl SPC "created");
} }
function GuiInspectorTypeSoundAssetPtr::onControlDropped( %this, %payload, %position ) function GuiInspectorTypeSoundAssetPtr::onControlDropped( %this, %payload, %position )

View file

@ -1,161 +0,0 @@
function AssetBrowser::createStateMachineAsset(%this)
{
%assetName = AssetBrowser.newAssetSettings.assetName;
%moduleName = AssetBrowser.selectedModule;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%assetQuery = new AssetQuery();
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %assetName);
%i=1;
while(%matchingAssetCount > 0)
{
%newAssetName = %assetName @ %i;
%i++;
%matchingAssetCount = AssetDatabase.findAssetName(%assetQuery, %newAssetName);
}
%assetName = %newAssetName;
%assetQuery.delete();
%tamlpath = %assetPath @ %assetName @ ".asset.taml";
%smFilePath = %assetPath @ %assetName @ ".xml";
%asset = new StateMachineAsset()
{
AssetName = %assetName;
versionId = 1;
stateMachineFile = %assetName @ ".xml";
};
%xmlDoc = new SimXMLDocument();
%xmlDoc.saveFile(%smFilePath);
%xmlDoc.delete();
TamlWrite(%asset, %tamlpath);
//Now write our XML file
%xmlFile = new FileObject();
%xmlFile.openForWrite(%smFilePath);
%xmlFile.writeLine("<StateMachine>");
%xmlFile.writeLine("</StateMachine>");
%xmlFile.close();
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh();
return %tamlpath;
}
function AssetBrowser::editStateMachineAsset(%this, %assetDef)
{
eval("AssetBrowser.tempAsset = new " @ %assetDef.getClassName() @ "();");
AssetBrowser.tempAsset.assignFieldsFrom(%assetDef);
SMAssetEditInspector.inspect(AssetBrowser.tempAsset);
AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId;
AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset;
//remove some of the groups we don't need:
for(%i=0; %i < SMAssetEditInspector.getCount(); %i++)
{
%caption = SMAssetEditInspector.getObject(%i).caption;
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
SMAssetEditInspector.remove(SMAssetEditInspector.getObject(%i));
%i--;
}
}
Canvas.pushDialog(StateMachineEditor);
StateMachineEditor.loadStateMachineAsset(EditAssetPopup.assetId);
StateMachineEditor-->Window.text = "State Machine Editor ("@EditAssetPopup.assetId@")";
}
function AssetBrowser::duplicateStateMachineAsset(%this, %assetDef)
{
// TODO:
%targetModule = "";
//Check if we have a target module, if not we need to select one
if(%targetModule $= "")
{
error("AssetBrowser::duplicateStateMachineAsset - No target module selected!");
return;
}
%assetId = %assetDef.getAssetId();
%assetName = AssetDatabase.getAssetName(%assetId);
//First step, copy the files
%modulePath = "data/" @ %targetModule @ "/stateMachines/";
if(!isDirectory(%modulePath))
createPath(%modulePath);
%assetFile = AssetDatabase.getAssetFilePath(%assetId);
%stateMachineFile = %assetDef.stateMachineFile;
echo("AssetBrowser::duplicateGameObjectAsset - duplicating! " @ %assetId @ " to " @ %targetModule);
%tamlPath = %modulePath @ fileName(%assetFile);
pathCopy(%assetFile, %tamlPath);
pathCopy(%stateMachineFile, %modulePath @ fileName(%stateMachineFile));
echo("AssetBrowser::duplicateStateMachineAsset - duplicated!");
//Register the asset
%moduleDef = ModuleDatabase.findModule(%targetModule, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlPath);
//Refresh the browser
AssetBrowser.refresh();
//Rename it for convenience
AssetBrowser.performRenameAsset(%assetName, "New" @ %assetName);
}
function AssetBrowser::renameGameObjectAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
%assetPath = AssetDatabase.getAssetFilePath(%newAssetId);
//rename the file to match
%path = filePath(%assetPath);
%oldScriptFilePath = %assetDef.stateMachineFile;
%scriptFilePath = filePath(%assetDef.stateMachineFile);
%scriptExt = fileExt(%assetDef.stateMachineFile);
%newScriptFileName = %scriptFilePath @ "/" @ %newName @ %scriptExt;
%newAssetFile = %path @ "/" @ %newName @ ".asset.taml";
%assetDef.stateMachineFile = %newScriptFileName;
TamlWrite(%assetDef, %newAssetFile);
fileDelete(%assetPath);
pathCopy(%oldScriptFilePath, %newScriptFileName);
fileDelete(%oldScriptFilePath);
}
function AssetBrowser::buildStateMachineAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = %assetDef.scriptFile;
%previewData.doubleClickCommand = "AssetBrowser.editStateMachineAsset( "@%assetDef@" );";
%previewData.previewImage = "ToolsModule:stateMachineIcon_image";
%previewData.assetFriendlyName = %assetDef.friendlyName;
%previewData.assetDesc = %assetDef.description;
%previewData.tooltip = %assetDef.friendlyName @ "\n" @ %assetDef;
}

View file

@ -0,0 +1,156 @@
AssetBrowser::registerAssetType("SubSceneAsset", "SubScenes");
function SubSceneAsset::setupCreateNew()
{
NewAssetPropertiesInspector.startGroup("SubScene");
NewAssetPropertiesInspector.addField("LevelName", "SubScene Name", "String", "Human-readable name of new subScene", "", "", $CurrentAssetBrowser.newAssetSettings);
NewAssetPropertiesInspector.endGroup();
}
function SubSceneAsset::onCreateNew(%this)
{
%moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName;
%assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetPath = NewAssetTargetAddress.getText() @ "/";
%misExtension = ".subMis";
%tamlpath = %assetPath @ %assetName @ ".asset.taml";
%levelPath = %assetPath @ %assetName @ %misExtension;
%asset = new SubSceneAsset()
{
AssetName = %assetName;
versionId = 1;
LevelFile = %assetName @ %misExtension;
LevelName = $CurrentAssetBrowser.newAssetSettings.levelName;
AssetDescription = $CurrentAssetBrowser.newAssetSettings.description;
};
TamlWrite(%asset, %tamlpath);
%fileObj = new FileObject();
if (!%fileObj.openForWrite(%levelPath))
{
echo("Unable to write subScene file!");
}
else
{
%fileObj.writeLine("");
%fileObj.close();
%fileObj.delete();
}
%moduleDef = ModuleDatabase.findModule(%moduleName, 1);
%addSuccess = AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
if(!%addSuccess)
{
error("SubSceneAsset::onCreateNew() - failed to add declared asset: " @ %tamlpath @ " for module: " @ %moduleDef);
}
$CurrentAssetBrowser.refresh();
if(%addSuccess && isObject($createAndAssignField))
{
$createAndAssignField.apply(%moduleName @ ":" @ %assetName);
$createAndAssignField = "";
}
return %tamlpath;
}
function SubSceneAsset::buildBrowserElement(%this, %previewData)
{
%previewData.assetName = %this.assetName;
%previewData.assetPath = %this.getLevelPath();
%previewData.doubleClickCommand = "AssetBrowser.selectAsset(" @ %this @ ");";
%levelPreviewImage = %this.PreviewImage;
if(isFile(%levelPreviewImage))
%previewData.previewImage = %levelPreviewImage;
else
%previewData.previewImage = "ToolsModule:levelIcon_image";
%previewData.assetFriendlyName = %this.assetName;
%previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %this.assetName @ "\n" @
"Asset Type: SubScene Asset\n" @
"Asset Definition ID: " @ %this @ "\n" @
"SubScene File path: " @ %this.getLevelPath();
}
function EWorldEditor::createSelectedAsSubScene( %this, %object )
{
//create new level asset here
AssetBrowser.setupCreateNewAsset("SubSceneAsset", AssetBrowser.selectedModule, "finishCreateSelectedAsSubScene");
%this.contextActionObject = %object;
}
function finishCreateSelectedAsSubScene(%assetId)
{
//echo("finishCreateSelectedAsSubScene");
%subScene = new SubScene() {
levelAsset = %assetId;
};
%levelAssetDef = AssetDatabase.acquireAsset(%assetId);
%levelFilePath = %levelAssetDef.getLevelPath();
//write out to file
EWorldEditor.contextActionObject.save(%levelFilePath);
AssetDatabase.releaseAsset(%assetId);
getRootScene().add(%subScene);
EWorldEditor.contextActionObject.delete();
%subScene.load();
%subScene.recalculateBounds();
%scalar = $SubScene::createScalar;
if(%scalar $= "")
%scalar = 1.5;
//pad for loading boundary
%subScene.scale = VectorScale(%subScene.scale, %scalar);
}
function SubSceneAsset::onWorldEditorDropped(%assetDef, %position)
{
%assetId = %assetDef.getAssetId();
if(!%assetDef.isSubScene)
{
errorf("Cannot drag-and-drop LevelAsset into WorldEditor");
return;
}
%newSubScene = new SubScene()
{
position = %position;
levelAsset = %assetId;
};
getScene(0).add(%newSubScene);
%newSubScene.load();
%newSubScene.recalculateBounds();
EWorldEditor.clearSelection();
EWorldEditor.selectObject(%newSubScene);
EWorldEditor.dropSelection();
EWorldEditor.isDirty = true;
MECreateUndoAction::submit(%newSubScene );
}

View file

@ -1,23 +1,25 @@
function AssetBrowser::setupCreateNewTerrainAsset(%this) AssetBrowser::registerAssetType("TerrainAsset", "Terrains");
function TerrainAsset::setupCreateNew()
{ {
NewAssetPropertiesInspector.startGroup("Terrain"); NewAssetPropertiesInspector.startGroup("Terrain");
NewAssetPropertiesInspector.addField("resolution", "Terrain Texture Resolution", "list", "Is this script used on the server?", "1024", "256,512,1024,2048,4096", %this.newAssetSettings); NewAssetPropertiesInspector.addField("resolution", "Terrain Texture Resolution", "list", "Is this script used on the server?", "1024", "256,512,1024,2048,4096", $CurrentAssetBrowser.newAssetSettings);
NewAssetPropertiesInspector.addField("genWithNoise", "Generate Terrain With Noise", "bool", "Is this script used on the server?", "0", "2", %this.newAssetSettings); NewAssetPropertiesInspector.addField("genWithNoise", "Generate Terrain With Noise", "bool", "Is this script used on the server?", "0", "2", $CurrentAssetBrowser.newAssetSettings);
NewAssetPropertiesInspector.endGroup(); NewAssetPropertiesInspector.endGroup();
/*NewAssetPropertiesInspector.startGroup("Terrain - Import"); /*NewAssetPropertiesInspector.startGroup("Terrain - Import");
NewAssetPropertiesInspector.addField("importDetails", "Import Heightmap", "button", "Import an existing heightmap", "", "Canvas.pushDialog( TerrainImportGui );", %this.newAssetSettings); NewAssetPropertiesInspector.addField("importDetails", "Import Heightmap", "button", "Import an existing heightmap", "", "Canvas.pushDialog( TerrainImportGui );", $CurrentAssetBrowser.newAssetSettings);
NewAssetPropertiesInspector.endGroup();*/ NewAssetPropertiesInspector.endGroup();*/
} }
function AssetBrowser::createTerrainAsset(%this) function TerrainAsset::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetType = AssetBrowser.newAssetSettings.assetType; %assetType = $CurrentAssetBrowser.newAssetSettings.assetType;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
//Ensure anything we generate goes into the right directory //Ensure anything we generate goes into the right directory
@ -31,8 +33,8 @@ function AssetBrowser::createTerrainAsset(%this)
AssetName = %assetName; AssetName = %assetName;
versionId = 1; versionId = 1;
terrainFile = %assetName @ ".ter"; terrainFile = %assetName @ ".ter";
resolution = %this.newAssetSettings.resolution; resolution = $CurrentAssetBrowser.newAssetSettings.resolution;
genWithNoise = %this.newAssetSettings.genWithNoise; genWithNoise = $CurrentAssetBrowser.newAssetSettings.genWithNoise;
}; };
TamlWrite(%asset, %tamlpath); TamlWrite(%asset, %tamlpath);
@ -40,9 +42,9 @@ function AssetBrowser::createTerrainAsset(%this)
%moduleDef = ModuleDatabase.findModule(%moduleName, 1); %moduleDef = ModuleDatabase.findModule(%moduleName, 1);
AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath); AssetDatabase.addDeclaredAsset(%moduleDef, %tamlpath);
AssetBrowser.refresh(); $CurrentAssetBrowser.refresh();
$createdTerrainBlock = TerrainBlock::createNew( %assetName, %this.newAssetSettings.resolution, "", %this.newAssetSettings.genWithNoise ); $createdTerrainBlock = TerrainBlock::createNew( %assetName, $CurrentAssetBrowser.newAssetSettings.resolution, "", $CurrentAssetBrowser.newAssetSettings.genWithNoise );
MECreateUndoAction::submit($createdTerrainBlock); MECreateUndoAction::submit($createdTerrainBlock);
@ -55,12 +57,12 @@ function AssetBrowser::createTerrainAsset(%this)
// This will update an existing terrain with the name %terrainName, // This will update an existing terrain with the name %terrainName,
// or create a new one if %terrainName isn't a TerrainBlock // or create a new one if %terrainName isn't a TerrainBlock
$createdTerrainBlock = TerrainBlock::import( $createdTerrainBlock, $createdTerrainBlock = TerrainBlock::import( $createdTerrainBlock,
AssetBrowser.newAssetSettings.heightMapPng, $CurrentAssetBrowser.newAssetSettings.heightMapPng,
AssetBrowser.newAssetSettings.metersPerPixel, $CurrentAssetBrowser.newAssetSettings.metersPerPixel,
AssetBrowser.newAssetSettings.heightScale, $CurrentAssetBrowser.newAssetSettings.heightScale,
AssetBrowser.newAssetSettings.opacityNames, $CurrentAssetBrowser.newAssetSettings.opacityNames,
AssetBrowser.newAssetSettings.materialNames, $CurrentAssetBrowser.newAssetSettings.materialNames,
AssetBrowser.newAssetSettings.flipYAxis ); $CurrentAssetBrowser.newAssetSettings.flipYAxis );
if ( isObject( $createdTerrainBlock ) ) if ( isObject( $createdTerrainBlock ) )
{ {
@ -130,87 +132,35 @@ function createTerrainBlock(%assetId)
// //
} }
function AssetBrowser::editTerrainAsset(%this, %assetDef)
function TerrainAsset::onWorldEditorDropped(%this, %position)
{ {
createTerrainBlock(%this.getAssetId());
} }
function AssetBrowser::duplicateTerrainAsset(%this, %assetDef, %targetModule) function TerrainAsset::buildBrowserElement(%this, %previewData)
{ {
} %previewData.assetName = %this.assetName;
function AssetBrowser::importTerrainAsset(%this, %assetDef)
{
}
function AssetBrowser::dragAndDropTerrainAsset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
}
function AssetBrowser::onTerrainAssetEditorDropped(%this, %assetDef, %position)
{
createTerrainBlock(%assetDef.getAssetId());
}
function AssetBrowser::renameTerrainAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
}
function AssetBrowser::deleteTerrainAsset(%this, %assetDef)
{
}
function AssetBrowser::moveTerrainAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getTerrainFilePath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildTerrainAssetPreview(%this, %assetDef, %previewData)
{
%previewData.assetName = %assetDef.assetName;
%previewData.assetPath = ""; %previewData.assetPath = "";
%previewData.previewImage = "ToolsModule:terrainIcon_image"; %previewData.previewImage = "ToolsModule:terrainIcon_image";
%previewData.assetFriendlyName = %assetDef.gameObjectName; %previewData.assetFriendlyName = %this.gameObjectName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ %previewData.tooltip = "Asset Name: " @ %this.assetName @
"\nAsset Type: Terrain Asset" @ "\nAsset Type: Terrain Asset" @
"\nAsset Definition ID: " @ %assetDef @ "\nAsset Definition ID: " @ %this @
"\nDefinition Path: " @ %assetDef.getTerrainFilePath(); "\nDefinition Path: " @ %this.getTerrainFilePath();
if(%this.selectMode) if(%this.selectMode)
{ {
%previewData.doubleClickCommand = "AssetBrowser.selectAsset( AssetBrowser.selectedAsset );"; %previewData.doubleClickCommand = $CurrentAssetBrowser @ ".selectAsset( " @ $CurrentAssetBrowser @ ".selectedAsset );";
} }
else else
{ {
if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset") if(EditorSettings.value("Assets/Browser/doubleClickAction", "Edit Asset") $= "Edit Asset")
%previewData.doubleClickCommand = ""; %previewData.doubleClickCommand = "";
else else
%previewData.doubleClickCommand = "createTerrainBlock(\""@%assetDef.getAssetId()@"\");"; %previewData.doubleClickCommand = "createTerrainBlock(\""@%this.getAssetId()@"\");";
} }
}
function GuiInspectorTypeTerrainAssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
}
function GuiInspectorTypeTerrainAssetPtr::onControlDropped( %this, %payload, %position )
{
} }

View file

@ -1,11 +1,13 @@
function AssetBrowser::createTerrainMaterialAsset(%this) AssetBrowser::registerAssetType("TerrainMaterialAsset", "Terrain Materials");
function TerrainMaterialAsset::onCreateNew()
{ {
%moduleName = AssetBrowser.newAssetSettings.moduleName; %moduleName = $CurrentAssetBrowser.newAssetSettings.moduleName;
%modulePath = "data/" @ %moduleName; %modulePath = "data/" @ %moduleName;
%assetName = AssetBrowser.newAssetSettings.assetName; %assetName = $CurrentAssetBrowser.newAssetSettings.assetName;
%assetType = AssetBrowser.newAssetSettings.assetType; %assetType = $CurrentAssetBrowser.newAssetSettings.assetType;
%assetPath = NewAssetTargetAddress.getText() @ "/"; %assetPath = NewAssetTargetAddress.getText() @ "/";
%tamlpath = %assetPath @ %assetName @ ".asset.taml"; %tamlpath = %assetPath @ %assetName @ ".asset.taml";
@ -57,7 +59,7 @@ function AssetBrowser::createTerrainMaterialAsset(%this)
AssetDatabase.acquireAsset("\"" @ %moduleName @ ":" @ %assetName @ "\""); AssetDatabase.acquireAsset("\"" @ %moduleName @ ":" @ %assetName @ "\"");
AssetBrowser.refresh(); $CurrentAssetBrowser.refresh();
//If we've got the terrain mat editor open, go ahead and update it all //If we've got the terrain mat editor open, go ahead and update it all
TerrainMaterialDlg.onWake(); TerrainMaterialDlg.onWake();
@ -65,112 +67,70 @@ function AssetBrowser::createTerrainMaterialAsset(%this)
return %tamlpath; return %tamlpath;
} }
function AssetBrowser::editTerrainMaterialAsset(%this, %assetDef) function TerrainAssetMaterial::onEdit(%this)
{ {
TerrainMaterialDlg.show(0, 0, 0); TerrainMaterialDlg.show(0, 0, 0);
TerrainMaterialDlg.setActiveMaterial(%assetDef.assetName); TerrainMaterialDlg.setActiveMaterial(%this.assetName);
} }
function AssetBrowser::duplicateTerrainMaterialAsset(%this, %assetDef, %targetModule) function TerrainAssetMaterial::buildBrowserElement(%this, %previewData)
{
}
function AssetBrowser::importTerrainMaterialAsset(%this, %assetDef)
{
}
function AssetBrowser::dragAndDropTerrainMaterialAsset(%this, %assetDef, %dropTarget)
{
if(!isObject(%dropTarget))
return;
}
function AssetBrowser::renameTerrainMaterialAsset(%this, %assetDef, %newAssetId, %originalName, %newName)
{
}
function AssetBrowser::deleteTerrainMaterialAsset(%this, %assetDef)
{
}
function AssetBrowser::moveTerrainMaterialAsset(%this, %assetDef, %destination)
{
%currentModule = AssetDatabase.getAssetModule(%assetDef.getAssetId());
%targetModule = AssetBrowser.dirHandler.getModuleFromAddress(%destination);
%newAssetPath = moveAssetFile(%assetDef, %destination);
if(%newAssetPath $= "")
return false;
moveAssetLooseFile(%assetDef.getScriptPath(), %destination);
AssetDatabase.removeDeclaredAsset(%assetDef.getAssetId());
AssetDatabase.addDeclaredAsset(%targetModule, %newAssetPath);
}
function AssetBrowser::buildTerrainMaterialAssetPreview(%this, %assetDef, %previewData, %forcePreviewRegenerate)
{ {
%previewData.previewImage = "ToolsModule:genericAssetIcon_image"; %previewData.previewImage = "ToolsModule:genericAssetIcon_image";
%previewData.previewLoaded = false; //this marks it for loading progressively later %previewData.previewLoaded = false; //this marks it for loading progressively later
%previewData.assetName = %assetDef.assetName; %previewData.assetName = %this.assetName;
%previewData.assetPath = ""; %previewData.assetPath = "";
%previewData.doubleClickCommand = ""; %previewData.doubleClickCommand = "";
%previewData.assetFriendlyName = %assetDef.gameObjectName; %previewData.assetFriendlyName = %this.gameObjectName;
%previewData.assetDesc = %assetDef.description; %previewData.assetDesc = %this.description;
%previewData.tooltip = %assetDef.gameObjectName; %previewData.tooltip = %this.gameObjectName;
%definitionPath = %assetDef.getScriptPath(); %definitionPath = %this.getScriptPath();
if(%definitionPath $= "") if(%definitionPath $= "")
%definitionPath = %assetDef.getFilename(); %definitionPath = %this.getFilename();
%previewData.tooltip = "Asset Name: " @ %assetDef.assetName @ %previewData.tooltip = "Asset Name: " @ %this.assetName @
"\nAsset Type: Terrain Material Asset" @ "\nAsset Type: Terrain Material Asset" @
"\nAsset Definition ID: " @ %assetDef @ "\nAsset Definition ID: " @ %this @
"\nDefinition Path: " @ %definitionPath; "\nDefinition Path: " @ %definitionPath;
} }
function AssetBrowser::generateTerrainMaterialAssetPreviewImage(%this, %previewButton, %forceRegenerate) function TerrainAssetMaterial::generatePreviewImage(%this, %previewButton, %forceRegenerate)
{ {
if(%forceRegenerate $= "") if(%forceRegenerate $= "")
%forceRegenerate = false; %forceRegenerate = false;
%assetId = %previewButton.moduleName @ ":" @ %previewButton.assetName; %module = $CurrentAssetBrowser.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%this.getAssetId()))));
%assetDef = AssetDatabase.acquireAsset(%assetId);
%module = %this.dirHandler.getModuleFromAddress(makeRelativePath(filePath(AssetDatabase.getAssetFilePath(%assetDef.getAssetId()))));
%previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/"; %previewPath = "tools/resources/previewCache/" @ %module.moduleId @ "/";
if(!IsDirectory(%previewPath)) if(!IsDirectory(%previewPath))
{ {
%this.dirHandler.createFolder(%previewPath); $CurrentAssetBrowser.dirHandler.createFolder(%previewPath);
} }
%generatePreview = false; %generatePreview = false;
%previewFilePath = %previewPath @ %assetDef.assetName @ "_Preview.dds"; %previewFilePath = %previewPath @ %this.assetName @ "_Preview.dds";
if(!isFile(%previewFilePath)) if(!isFile(%previewFilePath))
{ {
%generatePreview = true; %generatePreview = true;
} }
else else
{ {
if(isObject(%assetDef.materialDefinitionName)) if(isObject(%this.materialDefinitionName))
{ {
if(compareFileTimes(%assetDef.materialDefinitionName.getDiffuseMap(), %previewFilePath) == 1 || if(compareFileTimes(%this.materialDefinitionName.getDiffuseMap(), %previewFilePath) == 1 ||
compareFileTimes(%assetDef.materialDefinitionName.getFilename(), %previewFilePath) == 1) compareFileTimes(%this.materialDefinitionName.getFilename(), %previewFilePath) == 1)
%generatePreview = true; %generatePreview = true;
} }
} }
%previewAssetName = %module.moduleId @ "_" @ %assetDef.assetName @ "_PreviewImage"; %previewAssetName = %module.moduleId @ "_" @ %this.assetName @ "_PreviewImage";
if(%generatePreview || %forceRegenerate) if(%generatePreview || %forceRegenerate)
{ {
if(isObject(%assetDef.materialDefinitionName)) if(isObject(%this.materialDefinitionName))
{ {
%previewShapeDef = AssetDatabase.acquireAsset("ToolsModule:previewSphereShape"); %previewShapeDef = AssetDatabase.acquireAsset("ToolsModule:previewSphereShape");
%generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, DummyTerrMatPreview); %generatedFilePath = %previewShapeDef.generateCachedPreviewImage(256, DummyTerrMatPreview);
@ -178,7 +138,6 @@ function AssetBrowser::generateTerrainMaterialAssetPreviewImage(%this, %previewB
pathCopy(%generatedFilePath, %previewFilePath); pathCopy(%generatedFilePath, %previewFilePath);
fileDelete(%generatedFilePath); fileDelete(%generatedFilePath);
if(!AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName)) if(!AssetDatabase.isDeclaredAsset("ToolsModule:" @ %previewAssetName))
{ {
%previewAsset = new ImageAsset() %previewAsset = new ImageAsset()
@ -216,15 +175,4 @@ function AssetBrowser::generateTerrainMaterialAssetPreviewImage(%this, %previewB
} }
return false; return false;
}
function GuiInspectorTypeTerrainMaterialAssetPtr::onClick( %this, %fieldName )
{
//Get our data
%obj = %this.getInspector().getInspectObject(0);
}
function GuiInspectorTypeTerrainMaterialAssetPtr::onControlDropped( %this, %payload, %position )
{
} }

View file

@ -179,6 +179,39 @@ function directoryHandler::getModuleFromAddress(%this, %address)
return ""; return "";
} }
function getModuleFromAddress(%address)
{
%moduleList = ModuleDatabase.findModules();
for(%i=0; %i < getWordCount(%moduleList); %i++)
{
%module = getWord(%moduleList, %i);
%modulePath = makeRelativePath(%module.ModulePath);
//We don't want to add stuff directly to the root core or tools modules
//if(%modulePath $= "Core" || %modulePath $= "Tools")
// continue;
if(startsWith(%address, %modulePath))
{
return %module;
}
}
/*//break down the address
%folderCount = getTokenCount(%address, "/");
for(%f=0; %f < %folderCount; %f++)
{
%folderName = getToken(%address, "/", %f);
%module = ModuleDatabase.findModule(%folderName);
if(%module !$= "")
return %module;
}*/
return "";
}
function directoryHandler::getFolderTreeItemFromAddress(%this, %address) function directoryHandler::getFolderTreeItemFromAddress(%this, %address)
{ {
//break down the address //break down the address

View file

@ -1,67 +1,30 @@
function AssetBrowser_editAsset::saveAsset(%this) function AssetBrowser_editAsset::saveAsset(%this)
{ {
%file = AssetDatabase.getAssetFilePath(%this.editedAssetId); AssetBrowser_editAssetWindow.text = "Asset Properties";
%success = TamlWrite(AssetBrowser_editAsset.editedAsset, %file);
AssetBrowser.reloadAsset(%this.editedAssetId); AssetBrowser.callAssetTypeFunc(%this.editedObjectType, "onSaveProperties", %this.editedObjectData);
AssetBrowser.callAssetTypeFunc(%this.editedObjectType, "onChanged", %this.editedObjectData);
AssetBrowser.refresh();
%assetType = AssetDatabase.getAssetType(%this.editedAssetId);
%assetDef = AssetDatabase.acquireAsset(%this.editedAssetId);
%assetDef.refreshAsset();
AssetBrowser.call("on" @ %assetType @ "Changed", %assetDef);
AssetDatabase.releaseAsset(%this.editedAssetId);
Canvas.popDialog(AssetBrowser_editAsset); Canvas.popDialog(AssetBrowser_editAsset);
} }
function AssetBrowser::editAsset(%this, %assetDef) function AssetBrowser::editAsset(%this, %assetDef)
{ {
//Find out what type it is if(%this.selectMode)
//If the passed-in definition param is blank, then we're likely called via a popup
if(%assetDef $= "")
{ {
if(AssetDatabase.isDeclaredAsset(EditAssetPopup.assetId)) %this.selectAsset(%this.selectedAsset);
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
}
else
{
//if it's not a valid asset at all, then it's probably a folder
%folder = strreplace(EditAssetPopup.assetId, ":", "/");
if(isDirectory(%folder))
{
AssetBrowser.navigateTo(%folder);
}
else
{
%object = getToken(EditAssetPopup.assetId, ":", 1);
if(isObject(%object))
{
if(%object.isMemberOfClass("SimDatablock"))
{
DatablockEditorPlugin.openDatablock( %object );
}
}
}
}
} }
else if(AssetDatabase.isDeclaredAsset(%assetDef)) else
{ {
//Turns out we were passed an assetid, not an asset definition. if(isObject(%assetDef))
//Grab the asset def from that {
%assetDef = AssetDatabase.acquireAsset(%assetDef); %assetType = AssetDatabase.getAssetType(%assetDef.getAssetId());
} %this.callAssetTypeFunc(%assetType, "onEdit", %assetDef);
}
if(%assetDef !$= "") else if(%this.popupMenu.objectType !$= "" && %this.popupMenu.objectData !$= "")
{ {
%assetType = %assetDef.getClassName(); %this.callAssetTypeFunc(%this.popupMenu.objectType, "onEdit", %this.popupMenu.objectData);
}
//Build out the edit command
%buildCommand = %this @ ".edit" @ %assetType @ "(" @ %assetDef @ ");";
eval(%buildCommand);
} }
} }
@ -75,27 +38,9 @@ function AssetBrowser::appendSubLevel(%this)
function AssetBrowser::editAssetInfo(%this) function AssetBrowser::editAssetInfo(%this)
{ {
Canvas.pushDialog(AssetBrowser_editAsset); if(%this.popupMenu.objectType !$= "" && %this.popupMenu.objectData !$= "")
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
AssetBrowser.tempAsset = %assetDef.deepClone();
AssetEditInspector.inspect(AssetBrowser.tempAsset);
AssetBrowser_editAsset.editedAssetId = EditAssetPopup.assetId;
AssetBrowser_editAsset.editedAsset = AssetBrowser.tempAsset;
//remove some of the groups we don't need:
for(%i=0; %i < AssetEditInspector.getCount(); %i++)
{ {
%caption = AssetEditInspector.getObject(%i).caption; %this.callAssetTypeFunc(%this.popupMenu.objectType, "onEditProperties", %this.popupMenu.objectData);
if(%caption $= "Ungrouped" || %caption $= "Object" || %caption $= "Editing"
|| %caption $= "Persistence" || %caption $= "Dynamic Fields")
{
AssetEditInspector.remove(AssetEditInspector.getObject(%i));
%i--;
}
} }
} }
@ -127,17 +72,17 @@ function AssetBrowser::refreshAsset(%this, %assetId)
//------------------------------------------------------------ //------------------------------------------------------------
function AssetBrowser::regeneratePreviewImage(%this) function AssetBrowser::regeneratePreviewImage(%this)
{ {
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); %assetDef = AssetDatabase.acquireAsset(AssetBrowser.popupMenu.objectData);
%dummyObj = new ScriptObject(); %dummyObj = new ScriptObject();
%dummyObj.moduleName = AssetDatabase.getAssetModule(EditAssetPopup.assetId).moduleId; %dummyObj.moduleName = AssetDatabase.getAssetModule(AssetBrowser.popupMenu.objectData).moduleId;
%dummyObj.assetName = AssetDatabase.getAssetName(EditAssetPopup.assetId); %dummyObj.assetName = AssetDatabase.getAssetName(AssetBrowser.popupMenu.objectData);
%regenCommand = "AssetBrowser.generate" @ EditAssetPopup.assetType @ %assetType = AssetBrowser.popupMenu.objectType;
"PreviewImage(" @ %dummyObj @ ", true);";
eval(%regenCommand); AssetBrowser.callAssetTypeFunc(%assetType, "generatePreviewImage", %dummyObj, true);
%dummyObj.delete(); %dummyObj.delete();
AssetDatabase.releaseAsset(EditAssetPopup.assetId); AssetDatabase.releaseAsset(AssetBrowser.popupMenu.objectData);
} }
//------------------------------------------------------------ //------------------------------------------------------------
@ -344,8 +289,8 @@ function moveAssetLooseFile(%file, %destinationPath)
function AssetBrowser::duplicateAsset(%this) function AssetBrowser::duplicateAsset(%this)
{ {
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); %assetDef = AssetDatabase.acquireAsset(%this.popupMenu.objectData);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); %assetType = %this.popupMenu.objectType;
%trailingNum = getTrailingNumber(%assetDef.assetName); %trailingNum = getTrailingNumber(%assetDef.assetName);
if(%trailingNum != -1) if(%trailingNum != -1)
@ -370,18 +315,16 @@ function AssetBrowser::duplicateAsset(%this)
function AssetBrowser::doDuplicateAsset(%this) function AssetBrowser::doDuplicateAsset(%this)
{ {
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId); %assetType = %this.popupMenu.objectType;
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetId); %assetDef = AssetDatabase.acquireAsset(%this.popupMenu.objectData);
if(AssetBrowser_assetNameEditTxt.text !$= "" && AssetBrowser_assetNameEditTxt.text !$= %assetDef.assetName) if(AssetBrowser_assetNameEditTxt.text !$= "" && AssetBrowser_assetNameEditTxt.text !$= %assetDef.assetName)
{ {
//this acts as a redirect based on asset type and will enact the appropriate function AssetDatabase.releaseAsset(%this.popupMenu.objectData);
//so for a GameObjectAsset, it'll become %this.duplicateGameObjectAsset(%assetDef, %targetModule);
//and call to the tools/assetBrowser/scripts/assetTypes/gameObject.tscript file for implementation %this.callAssetTypeFunc(%assetType, "onDuplicate", %this.popupMenu.objectData, AssetBrowser_assetNameEditTxt.text);
if(%this.isMethod("duplicate"@%assetType))
eval(%this @ ".duplicate"@%assetType@"("@%assetDef@","@AssetBrowser_assetNameEditTxt.text@");"); %this.refresh();
AssetBrowser.refresh();
} }
} }
@ -440,31 +383,8 @@ function AssetBrowser::confirmDeleteAsset(%this)
%currentSelectedItem = AssetBrowserFilterTree.getSelectedItem(); %currentSelectedItem = AssetBrowserFilterTree.getSelectedItem();
%currentItemParent = AssetBrowserFilterTree.getParentItem(%currentSelectedItem); %currentItemParent = AssetBrowserFilterTree.getParentItem(%currentSelectedItem);
if(EditFolderPopup.visible) %this.callAssetTypeFunc(%this.popupMenu.objectType, "onDelete", %this.popupMenu.objectData);
{
if(EditFolderPopup.dirPath !$= "")
%folderPath = EditFolderPopup.dirPath;
else
%folderPath = AssetBrowserFilterTree.getItemValue(%currentSelectedItem) @ "/" @ AssetBrowserFilterTree.getItemText(%currentSelectedItem);
if(%this.isMethod("deleteFolder"))
eval(%this @ ".deleteFolder(\""@%folderPath@"\");");
}
else
{
%assetDef = AssetDatabase.acquireAsset(EditAssetPopup.assetId);
%assetType = AssetDatabase.getAssetType(EditAssetPopup.assetType);
if(!isObject(%assetDef))
return;
//Do any cleanup required given the type
if(%this.isMethod("delete"@%assetType))
eval(%this @ ".delete"@%assetType@"("@%assetDef@");");
AssetDatabase.deleteAsset(EditAssetPopup.assetId, true, false);
}
%this.refresh(); %this.refresh();
} }
@ -522,21 +442,27 @@ function AssetBrowser::updateAssetReference(%this, %targetPath, %oldAssetId, %ne
function AssetBrowser::openFileLocation(%this) function AssetBrowser::openFileLocation(%this)
{ {
%filePath = ""; if(isFunction("systemCommand"))
if(EditAssetPopup.assetId !$= "")
{ {
if(AssetDatabase.isDeclaredAsset(EditAssetPopup.assetId)) warnf("AssetBrowser::openFileLocation() - systemCommand function disabled in this build. Unable to launch application to edit file.");
return;
}
%filePath = "";
if(%this.popuMenu.assetId !$= "")
{
if(AssetDatabase.isDeclaredAsset(%this.popuMenu.objectData))
{ {
%filePath = AssetDatabase.getAssetPath(EditAssetPopup.assetId); %filePath = AssetDatabase.getAssetPath(%this.popuMenu.objectData);
} }
else else
{ {
//probably a file path //probably a file path
%pathSplit = strpos(EditAssetPopup.assetId, ":"); %pathSplit = strpos(%this.popuMenu.objectData, ":");
if(%pathSplit != -1) if(%pathSplit != -1)
{ {
%path = getSubStr(EditAssetPopup.assetId, 0, %pathSplit); %path = getSubStr(%this.popuMenu.objectData, 0, %pathSplit);
%file = getSubStr(EditAssetPopup.assetId, %pathSplit + 1); %file = getSubStr(%this.popuMenu.objectData, %pathSplit + 1);
//datablocks pack the originator file in the parent path as-is, so check that //datablocks pack the originator file in the parent path as-is, so check that
if(fileExt(%path) !$= "") if(fileExt(%path) !$= "")
@ -550,14 +476,6 @@ function AssetBrowser::openFileLocation(%this)
} }
} }
} }
else if(EditLevelAssetPopup.assetId !$= "")
{
%filePath = AssetDatabase.getAssetPath(EditAssetPopup.assetId);
}
else if(EditTerrainAssetPopup.assetId !$= "")
{
%filePath = AssetDatabase.getAssetPath(EditAssetPopup.assetId);
}
if(isFile(%filePath) || isDirectory(%filePath)) if(isFile(%filePath) || isDirectory(%filePath))
{ {
@ -578,20 +496,27 @@ function AssetBrowser::openFileLocation(%this)
} }
} }
function AssetBrowser::openFolderLocation(%this) function AssetBrowser::openFolderLocation(%this, %folderPath)
{ {
%filePath = AssetBrowser.dirHandler.currentAddress; if(!isFunction("systemCommand"))
{
warn("AssetBrowser::openFolderLocation() - systemCommand function disabled in this build. Unable to launch application to open this folder.");
return;
}
if(%filePath !$= "") if(%folderPath $= "")
%folderPath = filePath(%this.dirHandler.currentAddress);
if(%folderPath !$= "")
{ {
if($platform $= "windows") if($platform $= "windows")
{ {
%cmd = "cd \"" @ makeFullPath(%filePath) @ "\" && start ."; %cmd = "cd \"" @ makeFullPath(%folderPath) @ "\" && start .";
systemCommand(%cmd); systemCommand(%cmd);
} }
else else
{ {
%cmd = "open \"" @ makeFullPath(%filePath) @ "\""; %cmd = "open \"" @ makeFullPath(%folderPath) @ "\"";
systemCommand(%cmd); systemCommand(%cmd);
} }
} }

View file

@ -119,11 +119,7 @@ function AssetBrowser::setupCreateNewAsset(%this, %assetType, %moduleName, %call
NewAssetPropertiesInspector.addCallbackField("description", "Description", "Command", "Description of the new asset", "", "", "updateNewAssetField", %this.newAssetSettings); NewAssetPropertiesInspector.addCallbackField("description", "Description", "Command", "Description of the new asset", "", "", "updateNewAssetField", %this.newAssetSettings);
NewAssetPropertiesInspector.endGroup(); NewAssetPropertiesInspector.endGroup();
if(%this.isMethod("setupCreateNew"@%assetType)) %this.callAssetTypeFunc(%assetType, "setupCreateNew");
{
%command = %this @ ".setupCreateNew"@%assetType @"();";
eval(%command);
}
NewAssetPropertiesInspector.refresh(); NewAssetPropertiesInspector.refresh();
} }
@ -255,7 +251,7 @@ function CreateNewAsset()
return; return;
} }
%assetFilePath = eval(AssetBrowser @ ".create"@%assetType@"();"); %assetFilePath = AssetBrowser.callAssetTypeFunc(%assetType, "onCreateNew");
Canvas.popDialog(AssetBrowser_newAsset); Canvas.popDialog(AssetBrowser_newAsset);

View file

@ -183,8 +183,6 @@ function AssetBrowser::buildPopupMenus(%this)
item[12] = "View Loose Files" TAB "" TAB "AssetBrowser.importLooseFiles();"; item[12] = "View Loose Files" TAB "" TAB "AssetBrowser.importLooseFiles();";
Item[ 13 ] = "-"; Item[ 13 ] = "-";
item[ 14 ] = "Open Folder Location" TAB "" TAB "AssetBrowser.openFolderLocation();"; item[ 14 ] = "Open Folder Location" TAB "" TAB "AssetBrowser.openFolderLocation();";
}; };
} }
@ -266,13 +264,18 @@ function AssetBrowser::buildPopupMenus(%this)
radioSelection = false; radioSelection = false;
}; };
AssetTypeListPopup.addItem(0, AssetFilterTypeList.getKey(0) TAB "" TAB "AssetBrowser.toggleAssetTypeFilter(" @ 0 @ ");"); AssetTypeListPopup.addItem(0, "All" TAB "" TAB %this @ ".toggleAssetTypeFilter(0);");
AssetTypeListPopup.addItem(1, "-"); AssetTypeListPopup.addItem(1, "-");
for(%i=1; %i < AssetFilterTypeList.Count(); %i++) %listIndex = 1;
for(%i=0; %i < ABAssetTypesList.Count(); %i++)
{ {
%assetTypeName = AssetFilterTypeList.getKey(%i); %assetTypeData = ABAssetTypesList.getValue(%i);
AssetTypeListPopup.addItem(%i+1, %assetTypeName TAB "" TAB "AssetBrowser.toggleAssetTypeFilter(" @ %i + 1 @ ");"); if(getField(%assetTypeData, 3) != true)
continue;
AssetTypeListPopup.addItem(%listIndex, getField(%assetTypeData,1) TAB "" TAB %this @ ".toggleAssetTypeFilter(" @ %listIndex @ ");");
%listIndex++;
} }
} }
@ -315,44 +318,6 @@ function AssetBrowser::buildPopupMenus(%this)
}; };
} }
if( !isObject( EditGameObjectAssetPopup ) )
{
new PopupMenu( EditGameObjectAssetPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
//isPopup = true;
item[ 0 ] = "Open GameObject Editor" TAB "" TAB "echo(\"Not yet implemented.\");";
item[ 1 ] = "Edit GameObject Script" TAB "" TAB "AssetBrowser.editGameObjectAssetScript(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));";
item[ 2 ] = "-";
item[ 3 ] = "Apply Instance to GameObject" TAB "" TAB "AssetBrowser.applyInstanceToGameObject(AssetDatabase.acquireAsset(EditGameObjectAssetPopup.assetId));";
item[ 4 ] = "Reset Instance to GameObject" TAB "" TAB "echo(\"Not yet implemented.\");";
item[ 5 ] = "-";
item[ 6 ] = "Create Child GameObject" TAB "" TAB "echo(\"Not yet implemented.\");";
};
}
//Asset Import Resolution menus
if( !isObject( ImportAssetResolutionsPopup ) )
{
%this.ImportAssetResolutionsPopup = new PopupMenu( ImportAssetResolutionsPopup )
{
superClass = "MenuBuilder";
class = "EditorWorldMenu";
item[0] = "Use original Asset for duplicates" TAB "" TAB "";
item[1] = "Override duplicate with new Asset" TAB "" TAB "";
item[2] = "-";
item[3] = "Rename Asset" TAB "" TAB "";
item[4] = "-";
item[5] = "Find missing file" TAB "" TAB "ImportAssetWindow.findMissingFile(ImportAssetResolutionsPopup.assetItem);";
item[6] = "-";
item[7] = "Edit Asset properties" TAB "" TAB "";
};
}
// //
// Import Asset Actions // Import Asset Actions
// //

View file

@ -87,11 +87,11 @@ function GuiInspectorVariableGroup::buildListField(%this, %fieldName, %fieldLabe
eval(%setCommand); eval(%setCommand);
} }
%listCount = getTokenCount(%fieldDataVals, ","); %listCount = getTokenCount(%fieldDataVals, ",;");
for(%i=0; %i < %listCount; %i++) for(%i=0; %i < %listCount; %i++)
{ {
%entryText = getToken(%fieldDataVals, ",", %i); %entryText = getToken(%fieldDataVals, ",;", %i);
%editControl.add(%entryText); %editControl.add(%entryText);
} }