Add method to get selected blocks by player

This commit is contained in:
Norbi Peti 2020-06-08 00:10:10 +02:00
parent 448cf3af48
commit 3dcce18ceb
3 changed files with 32 additions and 0 deletions

View file

@ -8,6 +8,7 @@
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression> <PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl> <PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>
<NeutralLanguage>en-CA</NeutralLanguage> <NeutralLanguage>en-CA</NeutralLanguage>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
</PropertyGroup> </PropertyGroup>

View file

@ -366,6 +366,15 @@ namespace GamecraftModdingAPI
: null; : null;
} }
/// <summary>
/// Returns the blocks that are in the player's current selection.
/// </summary>
/// <returns>An array of blocks or an empty array</returns>
public Block[] GetSelectedBlocks()
{
return playerEngine.GetSelectedBlocks(Id);
}
public bool Equals(Player other) public bool Equals(Player other)
{ {
if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(null, other)) return false;

View file

@ -5,6 +5,7 @@ using RobocraftX.Character;
using RobocraftX.Character.Movement; using RobocraftX.Character.Movement;
using RobocraftX.Common.Players; using RobocraftX.Common.Players;
using RobocraftX.Common.Input; using RobocraftX.Common.Input;
using RobocraftX.CR.MachineEditing.BoxSelect;
using RobocraftX.Physics; using RobocraftX.Physics;
using RobocraftX.Blocks.Ghost; using RobocraftX.Blocks.Ghost;
using RobocraftX.Character.Camera; using RobocraftX.Character.Camera;
@ -408,5 +409,26 @@ namespace GamecraftModdingAPI.Players
return null; return null;
} }
public unsafe Block[] GetSelectedBlocks(uint playerid)
{
if (!entitiesDB.Exists<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup))
return new Block[0];
var state = entitiesDB.QueryEntity<BoxSelectStateEntityStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
var blocks = entitiesDB.QueryEntity<SelectedBlocksStruct>(playerid,
BoxSelectExclusiveGroups.BoxSelectVolumeExclusiveGroup);
if (!state.active) return new Block[0];
var pointer = (EGID*) blocks.selectedBlocks.ToPointer();
var ret = new Block[blocks.count];
for (int j = 0; j < blocks.count; j++)
{
var egid = pointer[j];
ret[j] = new Block(egid);
}
return ret;
}
} }
} }