Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions MonkeyLoader.Resonite.Core/FieldExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using FrooxEngine;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;

namespace MonkeyLoader.Resonite
{
Expand All @@ -14,10 +11,16 @@ namespace MonkeyLoader.Resonite
public static class FieldExtensions
{
/// <summary>
/// Creates a label describing the <paramref name="target"/> reference as a <see cref="RefEditor"/> would.
/// Creates a label describing the <paramref name="target"/> reference almost as a <see cref="RefEditor"/> would.
/// </summary>
/// <remarks>
/// For <see cref="Slot"/>s, their <see cref="Component"/>s, and the fields of those the behavior is the same.<br/>
/// For <see cref="User"/>s, this format is instead:
/// <c>$"&lt;noparse&gt;{<see cref="User">targetUser</see>.<see cref="User.UserName">UserName</see>}
/// ({<paramref name="target"/>.<see cref="IWorldElement.ReferenceID">ReferenceID</see>})&lt;/noparse&gt;"</c>
/// </remarks>
/// <param name="target">The reference to label.</param>
/// <returns>A label for the <paramref name="target"/> reference if it is not <c>null</c>; otherwise, <c>&lt;i&gt;null&lt;/i&gt;</c>.</returns>
/// <returns>A label for the <paramref name="target"/> reference if it is not <c>null</c>; otherwise, <c>"&lt;i&gt;null&lt;/i&gt;"</c>.</returns>
public static string GetReferenceLabel(this IWorldElement? target)
{
if (target is null)
Expand All @@ -26,6 +29,9 @@ public static string GetReferenceLabel(this IWorldElement? target)
if (target is Slot targetSlot)
return $"{targetSlot.Name} ({target.ReferenceID})";

if (target is User targetUser)
return $"<noparse>{targetUser.UserName} ({target.ReferenceID})</noparse>";

var component = target.FindNearestParent<Component>();
var slot = component?.Slot ?? target.FindNearestParent<Slot>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ private static async IAsyncEnumerable<DataFeedItem> EnumerateFlagsEnumItemsAsync
var flagsEnumGroup = new DataFeedGroup();
flagsEnumGroup.InitBase(configKey.FullId + ".Flags", path, groupKeys, Mod.GetLocaleString("EnumFlags.Name", ("KeyId", configKey.Id)));
flagsEnumGroup.InitSorting(-configKey.Priority);
flagsEnumGroup.InitDescription(configKey.GetLocaleKey("Description").AsLocaleKey());
flagsEnumGroup.InitDescription(configKey.GetLocaleKey("Description").AsModLocaleKey(Mod));
yield return flagsEnumGroup;

var flagsGrouping = groupKeys.Concat([configKey.FullId + ".Flags"]).ToArray();
Expand Down
7 changes: 6 additions & 1 deletion MonkeyLoader.Resonite.Integration/Locale/General/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"MonkeyLoader.GamePacks.Resonite.Tooltip.OpenHyperlink.WithLabel": "{label}<size=50%><br/><br/></size><b>Grund:</b> <i>{reason}</i><br/><b>URL:</b> <i>{url}</i>",

"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.Component": "Öffnet den Resonite Wiki Artikel über diese Komponente.",
"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.ProtoFlux": "Öffnet den Resonite Wiki Artikel über diese ProtoFlux Node."
"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.ProtoFlux": "Öffnet den Resonite Wiki Artikel über diese ProtoFlux Node.",

"MonkeyLoader.GamePacks.Resonite.Tooltip.ReferenceProxySource": "Greif eine Referenz zu {target}.",

"MonkeyLoader.GamePacks.Resonite.Tooltip.SlotRecord.Generic": "Greif eine Referenz zum Slot {target}, oder ziehe andere Slots hierher, um sie unter diesem einzuhängen, wobei ihre globale Position erhalten bleibt.",
"MonkeyLoader.GamePacks.Resonite.Tooltip.SlotRecord.Inspector": "Öffnet diesen Slot im Inspektor, greif eine Referenz zu ihm, oder ziehe andere Slots hierher, um sie unter diesem einzuhängen, wobei ihre globale Position erhalten bleibt."
}
}
7 changes: 6 additions & 1 deletion MonkeyLoader.Resonite.Integration/Locale/General/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
"MonkeyLoader.GamePacks.Resonite.Tooltip.OpenHyperlink.WithLabel": "{label}<size=50%><br/><br/></size><b>Reason:</b> <i>{reason}</i><br/><b>URL:</b> <i>{url}</i>",

"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.Component": "Opens the Resonite Wiki article about this Component.",
"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.ProtoFlux": "Opens the Resonite Wiki article about this ProtoFlux node."
"MonkeyLoader.GamePacks.Resonite.Tooltip.WikiHyperlink.ProtoFlux": "Opens the Resonite Wiki article about this ProtoFlux node.",

"MonkeyLoader.GamePacks.Resonite.Tooltip.ReferenceProxySource": "Grab a reference to {target}.",

"MonkeyLoader.GamePacks.Resonite.Tooltip.SlotRecord.Generic": "Grab a reference to the slot {target}, or drag'n'drop other slots onto here to parent them to it while preserving their global position.",
"MonkeyLoader.GamePacks.Resonite.Tooltip.SlotRecord.Inspector": "Opens this slot in the inspector, grab a reference to it, or drag'n'drop other slots onto here to parent them to this slot while preserving their global position."
}
}
145 changes: 92 additions & 53 deletions MonkeyLoader.Resonite.Integration/LocaleExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
using Elements.Core;
using FrooxEngine;
using MonkeyLoader.Configuration;
using MonkeyLoader.Meta;
using MonkeyLoader.Resonite.Locale;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using LocaleResourceData = Elements.Assets.LocaleResource;

#pragma warning disable CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)

namespace MonkeyLoader.Resonite
{
/// <summary>
Expand Down Expand Up @@ -41,6 +39,62 @@ public static class LocaleExtensions
/// </summary>
public static LocaleResourceData FallbackLocale { get; private set; } = new();

/// <summary>
/// Uses this string as the <paramref name="key"/> to create a <see cref="LocaleString"/> using the other arguments,
/// which <see cref="IsModLocaleString">is indicated to be from a mod</see>.
/// </summary>
/// <param name="identifiable"><para>
/// The <see cref="IIdentifiable"/> used to indicate that the resulting
/// <see cref="LocaleString"/> <see cref="IsModLocaleString">is from a mod</see>.
/// </para><para>
/// Typically, this should be the <see cref="Mod"/> that this method is being called by,
/// but its children like <see cref="IMonkey">Monkeys</see>, or any config elements
/// (<see cref="Config"/>/<see cref="ConfigSection"/>/<see cref="DefiningConfigKey{T}"/>) work too.
/// </para></param>
/// <param name="key">The locale key to use.</param>
/// <param name="argName">The name of the single argument used to format the locale message.</param>
/// <param name="argField">The value of the single argument used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, string argName, object argField)
=> key.AsLocaleKey((argName, argField), (ModLocaleStringIndicatorArgumentName, identifiable.GetMod()));

/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="argName">The name of the single argument used to format the locale message.</param>
/// <param name="argField">The value of the single argument used to format the locale message.</param>
/// <inheritdoc cref="AsModLocaleKey(string, IIdentifiable, string, object)"/>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, string format, string argName, object argField)
=> key.AsLocaleKey(format, (argName, argField), (ModLocaleStringIndicatorArgumentName, identifiable.GetMod()));

/// <param name="arguments">The arguments used to format the locale message.</param>
/// <inheritdoc cref="AsModLocaleKey(string, IIdentifiable, string, object)"/>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, params (string, object)[] arguments)
=> key.AsLocaleKey(arguments.AddModIndicator(identifiable));

/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="arguments">The arguments used to format the locale message.</param>
/// <inheritdoc cref="AsModLocaleKey(string, IIdentifiable, string, object)"/>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, string format, params (string, object)[] arguments)
=> key.AsLocaleKey(format, arguments.AddModIndicator(identifiable));

/// <param name="continuous">Whether to assign the locale message once or continuously.</param>
/// <param name="arguments">
/// The arguments used to format the locale message.<br/>
/// Note that <see cref="ModLocaleStringIndicatorArgumentName">mod indicator</see> will be added to this.
/// </param>
/// <inheritdoc cref="AsModLocaleKey(string, IIdentifiable, string, object)"/>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, bool continuous, Dictionary<string, object>? arguments = null)
=> key.AsLocaleKey(continuous, arguments.AddModIndicator(identifiable));

/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="continuous">Whether to assign the locale message once or continuously.</param>
/// <param name="arguments">
/// The arguments used to format the locale message.<br/>
/// Note that <see cref="ModLocaleStringIndicatorArgumentName">mod indicator</see> will be added to this.
/// </param>
/// <inheritdoc cref="AsModLocaleKey(string, IIdentifiable, string, object)"/>
public static LocaleString AsModLocaleKey(this string key, IIdentifiable identifiable, string? format = null, bool continuous = true, Dictionary<string, object>? arguments = null)
=> key.AsLocaleKey(format!, continuous, arguments.AddModIndicator(identifiable));

/// <summary>
/// Exports the fallback <see cref="Elements.Assets.LocaleData">locale
/// data</see> of this mod into a json file.
Expand Down Expand Up @@ -154,76 +208,59 @@ public static string GetLocaleKey(this IIdentifiable identifiable, string key)

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// as the key to create a <see cref="LocaleString"/> using the other arguments,
/// which <see cref="IsModLocaleString">is indicated to be from a mod</see>.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="identifiable"><para>
/// The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix for the <paramref name="key"/>.
/// </para><para>
/// Typically, this should be the <see cref="Mod"/> that this method is being called by,
/// but its children like <see cref="IMonkey">Monkeys</see>, or any config elements
/// (<see cref="Config"/>/<see cref="ConfigSection"/>/<see cref="DefiningConfigKey{T}"/>) work too.
/// </para></param>
/// <param name="key">The locale key fragment to prefix.</param>
/// <param name="argName">The name of the single argument used to format the locale message.</param>
/// <param name="argField">The value of the single argument used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string argName, object argField)
=> identifiable.GetLocaleKey(key).AsLocaleKey((argName, argField), (ModLocaleStringIndicatorArgumentName, identifiable.GetMod()));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, argName, argField);

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="argName">The name of the single argument used to format the locale message.</param>
/// <param name="argField">The value of the single argument used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
/// <inheritdoc cref="GetLocaleString(IIdentifiable, string, string, object)"/>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, string argName, object argField)
=> identifiable.GetLocaleKey(key).AsLocaleKey(format, (argName, argField), (ModLocaleStringIndicatorArgumentName, identifiable.GetMod()));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, format, argName, argField);

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="arguments">The arguments used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
/// <inheritdoc cref="GetLocaleString(IIdentifiable, string, string, object)"/>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, params (string, object)[] arguments)
=> identifiable.GetLocaleKey(key).AsLocaleKey(arguments.AddModIndicator(identifiable));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, arguments);

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="arguments">The arguments used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
/// <inheritdoc cref="GetLocaleString(IIdentifiable, string, string, object)"/>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string format, params (string, object)[] arguments)
=> identifiable.GetLocaleKey(key).AsLocaleKey(format, arguments.AddModIndicator(identifiable));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, format, arguments);

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="continuous">Whether to assign the locale message once or continuously.</param>
/// <param name="arguments">The arguments used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
/// <param name="arguments">
/// The arguments used to format the locale message.<br/>
/// Note that <see cref="ModLocaleStringIndicatorArgumentName">mod indicator</see> will be added to this.
/// </param>
/// <inheritdoc cref="GetLocaleString(IIdentifiable, string, string, object)"/>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, bool continuous, Dictionary<string, object>? arguments = null)
=> identifiable.GetLocaleKey(key).AsLocaleKey(continuous, arguments.AddModIndicator(identifiable));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, continuous, arguments);

/// <summary>
/// Uses <c><paramref name="identifiable"/>.<see cref="GetLocaleKey">GetLocaleKey</see>(<paramref name="key"/>)</c>
/// as the key to create a <see cref="LocaleString"/> using the other arguments.
/// </summary>
/// <param name="identifiable">The <see cref="IIdentifiable"/> whose <see cref="IIdentifiable.FullId">FullId</see> to use as a prefix.</param>
/// <param name="key">The locale key to prefix.</param>
/// <param name="format">An additional format string to insert the locale message into.</param>
/// <param name="continuous">Whether to assign the locale message once or continuously.</param>
/// <param name="arguments">The arguments used to format the locale message.</param>
/// <returns>The <see cref="IsModLocaleString">Mod</see>-<see cref="LocaleString"/> created from the key with the arguments.</returns>
/// <param name="arguments">
/// The arguments used to format the locale message.<br/>
/// Note that <see cref="ModLocaleStringIndicatorArgumentName">mod indicator</see> will be added to this.
/// </param>
/// <inheritdoc cref="GetLocaleString(IIdentifiable, string, string, object)"/>
public static LocaleString GetLocaleString(this IIdentifiable identifiable, string key, string? format = null, bool continuous = true, Dictionary<string, object>? arguments = null)
=> identifiable.GetLocaleKey(key).AsLocaleKey(format!, continuous, arguments.AddModIndicator(identifiable));
=> identifiable.GetLocaleKey(key).AsModLocaleKey(identifiable, format!, continuous, arguments);

/// <summary>
/// Gets the formatted, localized message of the given locale <paramref name="key"/>
Expand Down Expand Up @@ -370,4 +407,6 @@ private static Dictionary<string, object> AddModIndicator(this Dictionary<string
private static string GetMod(this IIdentifiable identifiable)
=> (identifiable.TryFindNearestParent<Mod>(out var mod) ? mod : EngineInitHook.Mod).Id;
}
}
}

#pragma warning restore CS1573 // Parameter has no matching param tag in the XML comment (but other parameters do)
Loading
Loading