-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathVaultType.cs
More file actions
113 lines (110 loc) · 4.13 KB
/
VaultType.cs
File metadata and controls
113 lines (110 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using InnoVault.GameSystem;
using System;
using System.Collections.Generic;
using Terraria.ModLoader;
namespace InnoVault
{
/// <summary>
/// 实现InnoVault的基本类型
/// </summary>
public abstract class VaultType<T> : ModType where T : VaultType<T>
{
/// <summary>
/// 是否自动加载<see cref="TypeToMod"/>,默认返回<see langword="true"/>
/// </summary>
protected virtual bool AutoMapMod => true;
/// <summary>
/// 是否自动在<see cref="ModType.Register"/>中调用<see cref="VaultTypeRegistry{T}.Register(T)"/>,默认返回<see langword="true"/>
/// </summary>
protected virtual bool AutoVaultRegistryRegister => true;
/// <summary>
/// 是否自动在<see cref="ModType.SetupContent"/>中调用<see cref="VaultTypeRegistry{T}.CompleteLoading"/>,默认返回<see langword="true"/>
/// </summary>
protected virtual bool AutoVaultRegistryFinishLoading => true;
/// <summary>
/// 所有修改的实例集合
/// </summary>
public static List<T> Instances { get; internal set; } = [];
/// <summary>
/// 从类型映射到实例
/// </summary>
public static Dictionary<Type, T> TypeToInstance { get; internal set; } = [];
/// <summary>
/// 从类型映射到Mod实例
/// </summary>
public static Dictionary<Type, Mod> TypeToMod { get; internal set; } = [];
/// <summary>
/// 按ID和类型分类的实例集合
/// </summary>
public static Dictionary<int, Dictionary<Type, T>> ByID { get; internal set; } = [];
/// <summary>
/// 所有的通用实例集合
/// </summary>
public static List<T> UniversalInstances { get; internal set; } = [];
/// <summary>
/// 程序进行防御性处理时会用到的值,如果该实例内部发生错误,则会将该值设置为大于0的值,期间不会再自动调用该实例
/// 这个值应当每帧减一,直到不再大于0
/// </summary>
public int ignoreBug = -1;
/// <summary>
/// 记录发生错误的次数,不要自行设置它
/// </summary>
public int errorCount;
/// <summary>
/// 是否加载这个实例,默认返回<see langword="true"/>
/// </summary>
/// <returns></returns>
public virtual bool CanLoad() { return true; }
/// <summary>
/// 是否进行覆盖
/// </summary>
/// <returns></returns>
public virtual bool CanOverride() {
return true;
}
/// <summary>
/// 返回该TP实体的填充名
/// </summary>
/// <param name="modName"></param>
/// <param name="name"></param>
/// <returns></returns>
public static string GetFullName(string modName, string name) => modName + "/" + name;//设置这个函数是为了防止其他地方硬编码拼接内部名
/// <summary>
/// 注册这个实例到列表中
/// </summary>
protected sealed override void Register() {
if (!CanLoad()) {
return;
}
if (AutoMapMod) {
TypeToMod[GetType()] = Mod;
}
if (AutoVaultRegistryRegister) {
VaultTypeRegistry<T>.Register((T)this);
}
VaultRegister();
}
/// <summary>
/// 如果继承了这个类,请重写这个函数以进行内容加载
/// </summary>
protected virtual void VaultRegister() {
}
/// <summary>
/// 加载内容
/// </summary>
public sealed override void SetupContent() {
if (!CanLoad()) {
return;
}
if (AutoVaultRegistryFinishLoading) {
VaultTypeRegistry<T>.CompleteLoading();
}
VaultSetup();
}
/// <summary>
/// 如果继承了这个类,请重写这个函数以进行内容加载
/// </summary>
public virtual void VaultSetup() {
}
}
}