Skip to content

Commit

Permalink
Added utils_render_module_issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Aragas committed Jun 2, 2024
1 parent 0c2ce87 commit 0b955af
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object>());

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();
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { ModuleInfoExtended } from "./BannerlordModuleManager";
import { ModuleInfoExtended, ModuleIssue } from "./BannerlordModuleManager";

export interface IUtils {
isLoadOrderCorrect(modules: Array<ModuleInfoExtended>): Array<string>;

getDependencyHint(module: ModuleInfoExtended): string;

renderModuleIssue(moduleIssue: ModuleIssue): string;

loadLocalization(xml: string): void;
setLanguage(language: string): void;
localizeString(template: string, values: { [value: string]: string }): string;
Expand Down
19 changes: 19 additions & 0 deletions src/Bannerlord.LauncherManager.Native/Bindings.Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IsPtrConst>]
public static return_value_string* RenderModuleIssue([IsConst<IsPtrConst>] 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)
Expand Down

0 comments on commit 0b955af

Please sign in to comment.