Failed to make the packet.
制作数据包失败。
This commit is contained in:
parent
07816194cb
commit
5bdd68b61f
|
@ -121,6 +121,7 @@ public static class Config
|
|||
public const string DefaultVersionName = "Default";
|
||||
|
||||
public const string DataPackDirectoryName = "DataPacks";
|
||||
public const string CacheDirectoryName = "Caches";
|
||||
public const string DataBaseDirectoryName = "DataBases";
|
||||
|
||||
/// <summary>
|
||||
|
@ -153,6 +154,22 @@ public static class Config
|
|||
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>
|
||||
/// <para>Get database directory</para>
|
||||
/// <para>获取数据库目录</para>
|
||||
|
|
|
@ -12,6 +12,7 @@ using ColdMint.scripts.debug;
|
|||
using ColdMint.scripts.inventory;
|
||||
using ColdMint.scripts.utils;
|
||||
using ColdMint.scripts.weapon;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
/// <summary>
|
||||
/// <para>玩家角色</para>
|
||||
|
@ -287,10 +288,11 @@ public partial class Player : CharacterTemplate
|
|||
var query = from itemInfoData in itemInfoDbSet
|
||||
where itemInfoData.Id == "staffOfTheDead" && itemInfoData.Namespace == Config.DefaultNamespace
|
||||
select itemInfoData;
|
||||
var itemInfo = query.FirstOrDefault();
|
||||
var itemInfo = await query.FirstOrDefaultAsync();
|
||||
if (itemInfo != null)
|
||||
{
|
||||
var item = new LocalItem(itemInfo);
|
||||
await item.LoadIcon();
|
||||
GameSceneNodeHolder.HotBar.AddItem(item);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ using ColdMint.scripts.database;
|
|||
using ColdMint.scripts.database.dataPackEntity;
|
||||
using ColdMint.scripts.dataPack.local;
|
||||
using ColdMint.scripts.serialization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ColdMint.scripts.dataPack.entryLoader;
|
||||
|
||||
|
@ -55,7 +56,7 @@ public class DataPackManifestLoader : IEntryLoader
|
|||
var dataPackQuery = from dataPack in dataPackInfoDbSet
|
||||
where dataPack.ZipFileName == zipFileName
|
||||
select dataPack;
|
||||
var oldDataPackInfo = dataPackQuery.FirstOrDefault();
|
||||
var oldDataPackInfo = await dataPackQuery.FirstOrDefaultAsync();
|
||||
if (oldDataPackInfo == null)
|
||||
{
|
||||
//There was no list to record before, create one.
|
||||
|
|
|
@ -14,6 +14,7 @@ using ColdMint.scripts.debug;
|
|||
using ColdMint.scripts.serialization;
|
||||
using ColdMint.scripts.utils;
|
||||
using Godot;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ColdMint.scripts.dataPack.local;
|
||||
|
||||
|
@ -50,7 +51,7 @@ public class LocalDataPack : IDataPack
|
|||
var query = from zipFileInfo in zipFileInfoDbSet
|
||||
where zipFileInfo.ZipFileName == zipFileName
|
||||
select zipFileInfo;
|
||||
var oldZipFileInfo = query.FirstOrDefault();
|
||||
var oldZipFileInfo = await query.FirstOrDefaultAsync();
|
||||
if (oldZipFileInfo == null || oldZipFileInfo.ZipFileMd5 != md5)
|
||||
{
|
||||
//Get the list file GetEntry internal Dictionary based implementation, very fast
|
||||
|
@ -174,7 +175,7 @@ public class LocalDataPack : IDataPack
|
|||
select dataPack;
|
||||
if (dataPackInfo != null)
|
||||
{
|
||||
manifest = dataPackInfo.FirstOrDefault();
|
||||
manifest = await dataPackInfo.FirstOrDefaultAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public interface IItem
|
|||
/// <para>Items can be set with Icon</para>
|
||||
/// <para>物品可以设置图标</para>
|
||||
/// </summary>
|
||||
Texture2D Icon { get; set; }
|
||||
Texture2D Icon { get; }
|
||||
|
||||
/// <summary>
|
||||
/// <para>Item has a name</para>
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ColdMint.scripts.database;
|
||||
using ColdMint.scripts.database.dataPackEntity;
|
||||
using ColdMint.scripts.debug;
|
||||
using ColdMint.scripts.serialization;
|
||||
using Godot;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace ColdMint.scripts.inventory;
|
||||
|
||||
|
@ -17,6 +21,7 @@ public class LocalItem : IItem
|
|||
{
|
||||
private ItemInfo _itemInfo;
|
||||
private int quantity;
|
||||
private ImageTexture texture2D;
|
||||
|
||||
public LocalItem(ItemInfo itemInfo)
|
||||
{
|
||||
|
@ -24,6 +29,51 @@ public class LocalItem : IItem
|
|||
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 int Quantity
|
||||
|
@ -33,7 +83,7 @@ public class LocalItem : IItem
|
|||
}
|
||||
|
||||
public int MaxStackQuantity => _itemInfo.MaxStackQuantity;
|
||||
public Texture2D Icon { get; set; }
|
||||
public Texture2D Icon => texture2D;
|
||||
public string Name => _itemInfo.Name;
|
||||
public string Namespace => _itemInfo.Namespace;
|
||||
public Action<IItem> OnUse { get; set; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user