Newer
Older
DungeonShooting / DungeonShooting_Godot / src / framework / map / serialize / tileSet / TileSetSourceInfo.cs
@小李xl 小李xl on 6 Jan 2024 1 KB 保存TileSet数据完成
  1.  
  2. using System.Collections.Generic;
  3. using System.Text.Json.Serialization;
  4. using Godot;
  5.  
  6. /// <summary>
  7. /// 图集资源数据
  8. /// </summary>
  9. public class TileSetSourceInfo : IClone<TileSetSourceInfo>
  10. {
  11. /// <summary>
  12. /// 资源名称
  13. /// </summary>
  14. [JsonInclude]
  15. public string Name;
  16.  
  17. /// <summary>
  18. /// 资源路径
  19. /// </summary>
  20. [JsonInclude]
  21. public string SourcePath;
  22.  
  23. /// <summary>
  24. /// 地形配置数据
  25. /// </summary>
  26. [JsonInclude]
  27. public TileSetTerrainInfo Terrain;
  28.  
  29. /// <summary>
  30. /// 组合数据
  31. /// </summary>
  32. [JsonInclude]
  33. public List<TileCombinationInfo> Combination;
  34. [JsonIgnore]
  35. private Image _sourceImage;
  36. [JsonIgnore]
  37. private bool _overWriteImage;
  38.  
  39. /// <summary>
  40. /// 初始化默认数据
  41. /// </summary>
  42. public void InitData()
  43. {
  44. Terrain = new TileSetTerrainInfo();
  45. Combination = new List<TileCombinationInfo>();
  46. }
  47.  
  48. /// <summary>
  49. /// 是否重写过Image
  50. /// </summary>
  51. public bool IsOverWriteImage()
  52. {
  53. return _overWriteImage;
  54. }
  55. /// <summary>
  56. /// 获取资源图像数据
  57. /// </summary>
  58. public Image GetSourceImage()
  59. {
  60. if (_sourceImage == null && string.IsNullOrEmpty(SourcePath))
  61. {
  62. return null;
  63. }
  64. return _sourceImage ??= Image.LoadFromFile(SourcePath);
  65. }
  66. /// <summary>
  67. /// 设置图像资源
  68. /// </summary>
  69. public void SetSourceImage(Image image)
  70. {
  71. _overWriteImage = true;
  72. _sourceImage = image;
  73. }
  74.  
  75. public TileSetSourceInfo Clone()
  76. {
  77. var tileSetSourceInfo = new TileSetSourceInfo();
  78. tileSetSourceInfo.Name = Name;
  79. tileSetSourceInfo.Terrain = Terrain;
  80. tileSetSourceInfo.Combination = Combination;
  81. tileSetSourceInfo.SourcePath = SourcePath;
  82. tileSetSourceInfo._sourceImage = _sourceImage;
  83. return tileSetSourceInfo;
  84. }
  85. }