mikymod пре 11 година
родитељ
комит
de01cd9e95

+ 7 - 1
tools/gui/UnitEditor/UnitEditor/MainMenu.cs

@@ -3,6 +3,10 @@ using Gtk;
 using System.Xml;
 using System.Xml;
 using System.Xml.Linq;
 using System.Xml.Linq;
 using System.Collections.Generic;
 using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+using System.IO;
+using Newtonsoft.Json;
+using System.Data;
 
 
 namespace UnitEditor
 namespace UnitEditor
 {
 {
@@ -167,7 +171,9 @@ namespace UnitEditor
 
 
 			if (fc.Run() == (int)ResponseType.Ok)
 			if (fc.Run() == (int)ResponseType.Ok)
 			{
 			{
-				Console.WriteLine(fc.Filename);
+				UnitFile u = new UnitFile (fc.Filename);
+				u.deserialize ();
+				u.serialize ();
 			}
 			}
 
 
 			//Don't forget to call Destroy() or the FileChooserDialog window won't get closed.
 			//Don't forget to call Destroy() or the FileChooserDialog window won't get closed.

+ 17 - 2
tools/gui/UnitEditor/UnitEditor/Types.cs

@@ -1,6 +1,8 @@
+using System.Collections.Generic;
+
 namespace UnitEditor
 namespace UnitEditor
 {
 {
-
+	
 //------------------------------------------------------------------------------
 //------------------------------------------------------------------------------
 public class Renderable
 public class Renderable
 {
 {
@@ -16,6 +18,19 @@ public class Renderable
 	public string type { set; get; }
 	public string type { set; get; }
 	public string resource { set; get; }
 	public string resource { set; get; }
 	public bool visible { set; get; }
 	public bool visible { set; get; }
+
+	public override string ToString()
+	{
+		return "node: " + node + ", type: " + type + ", resource: " + resource + ", visible: " + visible + "\n";
+	}
+}
+
+//------------------------------------------------------------------------------
+public class Node
+{
+	public string parent { set; get; }
+	public float[] position = new float[3];
+	public float[] rotation = new float[4];
 }
 }
 
 
-} // namespace UnitEditor
+} // namespace UnitEditor

+ 5 - 0
tools/gui/UnitEditor/UnitEditor/UnitEditor.csproj

@@ -57,6 +57,10 @@
     </Reference>
     </Reference>
     <Reference Include="System.Xml" />
     <Reference Include="System.Xml" />
     <Reference Include="System.Xml.Linq" />
     <Reference Include="System.Xml.Linq" />
+    <Reference Include="Newtonsoft.Json">
+      <HintPath>..\..\..\..\..\..\Scaricati\jsondotnet\Bin\Net35\Newtonsoft.Json.dll</HintPath>
+    </Reference>
+    <Reference Include="System.Data" />
   </ItemGroup>
   </ItemGroup>
   <ItemGroup>
   <ItemGroup>
     <EmbeddedResource Include="gtk-gui\gui.stetic">
     <EmbeddedResource Include="gtk-gui\gui.stetic">
@@ -74,6 +78,7 @@
     <Compile Include="Types.cs" />
     <Compile Include="Types.cs" />
     <Compile Include="MainMenu.cs" />
     <Compile Include="MainMenu.cs" />
     <Compile Include="gtk-gui\UnitEditor.MainMenu.cs" />
     <Compile Include="gtk-gui\UnitEditor.MainMenu.cs" />
+    <Compile Include="UnitFile.cs" />
   </ItemGroup>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
 </Project>
 </Project>

+ 70 - 0
tools/gui/UnitEditor/UnitEditor/UnitFile.cs

@@ -0,0 +1,70 @@
+using System;
+using Newtonsoft.Json;
+using Newtonsoft.Json.Linq;
+using System.IO;
+using System.Text;
+using System.Collections.Generic;
+using System.Linq;
+
+namespace UnitEditor
+{
+	public class UnitFile
+	{
+		private JObject root;
+		private Dictionary<string, Renderable> renderables;
+		private Dictionary<string, Node> nodes;
+
+		public UnitFile (string file_name)
+		{
+			string json_string = string.Empty;
+
+			using (StreamReader streamReader = new StreamReader(file_name))
+			{            
+				json_string = streamReader.ReadToEnd();
+				root = JObject.Parse (json_string);
+			}
+		}
+
+		public void deserialize()
+		{
+			// Deserialize renderables
+			JToken renderables_token = root ["renderables"];
+			renderables = JsonConvert.DeserializeObject<Dictionary<string, Renderable>>(renderables_token.ToString());
+
+			// Deserialize Nodes
+			JToken nodes_token = root ["nodes"];
+			nodes = JsonConvert.DeserializeObject<Dictionary<string, Node>> (nodes_token.ToString ());
+		}
+
+		public void serialize()
+		{
+			string json_string = "{";
+			json_string += "\"renderables\": {";
+			string last = renderables.Keys.Last ();
+			foreach (var r in renderables)
+			{
+				var k = r.Key;
+				var v = r.Value;
+				string renderables_token = string.Format ("\t\"{0}\" : {1}", k, JsonConvert.SerializeObject(v));
+				if (k != last)
+					json_string += ",";
+				json_string += renderables_token;
+			}
+			json_string += "},\n";
+
+			json_string += "\"nodes\": {";
+			foreach (var n in nodes)
+			{
+				var k = n.Key;
+				var v = n.Value;
+				string nodes_token = string.Format ("\t\"{0}\" : {1}", k, JsonConvert.SerializeObject(v));
+				json_string += nodes_token;
+			}
+			json_string += "}";
+			json_string += "}";
+
+			Console.Write (json_string);
+		}
+	}
+}
+