Files
sbox-public/engine/Sandbox.Tools/MapEditor/MapDoc/Internal/EditorContextInstance.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

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();
}
}