Browse Source

Update Lua API, Add Load and Save function in Resource.

aster2013 12 years ago
parent
commit
eda1b8c16f

+ 42 - 0
Source/Engine/LuaScript/pkgs/Audio/Sound.pkg

@@ -1,12 +1,18 @@
+$#include "File.h"
 $#include "Sound.h"
 
 class Sound : public Resource
 {
     Sound();
     ~Sound();
+    
     bool LoadRaw(Deserializer& source);
     bool LoadWav(Deserializer& source);
     bool LoadOggVorbis(Deserializer& source);
+    tolua_outside bool SoundLoadRaw @ LoadRaw(const String fileName);
+    tolua_outside bool SoundLoadWav @ LoadWav(const String fileName);
+    tolua_outside bool SoundLoadOggVorbis @ LoadOggVorbis(const String fileName);
+
     void SetSize(unsigned dataSize);
     void SetData(const void* data, unsigned dataSize);
     void SetFormat(unsigned frequency, bool sixteenBit, bool stereo);
@@ -46,4 +52,40 @@ static int tolua_AudioLuaAPI_Sound_new00_local(lua_State* tolua_S)
 {
     return ToluaNewObjectGC<Sound>(tolua_S);
 }
+
+static bool SoundLoadRaw(Sound* sound, const String& fileName)
+{
+    if (!sound)
+        return false;
+
+    File file(sound->GetContext());
+    if (!file.Open(fileName, FILE_READ))
+        return false;
+
+    return sound->LoadRaw(file);
+}
+
+static bool SoundLoadWav(Sound* sound, const String& fileName)
+{
+    if (!sound)
+        return false;
+
+    File file(sound->GetContext());
+    if (!file.Open(fileName, FILE_READ))
+        return false;
+
+    return sound->LoadWav(file);
+}
+
+static bool SoundLoadOggVorbis(Sound* sound, const String& fileName)
+{
+    if (!sound)
+        return false;
+
+    File file(sound->GetContext());
+    if (!file.Open(fileName, FILE_READ))
+        return false;
+
+    return sound->LoadOggVorbis(file);
+}
 $}

+ 16 - 0
Source/Engine/LuaScript/pkgs/Resource/Image.pkg

@@ -17,6 +17,10 @@ class Image : public Resource
 {
     Image();
     ~Image();
+    
+    bool LoadColorLUT(Deserializer& source);
+    tolua_outside bool ImageLoadColorLUT @ LoadColorLUT(const String& fileName);
+
     void FlipVertical();
     bool SaveBMP(const String fileName);
     bool SavePNG(const String fileName);
@@ -53,4 +57,16 @@ static int tolua_ResourceLuaAPI_Image_new00_local(lua_State* tolua_S)
 {
     return ToluaNewObjectGC<Image>(tolua_S);
 }
+
+static bool ImageLoadColorLUT(Image* image, const String& fileName)
+{
+    if (!image)
+        return false;
+
+    File file(image->GetContext());
+    if (!file.Open(fileName, FILE_READ))
+        return false;
+
+    return image->LoadColorLUT(file);
+}
 $}

+ 32 - 0
Source/Engine/LuaScript/pkgs/Resource/Resource.pkg

@@ -1,7 +1,13 @@
+$#include "File.h"
 $#include "Resource.h"
 
 class Resource
 {
+    bool Load(Deserializer& source);
+    bool Save(Serializer& dest) const;
+    tolua_outside bool ResourceLoad @ Load(const String fileName);
+    tolua_outside bool ResourceSave @ Save(const String fileName) const;
+    
     const String GetName() const;
     StringHash GetNameHash() const;
     unsigned GetMemoryUse() const;
@@ -10,3 +16,29 @@ class Resource
     tolua_readonly tolua_property__get_set StringHash nameHash;
     tolua_readonly tolua_property__get_set unsigned memoryUse;
 };
+
+${
+static bool ResourceLoad(Resource* resource, const String& fileName)
+{
+    if (!resource)
+        return false;
+
+    File file(resource->GetContext());
+    if (!file.Open(fileName, FILE_READ))
+        return false;
+
+    return resource->Save(file);
+}
+
+static bool ResourceSave(const Resource* resource, const String& fileName)
+{
+    if (!resource)
+        return false;
+
+    File file(resource->GetContext());
+    if (!file.Open(fileName, FILE_WRITE))
+        return false;
+
+    return resource->Save(file);
+}
+$}

+ 19 - 0
Source/Engine/LuaScript/pkgs/Resource/XMLFile.pkg

@@ -2,7 +2,26 @@ $#include "XMLFile.h"
 
 class XMLFile : public Resource
 {
+    XMLFile();
+    ~XMLFile();
+
+    XMLElement CreateRoot(const String name = String::EMPTY);
     XMLElement GetRoot(const String name = String::EMPTY);
+            
     void Patch(XMLFile* patchFile);
     void Patch(XMLElement patchElement);
 };
+
+${
+#define TOLUA_DISABLE_tolua_ResourceLuaAPI_XMLFile_new00
+static int tolua_ResourceLuaAPI_XMLFile_new00(lua_State* tolua_S)
+{
+    return ToluaNewObject<XMLFile>(tolua_S);
+}
+
+#define TOLUA_DISABLE_tolua_ResourceLuaAPI_XMLFile_new00_local
+static int tolua_ResourceLuaAPI_XMLFile_new00_local(lua_State* tolua_S)
+{
+    return ToluaNewObjectGC<XMLFile>(tolua_S);
+}
+$}