Skip to content

Commit 50d98e9

Browse files
authored
Merge pull request #53 from CommunalHelper/aonkeeper4/ignored-anchor-modinterop
Add ModInterop for adding ignored anchor fields
2 parents 83345e2 + a3cce14 commit 50d98e9

4 files changed

Lines changed: 44 additions & 27 deletions

File tree

Code/Components/EntityContainerMover.cs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using MonoMod.Utils;
66
using System;
77
using System.Collections.Generic;
8+
using System.Linq;
89

910
namespace Celeste.Mod.EeveeHelper.Components;
1011

@@ -19,6 +20,8 @@ public class EntityContainerMover : EntityContainer
1920
{
2021
"Position", "ExactPosition", "TopLeft", "TopCenter", "TopRight", "Center", "CenterLeft", "CenterRight", "BottomLeft", "BottomCenter", "BottomRight"
2122
};
23+
private static Dictionary<Type, HashSet<string>> IgnoredAnchorsPerType = new();
24+
2225
private static HashSet<string> CommonAnchors = new()
2326
{
2427
"anchor", "anchorPosition", "start", "startPosition"
@@ -271,16 +274,29 @@ public static List<string> FindAnchors(Entity entity)
271274
{
272275
var result = new List<string>();
273276
var data = new InheritedDynData(entity);
277+
278+
var type = entity.GetType();
279+
var ignoredAnchorsForType = IgnoredAnchorsPerType.SelectMany(kvp => kvp.Key.IsAssignableFrom(type) ? kvp.Value : []).ToArray();
280+
274281
foreach (var pair in data)
275282
{
276-
if (pair.Value is Vector2 vector && !IgnoredAnchors.Contains(pair.Key) && (vector == EeveeUtils.GetPosition(entity) || CommonAnchors.Contains(pair.Key)))
277-
{
283+
if (pair.Value is Vector2 vector
284+
&& !IgnoredAnchors.Contains(pair.Key)
285+
&& !ignoredAnchorsForType.Contains(pair.Key)
286+
&& (vector == EeveeUtils.GetPosition(entity) || CommonAnchors.Contains(pair.Key)))
278287
result.Add(pair.Key);
279-
}
280288
}
281289
return result;
282290
}
283291

292+
public static void AddIgnoredAnchors(Type type, HashSet<string> anchors)
293+
{
294+
if (IgnoredAnchorsPerType.TryGetValue(type, out var alreadyIgnoredAnchors))
295+
alreadyIgnoredAnchors.UnionWith(anchors);
296+
else
297+
IgnoredAnchorsPerType.Add(type, anchors);
298+
}
299+
284300
public static void AddEntityHandler(Type entityType, Type handlerType)
285301
{
286302
foreach (var type in FakeAssembly.GetEntryAssembly().GetTypesSafe())

Code/EeveeHelper.csproj

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,6 @@
88
<CelestePrefix Condition="'$(CelestePrefix)' == '' And Exists('..\..\Celeste.dll')">..\..</CelestePrefix>
99
<CelestePrefix Condition="'$(CelestePrefix)' == '' And Exists('..\..\..\Celeste.dll')">..\..\..</CelestePrefix>
1010
<CelestePrefix Condition="'$(CelestePrefix)' == ''">lib-stripped</CelestePrefix>
11-
12-
<CelesteType Condition="'$(CelesteType)' == '' And Exists('$(CelestePrefix)\BuildIsXNA.txt')">XNA</CelesteType>
13-
<CelesteType Condition="'$(CelesteType)' == ''">FNA</CelesteType>
14-
<XNAPath Condition="'$(XNAPath)' == ''">$(WINDIR)\Microsoft.NET\assembly\GAC_32\{0}\v4.0_4.0.0.0__842cf8be1de50553\{0}.dll</XNAPath>
1511
</PropertyGroup>
1612

1713
<!--Disable "Copy Local" for all references-->
@@ -21,32 +17,21 @@
2117
</ItemDefinitionGroup>
2218

2319
<ItemGroup>
24-
<PackageReference Include="MonoMod.RuntimeDetour" Version="22.01.04.03" />
25-
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" />
20+
<PackageReference Include="MonoMod.RuntimeDetour" Version="25.3.1" PrivateAssets="all" ExcludeAssets="runtime" />
21+
<PackageReference Include="MonoMod.Patcher" Version="25.0.0-prerelease.2" />
22+
<PackageReference Include="CelesteAnalyzer" Version="*" />
2623
</ItemGroup>
2724

2825
<ItemGroup>
29-
<Reference Include="$(CelestePrefix)\Celeste.dll" Publicize="true" />
30-
<Reference Include="$(CelestePrefix)\MMHOOK_Celeste.dll" />
26+
<PackageReference Include="CelesteMod.Publicizer" Version="*" CelesteAssembly="$(CelestePrefix)\Celeste.dll" />
27+
<Reference Include="$(CelestePrefix)\MMHOOK_Celeste.dll" Private="false" />
28+
<Reference Include="$(CelestePrefix)\FNA.dll" Private="false" />
29+
</ItemGroup>
30+
31+
<ItemGroup>
3132
<Reference Include="lib-stripped\StyleMaskHelper.dll" />
3233
</ItemGroup>
3334

34-
<Choose>
35-
<When Condition="'$(CelesteType)' == 'FNA'">
36-
<ItemGroup>
37-
<Reference Include="$(CelestePrefix)\FNA.dll" />
38-
</ItemGroup>
39-
</When>
40-
41-
<When Condition="'$(CelesteType)' == 'XNA'">
42-
<ItemGroup>
43-
<Reference Include="$([System.String]::Format('$(XNAPath)', 'Microsoft.Xna.Framework'))" />
44-
<Reference Include="$([System.String]::Format('$(XNAPath)', 'Microsoft.Xna.Framework.Game'))" />
45-
<Reference Include="$([System.String]::Format('$(XNAPath)', 'Microsoft.Xna.Framework.Graphics'))" />
46-
</ItemGroup>
47-
</When>
48-
</Choose>
49-
5035
<Target Name="CopyFiles" AfterTargets="Build">
5136
<Copy SourceFiles="$(OutputPath)\$(AssemblyName).dll" DestinationFolder="bin" />
5237
<Copy SourceFiles="$(OutputPath)\$(AssemblyName).pdb" DestinationFolder="bin" />

Code/EeveeHelperModule.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Celeste.Mod.EeveeHelper.Handlers;
66
using Celeste.Mod.EeveeHelper.Handlers.Impl;
77
using Monocle;
8+
using MonoMod.ModInterop;
89
using System;
910
using System.Collections.Generic;
1011

@@ -32,6 +33,8 @@ public EeveeHelperModule()
3233

3334
public override void Load()
3435
{
36+
typeof(Exports).ModInterop();
37+
3538
MiscHooks.Load();
3639
RoomChest.Load();
3740
HoldableTiles.Load();

Code/Exports.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Celeste.Mod.EeveeHelper.Components;
2+
using MonoMod.ModInterop;
3+
using System;
4+
using System.Collections.Generic;
5+
6+
namespace Celeste.Mod.EeveeHelper;
7+
8+
[ModExportName("EeveeHelper")]
9+
public static class Exports
10+
{
11+
public static void RegisterIgnoredAnchors(Type forType, HashSet<string> fieldNames)
12+
=> EntityContainerMover.AddIgnoredAnchors(forType, fieldNames);
13+
}

0 commit comments

Comments
 (0)