mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-25 21:28:14 +00:00
Created MaterialsFile IO methods
This commit is contained in:
42
PCK-Studio/Classes/IO/Materials/MaterialsReader.cs
Normal file
42
PCK-Studio/Classes/IO/Materials/MaterialsReader.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using PckStudio.Classes.FileTypes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PckStudio.Classes.IO.Materials
|
||||
{
|
||||
public class MaterialsReader : StreamDataReader<MaterialsFile>
|
||||
{
|
||||
public static MaterialsFile Read(Stream stream)
|
||||
{
|
||||
return new MaterialsReader().ReadFromStream(stream);
|
||||
}
|
||||
|
||||
protected MaterialsReader() : base(false) // Doesn't seem that Behaviours uses little endian
|
||||
{
|
||||
}
|
||||
|
||||
protected override MaterialsFile ReadFromStream(Stream stream)
|
||||
{
|
||||
MaterialsFile materialsFile = new MaterialsFile();
|
||||
_ = ReadInt(stream);
|
||||
int entryCount = ReadInt(stream);
|
||||
for (int i = 0; i < entryCount; i++)
|
||||
{
|
||||
string name = ReadString(stream);
|
||||
string material_type = ReadString(stream);
|
||||
materialsFile.entries.Add(new MaterialsFile.MaterialEntry(name, material_type));
|
||||
}
|
||||
return materialsFile;
|
||||
}
|
||||
|
||||
private string ReadString(Stream stream)
|
||||
{
|
||||
short length = ReadShort(stream);
|
||||
return ReadString(stream, length, Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
}
|
||||
39
PCK-Studio/Classes/IO/Materials/MaterialsWriter.cs
Normal file
39
PCK-Studio/Classes/IO/Materials/MaterialsWriter.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using PckStudio.Classes.FileTypes;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace PckStudio.Classes.IO.Materials
|
||||
{
|
||||
internal class MaterialsWriter : StreamDataWriter
|
||||
{
|
||||
private MaterialsFile materialsFile;
|
||||
|
||||
public static void Write(Stream stream, MaterialsFile file)
|
||||
{
|
||||
new MaterialsWriter(file).WriteToStream(stream);
|
||||
}
|
||||
|
||||
public MaterialsWriter(MaterialsFile file) : base(false)
|
||||
{
|
||||
materialsFile = file;
|
||||
}
|
||||
|
||||
protected override void WriteToStream(Stream stream)
|
||||
{
|
||||
WriteInt(stream, 0);
|
||||
WriteInt(stream, materialsFile.entries.Count);
|
||||
foreach (var entry in materialsFile.entries)
|
||||
{
|
||||
WriteString(stream, entry.name);
|
||||
WriteString(stream, entry.material_type);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteString(Stream stream, string s)
|
||||
{
|
||||
WriteShort(stream, (short)s.Length);
|
||||
WriteString(stream, s, Encoding.ASCII);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user