Преглед изворни кода

Updated Lua API with scene and node JSON load/save capabilities.

Nick Royer пре 10 година
родитељ
комит
79bc4feb1e

+ 7 - 0
Source/Urho3D/LuaScript/pkgs/Scene/Node.pkg

@@ -23,6 +23,7 @@ class Node : public Animatable
     virtual ~Node();
 
     tolua_outside bool NodeSaveXML @ SaveXML(File* dest, const String indentation = "\t") const;
+    tolua_outside bool NodeSaveJSON @ SaveJSON(File* dest, const String indentation = "\t") const;
     void SetName(const String name);
 
     void SetPosition(const Vector3& position);
@@ -186,6 +187,7 @@ class Node : public Animatable
 
     bool Load(Deserializer& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
     bool LoadXML(const XMLElement& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
+    bool LoadJSON(const JSONValue& source, SceneResolver& resolver, bool loadChildren = true, bool rewriteIDs = false, CreateMode mode = REPLICATED);
 
     Node* CreateChild(unsigned id, CreateMode mode);
     void AddComponent(Component* component, unsigned id, CreateMode mode);
@@ -241,6 +243,11 @@ static bool NodeSaveXML(const Node* node, File* file, const String& indentation)
     return file ? node->SaveXML(*file, indentation) : false;
 }
 
+static bool NodeSaveJSON(const Node* node, File* file, const String& indentation)
+{
+    return file ? node->SaveJSON(*file, indentation) : false;
+}
+
 #define TOLUA_DISABLE_tolua_SceneLuaAPI_Node_CreateScriptObject00
 
 static int tolua_SceneLuaAPI_Node_CreateScriptObject00(lua_State* tolua_S)

+ 28 - 0
Source/Urho3D/LuaScript/pkgs/Scene/Scene.pkg

@@ -25,6 +25,10 @@ class Scene : public Node
     tolua_outside bool SceneSaveXML @ SaveXML(File* dest, const String indentation = "\t") const;
     tolua_outside bool SceneLoadXML @ LoadXML(const String fileName);
     tolua_outside bool SceneSaveXML @ SaveXML(const String fileName, const String indentation = "\t") const;
+    tolua_outside bool SceneLoadJSON @ LoadJSON(File* source);
+    tolua_outside bool SceneSaveJSON @ SaveJSON(File* dest, const String indentation = "\t") const;
+    tolua_outside bool SceneLoadJSON @ LoadJSON(const String fileName);
+    tolua_outside bool SceneSaveJSON @ SaveJSON(const String fileName, const String indentation = "\t") const;
     tolua_outside Node* SceneInstantiate @ Instantiate(File* source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
     tolua_outside Node* SceneInstantiate @ Instantiate(const String fileName, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
     tolua_outside Node* SceneInstantiateXML @ InstantiateXML(File* source, const Vector3& position, const Quaternion& rotation, CreateMode mode = REPLICATED);
@@ -152,6 +156,30 @@ static bool SceneSaveXML(const Scene* scene, const String& fileName, const Strin
     return scene->SaveXML(file, indentation);
 }
 
+static bool SceneLoadJSON(Scene* scene, File* file)
+{
+    return file ? scene->LoadJSON(*file) : false;
+}
+
+static bool SceneSaveJSON(const Scene* scene, File* file, const String& indentation)
+{
+    return file ? scene->SaveJSON(*file, indentation) : false;
+}
+
+static bool SceneLoadJSON(Scene* scene, const String& fileName)
+{
+    File file(scene->GetContext(), fileName, FILE_READ);
+    return file.IsOpen() && scene->LoadJSON(file);
+}
+
+static bool SceneSaveJSON(const Scene* scene, const String& fileName, const String& indentation)
+{
+    File file(scene->GetContext(), fileName, FILE_WRITE);
+    if (!file.IsOpen())
+        return false;
+    return scene->SaveJSON(file, indentation);
+}
+
 static bool SceneLoadAsync(Scene* scene, const String& fileName, LoadMode mode)
 {
     SharedPtr<File> file(new File(scene->GetContext(), fileName, FILE_READ));