From dd57d715f995064a809331bb5b22778e1e378cf9 Mon Sep 17 00:00:00 2001 From: miku-666 <74728189+NessieHax@users.noreply.github.com> Date: Sat, 6 Dec 2025 06:01:41 +0100 Subject: [PATCH] Core - Rename 'UnknownDLCPackage' to 'RawAssetDLCPackage' --- PCK-Studio/Controls/PckAssetBrowserEditor.cs | 145 +++++++++--------- PCK-Studio/MainForm.cs | 45 +++--- PckStudio.Core/AtlasResource.cs | 1 - PckStudio.Core/DLC/DLCManager.cs | 19 ++- PckStudio.Core/DLC/DLCPackageType.cs | 4 +- ...ownDLCPackage.cs => RawAssetDLCPackage.cs} | 12 +- PckStudio.Core/PackInfo.cs | 28 ---- PckStudio.Core/PckStudio.Core.csproj | 3 +- .../TextureChangingEventArgs.cs | 22 --- 9 files changed, 114 insertions(+), 165 deletions(-) rename PckStudio.Core/DLC/{UnknownDLCPackage.cs => RawAssetDLCPackage.cs} (51%) delete mode 100644 PckStudio.Core/PackInfo.cs diff --git a/PCK-Studio/Controls/PckAssetBrowserEditor.cs b/PCK-Studio/Controls/PckAssetBrowserEditor.cs index df5e800d..7bdb0c52 100644 --- a/PCK-Studio/Controls/PckAssetBrowserEditor.cs +++ b/PCK-Studio/Controls/PckAssetBrowserEditor.cs @@ -51,7 +51,7 @@ using PckStudio.Core.DLC; namespace PckStudio.Controls { - internal partial class PckAssetBrowserEditor : EditorControl + internal partial class PckAssetBrowserEditor : EditorControl { private string _location = string.Empty; @@ -85,21 +85,21 @@ namespace PckStudio.Controls private readonly IDictionary> _pckAssetTypeHandler; //private readonly IDictionary _viewPanels; - public PckAssetBrowserEditor(PackInfo packInfo, ISaveContext saveContext) - : base(packInfo, saveContext) + public PckAssetBrowserEditor(RawAssetDLCPackage rawAssetDLCPackage, ISaveContext saveContext) + : base(rawAssetDLCPackage, saveContext) { InitializeComponent(); _onModifiedChangeDelegate = OnModify; - _originalEndianness = packInfo.ByteOrder; - _currentEndianness = packInfo.ByteOrder; + _originalEndianness = rawAssetDLCPackage.ByteOrder; + _currentEndianness = rawAssetDLCPackage.ByteOrder; //! InitializeViewPanels { _default = new DefaultPanel(); _models = new ModelsPanel(TryGet.FromDelegate((string path, out Image img) => { - bool found = EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset asset) || - EditorValue.File.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out asset); + bool found = EditorValue.PckFile.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset asset) || + EditorValue.PckFile.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out asset); img = found ? asset.GetTexture() : default; return found; })); @@ -221,27 +221,24 @@ namespace PckStudio.Controls if (asset.Type != PckAssetType.SkinDataFile && asset.Type != PckAssetType.TexturePackInfoFile || asset.Size <= 0 || !Settings.Default.LoadSubPcks) return; - ISaveContext saveContext = new DelegatedSaveContext(false, (packInfo) => + ISaveContext saveContext = new DelegatedSaveContext(false, (rawAssetDLCPackage) => { - if (packInfo.IsValid) - { - asset.SetData(new PckFileWriter(packInfo.File, _currentEndianness)); - _wasModified = true; - } + asset.SetData(new PckFileWriter(rawAssetDLCPackage.PckFile, _currentEndianness)); + _wasModified = true; }); string caption = Path.GetFileName(asset.Filename); string identifier = _location + Path.GetFileName(asset.Filename); PckFile pckFile = asset.GetData(new PckFileReader(_originalEndianness)); - PackInfo packInfo = PackInfo.Create(pckFile, _originalEndianness, false); + RawAssetDLCPackage rawAssetDLCPackage = new RawAssetDLCPackage(asset.Filename, pckFile, _originalEndianness); // TODO: may change to use a new tab page that will be closed when the main pck is closed - //Program.MainInstance.OpenNewPckTab(caption, identifier, packInfo, saveContext); + //Program.MainInstance.OpenNewPckTab(caption, identifier, RawAssetDLCPackage, saveContext); } private void HandleTextureFile(PckAsset asset) { - _ = asset.IsMipmappedFile() && EditorValue.File.TryGetAsset(asset.GetNormalPath(), PckAssetType.TextureFile, out asset); + _ = asset.IsMipmappedFile() && EditorValue.PckFile.TryGetAsset(asset.GetNormalPath(), PckAssetType.TextureFile, out asset); if (asset.Size <= 0) { @@ -268,7 +265,7 @@ namespace PckStudio.Controls ITryGet tryGet = TryGet.FromDelegate((string path, out Image img) => { img = null; - if (EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset armorAsset)) + if (EditorValue.PckFile.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset armorAsset)) { img = armorAsset.GetTexture(); Debug.WriteLine($"Got texture for: {path}"); @@ -309,7 +306,7 @@ namespace PckStudio.Controls bool hasCustomModel = false; bool hasDefaultModel = TryGetDefaultEntityModel(modelName, out Model model); - if (EditorValue.File.TryGetAsset("models.bin", PckAssetType.ModelsFile, out PckAsset modelsAsset)) + if (EditorValue.PckFile.TryGetAsset("models.bin", PckAssetType.ModelsFile, out PckAsset modelsAsset)) { ModelContainer models = modelsAsset.GetData(new ModelFileReader()); hasCustomModel = models.ContainsModel(modelName); @@ -354,13 +351,13 @@ namespace PckStudio.Controls case ResourceCategory.Atlas: Atlas atlas = asset.GetDeserializedData(new AtlasDeserializer(resourceLocation)); ColorContainer colorContainer = default; - if (EditorValue.File.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out PckAsset colAsset)) + if (EditorValue.PckFile.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out PckAsset colAsset)) colorContainer = colAsset.GetData(new COLFileReader()); ITryGet tryGetAnimation = TryGet.FromDelegate((string key, out Animation animation) => { - bool found = EditorValue.File.TryGetAsset(key + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || - EditorValue.File.TryGetAsset(key + ".tga", PckAssetType.TextureFile, out foundAsset); + bool found = EditorValue.PckFile.TryGetAsset(key + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || + EditorValue.PckFile.TryGetAsset(key + ".tga", PckAssetType.TextureFile, out foundAsset); if (found) { animation = foundAsset.GetDeserializedData(AnimationDeserializer.DefaultDeserializer); @@ -373,8 +370,8 @@ namespace PckStudio.Controls ITryGet> tryGetAnimationSaveContext = TryGet> .FromDelegate((string key, out ISaveContext animationSaveContext) => { - bool found = EditorValue.File.TryGetAsset(key + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || - EditorValue.File.TryGetAsset(key + ".tga", PckAssetType.TextureFile, out foundAsset); + bool found = EditorValue.PckFile.TryGetAsset(key + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || + EditorValue.PckFile.TryGetAsset(key + ".tga", PckAssetType.TextureFile, out foundAsset); if (found) { @@ -391,7 +388,7 @@ namespace PckStudio.Controls Debug.WriteLine("New animation has 0 frames. Aborting saving."); return; } - PckAsset newAnimationAsset = EditorValue.File.CreateNewAsset(key + ".png", PckAssetType.TextureFile); + PckAsset newAnimationAsset = EditorValue.PckFile.CreateNewAsset(key + ".png", PckAssetType.TextureFile); newAnimationAsset.SetSerializedData(animation, AnimationSerializer.DefaultSerializer); BuildMainTreeView(); }); @@ -503,7 +500,7 @@ namespace PckStudio.Controls if (asset.HasProperty("CAPEPATH")) { string capeAssetPath = asset.GetProperty("CAPEPATH"); - if (EditorValue.File.TryGetAsset(capeAssetPath, PckAssetType.CapeFile, out PckAsset capeAsset)) + if (EditorValue.PckFile.TryGetAsset(capeAssetPath, PckAssetType.CapeFile, out PckAsset capeAsset)) { skin.CapeId = capeAsset.GetId(); cape = capeAsset.GetTexture(); @@ -517,7 +514,7 @@ namespace PckStudio.Controls asset.SetSkin(customSkin, locFile); }); - using CustomSkinEditor skinEditor = new CustomSkinEditor(skin, cape, saveContext, EditorValue.File.HasVerionString); + using CustomSkinEditor skinEditor = new CustomSkinEditor(skin, cape, saveContext, EditorValue.PckFile.HasVerionString); if (skinEditor.ShowDialog() == DialogResult.OK) { _wasModified = true; @@ -536,22 +533,22 @@ namespace PckStudio.Controls TryGetDelegate tryGetTexture = (string path, out Image img) => { - bool found = EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset asset) || - EditorValue.File.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out asset); + bool found = EditorValue.PckFile.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset asset) || + EditorValue.PckFile.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out asset); img = found ? asset.GetTexture() : default; return found; }; TrySetDelegate trySetTexture = (string path, Image img) => { - bool found = EditorValue.File.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || - EditorValue.File.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out foundAsset); - PckAsset asset = foundAsset ?? EditorValue.File.CreateNewAsset(path + ".png", PckAssetType.TextureFile); + bool found = EditorValue.PckFile.TryGetAsset(path + ".png", PckAssetType.TextureFile, out PckAsset foundAsset) || + EditorValue.PckFile.TryGetAsset(path + ".tga", PckAssetType.TextureFile, out foundAsset); + PckAsset asset = foundAsset ?? EditorValue.PckFile.CreateNewAsset(path + ".png", PckAssetType.TextureFile); asset.SetTexture(img); return true; }; - bool hasMaterialAsset = EditorValue.File.TryGetAsset("entityMaterials.bin", PckAssetType.MaterialFile, out PckAsset entityMaterialAsset); + bool hasMaterialAsset = EditorValue.PckFile.TryGetAsset("entityMaterials.bin", PckAssetType.MaterialFile, out PckAsset entityMaterialAsset); IReadOnlyDictionary entityMaterials = hasMaterialAsset ? entityMaterialAsset?.GetData(new MaterialFileReader()).ToDictionary(mat => mat.Name) @@ -595,7 +592,7 @@ namespace PckStudio.Controls private void CheckForPasswordAndRemove() { - if (EditorValue.File.TryGetAsset("0", PckAssetType.InfoFile, out PckAsset asset)) + if (EditorValue.PckFile.TryGetAsset("0", PckAssetType.InfoFile, out PckAsset asset)) { asset.RemoveProperties("LOCK"); } @@ -619,7 +616,7 @@ namespace PckStudio.Controls string selectedNodeText = treeViewMain.SelectedNode is TreeNode node ? node.FullPath : string.Empty; _currentViewPanel.Reset(); treeViewMain.Nodes.Clear(); - BuildPckTreeView(treeViewMain.Nodes, EditorValue.File); + BuildPckTreeView(treeViewMain.Nodes, EditorValue.PckFile); treeViewMain.Sort(); TreeNode[] selectedNodes = treeViewMain.FindPath(selectedNodeText); @@ -668,8 +665,8 @@ namespace PckStudio.Controls private bool TryGetLocFile(out LOCFile locFile) { - if (!EditorValue.File.TryGetAsset("localisation.loc", PckAssetType.LocalisationFile, out PckAsset locAsset) && - !EditorValue.File.TryGetAsset("languages.loc", PckAssetType.LocalisationFile, out locAsset)) + if (!EditorValue.PckFile.TryGetAsset("localisation.loc", PckAssetType.LocalisationFile, out PckAsset locAsset) && + !EditorValue.PckFile.TryGetAsset("languages.loc", PckAssetType.LocalisationFile, out locAsset)) { locFile = null; return false; @@ -690,8 +687,8 @@ namespace PckStudio.Controls private bool TrySetLocFile(in LOCFile locFile) { - if (!EditorValue.File.TryGetAsset("localisation.loc", PckAssetType.LocalisationFile, out PckAsset locAsset) && - !EditorValue.File.TryGetAsset("languages.loc", PckAssetType.LocalisationFile, out locAsset)) + if (!EditorValue.PckFile.TryGetAsset("localisation.loc", PckAssetType.LocalisationFile, out PckAsset locAsset) && + !EditorValue.PckFile.TryGetAsset("languages.loc", PckAssetType.LocalisationFile, out locAsset)) { return false; } @@ -751,12 +748,12 @@ namespace PckStudio.Controls using AddFilePrompt diag = new AddFilePrompt("res/" + Path.GetFileName(ofd.FileName)); if (diag.ShowDialog(this) == DialogResult.OK) { - if (EditorValue.File.Contains(diag.Filepath, diag.Filetype)) + if (EditorValue.PckFile.Contains(diag.Filepath, diag.Filetype)) { MessageBox.Show(this, $"'{diag.Filepath}' of type {diag.Filetype} already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } - PckAsset asset = EditorValue.File.CreateNewAsset(diag.Filepath, diag.Filetype, () => File.ReadAllBytes(ofd.FileName)); + PckAsset asset = EditorValue.PckFile.CreateNewAsset(diag.Filepath, diag.Filetype, () => File.ReadAllBytes(ofd.FileName)); BuildMainTreeView(); _wasModified = true; @@ -775,12 +772,12 @@ namespace PckStudio.Controls renamePrompt.LabelText = "Path"; if (renamePrompt.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(renamePrompt.NewText)) { - if (EditorValue.File.Contains(renamePrompt.NewText, PckAssetType.TextureFile)) + if (EditorValue.PckFile.Contains(renamePrompt.NewText, PckAssetType.TextureFile)) { MessageBox.Show(this, $"'{renamePrompt.NewText}' already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } - PckAsset asset = EditorValue.File.CreateNewAsset(renamePrompt.NewText, PckAssetType.TextureFile, () => File.ReadAllBytes(fileDialog.FileName)); + PckAsset asset = EditorValue.PckFile.CreateNewAsset(renamePrompt.NewText, PckAssetType.TextureFile, () => File.ReadAllBytes(fileDialog.FileName)); BuildMainTreeView(); _wasModified = true; } @@ -799,7 +796,7 @@ namespace PckStudio.Controls { string skinNameImport = Path.GetFileName(contents.FileName); byte[] data = File.ReadAllBytes(contents.FileName); - PckAsset mfNew = EditorValue.File.CreateNewAsset(skinNameImport, PckAssetType.SkinFile); + PckAsset mfNew = EditorValue.PckFile.CreateNewAsset(skinNameImport, PckAssetType.SkinFile); mfNew.SetData(data); string propertyFile = Path.GetFileNameWithoutExtension(contents.FileName) + ".txt"; if (File.Exists(propertyFile)) @@ -941,7 +938,7 @@ namespace PckStudio.Controls if (e.Button != MouseButtons.Left || e.Item is not TreeNode node) return; - if ((node.TryGetTagData(out PckAsset asset) && EditorValue.File.Contains(asset.Filename, asset.Type)) || node.Parent is TreeNode) + if ((node.TryGetTagData(out PckAsset asset) && EditorValue.PckFile.Contains(asset.Filename, asset.Type)) || node.Parent is TreeNode) { // TODO: add (mouse) scrolling while dragging item(s) treeViewMain.DoDragDrop(node, DragDropEffects.Scroll | DragDropEffects.Move); @@ -1117,14 +1114,14 @@ namespace PckStudio.Controls } } - if (EditorValue.File.Contains(filepath, assetType)) + if (EditorValue.PckFile.Contains(filepath, assetType)) { if (askForAssetType) MessageBox.Show(this, $"'{assetPath}' of type {assetType} already exists.\nSkiping file.", "File already exists", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1); Debug.WriteLine($"'{assetPath}' of type {assetType} already exists.\nSkiping file."); continue; } - PckAsset importedAsset = EditorValue.File.CreateNewAsset(assetPath, assetType, () => File.ReadAllBytes(filepath)); + PckAsset importedAsset = EditorValue.PckFile.CreateNewAsset(assetPath, assetType, () => File.ReadAllBytes(filepath)); string propertyFile = filepath + ".txt"; if (File.Exists(propertyFile)) { @@ -1165,12 +1162,12 @@ namespace PckStudio.Controls if (addFile.ShowDialog(this) != DialogResult.OK) continue; - if (EditorValue.File.Contains(addFile.Filepath, addFile.Filetype)) + if (EditorValue.PckFile.Contains(addFile.Filepath, addFile.Filetype)) { MessageBox.Show(this, $"'{addFile.Filepath}' of type {addFile.Filetype} already exists.", "Import failed", MessageBoxButtons.OK, MessageBoxIcon.Warning); continue; } - EditorValue.File.CreateNewAsset(addFile.Filepath, addFile.Filetype, () => File.ReadAllBytes(file)); + EditorValue.PckFile.CreateNewAsset(addFile.Filepath, addFile.Filetype, () => File.ReadAllBytes(file)); addedCount++; BuildMainTreeView(); @@ -1186,19 +1183,19 @@ namespace PckStudio.Controls { TryGetLocFile(out LOCFile locFile); PckAsset skinAsset = addNewSkinDialog.NewSkin.CreateFile(locFile); - EditorValue.File.AddAsset(skinAsset); + EditorValue.PckFile.AddAsset(skinAsset); bool hasSkinsFolder = treeViewMain.Nodes.ContainsKey("Skins"); if (hasSkinsFolder) skinAsset.Filename = skinAsset.Filename.Insert(0, "Skins/"); // Then Skins folder - EditorValue.File.AddAsset(skinAsset); + EditorValue.PckFile.AddAsset(skinAsset); if (addNewSkinDialog.HasCape) { PckAsset capeFile = addNewSkinDialog.NewSkin.CreateCapeFile(addNewSkinDialog.CapeTexture); if (hasSkinsFolder) capeFile.Filename = capeFile.Filename.Insert(0, "Skins/"); // Then Skins folder - EditorValue.File.AddAsset(capeFile); + EditorValue.PckFile.AddAsset(capeFile); } TrySetLocFile(locFile); @@ -1215,7 +1212,7 @@ namespace PckStudio.Controls string animationFilepath = $"{ResourceLocations.GetPathFromCategory(diag.Category)}/{diag.SelectedTile.InternalName}.png"; - if (EditorValue.File.Contains(animationFilepath, PckAssetType.TextureFile)) + if (EditorValue.PckFile.Contains(animationFilepath, PckAssetType.TextureFile)) { MessageBox.Show(this, $"{diag.SelectedTile.DisplayName} is already present.", "File already present"); return; @@ -1231,7 +1228,7 @@ namespace PckStudio.Controls if (animationEditor.ShowDialog() == DialogResult.OK && newAnimation is not null) { _wasModified = true; - PckAsset asset = EditorValue.File.CreateNewAsset(animationFilepath, PckAssetType.TextureFile); + PckAsset asset = EditorValue.PckFile.CreateNewAsset(animationFilepath, PckAssetType.TextureFile); asset.SetSerializedData(newAnimation, AnimationSerializer.DefaultSerializer); BuildMainTreeView(); _currentViewPanel.LoadAsset(asset, () => _wasModified = true); @@ -1240,7 +1237,7 @@ namespace PckStudio.Controls private void audiopckToolStripMenuItem_Click(object sender, EventArgs e) { - if (EditorValue.File.Contains(PckAssetType.AudioFile)) + if (EditorValue.PckFile.Contains(PckAssetType.AudioFile)) { // the chance of this happening is really really slim but just in case MessageBox.Show(this, "There is already an audio file in this PCK!", "Can't create audio.pck"); @@ -1264,7 +1261,7 @@ namespace PckStudio.Controls AudioEditor diag = new AudioEditor(newAudioFile, saveContext); if (diag.ShowDialog(this) == DialogResult.OK) { - EditorValue.File.AddAsset(newAudioAsset); + EditorValue.PckFile.AddAsset(newAudioAsset); } diag.Dispose(); BuildMainTreeView(); @@ -1272,51 +1269,51 @@ namespace PckStudio.Controls private void colourscolToolStripMenuItem_Click(object sender, EventArgs e) { - if (EditorValue.File.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out _)) + if (EditorValue.PckFile.TryGetAsset("colours.col", PckAssetType.ColourTableFile, out _)) { MessageBox.Show(this, "A color table file already exists in this PCK and a new one cannot be created.", "Operation aborted"); return; } - PckAsset newColorAsset = EditorValue.File.CreateNewAsset("colours.col", PckAssetType.ColourTableFile); + PckAsset newColorAsset = EditorValue.PckFile.CreateNewAsset("colours.col", PckAssetType.ColourTableFile); newColorAsset.SetData(Resources.tu69colours); BuildMainTreeView(); } private void CreateSkinsPCKToolStripMenuItem1_Click(object sender, EventArgs e) { - if (EditorValue.File.TryGetAsset("Skins.pck", PckAssetType.SkinDataFile, out _)) + if (EditorValue.PckFile.TryGetAsset("Skins.pck", PckAssetType.SkinDataFile, out _)) { MessageBox.Show(this, "A Skins.pck file already exists in this PCK and a new one cannot be created.", "Operation aborted"); return; } - EditorValue.File.CreateNewAsset("Skins.pck", PckAssetType.SkinDataFile, new PckFileWriter(new PckFile(3, true), _currentEndianness)); + EditorValue.PckFile.CreateNewAsset("Skins.pck", PckAssetType.SkinDataFile, new PckFileWriter(new PckFile(3, true), _currentEndianness)); BuildMainTreeView(); } private void behavioursbinToolStripMenuItem_Click(object sender, EventArgs e) { - if (EditorValue.File.TryGetAsset("behaviours.bin", PckAssetType.BehavioursFile, out _)) + if (EditorValue.PckFile.TryGetAsset("behaviours.bin", PckAssetType.BehavioursFile, out _)) { MessageBox.Show(this, "A behaviours file already exists in this PCK and a new one cannot be created.", "Operation aborted"); return; } - EditorValue.File.CreateNewAsset("behaviours.bin", PckAssetType.BehavioursFile, new BehavioursWriter(new BehaviourFile())); + EditorValue.PckFile.CreateNewAsset("behaviours.bin", PckAssetType.BehavioursFile, new BehavioursWriter(new BehaviourFile())); BuildMainTreeView(); } private void entityMaterialsbinToolStripMenuItem_Click(object sender, EventArgs e) { - if (EditorValue.File.TryGetAsset("entityMaterials.bin", PckAssetType.MaterialFile, out _)) + if (EditorValue.PckFile.TryGetAsset("entityMaterials.bin", PckAssetType.MaterialFile, out _)) { MessageBox.Show(this, "A behaviours file already exists in this PCK and a new one cannot be created.", "Operation aborted"); return; } var materialContainer = new MaterialContainer(); materialContainer.InitializeDefault(); - EditorValue.File.CreateNewAsset("entityMaterials.bin", PckAssetType.MaterialFile, new MaterialFileWriter(materialContainer)); + EditorValue.PckFile.CreateNewAsset("entityMaterials.bin", PckAssetType.MaterialFile, new MaterialFileWriter(materialContainer)); BuildMainTreeView(); } @@ -1333,7 +1330,7 @@ namespace PckStudio.Controls return; } // creates variable to indicate wether current pck skin structure is mashup or regular skin - bool hasSkinsPck = EditorValue.File.HasAsset("Skins.pck", PckAssetType.SkinDataFile); + bool hasSkinsPck = EditorValue.PckFile.HasAsset("Skins.pck", PckAssetType.SkinDataFile); foreach (var fullfilename in Directory.GetFiles(contents.ResultPath, "*.png")) { @@ -1380,7 +1377,7 @@ namespace PckStudio.Controls } if (hasSkinsPck) { - PckAsset skinsFileAsset = EditorValue.File.GetAsset("Skins.pck", PckAssetType.SkinDataFile); + PckAsset skinsFileAsset = EditorValue.PckFile.GetAsset("Skins.pck", PckAssetType.SkinDataFile); using (var ms = new MemoryStream(skinsFileAsset.Data)) { //var reader = new PckFileReader(LittleEndianCheckBox.Checked ? OMI.Endianness.LittleEndian : OMI.Endianness.BigEndian); @@ -1393,7 +1390,7 @@ namespace PckStudio.Controls } continue; } - EditorValue.File.AddAsset(newFile); + EditorValue.PckFile.AddAsset(newFile); } BuildMainTreeView(); _wasModified = true; @@ -1442,8 +1439,8 @@ namespace PckStudio.Controls { string mippedPath = $"{textureDirectory}/{textureName}MipMapLevel{i}{textureExtension}"; Debug.WriteLine(mippedPath); - if (EditorValue.File.HasAsset(mippedPath, PckAssetType.TextureFile)) - EditorValue.File.RemoveAsset(EditorValue.File.GetAsset(mippedPath, PckAssetType.TextureFile)); + if (EditorValue.PckFile.HasAsset(mippedPath, PckAssetType.TextureFile)) + EditorValue.PckFile.RemoveAsset(EditorValue.PckFile.GetAsset(mippedPath, PckAssetType.TextureFile)); PckAsset mipMappedAsset = new PckAsset(mippedPath, PckAssetType.TextureFile); Image originalTexture = asset.GetTexture(); @@ -1451,7 +1448,7 @@ namespace PckStudio.Controls mipMappedAsset.SetTexture(mippedTexture); - EditorValue.File.InsertAsset(EditorValue.File.IndexOfAsset(asset) + i - 1, mipMappedAsset); + EditorValue.PckFile.InsertAsset(EditorValue.PckFile.IndexOfAsset(asset) + i - 1, mipMappedAsset); } BuildMainTreeView(); } @@ -1532,7 +1529,7 @@ namespace PckStudio.Controls string selectedFolder = node.FullPath; - foreach (PckAsset asset in EditorValue.File.GetAssets().Where(asset => asset.Filename.StartsWith(selectedFolder))) + foreach (PckAsset asset in EditorValue.PckFile.GetAssets().Where(asset => asset.Filename.StartsWith(selectedFolder))) { extractFolderFile(outPath, asset); } @@ -1604,7 +1601,7 @@ namespace PckStudio.Controls TreeNodeCollection nodeCollection = node.Parent?.Nodes ?? treeViewMain.Nodes; nodeCollection.Insert(node.Index + 1, newNode); - EditorValue.File.InsertAsset(node.Index + 1, newFile); + EditorValue.PckFile.InsertAsset(node.Index + 1, newFile); BuildMainTreeView(); _wasModified = true; } @@ -1626,7 +1623,7 @@ namespace PckStudio.Controls { if (isFile) { - if (EditorValue.File.Contains(diag.NewText, asset.Type)) + if (EditorValue.PckFile.Contains(diag.NewText, asset.Type)) { MessageBox.Show(this, $"{diag.NewText} already exists", "File already exists"); return; @@ -1729,7 +1726,7 @@ namespace PckStudio.Controls if (node.TryGetTagData(out PckAsset asset)) { - if (!BeforeFileRemove(asset) && EditorValue.File.RemoveAsset(asset)) + if (!BeforeFileRemove(asset) && EditorValue.PckFile.RemoveAsset(asset)) { _currentViewPanel.Reset(); node.Remove(); @@ -1740,7 +1737,7 @@ namespace PckStudio.Controls MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { string pckFolderDir = node.FullPath; - EditorValue.File.RemoveAll(file => file.Filename.StartsWith(pckFolderDir) && !BeforeFileRemove(file)); + EditorValue.PckFile.RemoveAll(file => file.Filename.StartsWith(pckFolderDir) && !BeforeFileRemove(file)); node.Remove(); _wasModified = true; } diff --git a/PCK-Studio/MainForm.cs b/PCK-Studio/MainForm.cs index 35ad8cc8..20719e43 100644 --- a/PCK-Studio/MainForm.cs +++ b/PCK-Studio/MainForm.cs @@ -65,11 +65,11 @@ namespace PckStudio if (dlcPackage is null) return; SaveToRecentFiles(filepath); - if (dlcPackage.GetDLCPackageType() == DLCPackageType.Unknown) + if (dlcPackage.GetDLCPackageType() == DLCPackageType.RawAssets) AddEditorPage(dlcPackage); } - internal void OpenNewPckTab(string caption, string identifier, PackInfo packInfo, ISaveContext saveContext) + internal void OpenNewPckTab(string caption, string identifier, RawAssetDLCPackage packInfo, ISaveContext saveContext) { if (openTabPages.ContainsKey(identifier)) { @@ -80,7 +80,7 @@ namespace PckStudio AddPage(caption, identifier, editor); } - private void AddEditorPage(string caption, string identifier, PackInfo packInfo, ISaveContext saveContext = null) + private void AddEditorPage(string caption, string identifier, RawAssetDLCPackage packInfo, ISaveContext saveContext = null) { saveContext ??= GetDefaultSaveContext("./new.pck", "PCK (Minecraft Console Package)"); var editor = new PckAssetBrowserEditor(packInfo, saveContext); @@ -89,15 +89,14 @@ namespace PckStudio private void AddEditorPage(IDLCPackage dlcPackage) { - PackInfo packInfo = PackInfo.Create((dlcPackage as UnknownDLCPackage).PckFile, default, false); - ISaveContext saveContext = GetDefaultSaveContext("", "PCK (Minecraft Console Package)"); - var editor = new PckAssetBrowserEditor(packInfo, saveContext); + ISaveContext saveContext = GetDefaultSaveContext("", "PCK (Minecraft Console Package)"); + var editor = new PckAssetBrowserEditor(dlcPackage as RawAssetDLCPackage, saveContext); TabPage page = AddPage(dlcPackage.Name, dlcPackage.Name, editor); } - private static ISaveContext GetDefaultSaveContext(string filepath, string description) + private static ISaveContext GetDefaultSaveContext(string filepath, string description) { - return new DelegatedFileSaveContext(filepath, false, new FileDialogFilter(description, "*"+Path.GetExtension(filepath)),(packInfo, stream) => new PckFileWriter(packInfo.File, packInfo.ByteOrder).WriteToStream(stream)); + return new DelegatedFileSaveContext(filepath, false, new FileDialogFilter(description, "*"+Path.GetExtension(filepath)),(packInfo, stream) => new PckFileWriter(packInfo.PckFile, packInfo.ByteOrder).WriteToStream(stream)); } private TabPage AddPage(string caption, string identifier, Control control) @@ -114,9 +113,9 @@ namespace PckStudio return page; } - private bool TryGetEditor(TabPage page, out IEditor editor) + private bool TryGetEditor(TabPage page, out IEditor editor) { - if (page.Controls[0] is IEditor outEditor) + if (page.Controls[0] is IEditor outEditor) { editor = outEditor; return true; @@ -125,7 +124,7 @@ namespace PckStudio return false; } - private bool TryGetCurrentEditor(out IEditor editor) => TryGetEditor(tabControl.SelectedTab, out editor); + private bool TryGetCurrentEditor(out IEditor editor) => TryGetEditor(tabControl.SelectedTab, out editor); private void MainForm_Load(object sender, EventArgs e) { @@ -149,7 +148,7 @@ namespace PckStudio private void CloseTab(TabControl.TabPageCollection collection, TabPage page) { - if (TryGetEditor(page, out IEditor editor)) + if (TryGetEditor(page, out IEditor editor)) { editor.Close(); RemoveOpenFile(page); @@ -251,7 +250,7 @@ namespace PckStudio private void tabControl_PageClosing(object sender, PageClosingEventArgs e) { - if (TryGetEditor(e.Page, out IEditor editor)) + if (TryGetEditor(e.Page, out IEditor editor)) { editor.Close(); RemoveOpenFile(); @@ -343,8 +342,8 @@ namespace PckStudio if (namePrompt.ShowDialog(this) == DialogResult.OK) { PckFile skinPck = InitializePack(new Random().Next(8000, GameConstants.MAX_PACK_ID), 0, namePrompt.NewText, true); - PackInfo packInfo = PackInfo.Create(skinPck, OMI.ByteOrder.BigEndian, true); - AddEditorPage("Unsaved skin pack", "Unsaved skin pack", packInfo); + RawAssetDLCPackage newRawAssetDLCPackage = new RawAssetDLCPackage("New pack", skinPck, OMI.ByteOrder.BigEndian); + AddEditorPage(newRawAssetDLCPackage.Name, "Unsaved texture pack", newRawAssetDLCPackage); } } @@ -354,8 +353,8 @@ namespace PckStudio if (packPrompt.ShowDialog() == DialogResult.OK) { PckFile texturePackPck = InitializeTexturePack(new Random().Next(8000, GameConstants.MAX_PACK_ID), 0, packPrompt.PackName, packPrompt.PackRes, packPrompt.CreateSkinsPck); - PackInfo packInfo = PackInfo.Create(texturePackPck, OMI.ByteOrder.BigEndian, true); - AddEditorPage("Unsaved texture pack", "Unsaved texture pack", packInfo); + RawAssetDLCPackage newRawAssetDLCPackage = new RawAssetDLCPackage("New pack", texturePackPck, OMI.ByteOrder.BigEndian); + AddEditorPage(newRawAssetDLCPackage.Name, "Unsaved texture pack", newRawAssetDLCPackage); } } @@ -365,16 +364,16 @@ namespace PckStudio if (packPrompt.ShowDialog() == DialogResult.OK) { PckFile mashUpPck = InitializeMashUpPack(new Random().Next(8000, GameConstants.MAX_PACK_ID), 0, packPrompt.PackName, packPrompt.PackRes); - PackInfo packInfo = PackInfo.Create(mashUpPck, OMI.ByteOrder.BigEndian, true); - AddEditorPage("Unsaved mash-up pack", "Unsaved mash-up pack", packInfo); + RawAssetDLCPackage newRawAssetDLCPackage = new RawAssetDLCPackage("New pack", mashUpPck, OMI.ByteOrder.BigEndian); + AddEditorPage(newRawAssetDLCPackage.Name, "Unsaved texture pack", newRawAssetDLCPackage); } } private void quickChangeToolStripMenuItem_Click(object sender, EventArgs e) { - if (TryGetCurrentEditor(out IEditor editor)) + if (TryGetCurrentEditor(out IEditor editor)) { - using AdvancedOptions advanced = new AdvancedOptions(editor.EditorValue.File); + using AdvancedOptions advanced = new AdvancedOptions(editor.EditorValue.PckFile); advanced.IsLittleEndian = editor.EditorValue.ByteOrder == OMI.ByteOrder.LittleEndian; if (advanced.ShowDialog() == DialogResult.OK) { @@ -481,7 +480,7 @@ namespace PckStudio private void saveToolStripMenuItem_Click(object sender, EventArgs e) { - if (TryGetCurrentEditor(out IEditor editor)) + if (TryGetCurrentEditor(out IEditor editor)) { editor.Save(); } @@ -489,7 +488,7 @@ namespace PckStudio private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { - if (TryGetCurrentEditor(out IEditor editor)) + if (TryGetCurrentEditor(out IEditor editor)) { editor.SaveAs(); } diff --git a/PckStudio.Core/AtlasResource.cs b/PckStudio.Core/AtlasResource.cs index 414ba5b4..0b9472f7 100644 --- a/PckStudio.Core/AtlasResource.cs +++ b/PckStudio.Core/AtlasResource.cs @@ -21,7 +21,6 @@ using System.Drawing; using System.IO; using System.Linq; using PckStudio.Core.Json; -using static PckStudio.Core.AtlasResource; namespace PckStudio.Core { diff --git a/PckStudio.Core/DLC/DLCManager.cs b/PckStudio.Core/DLC/DLCManager.cs index a6e75eb9..a570ebd9 100644 --- a/PckStudio.Core/DLC/DLCManager.cs +++ b/PckStudio.Core/DLC/DLCManager.cs @@ -113,14 +113,14 @@ namespace PckStudio.Core.DLC if (!pckFile.TryGetAsset("0", PckAssetType.InfoFile, out PckAsset zeroAsset)) { Trace.TraceError("Could not find asset named:'0'."); - return new UnknownDLCPackage(fileInfo.Name, pckFile); + return new RawAssetDLCPackage(fileInfo.Name, pckFile, ByteOrder); } - int identifier = (zeroAsset?.HasProperty("PACKID") ?? default) ? zeroAsset.GetProperty("PACKID", int.Parse) : -1; + int identifier = zeroAsset.HasProperty("PACKID") ? zeroAsset.GetProperty("PACKID", int.Parse) : -1; if (identifier <= 0 || identifier > GameConstants.MAX_PACK_ID) { Trace.TraceError($"{nameof(identifier)}({identifier}) was out of range!"); - return new UnknownDLCPackage(fileInfo.Name, pckFile); + return new RawAssetDLCPackage(fileInfo.Name, pckFile, ByteOrder); } if (_packageRegistry.ContainsPackage(identifier)) @@ -128,9 +128,12 @@ namespace PckStudio.Core.DLC LOCFile localisation = pckFile.GetAssetsByType(PckAssetType.LocalisationFile).FirstOrDefault()?.GetData(new LOCFileReader()); if (localisation is null) - return new UnknownDLCPackage(fileInfo.Name, pckFile); + { + Trace.TraceError("No localisation asset found."); + return new RawAssetDLCPackage(fileInfo.Name, pckFile, ByteOrder); + } - IDLCPackage package = ScanForPackageType(fileInfo, identifier, pckFile, localisation, fileReader); + IDLCPackage package = LoadDLCPackage(fileInfo, identifier, pckFile, localisation, fileReader); if (package.GetDLCPackageType() != DLCPackageType.Invalid) { _packageRegistry.RegisterPackage(identifier, package, localisation); @@ -156,7 +159,7 @@ namespace PckStudio.Core.DLC return true; } - private IDLCPackage ScanForPackageType(FileInfo fileInfo, int identifier, PckFile pckFile, LOCFile localisation, PckFileReader fileReader) + private IDLCPackage LoadDLCPackage(FileInfo fileInfo, int identifier, PckFile pckFile, LOCFile localisation, PckFileReader fileReader) { bool hasLanguage = localisation?.Languages?.Contains(PreferredLanguage) ?? default; @@ -170,7 +173,7 @@ namespace PckStudio.Core.DLC bool couldBeMiniGamePack = fileInfo.Name == DEFAULT_MINIGAME_PACK_FILENAME; bool hasSkins = TryGetDLCSkinPackage(name, identifier, pckFile, fileReader, out IDLCPackage skinPackage); - DLCPackageType dlcPackageType = hasSkins ? DLCPackageType.SkinPack : DLCPackageType.Unknown; + DLCPackageType dlcPackageType = hasSkins ? DLCPackageType.SkinPack : DLCPackageType.RawAssets; DirectoryInfo dataDirectoryInfo = fileInfo.Directory.EnumerateDirectories().Where(dirInfo => dirInfo.Name == DATA_DIRECTORY_NAME).FirstOrDefault(); @@ -191,7 +194,7 @@ namespace PckStudio.Core.DLC } Debug.WriteLine(dlcPackageType); - return new UnknownDLCPackage(name, pckFile); + return new RawAssetDLCPackage(name, pckFile, ByteOrder); } private Dictionary> GetMapData(PckFile pck, DirectoryInfo dataDirectory) diff --git a/PckStudio.Core/DLC/DLCPackageType.cs b/PckStudio.Core/DLC/DLCPackageType.cs index c7a41062..1b51a600 100644 --- a/PckStudio.Core/DLC/DLCPackageType.cs +++ b/PckStudio.Core/DLC/DLCPackageType.cs @@ -2,8 +2,8 @@ { public enum DLCPackageType : int { - Unknown = -1, - Invalid, + Invalid = -1, + RawAssets, SkinPack, TexturePack, MashUpPack, diff --git a/PckStudio.Core/DLC/UnknownDLCPackage.cs b/PckStudio.Core/DLC/RawAssetDLCPackage.cs similarity index 51% rename from PckStudio.Core/DLC/UnknownDLCPackage.cs rename to PckStudio.Core/DLC/RawAssetDLCPackage.cs index 1184e5e3..cc24da7d 100644 --- a/PckStudio.Core/DLC/UnknownDLCPackage.cs +++ b/PckStudio.Core/DLC/RawAssetDLCPackage.cs @@ -3,21 +3,23 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using OMI; using OMI.Formats.Pck; -using PckStudio.Core.Interfaces; namespace PckStudio.Core.DLC { - public sealed class UnknownDLCPackage : DLCPackage + public sealed class RawAssetDLCPackage : DLCPackage { public PckFile PckFile { get; } + public ByteOrder ByteOrder { get; } - public UnknownDLCPackage(string name, PckFile pckFile) - : base(name ?? nameof(UnknownDLCPackage), -1, default) + public RawAssetDLCPackage(string name, PckFile pckFile, ByteOrder byteOrder) + : base(name ?? nameof(RawAssetDLCPackage), -1, default) { PckFile = pckFile; + ByteOrder = byteOrder; } - public override DLCPackageType GetDLCPackageType() => DLCPackageType.Unknown; + public override DLCPackageType GetDLCPackageType() => DLCPackageType.RawAssets; } } diff --git a/PckStudio.Core/PackInfo.cs b/PckStudio.Core/PackInfo.cs deleted file mode 100644 index e40f4b0f..00000000 --- a/PckStudio.Core/PackInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using OMI.Formats.Pck; - -namespace PckStudio.Core -{ - public sealed class PackInfo - { - public static readonly PackInfo Empty = new PackInfo(default, default, default); - public bool IsValid { get; } - public PckFile File { get; } - public OMI.ByteOrder ByteOrder { get; } - - public bool AllowByteOrderSwap { get; } - - public static PackInfo Create(PckFile file, OMI.ByteOrder byteOrder, bool allowByteOrderSwap) - { - return new PackInfo(file, byteOrder, allowByteOrderSwap); - } - - private PackInfo(PckFile file, OMI.ByteOrder byteOrder, bool allowByteOrderSwap) - { - File = file; - ByteOrder = byteOrder; - AllowByteOrderSwap = allowByteOrderSwap; - IsValid = file is not null && Enum.IsDefined(typeof(OMI.ByteOrder), byteOrder); - } - } -} \ No newline at end of file diff --git a/PckStudio.Core/PckStudio.Core.csproj b/PckStudio.Core/PckStudio.Core.csproj index 671efa3f..11c56dbf 100644 --- a/PckStudio.Core/PckStudio.Core.csproj +++ b/PckStudio.Core/PckStudio.Core.csproj @@ -78,7 +78,7 @@ - + @@ -159,7 +159,6 @@ - True diff --git a/PckStudio.Rendering/TextureChangingEventArgs.cs b/PckStudio.Rendering/TextureChangingEventArgs.cs index af9cbe7f..6174e509 100644 --- a/PckStudio.Rendering/TextureChangingEventArgs.cs +++ b/PckStudio.Rendering/TextureChangingEventArgs.cs @@ -18,7 +18,6 @@ using System.ComponentModel; using System.Drawing; -<<<<<<<< HEAD:PckStudio.Rendering/TextureChangingEventArgs.cs namespace PckStudio.Rendering { public class TextureChangingEventArgs : CancelEventArgs @@ -29,26 +28,5 @@ namespace PckStudio.Rendering { NewTexture = newTexture; } -======== -namespace PckStudio.Core -{ - public enum ResourceCategory - { - Unknown = -1, - ItemAnimation, - BlockAnimation, - MobEntityTextures, - ItemEntityTextures, - ItemAtlas, - BlockAtlas, - ParticleAtlas, - BannerAtlas, - PaintingAtlas, - ExplosionAtlas, - ExperienceOrbAtlas, - MoonPhaseAtlas, - MapIconAtlas, - AdditionalMapIconsAtlas, ->>>>>>>> main:PckStudio.Core/ResourceCategory.cs } } \ No newline at end of file