Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lua 节 #12

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 21 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
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "docs/extra_cmcc/cmcc"]
path = docs/extra_cmcc/cmcc
url = https://github.com/ForkKILLET/CelesteMapperCooperationInChina
[submodule "docs/extra/cmcc/remote"]
path = docs/extra/cmcc/remote
url = https://github.com/ForkKILLET/CelesteMapperCooperationInChina.git
16 changes: 8 additions & 8 deletions docs/advanced/cross_mod_interactions.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public static class MyCelesteModExports
// 添加于 1.0.0 版本
public static void LogStuff() => Logger.Log(LogLevel.Info, "MyCelesteMod", "Someone is calling this method!");
// 添加于 1.0.0 版本
public static void LogNumber(int number) => Logger.Log(LogLevel.Info, "MyCelesteMod", $"Number is {number}!");
// 添加于 1.0.0 版本
public static bool TryDoubleIfEven(int number, out int? doubledNumber)
{
if (number % 2 == 0)
Expand Down Expand Up @@ -138,11 +140,12 @@ public static class MyCelesteModAPI

// 如果没有返回值, 也就是返回值是 void 则使用 Action
public static Action LogStuff;
public static Action<int> LogNumber;

// 如果导出的方法参数中有 out 或 ref 需要定义自定义委托类型以进行导入
// Func 并不支持参数中带有 out 或 ref 的情况
public static TryDoubleIfEvenDelegate TryDoubleIfEven;
// 如果导出的方法参数中有 in, out 或 ref 需要定义自定义委托类型以进行导入
// Func 并不支持参数中带有 in, out 或 ref 的情况
public delegate bool TryDoubleIfEvenDelegate(int number, out int? doubledNumber);
public static TryDoubleIfEvenDelegate TryDoubleIfEven;
}
```

Expand All @@ -166,11 +169,9 @@ if (MyCelesteModAPI.MultiplyByTwo(myNumber) > 400)
MyCelesteModAPI.LogStuff();
}

int myDoubledNumber;

if (MyCelesteModAPI.TryDoubleIfEven(myNumber, out int? doubledNumber))
{
myDoubledNumber = doubledNumber;
MyCelesteModAPI.LogNumber(doubledNumber);
}
```

Expand Down Expand Up @@ -224,9 +225,8 @@ Everest 会将所有 Code Mod 的程序集使用 MonoMod 进行 patch 处理后

- GravityHelper.GravityHelper.dll
- ExtendedVariantMode.ExtendedVariantMode.dll
` FrostHelper.FrostTempleHelper.dll
- FrostHelper.FrostTempleHelper.dll

我们填写目标 Mod 在 `Cache` 中名称的前半段就行.

### lib-stripped

Expand Down
2 changes: 1 addition & 1 deletion docs/coding_setup/preference.md → docs/arc/preference.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

```
!!! note
这个文件是 XML 格式的, 如果你不熟悉 XML 的话你可以到[这里](../other/xml-speedrun.md)简单看一下, 免得你不知道我们讨论的东西都是什么
这个文件是 XML 格式的, 如果你不熟悉 XML 的话你可以到[这里](../extra/xml/xml_speedrun.md)简单看一下, 免得你不知道我们讨论的东西都是什么

其中我们只需要关注里面的 `PropertyGroup` 以及 `ItemGroup` 节点
`PropertyGroup` 节点定义了这个项目有哪些属性, 比如项目框架版本, 语言版本, 程序集昵称等
Expand Down
40 changes: 11 additions & 29 deletions docs/basics/session_settings_savedata.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Settings, 顾名思义就是选项的意思. Everest 为我们封装了一个非
在此之前, 我们先保存一下我们的 `EverestModule` 实例以方便我们访问它的实例(Everest 会确保它是单例的):

```cs
public class MyCelesteModModule : EverestModule
public sealed class MyCelesteModModule : EverestModule
{
public static MyCelesteModModule Instance { get; private set; }

Expand All @@ -33,7 +33,7 @@ public class MyCelesteModModule : EverestModule
然后新建一个名字最好以 mod 开头, `Settings` 结尾的 `MyCelesteModSettings` 类并继承 `EverestModuleSettings`:

```cs
public class MyCelesteModSettings : EverestModuleSettings
public sealed class MyCelesteModSettings : EverestModuleSettings
{

}
Expand All @@ -42,7 +42,7 @@ public class MyCelesteModSettings : EverestModuleSettings
然后在 module 类里这样注册这个类:

```cs hl_lines="5-6"
public class MyCelesteModModule : EverestModule
public sealed class MyCelesteModModule : EverestModule
{
public static MyCelesteModModule Instance { get; private set; }

Expand All @@ -63,7 +63,7 @@ public class MyCelesteModModule : EverestModule
现在, 我们向选项中新加一条**公开**的 bool 类型的属性:

```cs
public class MyCelesteModSettings : EverestModuleSettings
public sealed class MyCelesteModSettings : EverestModuleSettings
{
public bool AnInterestingSwitch { get; set; }
}
Expand All @@ -78,7 +78,7 @@ public class MyCelesteModSettings : EverestModuleSettings
除此之外 Everest 还支持枚举, 字符串和数字, 它们分别会生成这样的选项:

```cs
public class MyCelesteModSettings : EverestModuleSettings
public sealed class MyCelesteModSettings : EverestModuleSettings
{
public bool AnInterestingSwitch { get; set; }

Expand Down Expand Up @@ -126,7 +126,7 @@ public class MyCelesteModSettings : EverestModuleSettings
在这里, 我们需要的本地化键名是 `modoptions_{类名}_{属性名}`, 例如如下类:

```cs
public class MyCelesteModSettings : EverestModuleSettings
public sealed class MyCelesteModSettings : EverestModuleSettings
{
public bool EnableFunnyThing { get; set; }
}
Expand Down Expand Up @@ -201,17 +201,13 @@ Session 是一个蔚蓝中保存数据的概念, 它用于保存 "保存并退
与 Settings 相同, 我们需要先创建一个继承于 `EverestModuleSession` 的类, 然后在模块类中声明它:

```cs title="MyCelesteModSession.cs"
namespace Celeste.Mod.MyCelesteMod;

public class MyCelesteModSession : EverestModuleSession
public sealed class MyCelesteModSession : EverestModuleSession
{
}
```

```cs title="MyCelesteModModule.cs"
namespace Celeste.Mod.MyCelesteMod;

public class MyCelesteModModule : EverestModule
public sealed class MyCelesteModModule : EverestModule
{
public static MyCelesteModModule Instance { get; private set; }

Expand Down Expand Up @@ -239,19 +235,13 @@ public class MyCelesteModModule : EverestModule
退出了游戏, 再次进入时你会发现重生点是新的, 而 `PassByRefill` 的冲刺数又变回 `1` 了, 所以接下来我们尝试通过 `Session` 来修正这个错误.

```cs title="MyCelesteModSession.cs"
namespace Celeste.Mod.MyCelesteMod;

public class MyCelesteModSession : EverestModuleSession
public sealed class MyCelesteModSession : EverestModuleSession
{
public Dictionary<string, int> RoomIdToPassByRefillDashes = new(); // 我们将记录每个房间名对应的PassByRefill的冲刺数
}
```

```cs title="SetPassByRefillDashesTrigger.cs"
using Celeste.Mod.Entities;

namespace MyCelesteMod;

[CustomEntity("MyCelesteMod/SetPassByRefillDashesTrigger")]
public class SetPassByRefillDashesTrigger : Trigger
{
Expand All @@ -272,10 +262,6 @@ public class SetPassByRefillDashesTrigger : Trigger
```

```cs title="PassByRefill.cs"
using Celeste.Mod.Entities;

namespace MyCelesteMod;

[CustomEntity("MyCelesteMod/PassByRefill")]
public class PassByRefill : Entity
{
Expand Down Expand Up @@ -321,17 +307,13 @@ public class PassByRefill : Entity
使用它与使用 `Session` 极其相似:

```cs title="MyCelesteModSaveData.cs"
namespace Celeste.Mod.MyCelesteMod;

public class MyCelesteModSaveData : EverestModuleSaveData
public sealed class MyCelesteModSaveData : EverestModuleSaveData
{
}
```

```cs title="MyCelesteModModule.cs"
namespace Celeste.Mod.MyCelesteMod;

public class MyCelesteModModule : EverestModule
public sealed class MyCelesteModModule : EverestModule
{
public static MyCelesteModModule Instance { get; private set; }

Expand Down
19 changes: 9 additions & 10 deletions docs/coding_challenges/simple_entity.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
那么你应该会写出如下的代码:

```cs title="PassByRefill.cs"
namespace MyCelesteMod;

public class PassByRefill : Entity
{

Expand Down Expand Up @@ -60,8 +58,10 @@ public PassByRefill(Vector2 position, Vector2 size, int dashes)
接下来, 我们需要声明一个特殊的构造函数, 以让 Everest 反射调用并使得我们的实体可以正常获取地图的数据:
```cs title="PassByRefill.cs"
public PassByRefill(EntityData data, Vector2 offset)
: this(data.Position + offset, new Vector2(data.Width, data.Height), data.Int("dashes"))
{ }
: this(data.Position + offset, new Vector2(data.Width, data.Height), data.Int("dashes"))
{

}
```
在这里, `EntityData data` 储存了作图软件保存的相关数据, 我们要提取它们很简单.
比如说我们要提取一个名为 `dashes` 的 `int` 类型的数据, 我们就简单地调用它的方法 `Int(string name)`,
Expand All @@ -83,7 +83,8 @@ public PassByRefill(EntityData data, Vector2 offset)
[CustomEntity("MyCelesteMod/PassByRefill")]
public class PassByRefill : Entity
{
......
// ......
}
```
在这里 "名称 ID" 我们一般推荐以 "{Mod名}/该实体类名" 进行命名, 就像这里一样, Mod 名为 `MyCelesteMod`, 类名为 `PassByRefill`, 实体 "名称 ID" 就是 `MyCelesteMod/PassByRefill`. 这里我建议你记住它, 待会我们会在作图软件配置的时候用到.

Expand Down Expand Up @@ -243,10 +244,6 @@ Draw.Rect(Position, Width, Height, c);

如果你遇到了困难, 你可以对比一下最终的代码:
```cs title="PassByRefill.cs"
using Celeste.Mod.Entities;

namespace MyCelesteMod;

[CustomEntity("MyCelesteMod/PassByRefill")]
public class PassByRefill : Entity
{
Expand All @@ -262,7 +259,9 @@ public class PassByRefill : Entity

public PassByRefill(EntityData data, Vector2 offset)
: this(data.Position + offset, new Vector2(data.Width, data.Height), data.Int("dashes"))
{ }
{

}

public override void Update()
{
Expand Down
12 changes: 9 additions & 3 deletions docs/coding_challenges/simple_texturing.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

public PassByRefill(EntityData data, Vector2 offset)
: this(data.Position + offset, data.Int("dashes"))
{ }
{

}
```
=== "Before"
```cs title="PassByRefill.cs"
Expand All @@ -42,7 +44,9 @@

public PassByRefill(EntityData data, Vector2 offset)
: this(data.Position + offset, new Vector2(data.Width, data.Height), data.Int("dashes"))
{ }
{

}
```

!!! info
Expand Down Expand Up @@ -108,7 +112,9 @@ public class PassByRefill : Entity

public PassByRefill(EntityData data, Vector2 offset)
: this(data.Position + offset, data.Int("dashes"))
{ }
{

}

public override void Update()
{
Expand Down
4 changes: 0 additions & 4 deletions docs/coding_challenges/simple_trigger.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,6 @@ foreach(var refill in refills)

最后, 你的代码应该总体上是这个样子:
```cs title="SetPassByRefillDashesTrigger.cs"
using Celeste.Mod.Entities;

namespace MyCelesteMod;

[CustomEntity("MyCelesteMod/SetPassByRefillDashesTrigger")]
public class SetPassByRefillDashesTrigger : Trigger
{
Expand Down
Loading