From 0b955af5bdc88b1538addffdb63097497e6034ff Mon Sep 17 00:00:00 2001 From: Vitalii Mikhailov Date: Sun, 2 Jun 2024 21:06:37 +0300 Subject: [PATCH] Added utils_render_module_issue --- .../src/Bannerlord.Utils.hpp | 13 +++++++++++++ .../src/lib/Utils.ts | 5 +++++ .../src/lib/types/Utils.ts | 5 ++++- .../Bindings.Utils.cs | 19 +++++++++++++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.Utils.hpp b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.Utils.hpp index 9cab5e0..20d5388 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.Utils.hpp +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/Bannerlord.Utils.hpp @@ -33,6 +33,17 @@ namespace Bannerlord::Utils return ThrowOrReturnString(env, result); } + Value RenderModuleIssue(const CallbackInfo &info) + { + const auto env = info.Env(); + const auto moduleIssue = JSONStringify(env, info[0].As()); + + const auto moduleIssueCopy = CopyWithFree(moduleIssue.Utf16Value()); + + const auto result = utils_render_module_issue(moduleIssueCopy.get()); + return ThrowOrReturnString(env, result); + } + void LoadLocalization(const CallbackInfo &info) { const auto env = info.Env(); @@ -74,6 +85,8 @@ namespace Bannerlord::Utils exports.Set("getDependencyHint", Function::New(env, GetDependencyHint)); + exports.Set("renderModuleIssue", Function::New(env, RenderModuleIssue)); + exports.Set("loadLocalization", Function::New(env, LoadLocalization)); exports.Set("setLanguage", Function::New(env, SetLanguage)); exports.Set("localizeString", Function::New(env, LocalizeString)); diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/Utils.ts b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/Utils.ts index e6487d3..5c36fc0 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/Utils.ts +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/Utils.ts @@ -22,6 +22,11 @@ export class Utils { return Utils.addon.getDependencyHint(module); } + public static renderModuleIssue(moduleIssue: types.ModuleIssue): string { + Utils.initialize(); + return Utils.addon.renderModuleIssue(moduleIssue); + } + public static loadLocalization = (xml: string): void => { Utils.initialize(); return Utils.addon.loadLocalization(xml); diff --git a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/Utils.ts b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/Utils.ts index 8f4eff6..6935c23 100644 --- a/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/Utils.ts +++ b/src/Bannerlord.LauncherManager.Native.TypeScript/src/lib/types/Utils.ts @@ -1,9 +1,12 @@ -import { ModuleInfoExtended } from "./BannerlordModuleManager"; +import { ModuleInfoExtended, ModuleIssue } from "./BannerlordModuleManager"; export interface IUtils { isLoadOrderCorrect(modules: Array): Array; + getDependencyHint(module: ModuleInfoExtended): string; + renderModuleIssue(moduleIssue: ModuleIssue): string; + loadLocalization(xml: string): void; setLanguage(language: string): void; localizeString(template: string, values: { [value: string]: string }): string; diff --git a/src/Bannerlord.LauncherManager.Native/Bindings.Utils.cs b/src/Bannerlord.LauncherManager.Native/Bindings.Utils.cs index 903037d..df9b123 100644 --- a/src/Bannerlord.LauncherManager.Native/Bindings.Utils.cs +++ b/src/Bannerlord.LauncherManager.Native/Bindings.Utils.cs @@ -59,6 +59,25 @@ public static unsafe partial class Bindings return return_value_string.AsException(e, false); } } + [UnmanagedCallersOnly(EntryPoint = "utils_render_module_issue", CallConvs = [typeof(CallConvCdecl)]), IsNotConst] + public static return_value_string* RenderModuleIssue([IsConst] param_json* p_module_issue) + { + Logger.LogInput(p_module_issue); + try + { + var moduleIssue = BUTR.NativeAOT.Shared.Utils.DeserializeJson(p_module_issue, CustomSourceGenerationContext.ModuleIssue); + + var result = ModuleIssueRenderer.Render(moduleIssue); + + Logger.LogOutput(result); + return return_value_string.AsValue(result, false); + } + catch (Exception e) + { + Logger.LogException(e); + return return_value_string.AsException(e, false); + } + } [UnmanagedCallersOnly(EntryPoint = "utils_load_localization", CallConvs = [typeof(CallConvCdecl)])] public static return_value_void* LoadLocalization(param_string* p_xml)