Skip to content

Commit

Permalink
editor asset
Browse files Browse the repository at this point in the history
  • Loading branch information
nem0 committed Jul 31, 2023
1 parent 182f750 commit f9f5718
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/editor/editor_asset.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "editor_asset.h"

namespace Lumix {

EditorAssetPlugin::EditorAssetPlugin(const char* name, const char* ext, ResourceType type, StudioApp& app, IAllocator& allocator)
: AssetBrowser::Plugin(allocator)
, m_app(app)
, m_name(name)
, m_extension(ext)
, m_resource_type(type)
{
AssetCompiler& compiler = app.getAssetCompiler();
compiler.registerExtension(ext, type);
const char* extensions[] = { ext, nullptr };
compiler.addPlugin(*this, extensions);
AssetBrowser& browser = app.getAssetBrowser();
browser.addPlugin(*this);
}

EditorAssetPlugin::~EditorAssetPlugin() {
m_app.getAssetBrowser().removePlugin(*this);
m_app.getAssetCompiler().removePlugin(*this);
}

AssetBrowser::ResourceView& EditorAssetPlugin::createView(const Path& path, StudioApp& app) {
struct View : AssetBrowser::ResourceView {
View(const Path& path, ResourceType type, IAllocator& allocator)
: m_path(path)
, m_allocator(allocator)
, m_type(type)
{}

const struct Path& getPath() override { return m_path; }
struct ResourceType getType() override { return m_type; }
bool isEmpty() override { return false; }
bool isReady() override { return true; }
bool isFailure() override { return false; }
u64 size() override { return 0; }
void destroy() override { LUMIX_DELETE(m_allocator, this); }
Resource* getResource() override { ASSERT(false); return nullptr; }

IAllocator& m_allocator;
Path m_path;
ResourceType m_type;
};

IAllocator& allocator = app.getAllocator();
View* view = LUMIX_NEW(allocator, View)(path, m_resource_type, allocator);
return *view;
}

}
31 changes: 31 additions & 0 deletions src/editor/editor_asset.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "editor/asset_browser.h"
#include "editor/asset_compiler.h"

namespace Lumix {

// use this if you want an editor-only asset to be visible in asset browser
// editor only assets do not inherit from Resource, e.g. particle system function
struct EditorAssetPlugin : AssetBrowser::Plugin, AssetCompiler::IPlugin {
EditorAssetPlugin(const char* name, const char* ext, ResourceType type, StudioApp& app, IAllocator& allocator);
~EditorAssetPlugin();

bool compile(const Path& src) override { return true; }
bool canCreateResource() const override { return true; }
const char* getDefaultExtension() const override { return m_extension; }

bool onGUI(Span<AssetBrowser::ResourceView*> resource) override { return false; }
const char* getName() const override { return m_name; }
ResourceType getResourceType() const override { return m_resource_type; }
AssetBrowser::ResourceView& createView(const Path& path, StudioApp& app) override;

void deserialize(InputMemoryStream& blob) override { ASSERT(false); }
void serialize(OutputMemoryStream& blob) override {}

protected:
StudioApp& m_app;
const char* m_extension;
const char* m_name;
ResourceType m_resource_type;
};

}

0 comments on commit f9f5718

Please sign in to comment.