Updated handling of subscenes in assets to be it's own distinct definition to avoid parsing and detection issues, as well as fields to be handled distinctly between the types

This commit is contained in:
JeffR 2025-03-30 16:36:15 -05:00
parent c2af4e578b
commit 5566f8a396
9 changed files with 469 additions and 47 deletions

View file

@ -3,17 +3,9 @@ AssetBrowser::registerAssetType("LevelAsset", "Levels");
function LevelAsset::setupCreateNew()
{
NewAssetPropertiesInspector.startGroup("Level");
NewAssetPropertiesInspector.addField("LevelName", "Level Name", "String", "Human-readable name of new level", "", "", $CurrentAssetBrowser.callAssetTypeFunc(%assetType, "setupCreateNew");.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", "", "", $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();
}
@ -88,11 +80,17 @@ function LevelAsset::onCreateNew(%this)
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);
}
$CurrentAssetBrowser.refresh();
if(%addSuccess && isObject($createAndAssignField))
{
$createAndAssignField.apply(%moduleName @ ":" @ %assetName);
$createAndAssignField = "";
}
return %tamlpath;
}

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 );
}