-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathUnity.java
More file actions
211 lines (175 loc) · 6.77 KB
/
Unity.java
File metadata and controls
211 lines (175 loc) · 6.77 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package unity;
import arc.*;
import arc.scene.actions.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.*;
import mindustry.ctype.*;
import mindustry.game.EventType.*;
import mindustry.mod.*;
import mindustry.ui.dialogs.*;
import mindustry.ui.dialogs.JoinDialog.*;
import mindustry.ui.fragments.*;
import mindustry.world.blocks.environment.*;
import unity.annotations.Annotations.*;
import unity.content.*;
import unity.content.blocks.*;
import unity.gen.*;
import unity.graphics.*;
import unity.graphics.menu.*;
import unity.mod.*;
import unity.net.*;
import unity.parts.*;
import unity.ui.*;
import unity.util.*;
import unity.world.graph.*;
import static mindustry.Vars.*;
/**
* The mod's main mod class. Contains static references to other modules.
* @author Avant Team
*/
@LoadRegs("error") // Need this temporarily, so the class gets generated.
@SuppressWarnings("unchecked")
public class Unity extends Mod{
/** Whether the mod is in an asset-processing context. */
public static boolean tools = false;
/** Abstract developer build specification; dev builds allow users to have various developer accessibility. */
public static DevBuild dev;
/** Abstract music handler; will be overridden in a separate music mod. */
public static MusicHandler music;
/** Lists all the mod's classes by their canonical names. Generated at compile-time. */
@ListClasses
public static Seq<String> classes = Seq.with();
/** Lists all the mod's packages by their canonical names. Generated at compile-time. */
@ListPackages
public static Seq<String> packages = Seq.with();
/**UI**/
public static UnityUI ui= new UnityUI();
/** Default constructor for Mindustry mod loader to instantiate. */
public Unity(){
this(false);
}
/**
* Constructs the mod, and binds several functionality to the game under certain circumstances.
* @param tools Whether the mod is in an asset-processing context.
*/
public Unity(boolean tools){
Unity.tools = tools;
if(!headless){
// Load assets once they're added into `Vars.tree`.
Events.on(FileTreeInitEvent.class, e -> Core.app.post(UnitySounds::load));
// Disclaimer, because apparently we're stupid enough to need this
Events.on(ClientLoadEvent.class, e -> {
UnitySettings.init();
new DisclaimerDialog().show();
//bc they are not a contentType
ModularPartType.loadStatic();
for(var en: ModularPartType.partMap){
en.value.load();
}
for(Faction faction : Faction.all){
faction.load();
}
Graphs.load();
UnityParts.loadDoodads();
if(dev.isDev()){
Seq<Server> servers = ReflectUtils.getFieldValue(Vars.ui.join, JoinDialog.class,"servers");
boolean found = false;
for(Server s:servers){
if(s.ip.equals("mindustry.xeloboyo.art") || s.ip.equals("172.105.174.77")){
found = true;
}
}
if(!found){
Server xeloserver = new Server();
xeloserver.ip = "mindustry.xeloboyo.art";
servers.add(xeloserver);
ReflectUtils.invokeMethod(Vars.ui.join,"setupRemote");
ReflectUtils.invokeMethod(Vars.ui.join,"refreshRemote");
}
}
});
// Might break on mobile
try{
Reflect.set(MenuFragment.class, Vars.ui.menufrag, "renderer", new UnityMenuRenderer());
}catch(Exception ex){
Log.err("Failed to replace renderer", ex);
}
Events.on(FileTreeInitEvent.class, e -> Core.app.post(UnityShaders::load));
Events.on(DisposeEvent.class, e -> {
UnityShaders.dispose();
});
}else{
Events.run(Trigger.update , ()->{
if(Utils.isCrash){
throw new RuntimeException("DEATH");
}
});
}
Events.on(ContentInitEvent.class, e -> {
if(!headless){
Regions.load();
}
});
Utils.init();
try{
Class<? extends DevBuild> impl = (Class<? extends DevBuild>)Class.forName("unity.mod.DevBuildImpl", true, mods.mainLoader());
dev = impl.getDeclaredConstructor().newInstance();
Log.info("Dev build class implementation found and instantiated.");
}catch(Throwable e){
dev = new DevBuild(){};
Log.info("Dev build class implementation not found; defaulting to regular user implementation.");
}
music = new MusicHandler(){};
Core.app.post(() -> {
JSBridge.init();
JSBridge.importDefaults(JSBridge.unityScope);
});
}
@Override
public void init(){
dev.init();
music.init();
ui.init();
UnityCalls.registerPackets();;
}
@Override
public void loadContent(){
Faction.init();
UnityItems.load();
UnityStatusEffects.load();
UnityLiquids.load();
UnityBullets.load();
UnityUnitTypes.load();
KoruhBlocks.load();
YoungchaBlocks.load();
UnityParts.load();
//below has to be done after all things with faction tags are loaded.
FactionMeta.init();
UnityEntityMapping.init();
//logContent();
}
public void logContent(){
for(Faction faction : Faction.all){
Seq<Object> array = FactionMeta.getByFaction(faction, Object.class);
Log.debug("Faction @ has @ contents", faction, array.size);
}
Seq<Class<?>> ignoreDesc = Seq.with(Floor.class, Prop.class);
for(Seq<Content> content : content.getContentMap()){
for(Content c : content){
if(c.minfo.mod == null || c.minfo.mod.main != this || !(c instanceof UnlockableContent cont)) continue;
if(Core.bundle.getOrNull(cont.getContentType() + "." + cont.name + ".name") == null){
Log.debug("@ has no bundle entry for name.", cont);
}
if(
!ignoreDesc.contains(t -> t.isAssignableFrom(cont.getClass())) &&
Core.bundle.getOrNull(cont.getContentType() + "." + cont.name + ".description") == null
){
Log.debug("@ has no bundle entry for description.", cont);
}
}
}
}
}