Resource.pkg 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. $#include "File.h"
  2. $#include "Resource.h"
  3. class Resource
  4. {
  5. bool Load(Deserializer& source);
  6. bool Save(Serializer& dest) const;
  7. tolua_outside bool ResourceLoad @ Load(const String fileName);
  8. tolua_outside bool ResourceSave @ Save(const String fileName) const;
  9. const String GetName() const;
  10. StringHash GetNameHash() const;
  11. unsigned GetMemoryUse() const;
  12. tolua_readonly tolua_property__get_set String name;
  13. tolua_readonly tolua_property__get_set StringHash nameHash;
  14. tolua_readonly tolua_property__get_set unsigned memoryUse;
  15. };
  16. ${
  17. static bool ResourceLoad(Resource* resource, const String& fileName)
  18. {
  19. if (!resource)
  20. return false;
  21. File file(resource->GetContext());
  22. return file.Open(fileName, FILE_READ) && resource->Load(file);
  23. }
  24. static bool ResourceSave(const Resource* resource, const String& fileName)
  25. {
  26. if (!resource)
  27. return false;
  28. File file(resource->GetContext());
  29. return file.Open(fileName, FILE_WRITE) && resource->Save(file);
  30. }
  31. $}