mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 11:28:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
49 lines
1.2 KiB
C#
49 lines
1.2 KiB
C#
using Editor.MapDoc;
|
|
|
|
namespace Editor.MapEditor;
|
|
|
|
internal class EditorContextInstance : EditorContext
|
|
{
|
|
private MapDocument mapDoc;
|
|
|
|
public EditorContextInstance( MapDocument mapDoc )
|
|
{
|
|
this.mapDoc = mapDoc;
|
|
|
|
Selection = Editor.MapEditor.Selection
|
|
.All
|
|
.OfType<MapEntity>()
|
|
.Select( x => x.SerializedObject )
|
|
.Cast<EditorContext.EntityObject>()
|
|
.ToHashSet();
|
|
}
|
|
|
|
//
|
|
// TODO: we're iterating over a list provided by native
|
|
// we we might as well have World.FindTargets() and iterate over that
|
|
// from native somehow instead of trying to recreate it here
|
|
//
|
|
|
|
public override EditorContext.EntityObject FindTarget( string name )
|
|
{
|
|
return mapDoc.World.Children.OfType<MapEntity>()
|
|
.Where( x => IsTarget( x, name ) )
|
|
.Select( x => x.SerializedObject as EditorContext.EntityObject )
|
|
.FirstOrDefault();
|
|
}
|
|
|
|
private bool IsTarget( MapEntity x, string name )
|
|
{
|
|
return x.entityNative.TargetNameMatches( name );
|
|
}
|
|
|
|
public override EditorContext.EntityObject[] FindTargets( string name )
|
|
{
|
|
return mapDoc.World.Children.OfType<MapEntity>()
|
|
.Where( x => IsTarget( x, name ) )
|
|
.Select( x => x.SerializedObject as EditorContext.EntityObject )
|
|
.ToArray();
|
|
}
|
|
|
|
}
|