Asset.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  3. // LICENSE: Atomic Game Engine Editor and Tools EULA
  4. // Please see LICENSE_ATOMIC_EDITOR_AND_TOOLS.md in repository root for
  5. // license information: https://github.com/AtomicGameEngine/AtomicGameEngine
  6. //
  7. #pragma once
  8. #include <Atomic/Core/Object.h>
  9. #include <Atomic/Resource/Resource.h>
  10. #include <Atomic/Scene/Node.h>
  11. #include "AssetImporter.h"
  12. using namespace Atomic;
  13. namespace ToolCore
  14. {
  15. #define ASSET_VERSION 1
  16. class Asset : public Object
  17. {
  18. friend class AssetDatabase;
  19. OBJECT(Asset);
  20. public:
  21. /// Construct.
  22. Asset(Context* context);
  23. virtual ~Asset();
  24. bool Import();
  25. bool Preload();
  26. // the .fbx, .png, etc path, attempts to load .asset, creates missing .asset
  27. bool SetPath(const String& path);
  28. const String& GetGUID() const { return guid_; }
  29. const String& GetName() const { return name_; }
  30. const String& GetPath() const { return path_; }
  31. String GetExtension() const;
  32. /// Get the path relative to project
  33. String GetRelativePath();
  34. String GetCachePath() const;
  35. Resource* GetResource(const String& typeName = String::EMPTY);
  36. const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
  37. const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
  38. AssetImporter* GetImporter() { return importer_; }
  39. void PostImportError(const String& message);
  40. Asset* GetParent();
  41. void SetDirty(bool dirty) { dirty_ = dirty; }
  42. bool IsDirty() const { return dirty_; }
  43. /// Get the last timestamp as seen by the AssetDatabase
  44. unsigned GetFileTimestamp() { return fileTimestamp_; }
  45. /// Sets the time stamp to the asset files current time
  46. void UpdateFileTimestamp();
  47. // get the .asset filename
  48. String GetDotAssetFilename();
  49. bool IsFolder() const { return isFolder_; }
  50. // load .asset
  51. bool Load();
  52. // save .asset
  53. bool Save();
  54. /// Instantiate a node from the asset
  55. Node* InstantiateNode(Node* parent, const String& name);
  56. private:
  57. bool CreateImporter();
  58. bool CheckCacheFile();
  59. String guid_;
  60. // can change
  61. String path_;
  62. String name_;
  63. bool dirty_;
  64. bool isFolder_;
  65. // the current timestamp of the asset as seen by the asset database
  66. // used to catch when the asset needs to be marked dirty when notified
  67. // that the file has changed (the resource system will send a changed file
  68. // event when the resource is first added)
  69. unsigned fileTimestamp_;
  70. SharedPtr<JSONFile> json_;
  71. SharedPtr<AssetImporter> importer_;
  72. };
  73. }