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);
|
}
|
|
}
|
}
|