Asset.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. friend class AssetImporter;
  20. OBJECT(Asset);
  21. public:
  22. /// Construct.
  23. Asset(Context* context);
  24. virtual ~Asset();
  25. bool Import();
  26. bool Preload();
  27. // the .fbx, .png, etc path, attempts to load .asset, creates missing .asset
  28. bool SetPath(const String& path);
  29. const String& GetGUID() const { return guid_; }
  30. const String& GetName() const { return name_; }
  31. const String& GetPath() const { return path_; }
  32. String GetExtension() const;
  33. /// Get the path relative to project
  34. String GetRelativePath();
  35. String GetCachePath() const;
  36. Resource* GetResource(const String& typeName = String::EMPTY);
  37. const StringHash GetImporterType() { return importer_.Null() ? String::EMPTY : importer_->GetType(); }
  38. const String& GetImporterTypeName() { return importer_.Null() ? String::EMPTY : importer_->GetTypeName(); }
  39. AssetImporter* GetImporter() { return importer_; }
  40. void PostImportError(const String& message);
  41. Asset* GetParent();
  42. void SetDirty(bool dirty) { dirty_ = dirty; }
  43. bool IsDirty() const { return dirty_; }
  44. /// Get the last timestamp as seen by the AssetDatabase
  45. unsigned GetFileTimestamp() { return fileTimestamp_; }
  46. /// Sets the time stamp to the asset files current time
  47. void UpdateFileTimestamp();
  48. // get the .asset filename
  49. String GetDotAssetFilename();
  50. /// Rename the asset, which depending on the asset type may be nontrivial
  51. bool Rename(const String& newName);
  52. /// Move the asset, which depending on the asset type may be nontrivial
  53. bool Move(const String& newPath);
  54. bool IsFolder() const { return isFolder_; }
  55. // load .asset
  56. bool Load();
  57. // save .asset
  58. bool Save();
  59. /// Instantiate a node from the asset
  60. Node* InstantiateNode(Node* parent, const String& name);
  61. private:
  62. bool CreateImporter();
  63. bool CheckCacheFile();
  64. String guid_;
  65. // can change
  66. String path_;
  67. String name_;
  68. bool dirty_;
  69. bool isFolder_;
  70. // the current timestamp of the asset as seen by the asset database
  71. // used to catch when the asset needs to be marked dirty when notified
  72. // that the file has changed (the resource system will send a changed file
  73. // event when the resource is first added)
  74. unsigned fileTimestamp_;
  75. SharedPtr<JSONFile> json_;
  76. SharedPtr<AssetImporter> importer_;
  77. };
  78. }