Failed to make the packet.

制作数据包失败。
This commit is contained in:
Cold-Mint 2024-04-29 21:57:24 +08:00
parent 07816194cb
commit 5bdd68b61f
Signed by: Cold-Mint
GPG Key ID: C5A9BF8A98E0CE99
6 changed files with 78 additions and 7 deletions

View File

@ -121,6 +121,7 @@ public static class Config
public const string DefaultVersionName = "Default"; public const string DefaultVersionName = "Default";
public const string DataPackDirectoryName = "DataPacks"; public const string DataPackDirectoryName = "DataPacks";
public const string CacheDirectoryName = "Caches";
public const string DataBaseDirectoryName = "DataBases"; public const string DataBaseDirectoryName = "DataBases";
/// <summary> /// <summary>
@ -153,6 +154,22 @@ public static class Config
return Path.Join(GetGameDataDirectory(), DataPackDirectoryName); return Path.Join(GetGameDataDirectory(), DataPackDirectoryName);
} }
/// <summary>
/// <para>Gets the packet cache directory</para>
/// <para>获取数据包缓存目录</para>
/// </summary>
/// <param name="nameS"></param>
/// <returns></returns>
public static string GetDataPackCacheDirectory(string namespaceStr)
{
var path = Path.Join(GetGameDataDirectory(), CacheDirectoryName, DataPackDirectoryName, namespaceStr);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
return path;
}
/// <summary> /// <summary>
/// <para>Get database directory</para> /// <para>Get database directory</para>
/// <para>获取数据库目录</para> /// <para>获取数据库目录</para>

View File

@ -12,6 +12,7 @@ using ColdMint.scripts.debug;
using ColdMint.scripts.inventory; using ColdMint.scripts.inventory;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using ColdMint.scripts.weapon; using ColdMint.scripts.weapon;
using Microsoft.EntityFrameworkCore;
/// <summary> /// <summary>
/// <para>玩家角色</para> /// <para>玩家角色</para>
@ -287,10 +288,11 @@ public partial class Player : CharacterTemplate
var query = from itemInfoData in itemInfoDbSet var query = from itemInfoData in itemInfoDbSet
where itemInfoData.Id == "staffOfTheDead" && itemInfoData.Namespace == Config.DefaultNamespace where itemInfoData.Id == "staffOfTheDead" && itemInfoData.Namespace == Config.DefaultNamespace
select itemInfoData; select itemInfoData;
var itemInfo = query.FirstOrDefault(); var itemInfo = await query.FirstOrDefaultAsync();
if (itemInfo != null) if (itemInfo != null)
{ {
var item = new LocalItem(itemInfo); var item = new LocalItem(itemInfo);
await item.LoadIcon();
GameSceneNodeHolder.HotBar.AddItem(item); GameSceneNodeHolder.HotBar.AddItem(item);
} }

View File

@ -7,6 +7,7 @@ using ColdMint.scripts.database;
using ColdMint.scripts.database.dataPackEntity; using ColdMint.scripts.database.dataPackEntity;
using ColdMint.scripts.dataPack.local; using ColdMint.scripts.dataPack.local;
using ColdMint.scripts.serialization; using ColdMint.scripts.serialization;
using Microsoft.EntityFrameworkCore;
namespace ColdMint.scripts.dataPack.entryLoader; namespace ColdMint.scripts.dataPack.entryLoader;
@ -55,7 +56,7 @@ public class DataPackManifestLoader : IEntryLoader
var dataPackQuery = from dataPack in dataPackInfoDbSet var dataPackQuery = from dataPack in dataPackInfoDbSet
where dataPack.ZipFileName == zipFileName where dataPack.ZipFileName == zipFileName
select dataPack; select dataPack;
var oldDataPackInfo = dataPackQuery.FirstOrDefault(); var oldDataPackInfo = await dataPackQuery.FirstOrDefaultAsync();
if (oldDataPackInfo == null) if (oldDataPackInfo == null)
{ {
//There was no list to record before, create one. //There was no list to record before, create one.

View File

@ -14,6 +14,7 @@ using ColdMint.scripts.debug;
using ColdMint.scripts.serialization; using ColdMint.scripts.serialization;
using ColdMint.scripts.utils; using ColdMint.scripts.utils;
using Godot; using Godot;
using Microsoft.EntityFrameworkCore;
namespace ColdMint.scripts.dataPack.local; namespace ColdMint.scripts.dataPack.local;
@ -50,7 +51,7 @@ public class LocalDataPack : IDataPack
var query = from zipFileInfo in zipFileInfoDbSet var query = from zipFileInfo in zipFileInfoDbSet
where zipFileInfo.ZipFileName == zipFileName where zipFileInfo.ZipFileName == zipFileName
select zipFileInfo; select zipFileInfo;
var oldZipFileInfo = query.FirstOrDefault(); var oldZipFileInfo = await query.FirstOrDefaultAsync();
if (oldZipFileInfo == null || oldZipFileInfo.ZipFileMd5 != md5) if (oldZipFileInfo == null || oldZipFileInfo.ZipFileMd5 != md5)
{ {
//Get the list file GetEntry internal Dictionary based implementation, very fast //Get the list file GetEntry internal Dictionary based implementation, very fast
@ -174,7 +175,7 @@ public class LocalDataPack : IDataPack
select dataPack; select dataPack;
if (dataPackInfo != null) if (dataPackInfo != null)
{ {
manifest = dataPackInfo.FirstOrDefault(); manifest = await dataPackInfo.FirstOrDefaultAsync();
} }
} }

View File

@ -27,7 +27,7 @@ public interface IItem
/// <para>Items can be set with Icon</para> /// <para>Items can be set with Icon</para>
/// <para>物品可以设置图标</para> /// <para>物品可以设置图标</para>
/// </summary> /// </summary>
Texture2D Icon { get; set; } Texture2D Icon { get; }
/// <summary> /// <summary>
/// <para>Item has a name</para> /// <para>Item has a name</para>

View File

@ -1,11 +1,15 @@
using System; using System;
using System.IO;
using System.IO.Compression;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using ColdMint.scripts.database; using ColdMint.scripts.database;
using ColdMint.scripts.database.dataPackEntity; using ColdMint.scripts.database.dataPackEntity;
using ColdMint.scripts.debug; using ColdMint.scripts.debug;
using ColdMint.scripts.serialization; using ColdMint.scripts.serialization;
using Godot; using Godot;
using Microsoft.EntityFrameworkCore;
namespace ColdMint.scripts.inventory; namespace ColdMint.scripts.inventory;
@ -17,6 +21,7 @@ public class LocalItem : IItem
{ {
private ItemInfo _itemInfo; private ItemInfo _itemInfo;
private int quantity; private int quantity;
private ImageTexture texture2D;
public LocalItem(ItemInfo itemInfo) public LocalItem(ItemInfo itemInfo)
{ {
@ -24,6 +29,51 @@ public class LocalItem : IItem
quantity = itemInfo.Quantity; quantity = itemInfo.Quantity;
} }
public async Task LoadIcon()
{
if (_itemInfo == null)
{
return;
}
var icon = _itemInfo.Icon;
if (icon == null)
{
return;
}
//查找图标路径
var dataPackDbContext = DataBaseManager.GetRequiredService<DataPackDbContext>();
var spriteDbSet = dataPackDbContext.SpriteInfo;
//在同一个命名空间下查找
var query = from sprite in spriteDbSet
where sprite.FileName == icon && sprite.Namespace == _itemInfo.Namespace
select sprite;
var spriteInfo = await query.FirstOrDefaultAsync();
if (spriteInfo == null)
{
return;
}
var zipFilePath = Path.Join(Config.GetDataPackDirectory(), spriteInfo.ZipFileName);
using var archive = ZipFile.Open(zipFilePath, ZipArchiveMode.Read, Encoding.GetEncoding("GBK"));
var zipArchiveEntry = archive.GetEntry(spriteInfo.FullName);
if (zipArchiveEntry == null)
{
return;
}
var outPath = Path.Join(Config.GetDataPackCacheDirectory(_itemInfo.Namespace), spriteInfo.FileName+".jpg");
zipArchiveEntry.ExtractToFile(outPath);
var image = Image.LoadFromFile(outPath);
if (image == null)
{
LogCat.Log("无法加载"+outPath);
return;
}
texture2D = ImageTexture.CreateFromImage(image);
}
public string Id => _itemInfo.Id; public string Id => _itemInfo.Id;
public int Quantity public int Quantity
@ -33,7 +83,7 @@ public class LocalItem : IItem
} }
public int MaxStackQuantity => _itemInfo.MaxStackQuantity; public int MaxStackQuantity => _itemInfo.MaxStackQuantity;
public Texture2D Icon { get; set; } public Texture2D Icon => texture2D;
public string Name => _itemInfo.Name; public string Name => _itemInfo.Name;
public string Namespace => _itemInfo.Namespace; public string Namespace => _itemInfo.Namespace;
public Action<IItem> OnUse { get; set; } public Action<IItem> OnUse { get; set; }