Fix picking block groups...

This commit is contained in:
Norbi Peti 2020-11-14 22:43:45 +01:00
parent 1f911b1d32
commit fad3b5cbf4
7 changed files with 48 additions and 112 deletions

View file

@ -365,7 +365,7 @@ namespace GamecraftModdingAPI
private BlockGroup blockGroup;
/// <summary>
/// Returns the block group this block is a part of. Block groups can be placed using blueprints.
/// Returns the block group this block is a part of. Block groups can also be placed using blueprints.
/// Returns null if not part of a group.<br />
/// Setting the group after the block has been initialized will not update everything properly,
/// so you can only set this property on blocks newly placed by your code.<br />
@ -385,9 +385,6 @@ namespace GamecraftModdingAPI
{
if (Exists)
{
/*var copy = Copy<Block>();
copy.BlockGroup = value; //It won't run this on the new instance as it won't 'exist' yet
Remove();*/
Logging.LogWarning("Attempted to set group of existing block. This is not supported."
+ " Copy the block and set the group of the resulting block.");
return;

View file

@ -55,7 +55,7 @@ namespace GamecraftModdingAPI
}
/// <summary>
/// The position of the block group (center). Recalculated if blocks have been added/removed since the last query.
/// The position of the block group (center). Can only be used after initialization is complete.
/// </summary>
public float3 Position
{
@ -78,7 +78,7 @@ namespace GamecraftModdingAPI
}
/// <summary>
/// The rotation of the block group. Recalculated if blocks have been added/removed since the last query.
/// The rotation of the block group. Can only be used after initialization is complete.
/// </summary>
public float3 Rotation
{
@ -121,7 +121,7 @@ namespace GamecraftModdingAPI
/// <returns>A new block group containing the given block</returns>
public static BlockGroup Create(Block block)
{
var bg = new BlockGroup(_engine.CreateBlockGroup(default, default), block);
var bg = new BlockGroup(_engine.CreateBlockGroup(block.Position, Quaternion.Euler(block.Rotation)), block);
block.BlockGroup = bg;
return bg;
}
@ -166,7 +166,11 @@ namespace GamecraftModdingAPI
item.BlockGroup = this; //Calls AddInternal
}
internal void AddInternal(Block item) => blocks.Add(item);
internal void AddInternal(Block item)
{
blocks.Add(item);
_engine.AddBlockToGroup(item.Id, Id);
}
/// <summary>
/// Removes all blocks from this group.

View file

@ -29,6 +29,7 @@ namespace GamecraftModdingAPI.Blocks
private NativeDynamicArray selectedBlocksInGroup;
private NativeHashSet<ulong> removedConnections = new NativeHashSet<ulong>();
private int addingToBlockGroup = -1;
private static readonly Type PlaceBlueprintUtilityType =
AccessTools.TypeByName("RobocraftX.CR.MachineEditing.PlaceBlueprintUtility");
@ -57,6 +58,7 @@ namespace GamecraftModdingAPI.Blocks
}
public EntitiesDB entitiesDB { get; set; }
public void Dispose()
{
selectedBlocksInGroup.Dispose();
@ -96,6 +98,20 @@ namespace GamecraftModdingAPI.Blocks
return nextFilterId;
}
public void AddBlockToGroup(EGID blockID, int groupID)
{
if (globalBlockMap == null)
globalBlockMap = FullGameFields._deserialisedBlockMap;
if (groupID != addingToBlockGroup)
{
Logging.MetaDebugLog("Changing current block group from " + addingToBlockGroup + " to " + groupID);
addingToBlockGroup = groupID;
globalBlockMap.Clear();
}
globalBlockMap.Add(blockID);
}
public void SelectBlueprint(uint resourceID)
{
if (resourceID == uint.MaxValue)
@ -173,11 +189,12 @@ namespace GamecraftModdingAPI.Blocks
}
}
int nextFilterId1 = BlockGroupUtility.NextFilterId;
entityFactory.BuildEntity<BlockGroupEntityDescriptor>(new EGID((uint) nextFilterId1, BlockGroupExclusiveGroups.BlockGroupEntityGroup)).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridPosition = selectionPosition.position,
blockGroupGridRotation = selectionRotation.rotation
});
entityFactory.BuildEntity<BlockGroupEntityDescriptor>(new EGID((uint) nextFilterId1,
BlockGroupExclusiveGroups.BlockGroupEntityGroup)).Init(new BlockGroupTransformEntityComponent
{
blockGroupGridPosition = selectionPosition.position,
blockGroupGridRotation = selectionRotation.rotation
});
var frot = Quaternion.Euler(rot);
var grid = new GridRotationStruct {position = pos, rotation = frot};
var poss = new PositionEntityStruct {position = pos};
@ -284,17 +301,17 @@ namespace GamecraftModdingAPI.Blocks
}
[HarmonyPatch]
private static class BuildGhostBlueprintPatch
private static class BuildGhostBlueprintPatch
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
public static void Postfix(GhostChildEntityFactory ghostChildEntityFactory)
{
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}
BuildGhostBlueprintFactory = ghostChildEntityFactory;
}
public static MethodBase TargetMethod()
{RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
public static MethodBase TargetMethod()
{
return AccessTools.GetDeclaredConstructors(AccessTools.TypeByName("RobocraftX.CR.MachineEditing.BuildGhostChildForMultiblockPickEngine"))[0];
}
}
public IEntityFactory Factory { get; set; }

View file

@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Version>1.8.0</Version>
<Version>1.7.0</Version>
<Authors>Exmods</Authors>
<PackageLicenseExpression>GNU General Public Licence 3+</PackageLicenseExpression>
<PackageProjectUrl>https://git.exmods.org/modtainers/GamecraftModdingAPI</PackageProjectUrl>

View file

@ -410,88 +410,6 @@ namespace GamecraftModdingAPI.Tests
return ((Action) MinimumSpecsCheck.CheckRequirementsMet).Method;
}
}
[HarmonyPatch]
public class BugHuntPatch
{
public static MethodInfo method =
SymbolExtensions.GetMethodInfo<string>(str => Console.WriteLine(str));
public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
int i = 0;
foreach (var instruction in instructions)
{
i++;
yield return instruction; //Return the instruction first
//stloc, dup, callvirt
if (instruction.opcode.Name.ToLower().StartsWith("stloc")
|| instruction.opcode == OpCodes.Dup
|| instruction.opcode == OpCodes.Callvirt)
{
yield return new CodeInstruction(OpCodes.Ldstr,
"Just ran the " + i + ". instruction ending with " + instruction.opcode.Name);
yield return new CodeInstruction(OpCodes.Call, method);
}
}
}
public static MethodInfo TargetMethod()
{
return AccessTools.Method("RobocraftX.CR.MachineEditing.BoxSelect.CopySelectionEngine:GenerateThumbnail");
}
}
[HarmonyPatch]
public class BugHuntPatch2
{
public static void Prefix(int width, float fieldOfView, Vector3 cameraDirection, Vector3 lightDirection)
{
Console.WriteLine("TakeThumbnail invoked with parameters: " + width + ", " + fieldOfView + ", " +
cameraDirection + ", " + lightDirection);
GPUInstancerManager manager = GPUInstancerAPI.GetActiveManagers().Find(m => m is GPUInstancerPrefabManager);
Bounds instancesBounds = manager.ComputeInstancesBounds(2);
Console.WriteLine("Bounds: " + instancesBounds);
Console.WriteLine("Size: " + instancesBounds.size);
Console.WriteLine("Size.x < 0: " + (instancesBounds.size.x < 0));
}
public static void Postfix(Texture2D __result)
{
Console.WriteLine("TakeThumbnail returned: " + (__result == null ? null : __result.name));
}
private delegate Texture2D TakeThumbnailDel(int width, float fieldOfView, Vector3 cameraDirection,
Vector3 lightDirection);
public static MethodInfo TargetMethod()
{
return ((TakeThumbnailDel) ThumbnailUtility.TakeThumbnail).Method;
}
}
[HarmonyPatch]
public class BugHuntPatch3
{
public static void Prefix(int width, int filterLayerMask, GPUInstancerManager manager,
Vector3 cameraPosition, Quaternion cameraRotation, float cameraFov, Vector3 lightDirection,
int cullingLayer)
{
Console.WriteLine("Inner TakeThumbnail invoked with parameters: " + width + ", " + filterLayerMask +
", " + (manager != null ? manager.name : null) + ", " + cameraPosition + ", " +
cameraRotation + ", " + cameraFov + ", " + lightDirection + ", " + cullingLayer);
}
private delegate Texture2D TakeThumbnailDel(int width, int filterLayerMask, GPUInstancerManager manager,
Vector3 cameraPosition, Quaternion cameraRotation, float cameraFov, Vector3 lightDirection,
int cullingLayer);
public static MethodInfo TargetMethod()
{
return ((TakeThumbnailDel) ThumbnailUtility.TakeThumbnail).Method;
}
}
}
#endif
}

View file

@ -38,7 +38,7 @@ PROJECT_NAME = "GamecraftModdingAPI"
# could be handy for archiving the generated documentation or if some version
# control system is used.
PROJECT_NUMBER = "v1.8.0"
PROJECT_NUMBER = "v1.7.0"
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a