Skip to content

Commit 4a44252

Browse files
committed
up 大部分重构核心
1 parent c24dfd6 commit 4a44252

84 files changed

Lines changed: 1483 additions & 1711 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ColorMC.Core/Chunk/ChunkMca.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,16 +187,16 @@ await Parallel.ForAsync(0, data.Pos.Length, async (a, cancel) =>
187187
//获取区块位置
188188
if (nbt!.TryGet("xPos") is NbtInt value)
189189
{
190-
nbt.X = value.Value;
190+
nbt.X = value.ValueInt;
191191
}
192192
if (nbt.TryGet("zPos") is NbtInt value1)
193193
{
194-
nbt.Z = value1.Value;
194+
nbt.Z = value1.ValueInt;
195195
}
196196
if (nbt.TryGet("Position") is NbtIntArray value2)
197197
{
198-
nbt.X = value2.Value[0];
199-
nbt.Z = value2.Value[1];
198+
nbt.X = value2.ValueIntArray[0];
199+
nbt.Z = value2.ValueIntArray[1];
200200
}
201201

202202
list1[a] = nbt;

src/ColorMC.Core/CoreMain.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ public static class ColorMCCore
3333
/// <returns>是否同意</returns>
3434
public delegate Task<bool> Request(string text);
3535
/// <summary>
36-
/// 压缩包更新
37-
/// </summary>
38-
/// <param name="text">名字</param>
39-
/// <param name="size">目前进度</param>
40-
/// <param name="all">总进度</param>
41-
public delegate void ZipUpdate(string text, int size, int all);
42-
/// <summary>
4336
/// 请求是否运行程序
4437
/// </summary>
4538
/// <param name="pre">是否为运行前启动</param>
@@ -59,11 +52,6 @@ public static class ColorMCCore
5952
/// <summary>
6053
/// 没有Java
6154
/// </summary>
62-
public delegate void NoJava(int version);
63-
/// <summary>
64-
/// Java解压
65-
/// </summary>
66-
public delegate void JavaUnzip();
6755
/// <summary>
6856
/// 登录失败是否继续运行
6957
/// </summary>
@@ -133,7 +121,7 @@ public static class ColorMCCore
133121
/// <summary>
134122
/// 启动器核心参数
135123
/// </summary>
136-
internal static CoreInitArg CoreArg;
124+
internal static CoreInitObj CoreArg;
137125

138126
/// <summary>
139127
/// 游戏窗口句柄
@@ -148,7 +136,7 @@ public static class ColorMCCore
148136
/// 初始化阶段1
149137
/// </summary>
150138
/// <param name="dir">运行的路径</param>
151-
public static void Init(CoreInitArg arg)
139+
public static void Init(CoreInitObj arg)
152140
{
153141
if (string.IsNullOrWhiteSpace(arg.Local))
154142
{

src/ColorMC.Core/Game/GameArg.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ private static async Task<JvmArgRes> MakeJvmArgAsync(this GameSettingObj obj, Lo
545545
jvm.Add($"-Dcolormc.game.dir={obj.GetGamePath()}");
546546

547547
return new JvmArgRes
548-
{
548+
{
549549
Args = jvm,
550550
Asm = useasm
551551
};
@@ -775,7 +775,7 @@ await Task.Run(async () =>
775775
}
776776
if (res2 == null)
777777
{
778-
res2 = await obj.BuildForgeAsync()
778+
res2 = await obj.BuildForgeAsync()
779779
?? throw new LaunchException(LaunchError.LostLoaderFile);
780780
}
781781
loader = res2.Loaders;
@@ -825,7 +825,7 @@ await Task.Run(async () =>
825825
{
826826
return;
827827
}
828-
var res1 = await GameDownloadHelper.DecodeLoaderJarAsync(obj, obj.GetGameLoaderFile(), cancel)
828+
var res1 = await GameDownloadHelper.DecodeLoaderJarAsync(obj, obj.GetGameLoaderFile(), cancel)
829829
?? throw new LaunchException(LaunchError.LostLoaderFile);
830830
loader = res1.List?.ToList();
831831
break;
@@ -891,8 +891,11 @@ await Task.Run(async () =>
891891
if (assets == null)
892892
{
893893
//不存在json文件
894-
var res = await GameAPI.GetAssetsAsync(game.AssetIndex.Url)
895-
?? throw new LaunchException(LaunchError.LostAssetsFile, data: game.AssetIndex.Id);
894+
using var res = await GameAPI.GetAssetsAsync(game.AssetIndex.Url);
895+
if (res == null || res.Assets == null)
896+
{
897+
throw new LaunchException(LaunchError.LostAssetsFile, data: game.AssetIndex.Id);
898+
}
896899
assets = res.Assets;
897900
game.AddIndex(res.Text);
898901
}
@@ -945,8 +948,11 @@ await Task.Run(async () =>
945948
var assets = item.AssetIndex.GetIndex();
946949
if (assets == null)
947950
{
948-
var res = await GameAPI.GetAssetsAsync(item.AssetIndex.Url)
949-
?? throw new LaunchException(LaunchError.LostAssetsFile, data: item.AssetIndex.Id);
951+
using var res = await GameAPI.GetAssetsAsync(item.AssetIndex.Url);
952+
if (res == null || res.Assets == null)
953+
{
954+
throw new LaunchException(LaunchError.LostAssetsFile, data: item.AssetIndex.Id);
955+
}
950956
assets = res.Assets;
951957
item.AddIndex(res.Text);
952958
}

src/ColorMC.Core/Game/GameAuth.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using ColorMC.Core.GuiHandel;
12
using ColorMC.Core.Net.Apis;
23
using ColorMC.Core.Net.Login;
34
using ColorMC.Core.Objs;
@@ -16,7 +17,7 @@ public static class GameAuth
1617
/// </summary>
1718
/// <param name="loginOAuth">登录参数</param>
1819
/// <returns>登录状态</returns>
19-
public static async Task<LoginObj?> LoginOAuthAsync(ILoginOAuth loginOAuth)
20+
public static async Task<LoginObj?> LoginOAuthAsync(ILoginOAuthGui loginOAuth)
2021
{
2122
//获取登录码
2223
var res1 = await OAuthApi.GetCodeAsync(loginOAuth.Token);

src/ColorMC.Core/Game/GameLaunch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Diagnostics;
22
using ColorMC.Core.Config;
33
using ColorMC.Core.Downloader;
4+
using ColorMC.Core.Game;
45
using ColorMC.Core.Helpers;
56
using ColorMC.Core.LaunchPath;
67
using ColorMC.Core.Objs;

src/ColorMC.Core/Game/GameSaves.cs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Concurrent;
2+
using ColorMC.Core.GuiHandel;
23
using ColorMC.Core.Helpers;
34
using ColorMC.Core.LaunchPath;
45
using ColorMC.Core.Nbt;
@@ -172,26 +173,22 @@ public static async Task BackupAsync(this SaveObj world)
172173
/// <param name="obj">游戏实例</param>
173174
/// <param name="arg">参数</param>
174175
/// <returns>是否成功还原</returns>
175-
public static async Task<bool> UnzipBackupWorldAsync(this GameSettingObj obj, UnzipBackupWorldArg arg)
176+
public static async Task<bool> UnzipBackupWorldAsync(this GameSettingObj obj, string file, IZipGui? gui)
176177
{
177-
var local = Path.Combine(obj.GetSavesPath(), Path.GetFileName(arg.File));
178+
var local = Path.Combine(obj.GetSavesPath(), Path.GetFileName(file));
178179
if (Directory.Exists(local))
179180
{
180-
await PathHelper.DeleteFilesAsync(new DeleteFilesArg
181-
{
182-
Local = local,
183-
Request = arg.Request
184-
});
181+
await PathHelper.MoveToTrashAsync(local);
185182
}
186183
try
187184
{
188-
await new ZipProcess().UnzipAsync(local, arg.File,
189-
PathHelper.OpenRead(arg.File)!);
185+
await new ZipProcess(gui).UnzipAsync(local, file,
186+
PathHelper.OpenRead(file)!);
190187
return true;
191188
}
192189
catch (Exception e)
193190
{
194-
ColorMCCore.OnError(new GameSaveRestoreErrorEventArgs(obj, arg.File, e));
191+
ColorMCCore.OnError(new GameSaveRestoreErrorEventArgs(obj, file, e));
195192
return false;
196193
}
197194
}
@@ -226,16 +223,16 @@ await PathHelper.DeleteFilesAsync(new DeleteFilesArg
226223

227224
//读数据
228225
var tag1 = tag.TryGet<NbtCompound>("Data")!;
229-
obj.LastPlayed = tag1.TryGet<NbtLong>("LastPlayed")!.Value;
226+
obj.LastPlayed = tag1.TryGet<NbtLong>("LastPlayed")!.ValueLong;
230227
if (tag1.TryGet<NbtLong>("RandomSeed") is { } seed)
231228
{
232-
obj.RandomSeed = seed.Value;
229+
obj.RandomSeed = seed.ValueLong;
233230
}
234231
if (tag1.TryGet<NbtCompound>("WorldGenSettings") is { } setting)
235232
{
236233
if (setting.TryGet<NbtLong>("seed") is { } seed1)
237234
{
238-
obj.RandomSeed = seed1.Value;
235+
obj.RandomSeed = seed1.ValueLong;
239236
}
240237
if (setting.TryGet<NbtCompound>("dimensions")?
241238
.TryGet<NbtCompound>("minecraft:overworld")?
@@ -250,9 +247,9 @@ await PathHelper.DeleteFilesAsync(new DeleteFilesArg
250247
obj.GeneratorName = "minecraft:" + name1.Value;
251248
}
252249

253-
obj.GameType = tag1.TryGet<NbtInt>("GameType")!.Value;
254-
obj.Hardcore = tag1.TryGet<NbtByte>("hardcore")!.Value;
255-
obj.Difficulty = tag1.TryGet<NbtByte>("Difficulty")!.Value;
250+
obj.GameType = tag1.TryGet<NbtInt>("GameType")!.ValueInt;
251+
obj.Hardcore = tag1.TryGet<NbtByte>("hardcore")!.ValueByte;
252+
obj.Difficulty = tag1.TryGet<NbtByte>("Difficulty")!.ValueByte;
256253
obj.LevelName = tag1.TryGet<NbtString>("LevelName")!.Value;
257254

258255
var icon = dir.GetFiles().Where(a => a.Name == Names.NameIconFile).FirstOrDefault();

src/ColorMC.Core/Game/GameSchematic.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ private static async Task<SchematicObj> ReadNBTAsync(string file)
153153
Name = Path.GetFileName(file),
154154
Broken = false,
155155
Local = file,
156-
Width = (size[0] as NbtInt)!.Value,
157-
Height = (size[1] as NbtInt)!.Value,
158-
Length = (size[2] as NbtInt)!.Value,
156+
Width = (size[0] as NbtInt)!.ValueInt,
157+
Height = (size[1] as NbtInt)!.ValueInt,
158+
Length = (size[2] as NbtInt)!.ValueInt,
159159
Type = SchematicType.Create
160160
};
161161

@@ -181,9 +181,9 @@ private static async Task<SchematicObj> ReadSchematicAsync(string file)
181181
return new()
182182
{
183183
Name = Path.GetFileName(file),
184-
Height = tag.TryGet<NbtShort>("Height")!.Value,
185-
Length = tag.TryGet<NbtShort>("Length")!.Value,
186-
Width = tag.TryGet<NbtShort>("Width")!.Value,
184+
Height = tag.TryGet<NbtShort>("Height")!.ValueShort,
185+
Length = tag.TryGet<NbtShort>("Length")!.ValueShort,
186+
Width = tag.TryGet<NbtShort>("Width")!.ValueShort,
187187
Broken = false,
188188
Local = file
189189
};
@@ -220,9 +220,9 @@ private static async Task<SchematicObj> ReadLitematicAsync(string file)
220220
var pos = com1.TryGet<NbtCompound>("EnclosingSize")!;
221221
if (pos != null)
222222
{
223-
item.Height = pos.TryGet<NbtInt>("y")!.Value;
224-
item.Length = pos.TryGet<NbtInt>("x")!.Value;
225-
item.Width = pos.TryGet<NbtInt>("z")!.Value;
223+
item.Height = pos.TryGet<NbtInt>("y")!.ValueInt;
224+
item.Length = pos.TryGet<NbtInt>("x")!.ValueInt;
225+
item.Width = pos.TryGet<NbtInt>("z")!.ValueInt;
226226
}
227227

228228
return item;

src/ColorMC.Core/Game/GameServers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private static async Task SaveServerAsync(this GameSettingObj game, IEnumerable<
143143
tag1.Add("icon", new NbtString() { Value = item.Icon });
144144
}
145145
tag1.Add("acceptTextures", new NbtByte()
146-
{ Value = item.AcceptTextures ? (byte)1 : (byte)0 });
146+
{ ValueByte = item.AcceptTextures ? (byte)1 : (byte)0 });
147147
list1.Add(tag1);
148148
}
149149

@@ -163,7 +163,7 @@ private static ServerInfoObj ToServerInfo(NbtCompound tag)
163163
Name = tag.TryGet<NbtString>("name")!.Value,
164164
IP = tag.TryGet<NbtString>("ip")!.Value,
165165
Icon = (tag.TryGet("icon") as NbtString)?.Value,
166-
AcceptTextures = tag.TryGet("acceptTextures") is NbtByte { Value: 1 }
166+
AcceptTextures = tag.TryGet("acceptTextures") is NbtByte { ValueByte: 1 }
167167
};
168168

169169
return info;

0 commit comments

Comments
 (0)