Fix NetworkManager, add more entity management, default command permission level to "Admin"

This commit is contained in:
John Gross
2017-06-02 19:40:52 -07:00
parent 8ad9ecf2bb
commit c40b17ac30
37 changed files with 489 additions and 114 deletions

View File

@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Drawing.Text;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI;
using Sandbox.ModAPI.Interfaces;
using Torch.Server.ViewModels.Entities;
@@ -26,9 +29,22 @@ namespace Torch.Server.ViewModels.Blocks
}
}
/// <inheritdoc />
public override string Position { get => base.Position; set { } }
public long BuiltBy
{
get => ((MySlimBlock)Block.SlimBlock).BuiltBy;
set
{
TorchBase.Instance.InvokeBlocking(() => ((MySlimBlock)Block.SlimBlock).TransferAuthorship(value));
OnPropertyChanged();
}
}
public override bool CanStop => false;
public BlockViewModel(IMyTerminalBlock block) : base(block)
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
{
Block = block;
var propList = new List<ITerminalProperty>();

View File

@@ -4,7 +4,7 @@ namespace Torch.Server.ViewModels.Entities
{
public class CharacterViewModel : EntityViewModel
{
public CharacterViewModel(MyCharacter character) : base(character)
public CharacterViewModel(MyCharacter character, EntityTreeViewModel tree) : base(character, tree)
{
}

View File

@@ -6,6 +6,7 @@ namespace Torch.Server.ViewModels.Entities
{
public class EntityViewModel : ViewModel
{
protected EntityTreeViewModel Tree { get; }
public IMyEntity Entity { get; }
public long Id => Entity.EntityId;
@@ -36,7 +37,7 @@ namespace Torch.Server.ViewModels.Entities
public virtual bool CanDelete => !(Entity is IMyCharacter);
public EntityViewModel(IMyEntity entity)
public EntityViewModel(IMyEntity entity, EntityTreeViewModel tree)
{
Entity = entity;
}

View File

@@ -9,6 +9,6 @@ namespace Torch.Server.ViewModels
public override string Name => $"{base.Name} ({Floating.Amount})";
public FloatingObjectViewModel(MyFloatingObject floating) : base(floating) { }
public FloatingObjectViewModel(MyFloatingObject floating, EntityTreeViewModel tree) : base(floating, tree) { }
}
}

View File

@@ -11,15 +11,17 @@ namespace Torch.Server.ViewModels.Entities
public MTObservableCollection<BlockViewModel> Blocks { get; } = new MTObservableCollection<BlockViewModel>();
/// <inheritdoc />
public override string Name => $"{base.Name} ({Grid.BlocksCount} blocks)";
public string DescriptiveName => $"{Name} ({Grid.BlocksCount} blocks)";
public GridViewModel(MyCubeGrid grid) : base(grid)
public GridViewModel() { }
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));
Blocks.Add(new BlockViewModel((IMyTerminalBlock)block, tree));
}
});
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
@@ -39,8 +41,9 @@ namespace Torch.Server.ViewModels.Entities
private void Grid_OnBlockAdded(Sandbox.Game.Entities.Cube.MySlimBlock obj)
{
if (obj.FatBlock != null)
Blocks.Add(new BlockViewModel((IMyTerminalBlock)obj.FatBlock));
var block = obj.FatBlock as IMyTerminalBlock;
if (block != null)
Blocks.Add(new BlockViewModel(block, Tree));
Blocks.Sort(b => b.Block.GetType().AssemblyQualifiedName);
OnPropertyChanged(nameof(Name));

View File

@@ -1,4 +1,9 @@
using Sandbox.Game.Entities;
using System.Collections.Generic;
using System.Linq;
using Sandbox.Game.Entities;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.Library.Collections;
namespace Torch.Server.ViewModels.Entities
{
@@ -10,6 +15,35 @@ namespace Torch.Server.ViewModels.Entities
public override bool CanStop => false;
public VoxelMapViewModel(MyVoxelBase e) : base(e) { }
public MTObservableCollection<GridViewModel> AttachedGrids { get; } = new MTObservableCollection<GridViewModel>();
public void UpdateAttachedGrids()
{
AttachedGrids.Clear();
var box = Entity.WorldAABB;
var entities = new List<MyEntity>();
MyGamePruningStructure.GetTopMostEntitiesInBox(ref box, entities, MyEntityQueryType.Static);
foreach (var entity in entities.Where(e => e is IMyCubeGrid))
{
var gridModel = Tree.Grids.FirstOrDefault(g => g.Entity.EntityId == entity.EntityId);
if (gridModel == null)
{
gridModel = new GridViewModel((MyCubeGrid)entity, Tree);
Tree.Grids.Add(gridModel);
}
AttachedGrids.Add(gridModel);
}
}
public VoxelMapViewModel(MyVoxelBase e, EntityTreeViewModel tree) : base(e, tree)
{
}
public VoxelMapViewModel()
{
}
}
}

View File

@@ -53,20 +53,23 @@ namespace Torch.Server.ViewModels
private void MyEntities_OnEntityAdd(VRage.Game.Entity.MyEntity obj)
{
//TODO: make view models
switch (obj)
{
case MyCubeGrid grid:
Grids.Add(new GridViewModel(grid));
if (Grids.All(g => g.Entity.EntityId != obj.EntityId))
Grids.Add(new GridViewModel(grid, this));
break;
case MyCharacter character:
Characters.Add(new CharacterViewModel(character));
if (Characters.All(g => g.Entity.EntityId != obj.EntityId))
Characters.Add(new CharacterViewModel(character, this));
break;
case MyFloatingObject floating:
FloatingObjects.Add(new FloatingObjectViewModel(floating));
if (FloatingObjects.All(g => g.Entity.EntityId != obj.EntityId))
FloatingObjects.Add(new FloatingObjectViewModel(floating, this));
break;
case MyVoxelBase voxel:
VoxelMaps.Add(new VoxelMapViewModel(voxel));
if (VoxelMaps.All(g => g.Entity.EntityId != obj.EntityId))
VoxelMaps.Add(new VoxelMapViewModel(voxel, this));
break;
}
}