Skip to content

Commit 0cf9547

Browse files
committed
Feature: Add framework of optional mod dependency example
1 parent b2eb71c commit 0cf9547

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

ExampleMod.csproj

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<DebugType>full</DebugType>
1919
<Optimize>false</Optimize>
2020
<OutputPath>bin\Debug\</OutputPath>
21-
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<DefineConstants>DEBUG;TRACE;一米_中文名</DefineConstants>
2222
<ErrorReport>prompt</ErrorReport>
2323
<WarningLevel>4</WarningLevel>
2424
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
@@ -56,5 +56,12 @@
5656
<HintPath>..\..\worldbox_Data\Managed\UnityEngine.UI.dll</HintPath>
5757
</Reference>
5858
</ItemGroup>
59+
<ItemGroup>
60+
<ProjectReference Include="..\Chinese_Name\Chinese_Name.csproj"/>
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Folder Include="additional_resources\name_generators\"/>
64+
<Folder Include="additional_resources\word_libraries\"/>
65+
</ItemGroup>
5966

6067
</Project>

ExampleModCode.cs

+28-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
using System.IO;
2-
using NeoModLoader.api;
3-
using ExampleMod.UI;
42
using ExampleMod.Content;
3+
using ExampleMod.UI;
4+
using NeoModLoader.api;
55
using NeoModLoader.api.attributes;
66
using NeoModLoader.General;
77

88
namespace ExampleMod;
99

10-
public class ExampleModMain : BasicMod<ExampleModMain>, IReloadable{
11-
protected override void OnModLoad(){
12-
LogInfo("Hello World!");
13-
ExampleGodPowers.init();
14-
ExampleTab.Init();
15-
ExampleTraits.Init();
16-
}
17-
public static void Called(){
18-
LogInfo("Hello World From Another!");
19-
}
20-
10+
public class ExampleModMain : BasicMod<ExampleModMain>, IReloadable
11+
{
2112
private static bool _reload_switch;
13+
2214
[Hotfixable]
2315
public void Reload()
2416
{
2517
// Reload locales when mod loaded, it's optional.
2618
// 重载模组时重新加载语言文件, 不是必需的
2719
var locale_dir = GetLocaleFilesDirectory(GetDeclaration());
28-
foreach(var file in Directory.GetFiles(locale_dir, "*.json")){
20+
foreach (var file in Directory.GetFiles(locale_dir, "*.json"))
21+
{
2922
LM.LoadLocale(Path.GetFileNameWithoutExtension(file), file);
3023
}
31-
24+
3225
// 实现了重载切换ExampleTrait的action_special_effect
3326
_reload_switch = !_reload_switch;
3427
var example_trait_to_update = AssetManager.traits.get("ExampleTrait");
@@ -40,18 +33,34 @@ public void Reload()
4033
if (pTarget != null) return false;
4134
// You can modify the method when game running. And click the reload button in the mod menu to reload the method.
4235
// 你可以在游戏运行时修改方法,然后点击mod菜单中的reload按钮来重新加载方法。
43-
ExampleModMain.LogInfo($"lambda function called");
36+
LogInfo($"lambda function called");
4437
return true;
4538
};
4639
example_trait_to_update.special_effect_interval = 1f;
4740
// 重载匿名函数示例
4841
if (!_reload_switch) example_trait_to_update.action_special_effect(null, null);
49-
42+
5043
// 将特质的效果更新即时应用于所有单位.
51-
foreach(var actor in World.world.units){
52-
if(actor!=null && actor.isAlive() && actor.hasTrait("ExampleTrait")){
44+
foreach (var actor in World.world.units)
45+
{
46+
if (actor != null && actor.isAlive() && actor.hasTrait("ExampleTrait"))
47+
{
5348
actor.setStatsDirty();
5449
}
5550
}
5651
}
52+
53+
protected override void OnModLoad()
54+
{
55+
LogInfo("Hello World!");
56+
ExampleNameGenerators.init();
57+
ExampleGodPowers.init();
58+
ExampleTab.Init();
59+
ExampleTraits.Init();
60+
}
61+
62+
public static void Called()
63+
{
64+
LogInfo("Hello World From Another!");
65+
}
5766
}

content/ExampleNameGenerators.cs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#if 一米_中文名
2+
using System.IO;
3+
using Chinese_Name;
4+
#endif
5+
6+
namespace ExampleMod.Content;
7+
8+
internal static class ExampleNameGenerators
9+
{
10+
public static void init()
11+
{
12+
#if 一米_中文名
13+
init_chinese_name_generators();
14+
#else
15+
init_vanilla_name_generators();
16+
#endif
17+
}
18+
#if 一米_中文名
19+
private static void init_chinese_name_generators()
20+
{
21+
WordLibraryManager.SubmitDirectoryToLoad(Path.Combine(ExampleModMain.Instance.GetDeclaration().FolderPath,
22+
"additional_resources/word_libraries"));
23+
CN_NameGeneratorLibrary.SubmitDirectoryToLoad(Path.Combine(ExampleModMain.Instance.GetDeclaration().FolderPath,
24+
"additional_resources/name_generators"));
25+
}
26+
#endif
27+
private static void init_vanilla_name_generators()
28+
{
29+
}
30+
}

mod.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "An example mod for NeoModLoader.",
66
"iconPath": "icon.png",
77
"Dependencies": [],
8-
"OptionalDependencies": [],
8+
"OptionalDependencies": [
9+
"一米.中文名"
10+
],
911
"IncompatibleWith": []
1012
}

0 commit comments

Comments
 (0)