JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Shared.SimpleControl;
 
namespace Shared
{
    /// <summary>
    /// 场景
    /// </summary>
[System.Serializable]
    public class Scene : Common
    {
        public readonly static string GlobalSceneFilePath = "GlobalScene";
        static Scene ()
        {
            Refresh (); 
        }
 
        public static void Refresh()
        {
            if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (Encoding.UTF8.GetString (IO.FileUtils.ReadFile (GlobalSceneFilePath)))) {
                //初始化房间列表
                IO.FileUtils.WriteFileByBytes (GlobalSceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (new List<string> ())));
            }
        }
 
        public Scene ()
        {
            this.Type = DeviceType.Scene;
            DeviceTextID = SimpleControl.R.MyInternationalizationString.Scenes;
        }
 
        /// <summary>
        /// 场景图标
        /// </summary>
        public string SceneIconPath = "";
 
        /// <summary>
        /// 场景的背景图
        /// </summary>
        public string BackgroundImagePath = "Scene/s1.png";
 
        /// <summary>
        /// 根据场景路径恢复场景对象
        /// </summary>
        /// <returns>The by file path.</returns>
        /// <param name="sceneFilePath">Room file path.</param>
        public static Scene GetSceneByFilePath (string sceneFilePath)
        {
            try {
                return Newtonsoft.Json.JsonConvert.DeserializeObject<Scene> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (sceneFilePath)));
            } catch {
                return new Scene ();
            }
        }
 
        /// <summary>
        /// 控制目标的文件路径,格式如:RoomScene100000000_+LightSwitch_Equipment_
        /// </summary>
        public readonly List<string> DeviceFilePathList = new List<string> ();
 
        /// <summary>
        /// 全局场景里所有的视图类型
        /// </summary>
        public List<Common> GlobalSceneDeviceList = new List<Common> { };
 
        /// <summary>
        /// 保存当前场景
        /// </summary>
        /// <param name="sceneFilePath">Scence file path.</param>
        public void Save (string sceneFilePath)
        {
            IO.FileUtils.WriteFileByBytes (sceneFilePath, System.Text.Encoding.UTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (this)));
        }
 
        /// <summary>
        /// bus上传的场景标识
        /// </summary>
        public bool busScene = false;
 
 
        public void initBusScene ()
        {
            //var sceneFileList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>> (System.Text.Encoding.UTF8.GetString (IO.FileUtils.ReadFile (Scene.GlobalSceneFilePath)));
            //sceneFileList.Add ("GlobalScene_busScene");
            //var ss = new Scene ();
            //ss.Name = "busScene";
            //ss.BackgroundImagePath = "Scene/s0.png";
            //ss.GlobalSceneDeviceList.Add (new Common () { SubnetID = 1, DeviceID = 1, obj1 = 1, obj2 = 1, obj3 = 1, obj4 = 1, obj5 = 1, });
            //ss.GlobalSceneDeviceList.Add (new Common () { SubnetID = 2, DeviceID = 2, obj1 = 2, obj2 = 2, obj3 = 2, obj4 = 2, obj5 = 2, });
            //IO.FileUtils.WriteFileByBytes ("GlobalScene_busScene", CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (ss)));
            //IO.FileUtils.WriteFileByBytes (Scene.GlobalSceneFilePath, CommonPage.MyEncodingUTF8.GetBytes (Newtonsoft.Json.JsonConvert.SerializeObject (sceneFileList)));
            //var ssfsdf = IO.FileUtils.ReadFile ("GlobalScene_busScene");
            //var cp = CommonPage.MyEncodingUTF8.GetString (ssfsdf);
        }
    
    }
}