Skip to content

Commit

Permalink
Merge pull request #306 from BUTR/dev
Browse files Browse the repository at this point in the history
Release 2.12.0
  • Loading branch information
Aragas authored Jul 29, 2024
2 parents 11f952f + e659d53 commit e238c96
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
artifact_name: bannerlord
secrets:
NEXUSMODS_APIKEY: ${{ secrets.ARAGAS_NEXUSMODS_API_KEY }}
NEXUSMODS_COOKIES: ${{ secrets.ARAGAS_NEXUSMODS_COOKIE_SID_DEVELOP }}
NEXUSMODS_SESSION_COOKIE: ${{ secrets.ARAGAS_NEXUSMODS_SESSION_COOKIE }}

###########################
# STEAM #
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
shell: pwsh

- name: ReportGenerator
uses: danielpalme/ReportGenerator-GitHub-Action@5.2.1
uses: danielpalme/ReportGenerator-GitHub-Action@5.3.8
with:
reports: 'coverage_uiextenderex_debug.xml;coverage_uiextenderex_release.xml'
targetdir: 'coveragereport'
Expand All @@ -76,7 +76,7 @@ jobs:
path: coveragereport

- name: Upload ReportGenerator to CodeCov
uses: codecov/codecov-action@v4.0.1
uses: codecov/codecov-action@v4.5.0
with:
token: ${{secrets.CODECOV_TOKEN}}
file: coveragereport/Cobertura.xml
Expand Down
2 changes: 1 addition & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<!--Development Variables-->
<PropertyGroup>
<!--Module Version-->
<Version>2.11.0</Version>
<Version>2.12.0</Version>
<!--Harmony Version-->
<HarmonyVersion>2.2.2</HarmonyVersion>
<HarmonyExtensionsVersion>3.2.0.77</HarmonyExtensionsVersion>
Expand Down
4 changes: 4 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------------------------------------
Version: 2.12.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.x
* Fixed postfix being a prefix by kemoiii
---------------------------------------------------------------------------------------------------
Version: 2.11.0
Game Versions: v1.0.0,v1.0.1,v1.0.2,v1.0.3,v1.1.0,v1.1.1,v1.1.2,v1.1.3,v1.1.4,v1.1.5,v1.1.6,v1.2.x
* Disabled the BETA changes due to regression
Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.UIExtenderEx/Bannerlord.UIExtenderEx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<!--NuGet Package-->

<ItemGroup>
<PackageReference Include="Bannerlord.Lib.Harmony" Version="$(HarmonyVersion)" PrivateAssets="all" IncludeAssets="compile" />
<PackageReference Include="Lib.Harmony" Version="$(HarmonyVersion)" PrivateAssets="all" IncludeAssets="compile" />
<PackageReference Include="Bannerlord.ReferenceAssemblies.Core" Version="$(GameVersion).*" PrivateAssets="all" IncludeAssets="compile" GeneratePathProperty="true" />
<PackageReference Include="BUTR.MessageBoxPInvoke" Version="1.0.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" PrivateAssets="all" />
Expand Down
4 changes: 2 additions & 2 deletions src/Bannerlord.UIExtenderEx/Components/PrefabComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void RegisterPatch(string movie, Type prefabType, Action<XmlDocument> pat
return;
}

MoviePatches.GetOrAdd(movie, _ => new List<PrefabPatch>()).Add(new(prefabType, patcher));
MoviePatches.GetOrAdd(movie, _ => []).Add(new(prefabType, patcher));
_enabledPatches[prefabType] = false;
}

Expand All @@ -125,7 +125,7 @@ public void RegisterPatch(string movie, Type prefabType, Action<XmlNode> patcher
return;
}

MoviePatches.GetOrAdd(movie, _ => new List<PrefabPatch>()).Add(new(prefabType, patcher));
MoviePatches.GetOrAdd(movie, _ => []).Add(new(prefabType, patcher));
_enabledPatches[prefabType] = false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Bannerlord.UIExtenderEx/Components/ViewModelComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,13 @@ public void Deregister()
/// <param name="instance">instance of extended VM</param>
public void InitializeMixinsForVMInstance(ViewModel instance)
{
var mixins = MixinInstanceCache.GetOrAdd(instance, _ => new List<IViewModelMixin>());
var mixins = MixinInstanceCache.GetOrAdd(instance, _ => []);

var type = instance.GetType();
if (!Mixins.ContainsKey(type))
if (!Mixins.TryGetValue(type, out var mixinTypes))
return;

var newMixins = Mixins[type]
var newMixins = mixinTypes
.Where(mixinType => _mixinTypeEnabled.TryGetValue(mixinType, out var enabled) && enabled)
.Where(mixinType => mixins.All(mixin => mixin.GetType() != mixinType))
.Select(mixinType => Activator.CreateInstance(mixinType, instance) as IViewModelMixin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ internal static class ViewModelExtensions

public delegate object DataSourceTypeBindingPropertiesCollectionCtorDelegate(Dictionary<string, PropertyInfo> properties, Dictionary<string, MethodInfo> methods);
public static readonly DataSourceTypeBindingPropertiesCollectionCtorDelegate? DataSourceTypeBindingPropertiesCollectionCtor =
AccessTools2.GetDeclaredConstructorDelegate<DataSourceTypeBindingPropertiesCollectionCtorDelegate>(NestedType, new[] { typeof(Dictionary<string, PropertyInfo>), typeof(Dictionary<string, MethodInfo>) });
AccessTools2.GetDeclaredConstructorDelegate<DataSourceTypeBindingPropertiesCollectionCtorDelegate>(NestedType, [typeof(Dictionary<string, PropertyInfo>), typeof(Dictionary<string, MethodInfo>)
]);

public static void AddProperty(this ViewModel viewModel, string name, PropertyInfo propertyInfo)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private static void Refresh(ViewModel viewModel, string methodName)
// Refresh was called from VM Constructor, delay the call to Refresh()
if (!runtime.ViewModelComponent.MixinInstanceCache.TryGetValue(viewModel, out var list))
{
runtime.ViewModelComponent.MixinInstanceRefreshFromConstructorCache.GetOrAdd(viewModel, _ => new List<string>()).Add(methodName);
runtime.ViewModelComponent.MixinInstanceRefreshFromConstructorCache.GetOrAdd(viewModel, _ => []).Add(methodName);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static void Patch(Harmony harmony)

harmony.Patch(
AccessTools2.DeclaredMethod(typeof(WidgetFactory), "GetWidgetTypes"),
prefix: new HarmonyMethod(typeof(WidgetFactoryManager), nameof(GetWidgetTypesPostfix)));
postfix: new HarmonyMethod(typeof(WidgetFactoryManager), nameof(GetWidgetTypesPostfix)));

harmony.Patch(
AccessTools2.DeclaredMethod(typeof(WidgetFactory), "IsCustomType"),
Expand Down Expand Up @@ -118,7 +118,7 @@ private static bool CreateBuiltinWidgetPrefix(UIContext context, string typeName
if (!BuiltinTypes.TryGetValue(typeName, out var type))
return true;

var ctor = WidgetConstructors.GetOrAdd(type, static x => AccessTools2.GetDeclaredConstructorDelegate<WidgetConstructor>(x, new[] { typeof(UIContext) }));
var ctor = WidgetConstructors.GetOrAdd(type, static x => AccessTools2.GetDeclaredConstructorDelegate<WidgetConstructor>(x, [typeof(UIContext)]));
if (ctor is null)
return true;

Expand Down
2 changes: 1 addition & 1 deletion src/Bannerlord.UIExtenderEx/UIExtenderRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void Register(IEnumerable<Type> types)
}

// gauntlet xml extension
switch (constructor.Invoke(Array.Empty<object>()))
switch (constructor.Invoke([]))
{
case Prefabs.PrefabExtensionSetAttributePatch patch:
PrefabComponent.RegisterPatch(xmlExtension.Movie, xmlExtension.XPath, patch);
Expand Down
10 changes: 2 additions & 8 deletions src/Bannerlord.UIExtenderEx/UIPatchSubModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,12 @@ public class UIPatchSubModule : MBSubModuleBase
[PrefabExtension("ClanParties", "descendant::Prefab/Window/Widget/Children/ListPanel/Children/Widget/Children/Widget/Children/Widget/Children/ListPanel/Children/ListPanel")]
private sealed class ClanPartiesPrefabExtensionPoste180_1 : PrefabExtensionSetAttributePatch
{
public override List<Attribute> Attributes => new()
{
new Attribute("IsEnabled", "@CanUseActions")
};
public override List<Attribute> Attributes => [new Attribute("IsEnabled", "@CanUseActions")];
}
[PrefabExtension("ClanParties", "descendant::Prefab/Window/Widget/Children/ListPanel/Children/Widget/Children/Widget/Children/Widget/Children/ListPanel/Children/ListPanel/Children/Standard.DropdownWithHorizontalControl")]
private sealed class ClanPartiesPrefabExtensionPoste180_2 : PrefabExtensionSetAttributePatch
{
public override List<Attribute> Attributes => new()
{
new Attribute("Parameter.IsEnabled", "true")
};
public override List<Attribute> Attributes => [new Attribute("Parameter.IsEnabled", "true")];
}

private static readonly UIExtender Extender = UIExtender.Create("Bannerlord.UIExtenderEx.UIPatch");
Expand Down
14 changes: 7 additions & 7 deletions src/Bannerlord.UIExtenderEx/ViewModels/BaseViewModelMixin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,31 @@ public abstract class BaseViewModelMixin<TViewModel> : IViewModelMixin where TVi

private delegate void OnPropertyChangedWithValueDelegate2(ViewModel instance, bool value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate2? OnPropertyChangedWithValue2 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate2>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(bool), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate2>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(bool), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate3(ViewModel instance, int value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate3? OnPropertyChangedWithValue3 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate3>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(int), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate3>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(int), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate4(ViewModel instance, float value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate4? OnPropertyChangedWithValue4 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate4>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(float), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate4>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(float), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate5(ViewModel instance, uint value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate5? OnPropertyChangedWithValue5 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate5>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(uint), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate5>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(uint), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate6(ViewModel instance, Color value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate6? OnPropertyChangedWithValue6 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate6>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(Color), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate6>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(Color), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate7(ViewModel instance, double value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate7? OnPropertyChangedWithValue7 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate7>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(double), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate7>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(double), typeof(string)]);

private delegate void OnPropertyChangedWithValueDelegate8(ViewModel instance, Vec2 value, [CallerMemberName] string? propertyName = null);
private static readonly OnPropertyChangedWithValueDelegate8? OnPropertyChangedWithValue8 =
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate8>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), new[] { typeof(Vec2), typeof(string) });
AccessTools2.GetDelegate<OnPropertyChangedWithValueDelegate8>(typeof(ViewModel), nameof(OnPropertyChangedWithValue), [typeof(Vec2), typeof(string)]);


private readonly WeakReference<TViewModel> _vm;
Expand Down
2 changes: 1 addition & 1 deletion tests/Bannerlord.UIExtenderEx.Tests/BaseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public MockWidgetFactory() : base(ResourceDepotUtils.Create(), string.Empty)
new HarmonyMethod(typeof(MockWidgetFactory), nameof(GetPrefabNamesAndPathsFromCurrentPathPrefix)));
harmony.Patch(AccessTools2.DeclaredMethod("TaleWorlds.GauntletUI.PrefabSystem.WidgetFactory:GetCustomType"),
new HarmonyMethod(typeof(MockWidgetFactory), nameof(GetCustomTypePrefix)));
harmony.Patch(AccessTools2.DeclaredMethod("System.Xml.XmlReader:Create", new[] { typeof(string), typeof(XmlReaderSettings) }),
harmony.Patch(AccessTools2.DeclaredMethod("System.Xml.XmlReader:Create", [typeof(string), typeof(XmlReaderSettings)]),
new HarmonyMethod(typeof(MockWidgetFactory), nameof(CreatePrefix)));

if (GetCustomTypes?.Invoke(this) is { } dictionary)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ namespace Bannerlord.UIExtenderEx.Tests.Prefabs2;
[PrefabExtension("SetAttribute2", "descendant::OptionsScreenWidget[@Id='Options']/Children/Standard.TopPanel/Children/ListPanel/Children/OptionsTabToggle[@Id='SetAttribute']")]
internal class TestPrefabExtensionSetAttributePatch : PrefabExtensionSetAttributePatch
{
public override List<Attribute> Attributes => new()
{
public override List<Attribute> Attributes =>
[
new Attribute("CustomAttribute", "Value"),
new Attribute("CustomAttribute2", "Value2")
};
];
}
4 changes: 2 additions & 2 deletions tests/Bannerlord.UIExtenderEx.Tests/ViewModelMixinTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void MixinDerivedTest()
public void MixinMethodIsCalledTest()
{
var viewModel = new TestVM();
viewModel.ExecuteCommand(nameof(TestVMMixin.MixinMethod), Array.Empty<object>());
viewModel.ExecuteCommand(nameof(TestVMMixin.MixinMethod), []);
Assert.True(TestVMMixin.MixinMethodCalled);
Assert.True(DerivedTestVMMixin.DerivedMixinMethodCalled);
}
Expand All @@ -51,7 +51,7 @@ public void MixinMethodIsCalledTest()
public void MixinMethodIsCalledDerivedTest()
{
var viewModel = new TestVM();
viewModel.ExecuteCommand(nameof(DerivedTestVMMixin.DerivedMixinMethod), Array.Empty<object>());
viewModel.ExecuteCommand(nameof(DerivedTestVMMixin.DerivedMixinMethod), []);
Assert.False(TestVMMixin.MixinMethodCalled);
Assert.True(DerivedTestVMMixin.DerivedMixinMethodCalled);
}
Expand Down

0 comments on commit e238c96

Please sign in to comment.