mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2025-12-09 04:13:32 +08:00
fix a possible crash
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
namespace UXAssist.Functions;
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace UXAssist.Functions;
|
||||||
|
|
||||||
public static class DysonSphereFunctions
|
public static class DysonSphereFunctions
|
||||||
{
|
{
|
||||||
@@ -19,26 +21,54 @@ public static class DysonSphereFunctions
|
|||||||
if (star == null) return;
|
if (star == null) return;
|
||||||
var dysonSpheres = GameMain.data?.dysonSpheres;
|
var dysonSpheres = GameMain.data?.dysonSpheres;
|
||||||
if (dysonSpheres == null) return;
|
if (dysonSpheres == null) return;
|
||||||
|
var dysonEditor = UIRoot.instance?.uiGame.dysonEditor;
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
if (dysonSpheres[star.index] == null) return;
|
if (dysonSpheres[star.index] == null) return;
|
||||||
|
var idsToRemove = dysonSpheres[star.index].layersSorted.Select(layer => layer.id).ToArray();
|
||||||
var dysonSphere = new DysonSphere();
|
var dysonSphere = new DysonSphere();
|
||||||
dysonSpheres[star.index] = dysonSphere;
|
dysonSpheres[star.index] = dysonSphere;
|
||||||
dysonSphere.Init(GameMain.data, star);
|
dysonSphere.Init(GameMain.data, star);
|
||||||
dysonSphere.ResetNew();
|
dysonSphere.ResetNew();
|
||||||
|
if (dysonEditor == null) return;
|
||||||
|
foreach (var id in idsToRemove)
|
||||||
|
{
|
||||||
|
if (!dysonEditor.IsRender(id, false, true))
|
||||||
|
{
|
||||||
|
dysonEditor.SwitchRenderState(id, false, true);
|
||||||
|
}
|
||||||
|
if (!dysonEditor.IsRender(id, false, false))
|
||||||
|
{
|
||||||
|
dysonEditor.SwitchRenderState(id, false, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dysonEditor.selection.ClearAllSelection();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var ds = dysonSpheres[star.index];
|
var ds = dysonSpheres[star.index];
|
||||||
if (ds?.layersIdBased[index] == null) return;
|
if (ds?.layersIdBased[index] == null) return;
|
||||||
var pool = ds.rocketPool;
|
var pool = ds.rocketPool;
|
||||||
|
var idToRemove = -1;
|
||||||
for (var id = ds.rocketCursor - 1; id > 0; id--)
|
for (var id = ds.rocketCursor - 1; id > 0; id--)
|
||||||
{
|
{
|
||||||
if (pool[id].id != id) continue;
|
if (pool[id].id != id) continue;
|
||||||
if (pool[id].nodeLayerId != index) continue;
|
if (pool[id].nodeLayerId != index) continue;
|
||||||
ds.RemoveDysonRocket(id);
|
ds.RemoveDysonRocket(id);
|
||||||
|
idToRemove = id;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
if (idToRemove < 0) return;
|
||||||
ds.RemoveLayer(index);
|
ds.RemoveLayer(idToRemove);
|
||||||
|
if (dysonEditor == null) return;
|
||||||
|
if (!dysonEditor.IsRender(idToRemove, false, true))
|
||||||
|
{
|
||||||
|
dysonEditor.SwitchRenderState(idToRemove, false, true);
|
||||||
|
}
|
||||||
|
if (!dysonEditor.IsRender(idToRemove, false, false))
|
||||||
|
{
|
||||||
|
dysonEditor.SwitchRenderState(idToRemove, false, false);
|
||||||
|
}
|
||||||
|
dysonEditor.selection.ClearAllSelection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user