Refactor stuff, clean up managers
This commit is contained in:
@@ -47,6 +47,9 @@ namespace Torch.Server.ViewModels.Blocks
|
||||
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
|
||||
{
|
||||
Block = block;
|
||||
if (Block == null)
|
||||
return;
|
||||
|
||||
var propList = new List<ITerminalProperty>();
|
||||
block.GetProperties(propList);
|
||||
foreach (var prop in propList)
|
||||
|
@@ -1,14 +1,16 @@
|
||||
using System.Linq;
|
||||
using NLog;
|
||||
using Sandbox.Game.Entities;
|
||||
using Sandbox.ModAPI;
|
||||
using Torch.Server.ViewModels.Blocks;
|
||||
|
||||
namespace Torch.Server.ViewModels.Entities
|
||||
{
|
||||
public class GridViewModel : EntityViewModel
|
||||
public class GridViewModel : EntityViewModel, ILazyLoad
|
||||
{
|
||||
private MyCubeGrid Grid => (MyCubeGrid)Entity;
|
||||
public MTObservableCollection<BlockViewModel> Blocks { get; } = new MTObservableCollection<BlockViewModel>();
|
||||
private static readonly Logger Log = LogManager.GetLogger(nameof(GridViewModel));
|
||||
|
||||
/// <inheritdoc />
|
||||
public string DescriptiveName => $"{Name} ({Grid.BlocksCount} blocks)";
|
||||
@@ -17,17 +19,8 @@ namespace Torch.Server.ViewModels.Entities
|
||||
|
||||
public GridViewModel(MyCubeGrid grid, EntityTreeViewModel tree) : base(grid, tree)
|
||||
{
|
||||
TorchBase.Instance.InvokeBlocking(() =>
|
||||
{
|
||||
foreach (var block in grid.GetFatBlocks().Where(b => b is IMyTerminalBlock))
|
||||
{
|
||||
Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, tree));
|
||||
}
|
||||
});
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
|
||||
grid.OnBlockAdded += Grid_OnBlockAdded;
|
||||
grid.OnBlockRemoved += Grid_OnBlockRemoved;
|
||||
Log.Debug($"Creating model {Grid.DisplayName}");
|
||||
Blocks.Add(new BlockViewModel(null, Tree));
|
||||
}
|
||||
|
||||
private void Grid_OnBlockRemoved(Sandbox.Game.Entities.Cube.MySlimBlock obj)
|
||||
@@ -48,5 +41,27 @@ namespace Torch.Server.ViewModels.Entities
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
OnPropertyChanged(nameof(Name));
|
||||
}
|
||||
|
||||
private bool _load;
|
||||
public void Load()
|
||||
{
|
||||
if (_load)
|
||||
return;
|
||||
|
||||
Log.Debug($"Loading model {Grid.DisplayName}");
|
||||
_load = true;
|
||||
Blocks.Clear();
|
||||
TorchBase.Instance.InvokeBlocking(() =>
|
||||
{
|
||||
foreach (var block in Grid.GetFatBlocks().Where(b => b is IMyTerminalBlock))
|
||||
{
|
||||
Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, Tree));
|
||||
}
|
||||
});
|
||||
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
|
||||
|
||||
Grid.OnBlockAdded += Grid_OnBlockAdded;
|
||||
Grid.OnBlockRemoved += Grid_OnBlockRemoved;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -3,7 +3,6 @@ using System.Linq;
|
||||
using Sandbox.Game.Entities;
|
||||
using VRage.Game.Entity;
|
||||
using VRage.Game.ModAPI;
|
||||
using VRage.Library.Collections;
|
||||
|
||||
namespace Torch.Server.ViewModels.Entities
|
||||
{
|
||||
@@ -11,7 +10,7 @@ namespace Torch.Server.ViewModels.Entities
|
||||
{
|
||||
private MyVoxelBase Voxel => (MyVoxelBase)Entity;
|
||||
|
||||
public override string Name => Voxel.StorageName;
|
||||
public override string Name => string.IsNullOrEmpty(Voxel.StorageName) ? "Unnamed" : Voxel.StorageName;
|
||||
|
||||
public override bool CanStop => false;
|
||||
|
||||
@@ -19,6 +18,9 @@ namespace Torch.Server.ViewModels.Entities
|
||||
|
||||
public void UpdateAttachedGrids()
|
||||
{
|
||||
//TODO: fix
|
||||
return;
|
||||
|
||||
AttachedGrids.Clear();
|
||||
var box = Entity.WorldAABB;
|
||||
var entities = new List<MyEntity>();
|
||||
|
Reference in New Issue
Block a user