diff --git a/DungeonShooting_Godot/project.godot b/DungeonShooting_Godot/project.godot
index 8fdcd2e..843e374 100644
--- a/DungeonShooting_Godot/project.godot
+++ b/DungeonShooting_Godot/project.godot
@@ -11,7 +11,7 @@
[application]
config/name="DungeonShooting"
-run/main_scene="res://scene/Main.tscn"
+run/main_scene="res://scene/test/TestLoadTileSetConfig.tscn"
config/features=PackedStringArray("4.2", "C#")
config/icon="res://icon.png"
diff --git a/DungeonShooting_Godot/resource/map/tileSet/TileSet1/TileSet.json b/DungeonShooting_Godot/resource/map/tileSet/TileSet1/TileSet.json
index 4c3280f..d71c243 100644
--- a/DungeonShooting_Godot/resource/map/tileSet/TileSet1/TileSet.json
+++ b/DungeonShooting_Godot/resource/map/tileSet/TileSet1/TileSet.json
@@ -33,49 +33,166 @@
0,
16
],
- "_010_010_000": null,
- "_000_010_000": null,
- "_000_011_010": null,
- "_010_011_010": null,
- "_010_011_000": null,
- "_000_011_000": null,
- "_000_111_010": null,
- "_010_111_010": null,
- "_010_111_000": null,
- "_000_111_000": null,
- "_000_110_010": null,
- "_010_110_010": null,
- "_010_110_000": null,
- "_000_110_000": null,
- "_110_111_010": null,
- "_010_011_011": null,
- "_011_011_010": null,
- "_010_111_110": null,
- "_000_111_011": null,
- "_011_111_111": null,
- "_111_111_011": null,
- "_011_111_000": null,
- "_000_111_110": null,
- "_110_111_111": null,
- "_111_111_110": null,
- "_110_111_000": null,
- "_011_111_010": null,
- "_010_110_110": null,
- "_110_110_010": null,
- "_010_111_011": null,
- "_000_011_011": null,
- "_011_011_011": null,
- "_011_111_011": null,
+ "_010_010_000": [
+ 0,
+ 32
+ ],
+ "_000_010_000": [
+ 0,
+ 48
+ ],
+ "_000_011_010": [
+ 16,
+ 0
+ ],
+ "_010_011_010": [
+ 16,
+ 16
+ ],
+ "_010_011_000": [
+ 16,
+ 32
+ ],
+ "_000_011_000": [
+ 16,
+ 48
+ ],
+ "_000_111_010": [
+ 32,
+ 0
+ ],
+ "_010_111_010": [
+ 32,
+ 16
+ ],
+ "_010_111_000": [
+ 32,
+ 32
+ ],
+ "_000_111_000": [
+ 32,
+ 48
+ ],
+ "_000_110_010": [
+ 48,
+ 0
+ ],
+ "_010_110_010": [
+ 48,
+ 16
+ ],
+ "_010_110_000": [
+ 48,
+ 32
+ ],
+ "_000_110_000": [
+ 48,
+ 48
+ ],
+ "_110_111_010": [
+ 64,
+ 0
+ ],
+ "_010_011_011": [
+ 64,
+ 16
+ ],
+ "_011_011_010": [
+ 64,
+ 32
+ ],
+ "_010_111_110": [
+ 64,
+ 48
+ ],
+ "_000_111_011": [
+ 80,
+ 0
+ ],
+ "_011_111_111": [
+ 80,
+ 16
+ ],
+ "_111_111_011": [
+ 80,
+ 32
+ ],
+ "_011_111_000": [
+ 80,
+ 48
+ ],
+ "_000_111_110": [
+ 96,
+ 0
+ ],
+ "_110_111_111": [
+ 96,
+ 16
+ ],
+ "_111_111_110": [
+ 96,
+ 32
+ ],
+ "_110_111_000": [
+ 96,
+ 48
+ ],
+ "_011_111_010": [
+ 112,
+ 0
+ ],
+ "_010_110_110": [
+ 112,
+ 16
+ ],
+ "_110_110_010": [
+ 112,
+ 32
+ ],
+ "_010_111_011": [
+ 112,
+ 48
+ ],
+ "_000_011_011": [
+ 128,
+ 0
+ ],
+ "_011_011_011": [
+ 128,
+ 16
+ ],
+ "_011_111_011": [
+ 128,
+ 32
+ ],
"_011_011_000": [
128,
48
],
- "_010_111_111": null,
- "_110_111_011": null,
- "_111_111_111": null,
- "_111_111_000": null,
- "_000_111_111": null,
- "_011_111_110": null,
+ "_010_111_111": [
+ 144,
+ 0
+ ],
+ "_110_111_011": [
+ 160,
+ 32
+ ],
+ "_111_111_111": [
+ 144,
+ 32
+ ],
+ "_111_111_000": [
+ 144,
+ 48
+ ],
+ "_000_111_111": [
+ 160,
+ 0
+ ],
+ "_011_111_110": [
+ 144,
+ 16
+ ],
"_111_111_010": [
160,
48
@@ -84,8 +201,14 @@
176,
0
],
- "_110_111_110": null,
- "_110_110_110": null,
+ "_110_111_110": [
+ 176,
+ 16
+ ],
+ "_110_110_110": [
+ 176,
+ 32
+ ],
"_110_110_000": [
176,
48
diff --git a/DungeonShooting_Godot/resource/tileSet/map2/TileSet2.tres b/DungeonShooting_Godot/resource/tileSet/map2/TileSet2.tres
index 95ad214..9248639 100644
--- a/DungeonShooting_Godot/resource/tileSet/map2/TileSet2.tres
+++ b/DungeonShooting_Godot/resource/tileSet/map2/TileSet2.tres
@@ -488,12 +488,10 @@
11:3/0/terrains_peering_bit/top_left_corner = 0
11:3/0/terrains_peering_bit/top_side = 0
0:4/0 = 0
-0:4/0/terrain_set = 0
0:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
0:4/0/physics_layer_0/angular_velocity = 0.0
1:4/0 = 0
1:4/0/y_sort_origin = 7
-1:4/0/terrain_set = 0
1:4/0/physics_layer_0/linear_velocity = Vector2(0, 0)
1:4/0/physics_layer_0/angular_velocity = 0.0
1:4/0/physics_layer_0/polygon_0/points = PackedVector2Array(-8, -8, 8, -8, 8, 8, -8, 8)
diff --git a/DungeonShooting_Godot/scene/test/TestLoadTileSetConfig.tscn b/DungeonShooting_Godot/scene/test/TestLoadTileSetConfig.tscn
new file mode 100644
index 0000000..e06b23c
--- /dev/null
+++ b/DungeonShooting_Godot/scene/test/TestLoadTileSetConfig.tscn
@@ -0,0 +1,10 @@
+[gd_scene load_steps=2 format=3 uid="uid://cye62nvkf8ld1"]
+
+[ext_resource type="Script" path="res://src/test/TestLoadTileSetConfig.cs" id="1_1wodj"]
+
+[node name="TestLoadTileSetConfig" type="Node2D"]
+script = ExtResource("1_1wodj")
+
+[node name="TileMap" type="TileMap" parent="."]
+scale = Vector2(4, 4)
+format = 2
diff --git a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetInfo.cs b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetInfo.cs
index 7c6c9ea..926df8f 100644
--- a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetInfo.cs
+++ b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetInfo.cs
@@ -5,8 +5,11 @@
///
/// 图块集数据
///
-public class TileSetInfo : IClone
+public class TileSetInfo : IClone, IDestroy
{
+ [JsonIgnore]
+ public bool IsDestroyed { get; private set; }
+
///
/// 图块集名称
///
@@ -41,14 +44,17 @@
}
return tileSetInfo;
}
-
- public void Dispose()
+
+ public void Destroy()
{
+ if (IsDestroyed) return;
+ IsDestroyed = true;
+
if (Sources != null)
{
foreach (var tileSetSourceInfo in Sources)
{
- tileSetSourceInfo.Dispose();
+ tileSetSourceInfo.Destroy();
}
Sources = null;
diff --git a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs
index 267d81b..a6f9f88 100644
--- a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs
+++ b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSourceInfo.cs
@@ -6,8 +6,11 @@
///
/// 图集资源数据
///
-public class TileSetSourceInfo : IClone
+public class TileSetSourceInfo : IClone, IDestroy
{
+ [JsonIgnore]
+ public bool IsDestroyed { get; private set; }
+
///
/// 资源名称
///
@@ -86,9 +89,11 @@
return tileSetSourceInfo;
}
-
- public void Dispose()
+
+ public void Destroy()
{
+ if (IsDestroyed) return;
+ IsDestroyed = true;
if (_sourceImage != null)
{
_sourceImage.Dispose();
diff --git a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSplit.cs b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSplit.cs
index 942f1e2..753ec10 100644
--- a/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSplit.cs
+++ b/DungeonShooting_Godot/src/framework/map/serialize/tileSet/TileSetSplit.cs
@@ -1,9 +1,13 @@
using System.Text.Json;
using System.Text.Json.Serialization;
+using Godot;
-public class TileSetSplit
+public class TileSetSplit : IDestroy
{
+ [JsonIgnore]
+ public bool IsDestroyed { get; private set; }
+
///
/// 错误类型
///
@@ -46,12 +50,23 @@
}
private TileSetInfo _tileSetInfo;
+ private TileSet _tileSet;
///
/// 设置图块集信息
///
public void SetTileSetInfo(TileSetInfo info)
{
+ if (_tileSetInfo != null)
+ {
+ _tileSetInfo.Destroy();
+ }
+
+ if (_tileSet != null)
+ {
+ _tileSet.Dispose();
+ _tileSet = null;
+ }
_tileSetInfo = info;
}
@@ -63,4 +78,76 @@
var asText = ResourceManager.LoadText("res://" + TileSetPath);
_tileSetInfo = JsonSerializer.Deserialize(asText);
}
+
+ ///
+ /// 获取由该对象生成的Godot.TileSet对象
+ ///
+ public TileSet GetTileSet()
+ {
+ if (_tileSet != null)
+ {
+ return _tileSet;
+ }
+
+ if (TileSetInfo == null)
+ {
+ return null;
+ }
+ _tileSet = new TileSet();
+ if (_tileSetInfo.Sources != null)
+ {
+ //TileSet网格大小
+ _tileSet.TileSize = GameConfig.TileCellSizeVector2I;
+ //物理层
+ _tileSet.AddPhysicsLayer();
+ _tileSet.SetPhysicsLayerCollisionLayer(0, PhysicsLayer.Wall);
+ _tileSet.SetPhysicsLayerCollisionMask(0, PhysicsLayer.None);
+ //地形层
+ _tileSet.AddTerrainSet();
+ _tileSet.SetTerrainSetMode(0, TileSet.TerrainMode.CornersAndSides);
+ _tileSet.AddTerrain(0);
+
+ //Source资源
+ foreach (var tileSetSourceInfo in _tileSetInfo.Sources)
+ {
+ var tileSetAtlasSource = new TileSetAtlasSource();
+ //纹理
+ var image = tileSetSourceInfo.GetSourceImage();
+ tileSetAtlasSource.Texture = ImageTexture.CreateFromImage(image);
+
+ var size = image.GetSize() / GameConfig.TileCellSize;
+ //创建cell
+ for (var i = 0; i < size.X; i++)
+ {
+ for (var j = 0; j < size.Y; j++)
+ {
+ tileSetAtlasSource.CreateTile(new Vector2I(i, j));
+ }
+ }
+
+ //初始化地形
+ tileSetAtlasSource.InitTerrain(tileSetSourceInfo.Terrain);
+
+ _tileSet.AddSource(tileSetAtlasSource);
+ }
+ }
+
+ return _tileSet;
+ }
+
+ public void Destroy()
+ {
+ if (IsDestroyed) return;
+ IsDestroyed = true;
+
+ if (_tileSetInfo != null)
+ {
+ _tileSetInfo.Destroy();
+ }
+
+ if (_tileSet != null)
+ {
+ _tileSet.Dispose();
+ }
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/framework/map/tileSet/TerrainPeering.cs b/DungeonShooting_Godot/src/framework/map/tileSet/TerrainPeering.cs
index 0019d3b..e6f73fe 100644
--- a/DungeonShooting_Godot/src/framework/map/tileSet/TerrainPeering.cs
+++ b/DungeonShooting_Godot/src/framework/map/tileSet/TerrainPeering.cs
@@ -76,4 +76,9 @@
return None;
}
+
+ public static void InitTerrain(this TileSetAtlasSource atlasSource, TileSetTerrainInfo terrainInfo)
+ {
+ //terrainInfo._000_110_010
+ }
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/ui/mapEditor/MapEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/mapEditor/MapEditorPanel.cs
index de3e1db..ef726dc 100644
--- a/DungeonShooting_Godot/src/game/ui/mapEditor/MapEditorPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/mapEditor/MapEditorPanel.cs
@@ -1,3 +1,4 @@
+using System.Linq;
using Godot;
namespace UI.MapEditor;
@@ -27,10 +28,8 @@
public override void OnCreateUi()
{
//临时处理, 加载TileSet
- var tileSet = ResourceManager.Load(ResourcePath.resource_tileSet_map2_TileSet2_tres);
- //var tileSet = ResourceManager.Load(ResourcePath.resource_tileSet_map1_TileSet1_tres);
- //var tileSetAtlasSource = (TileSetAtlasSource)tileSet.GetSource(0);
- //tileSetAtlasSource.Texture = ImageTexture.CreateFromImage(Image.LoadFromFile("resource/tileSprite/map1/16x16 dungeon ii wall reconfig v04 spritesheet.png"));
+ var tileSetSplit = GameApplication.Instance.TileSetConfig.First().Value;
+ var tileSet = tileSetSplit.GetTileSet();
S_TileMap.Instance.InitTileSet(tileSet);
S_TabContainer.Instance.SetTabTitle(0, "对象");
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
index 1bb91ac..96d3367 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditor/TileSetEditorPanel.cs
@@ -110,7 +110,7 @@
if (TileSetInfo != null)
{
- TileSetInfo.Dispose();
+ TileSetInfo.Destroy();
}
}
@@ -251,7 +251,7 @@
var findIndex = TileSetInfo.Sources.FindIndex(info => info.Name == name);
if (findIndex >= 0)
{
- TileSetInfo.Sources[findIndex].Dispose();
+ TileSetInfo.Sources[findIndex].Destroy();
TileSetInfo.Sources.RemoveAt(findIndex);
}
@@ -323,7 +323,6 @@
//保存
private void OnSaveClick()
{
- TileSetSplit.TileSetInfo.Dispose();
TileSetSplit.SetTileSetInfo(TileSetInfo.Clone());
EventManager.EmitEvent(EventEnum.OnTileSetSave, TileSetSplit);
IsDirty = false;
diff --git a/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs b/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
index 07a51c2..75a55a4 100644
--- a/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
+++ b/DungeonShooting_Godot/src/game/ui/tileSetEditorProject/TileSetEditorProjectPanel.cs
@@ -114,7 +114,7 @@
Directory.Delete(EditorTileSetManager.CustomTileSetPath + tileSetSplit.TileSetInfo.Name, true);
GameApplication.Instance.TileSetConfig.Remove(tileSetSplit.TileSetInfo.Name);
EditorTileSetManager.SaveTileSetConfig();
- tileSetSplit.TileSetInfo.Dispose();
+ tileSetSplit.Destroy();
//刷新
OnSearchClick();
}
diff --git a/DungeonShooting_Godot/src/test/TestLoadTileSetConfig.cs b/DungeonShooting_Godot/src/test/TestLoadTileSetConfig.cs
new file mode 100644
index 0000000..a375355
--- /dev/null
+++ b/DungeonShooting_Godot/src/test/TestLoadTileSetConfig.cs
@@ -0,0 +1,38 @@
+using Godot;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text.Json;
+
+public partial class TestLoadTileSetConfig : Node2D
+{
+ private Dictionary _tileSetConfig;
+ private TileMap _tileMap;
+
+ public override void _Ready()
+ {
+ InitTileSetConfig();
+ _tileMap = GetNode("TileMap");
+
+ var tileSetSplit = _tileSetConfig.First().Value;
+ var tileSet = tileSetSplit.GetTileSet();
+ _tileMap.TileSet = tileSet;
+
+ _tileMap.SetCell(0, new Vector2I(5, 5), 0, new Vector2I(0, 0));
+ }
+
+ //初始化TileSet配置
+ private void InitTileSetConfig()
+ {
+ //加载房间配置信息
+ var asText = ResourceManager.LoadText("res://" + GameConfig.RoomTileSetDir + GameConfig.TileSetConfigFile);
+ _tileSetConfig = JsonSerializer.Deserialize>(asText);
+
+ //加载所有数据
+ foreach (var tileSetSplit in _tileSetConfig)
+ {
+ tileSetSplit.Value.ReloadTileSetInfo();
+ }
+ }
+
+}