Skip to content

Commit 4160017

Browse files
committed
chore(release): merge dev into main for v0.0.66
2 parents d931b06 + 824a50e commit 4160017

16 files changed

Lines changed: 311 additions & 40 deletions

Const.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class Const
1818
/// <summary>
1919
/// Assembly / manifest version string.
2020
/// </summary>
21-
public const string Version = "0.0.65";
21+
public const string Version = "0.0.66";
2222

2323
/// <summary>
2424
/// Root key for RitsuLib JSON settings under the mod’s user folder.

Docs/en/ContentAuthoringToolkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RitsuLibFramework.CreateContentPack("MyMod")
3131
.Character<MyCharacter>()
3232
.Card<MyCardPool, MyCard>()
3333
.Relic<MyRelicPool, MyRelic>()
34-
.CardKeyword("my_keyword", locKeyPrefix: "my_mod_my_keyword", iconPath: "res://MyMod/art/kw.png")
34+
.CardKeywordOwnedByLocNamespace("my_keyword", iconPath: "res://MyMod/art/kw.png")
3535
.Story<MyStory>()
3636
.Epoch<MyEpoch>()
3737
.RequireEpoch<MyCard, MyEpoch>()

Docs/en/ContentPacksAndRegistries.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RitsuLibFramework.CreateContentPack("MyMod")
3636
.Character<MyCharacter>()
3737
.Card<MyCardPool, MyCard>()
3838
.Relic<MyRelicPool, MyRelic>()
39-
.CardKeyword("brew", locKeyPrefix: "my_mod_brew")
39+
.CardKeywordOwnedByLocNamespace("brew")
4040
.Epoch<MyCharacterEpoch>()
4141
.Story<MyStory>()
4242
.RequireEpoch<MyLateCard, MyCharacterEpoch>()
@@ -219,7 +219,7 @@ var contentEntries = new IContentRegistrationEntry[]
219219

220220
var keywordEntries = new[]
221221
{
222-
KeywordRegistrationEntry.Card("brew", "my_mod_brew"),
222+
KeywordRegistrationEntry.OwnedCardByLocNamespace("MyMod", "brew"),
223223
};
224224

225225
RitsuLibFramework.CreateContentPack("MyMod")

Docs/en/LocalizationAndKeywords.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,16 +107,35 @@ Use `ModKeywordRegistry` when you want reusable keyword definitions and hover ti
107107
```csharp
108108
var keywords = RitsuLibFramework.GetKeywordRegistry("MyMod");
109109

110-
keywords.RegisterCardKeyword(
111-
id: "brew",
112-
locKeyPrefix: "my_mod_brew",
110+
keywords.RegisterCardKeywordOwnedByLocNamespace(
111+
localKeywordStem: "brew",
113112
iconPath: "res://MyMod/ui/keywords/brew.png");
114113
```
115114

116115
This creates a normalized keyword id and binds it to title / description localization keys.
117116

118117
---
119118

119+
## Automatic keyword registration (optional: CLR attributes)
120+
121+
If you already use `ModTypeDiscoveryHub.RegisterModAssembly(...)` to let RitsuLib scan your assemblies, you can declare keyword registration with CLR attributes:
122+
123+
```csharp
124+
using STS2RitsuLib.Interop.AutoRegistration;
125+
126+
[RegisterOwnedCardKeyword("brew", LocNamespace = "my_mod", IconPath = "res://MyMod/ui/keywords/brew.png")]
127+
public sealed class BrewKeywordMarker;
128+
```
129+
130+
`LocNamespace` only affects the localization namespace (the `modid` portion). The keyword stem (`brew`) participates in the default rule `<namespace>_<keyword>`, producing:
131+
132+
- `<namespace>_<keyword>.title`
133+
- `<namespace>_<keyword>.description`
134+
135+
> Compatibility note: the legacy `LocKeyPrefix` / `locKeyPrefix` historically represents the **full stem** and is easy to misread as a prefix + keyword composition, so it is now obsolete. Use `LocNamespace` for new code.
136+
137+
---
138+
120139
## Using Keywords In Code
121140

122141
Common helpers:

Docs/zh/ContentAuthoringToolkit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ RitsuLibFramework.CreateContentPack("MyMod")
3131
.Character<MyCharacter>()
3232
.Card<MyCardPool, MyCard>()
3333
.Relic<MyRelicPool, MyRelic>()
34-
.CardKeyword("my_keyword", locKeyPrefix: "my_mod_my_keyword", iconPath: "res://MyMod/art/kw.png")
34+
.CardKeywordOwnedByLocNamespace("my_keyword", iconPath: "res://MyMod/art/kw.png")
3535
.Story<MyStory>()
3636
.Epoch<MyEpoch>()
3737
.RequireEpoch<MyCard, MyEpoch>()

Docs/zh/ContentPacksAndRegistries.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ RitsuLibFramework.CreateContentPack("MyMod")
3636
.Character<MyCharacter>()
3737
.Card<MyCardPool, MyCard>()
3838
.Relic<MyRelicPool, MyRelic>()
39-
.CardKeyword("brew", locKeyPrefix: "my_mod_brew")
39+
.CardKeywordOwnedByLocNamespace("brew")
4040
.Epoch<MyCharacterEpoch>()
4141
.Story<MyStory>()
4242
.RequireEpoch<MyLateCard, MyCharacterEpoch>()
@@ -219,7 +219,7 @@ var contentEntries = new IContentRegistrationEntry[]
219219

220220
var keywordEntries = new[]
221221
{
222-
KeywordRegistrationEntry.Card("brew", "my_mod_brew"),
222+
KeywordRegistrationEntry.OwnedCardByLocNamespace("MyMod", "brew"),
223223
};
224224

225225
RitsuLibFramework.CreateContentPack("MyMod")

Docs/zh/LocalizationAndKeywords.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,35 @@ user://mod-configs/<modId>/localization
102102
```csharp
103103
var keywords = RitsuLibFramework.GetKeywordRegistry("MyMod");
104104

105-
keywords.RegisterCardKeyword(
106-
id: "brew",
107-
locKeyPrefix: "my_mod_brew",
105+
keywords.RegisterCardKeywordOwnedByLocNamespace(
106+
localKeywordStem: "brew",
108107
iconPath: "res://MyMod/ui/keywords/brew.png");
109108
```
110109

111110
注册后会生成规范化标识,并绑定标题/描述的本地化键。
112111

113112
---
114113

114+
## 自动注册关键词(可选:CLR 特性)
115+
116+
如果你已经使用 `ModTypeDiscoveryHub.RegisterModAssembly(...)` 让 RitsuLib 扫描你的程序集,也可以用特性声明关键词注册:
117+
118+
```csharp
119+
using STS2RitsuLib.Interop.AutoRegistration;
120+
121+
[RegisterOwnedCardKeyword("brew", LocNamespace = "my_mod", IconPath = "res://MyMod/ui/keywords/brew.png")]
122+
public sealed class BrewKeywordMarker;
123+
```
124+
125+
这里 `LocNamespace` 只影响本地化键的 namespace(即 `modid` 部分)。关键词 stem(`brew`)会自动参与默认生成规则:`<namespace>_<keyword>`,并形成:
126+
127+
- `<namespace>_<keyword>.title`
128+
- `<namespace>_<keyword>.description`
129+
130+
> 兼容性说明:旧字段 `LocKeyPrefix`/`locKeyPrefix` 历史上实际代表“完整 stem”,容易误解为 prefix + keyword,已标记为过时;新代码请使用 `LocNamespace`
131+
132+
---
133+
115134
## 在代码里使用关键词
116135

117136
常用辅助方法:

Interop/AutoRegistration/AttributeAutoRegistrationTypeDiscoveryContributor.cs

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,44 @@ void Append(Attribute attribute, bool inherited)
440440
ownedCardKeyword.Order,
441441
$"RegisterOwnedCardKeyword:{ownedCardKeyword.LocalKeywordStem}:{type.FullName}",
442442
nameof(RegisterOwnedCardKeywordAttribute),
443-
() => keywordRegistry.RegisterCardKeywordOwned(
444-
ValidateNonEmpty(ownedCardKeyword.LocalKeywordStem,
445-
nameof(ownedCardKeyword.LocalKeywordStem)),
446-
ownedCardKeyword.LocKeyPrefix,
447-
ownedCardKeyword.IconPath,
448-
ownedCardKeyword.CardDescriptionPlacement,
449-
ownedCardKeyword.IncludeInCardHoverTip)));
443+
() =>
444+
{
445+
var localStem = ValidateNonEmpty(ownedCardKeyword.LocalKeywordStem,
446+
nameof(ownedCardKeyword.LocalKeywordStem));
447+
448+
if (!string.IsNullOrWhiteSpace(ownedCardKeyword.LocNamespace))
449+
{
450+
keywordRegistry.RegisterCardKeywordOwnedByLocNamespace(
451+
localStem,
452+
ownedCardKeyword.LocNamespace,
453+
ownedCardKeyword.IconPath,
454+
ownedCardKeyword.CardDescriptionPlacement,
455+
ownedCardKeyword.IncludeInCardHoverTip);
456+
return;
457+
}
458+
459+
#pragma warning disable CS0618
460+
if (!string.IsNullOrWhiteSpace(ownedCardKeyword.LocKeyPrefix))
461+
{
462+
keywordRegistry.RegisterCardKeywordOwned(
463+
localStem,
464+
ownedCardKeyword.LocKeyPrefix,
465+
ownedCardKeyword.IconPath,
466+
ownedCardKeyword.CardDescriptionPlacement,
467+
ownedCardKeyword.IncludeInCardHoverTip);
468+
return;
469+
}
470+
#pragma warning restore CS0618
471+
472+
#pragma warning disable CS0618
473+
keywordRegistry.RegisterCardKeywordOwned(
474+
localStem,
475+
null,
476+
ownedCardKeyword.IconPath,
477+
ownedCardKeyword.CardDescriptionPlacement,
478+
ownedCardKeyword.IncludeInCardHoverTip);
479+
#pragma warning restore CS0618
480+
}));
450481
});
451482
break;
452483
case AutoTimelineSlotAttribute autoTimelineSlot:

Interop/AutoRegistration/RegistrationAttributes.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,17 @@ public sealed class RegisterOwnedCardKeywordAttribute(string localKeywordStem)
319319
/// </summary>
320320
public string LocalKeywordStem { get; } = localKeywordStem;
321321

322+
/// <summary>
323+
/// Optional localization namespace used to form the default <c>card_keywords</c> entry stem
324+
/// <c>"{namespace}_{keyword}"</c>.
325+
/// </summary>
326+
public string? LocNamespace { get; set; }
327+
322328
/// <summary>
323329
/// Optional explicit localization key prefix.
324330
/// </summary>
331+
[Obsolete(
332+
"Pitfall: LocKeyPrefix is NOT a prefix that affects only the modid/namespace portion. It is the full card_keywords entry stem used to form '{stem}.title' and '{stem}.description'. Prefer LocNamespace.")]
325333
public string? LocKeyPrefix { get; set; }
326334

327335
/// <summary>

Keywords/KeywordRegistrationEntry.cs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using MegaCrit.Sts2.Core.Helpers;
12
using STS2RitsuLib.Content;
23

34
namespace STS2RitsuLib.Keywords
@@ -112,6 +113,55 @@ public void Register(ModKeywordRegistry registry)
112113
/// <summary>
113114
/// <c>card_keywords</c> row with an id from <see cref="ModContentRegistry.GetQualifiedKeywordId" />.
114115
/// </summary>
116+
public static KeywordRegistrationEntry OwnedCardByLocNamespace(
117+
string modId,
118+
string localKeywordStem,
119+
string? locNamespace,
120+
string? iconPath,
121+
ModKeywordCardDescriptionPlacement cardDescriptionPlacement,
122+
bool includeInCardHoverTip)
123+
{
124+
var ns = string.IsNullOrWhiteSpace(locNamespace)
125+
? StringHelper.Slugify(modId)
126+
: locNamespace;
127+
128+
var stem = StringHelper.Slugify(ns) + "_" + StringHelper.Slugify(localKeywordStem);
129+
var id = ModContentRegistry.GetQualifiedKeywordId(modId, localKeywordStem);
130+
131+
return new(
132+
id,
133+
"card_keywords",
134+
$"{stem}.title",
135+
"card_keywords",
136+
$"{stem}.description",
137+
iconPath,
138+
cardDescriptionPlacement,
139+
includeInCardHoverTip);
140+
}
141+
142+
/// <summary>
143+
/// <c>OwnedCardByLocNamespace</c> overload with legacy hover defaults.
144+
/// </summary>
145+
public static KeywordRegistrationEntry OwnedCardByLocNamespace(
146+
string modId,
147+
string localKeywordStem,
148+
string? locNamespace = null,
149+
string? iconPath = null)
150+
{
151+
return OwnedCardByLocNamespace(
152+
modId,
153+
localKeywordStem,
154+
locNamespace,
155+
iconPath,
156+
ModKeywordCardDescriptionPlacement.None,
157+
true);
158+
}
159+
160+
/// <summary>
161+
/// <c>card_keywords</c> row with an id from <see cref="ModContentRegistry.GetQualifiedKeywordId" />.
162+
/// </summary>
163+
[Obsolete(
164+
"Pitfall: locKeyPrefix is NOT a prefix that affects only the modid/namespace portion. It is the full card_keywords entry stem used to form '{stem}.title' and '{stem}.description'. Prefer OwnedCardByLocNamespace (default stem: '<modid>_<keyword>').")]
115165
public static KeywordRegistrationEntry OwnedCard(
116166
string modId,
117167
string localKeywordStem,
@@ -135,6 +185,8 @@ public static KeywordRegistrationEntry OwnedCard(
135185
/// <summary>
136186
/// <c>OwnedCard</c> overload with legacy hover defaults.
137187
/// </summary>
188+
[Obsolete(
189+
"Pitfall: locKeyPrefix is NOT a prefix that affects only the modid/namespace portion. It is the full card_keywords entry stem used to form '{stem}.title' and '{stem}.description'. Prefer OwnedCardByLocNamespace (default stem: '<modid>_<keyword>').")]
138190
public static KeywordRegistrationEntry OwnedCard(
139191
string modId,
140192
string localKeywordStem,

0 commit comments

Comments
 (0)