Resource.pkg 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. if (!file.Open(fileName, FILE_READ))
  23. return false;
  24. return resource->Save(file);
  25. }
  26. static bool ResourceSave(const Resource* resource, const String& fileName)
  27. {
  28. if (!resource)
  29. return false;
  30. File file(resource->GetContext());
  31. if (!file.Open(fileName, FILE_WRITE))
  32. return false;
  33. return resource->Save(file);
  34. }
  35. $}