mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/PCK-Studio.git
synced 2026-05-23 11:26:51 +00:00
Move JavaResourcePackConverter to its own cs proj
This commit is contained in:
9
JavaResourcePackConverter/Java/IMinecraftJavaVersion.cs
Normal file
9
JavaResourcePackConverter/Java/IMinecraftJavaVersion.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
interface IMinecraftJavaVersion : IEquatable<Version>
|
||||
{
|
||||
string ToString(string seperator);
|
||||
}
|
||||
}
|
||||
13
JavaResourcePackConverter/Java/ImportResult.cs
Normal file
13
JavaResourcePackConverter/Java/ImportResult.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public readonly struct ImportResult<TResult, TStats>(TResult result, TStats stats)
|
||||
{
|
||||
public readonly TResult Result = result;
|
||||
public readonly TStats Stats = stats;
|
||||
}
|
||||
}
|
||||
64
JavaResourcePackConverter/Java/ImportStatusReport.cs
Normal file
64
JavaResourcePackConverter/Java/ImportStatusReport.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public class ImportStatusReport
|
||||
{
|
||||
#if DEBUG
|
||||
public static ImportStatusReport Debug = new ImportStatusReport(System.Diagnostics.Debug.Listeners);
|
||||
#endif
|
||||
#if TRACE
|
||||
public static ImportStatusReport Trace = new ImportStatusReport(System.Diagnostics.Trace.Listeners);
|
||||
#endif
|
||||
|
||||
private readonly TraceListener[] _listeners;
|
||||
|
||||
private ImportStatusReport(TraceListenerCollection listeners)
|
||||
{
|
||||
_listeners = new TraceListener[listeners.Count];
|
||||
listeners.CopyTo(_listeners, 0);
|
||||
}
|
||||
|
||||
private ImportStatusReport(params TraceListener[] listeners)
|
||||
{
|
||||
_listeners = listeners;
|
||||
}
|
||||
|
||||
private class ImportStatusReportTextWriter : TextWriter
|
||||
{
|
||||
private readonly Action<string> _postMessage;
|
||||
|
||||
public override Encoding Encoding => Encoding.Default;
|
||||
|
||||
public ImportStatusReportTextWriter(Action<string> postMessage) => _postMessage = postMessage;
|
||||
|
||||
public override void Write(string value) => _postMessage(value);
|
||||
public override void WriteLine(string value) => _postMessage(value + Environment.NewLine);
|
||||
}
|
||||
|
||||
public static ImportStatusReport CreateCustom(Action<string> postMessage)
|
||||
{
|
||||
TextWriterTraceListener listener = new TextWriterTraceListener(new ImportStatusReportTextWriter(postMessage));
|
||||
return new ImportStatusReport(listener);
|
||||
}
|
||||
|
||||
public static ImportStatusReport CreateEmpty()
|
||||
{
|
||||
return new ImportStatusReport();
|
||||
}
|
||||
|
||||
public void Post(string message)
|
||||
{
|
||||
foreach (TraceListener listener in _listeners)
|
||||
{
|
||||
listener.WriteLine(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
127
JavaResourcePackConverter/Java/JavaConstants.cs
Normal file
127
JavaResourcePackConverter/Java/JavaConstants.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PckStudio.Core.Extensions;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public class JavaConstants
|
||||
{
|
||||
public static Dictionary<string, (Color foreground, Color background)> JavaColorCodeToColor { get; } = new Dictionary<string, (Color foreground, Color background)>()
|
||||
{
|
||||
["§0"] = (Color.FromArgb(0x00, 0x00, 0x00), Color.FromArgb(18, 18, 18)),
|
||||
["§1"] = (Color.FromArgb(0x00, 0x00, 0xAA), Color.FromArgb(0x00, 0x00, 0x2A)),
|
||||
["§2"] = (Color.FromArgb(0x00, 0xAA, 0x00), Color.FromArgb(0x00, 0x2A, 0x00)),
|
||||
["§3"] = (Color.FromArgb(0x00, 0xAA, 0xAA), Color.FromArgb(0x00, 0x2A, 0x2A)),
|
||||
["§4"] = (Color.FromArgb(0xAA, 0x00, 0x00), Color.FromArgb(0x2A, 0x00, 0x00)),
|
||||
["§5"] = (Color.FromArgb(0xAA, 0x00, 0xAA), Color.FromArgb(0x2A, 0x00, 0x2A)),
|
||||
["§6"] = (Color.FromArgb(0xFF, 0xAA, 0x00), Color.FromArgb(0x2A, 0x2A, 0x00)),
|
||||
["§7"] = (Color.FromArgb(0xAA, 0xAA, 0xAA), Color.FromArgb(0x2A, 0x2A, 0x2A)),
|
||||
["§8"] = (Color.FromArgb(0x55, 0x55, 0x55), Color.FromArgb(0x15, 0x15, 0x15)),
|
||||
["§9"] = (Color.FromArgb(0x55, 0x55, 0xFF), Color.FromArgb(0x15, 0x15, 0x3F)),
|
||||
["§a"] = (Color.FromArgb(0x55, 0xFF, 0x55), Color.FromArgb(0x15, 0x3F, 0x15)),
|
||||
["§b"] = (Color.FromArgb(0x55, 0xFF, 0xFF), Color.FromArgb(0x15, 0x3F, 0x3F)),
|
||||
["§c"] = (Color.FromArgb(0xFF, 0x55, 0x55), Color.FromArgb(0x3F, 0x15, 0x15)),
|
||||
["§d"] = (Color.FromArgb(0xFF, 0x55, 0xFF), Color.FromArgb(0x3F, 0x15, 0x3F)),
|
||||
["§e"] = (Color.FromArgb(0xFF, 0xFF, 0x55), Color.FromArgb(0x3F, 0x3F, 0x15)),
|
||||
["§f"] = (Color.FromArgb(0xFF, 0xFF, 0xFF), Color.FromArgb(0x3F, 0x3F, 0x3F)),
|
||||
["§g"] = (Color.FromArgb(0xDD, 0xD6, 0x05), Color.FromArgb(0x37, 0x35, 0x01)),
|
||||
["§h"] = (Color.FromArgb(0xE3, 0xD4, 0xD1), Color.FromArgb(0x38, 0x35, 0x34)),
|
||||
["§i"] = (Color.FromArgb(0xCE, 0xCA, 0xCA), Color.FromArgb(0x33, 0x32, 0x32)),
|
||||
["§j"] = (Color.FromArgb(0x44, 0x3A, 0x3B), Color.FromArgb(0x11, 0x0E, 0x0E)),
|
||||
["§m"] = (Color.FromArgb(0x97, 0x16, 0x07), Color.FromArgb(0x25, 0x05, 0x01)),
|
||||
["§n"] = (Color.FromArgb(0xB4, 0x68, 0x4D), Color.FromArgb(0x2D, 0x1A, 0x13)),
|
||||
["§p"] = (Color.FromArgb(0xDE, 0xB1, 0x2D), Color.FromArgb(0x37, 0x2C, 0x0B)),
|
||||
["§q"] = (Color.FromArgb(0x47, 0xA0, 0x36), Color.FromArgb(0x04, 0x28, 0x0D)),
|
||||
["§s"] = (Color.FromArgb(0x2C, 0xBA, 0xA8), Color.FromArgb(0x0B, 0x2E, 0x2A)),
|
||||
["§t"] = (Color.FromArgb(0x21, 0x49, 0x7B), Color.FromArgb(0x08, 0x12, 0x1E)),
|
||||
["§u"] = (Color.FromArgb(0x9A, 0x5C, 0xC6), Color.FromArgb(0x26, 0x17, 0x31)),
|
||||
};
|
||||
|
||||
public static readonly Color BirchLeaves = Color.FromArgb(unchecked((int)0xFF_80A755));
|
||||
public static readonly Color SpruceLeaves = Color.FromArgb(unchecked((int)0xFF_619961));
|
||||
public static readonly Color LilyPad = Color.FromArgb(unchecked((int)0xFF_208030));
|
||||
public static readonly Color AttachedMelonStem = Color.FromArgb(unchecked((int)0xFF_E0C71C));
|
||||
public static readonly Color AttachedPumpkinStem = Color.FromArgb(unchecked((int)0xFF_E0C71C));
|
||||
|
||||
public static string EsapceMiencarftJavaFormat(string text)
|
||||
=> text.Split(['§'], StringSplitOptions.RemoveEmptyEntries).ToString("");
|
||||
|
||||
|
||||
public struct HTMLString(string value)
|
||||
{
|
||||
private string value = value;
|
||||
|
||||
private List<string> _front = new();
|
||||
private List<string> _back = new();
|
||||
|
||||
public void AddTag(string tagName, params string[] parameters)
|
||||
{
|
||||
string param = string.Join(" ", parameters);
|
||||
_front.Add($"<{new string[] { tagName, param }.ToString(" ")}>");
|
||||
_back.Insert(0, $"</{tagName}>");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Join("", _front) + value + string.Join("", _back);
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertJavaTextFormatToHTML(string text)
|
||||
{
|
||||
string[] sections = text.Split(['§'], StringSplitOptions.RemoveEmptyEntries);
|
||||
if (sections.Length == 0)
|
||||
return text;
|
||||
Color textColor = Color.White;
|
||||
string formatText = string.Join("", sections
|
||||
.Select(s =>
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return "";
|
||||
string colorFormat = "§" + s[0];
|
||||
if (JavaColorCodeToColor.TryGetValue(colorFormat, out (Color foreground, Color background) color))
|
||||
{
|
||||
textColor = color.foreground;
|
||||
}
|
||||
|
||||
if (s.Length == 1)
|
||||
return "";
|
||||
|
||||
string colorText = s.Substring(1);
|
||||
bool hasNewLineAtEnd = colorText.EndsWith("\n");
|
||||
string text = hasNewLineAtEnd ? colorText.Substring(0, colorText.Length - 1) : colorText;
|
||||
string cr = hasNewLineAtEnd ? "\n" : "";
|
||||
HTMLString htmlString = new HTMLString(colorText);
|
||||
if (colorFormat == "§r")
|
||||
{
|
||||
textColor = Color.White;
|
||||
}
|
||||
if (textColor != Color.White)
|
||||
{
|
||||
string htmlForegroundColor = textColor.ToHTMLColor();
|
||||
htmlString.AddTag("font", $"color=\"{htmlForegroundColor}\"");
|
||||
}
|
||||
// italic
|
||||
if (colorFormat == "§o")
|
||||
htmlString.AddTag("i");
|
||||
// bold
|
||||
if (colorFormat == "§l")
|
||||
htmlString.AddTag("b");
|
||||
// strikethrough
|
||||
if (colorFormat == "§m")
|
||||
htmlString.AddTag("s");
|
||||
// underline
|
||||
if (colorFormat == "§n")
|
||||
htmlString.AddTag("u");
|
||||
|
||||
return $"{htmlString}{cr}";
|
||||
}
|
||||
));
|
||||
return formatText;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
JavaResourcePackConverter/Java/McPack.cs
Normal file
18
JavaResourcePackConverter/Java/McPack.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public struct McPack
|
||||
{
|
||||
[JsonIgnore]
|
||||
public Image Icon;
|
||||
|
||||
[JsonProperty("pack_format")]
|
||||
public int Format;
|
||||
|
||||
[JsonProperty("description")]
|
||||
public string Description;
|
||||
}
|
||||
}
|
||||
|
||||
24
JavaResourcePackConverter/Java/PointJsonConverter.cs
Normal file
24
JavaResourcePackConverter/Java/PointJsonConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public class PointJsonConverter : JsonConverter<Point>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, Point value, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = new JObject();
|
||||
jo.Add("x", value.X);
|
||||
jo.Add("y", value.Y);
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
|
||||
public override Point ReadJson(JsonReader reader, Type objectType, Point existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
return new Point((int)(jo["x"] ?? 0), (int)(jo["y"] ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
1051
JavaResourcePackConverter/Java/ResourcePackImporter.cs
Normal file
1051
JavaResourcePackConverter/Java/ResourcePackImporter.cs
Normal file
File diff suppressed because it is too large
Load Diff
15
JavaResourcePackConverter/Java/SingleVersion.cs
Normal file
15
JavaResourcePackConverter/Java/SingleVersion.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
class SingleVersion(Version version) : IMinecraftJavaVersion
|
||||
{
|
||||
private readonly Version _version = version;
|
||||
|
||||
public SingleVersion(string version) : this(new Version(version)) { }
|
||||
|
||||
public bool Equals(Version other) => _version.Equals(other);
|
||||
|
||||
public string ToString(string _) => _version.ToString();
|
||||
}
|
||||
}
|
||||
24
JavaResourcePackConverter/Java/SizeJsonConverter.cs
Normal file
24
JavaResourcePackConverter/Java/SizeJsonConverter.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
public class SizeJsonConverter : JsonConverter<Size>
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, Size value, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = new JObject();
|
||||
jo.Add("width", value.Width);
|
||||
jo.Add("height", value.Height);
|
||||
jo.WriteTo(writer);
|
||||
}
|
||||
|
||||
public override Size ReadJson(JsonReader reader, Type objectType, Size existingValue, bool hasExistingValue, JsonSerializer serializer)
|
||||
{
|
||||
JObject jo = JObject.Load(reader);
|
||||
return new Size((int)(jo["width"] ?? 0), (int)(jo["height"] ?? 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
14
JavaResourcePackConverter/Java/SpecificVerions.cs
Normal file
14
JavaResourcePackConverter/Java/SpecificVerions.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using PckStudio.Core.Extensions;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
class SpecificVerions(params Version[] versions) : IMinecraftJavaVersion
|
||||
{
|
||||
private readonly Version[] _versions = versions;
|
||||
|
||||
public bool Equals(Version other) => other?.EqualsAny(_versions) ?? default;
|
||||
|
||||
public string ToString(string seperator) => _versions.ToString(seperator);
|
||||
}
|
||||
}
|
||||
16
JavaResourcePackConverter/Java/VersionRange.cs
Normal file
16
JavaResourcePackConverter/Java/VersionRange.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace JavaResourcePackConverter
|
||||
{
|
||||
class VersionRange(Version min, Version max) : IMinecraftJavaVersion
|
||||
{
|
||||
private readonly Version _min = min;
|
||||
private readonly Version _max = max;
|
||||
|
||||
public VersionRange(string min, string max) : this(new Version(min), new Version(max)) { }
|
||||
|
||||
public bool Equals(Version other) => _min <= other && other <= _max;
|
||||
|
||||
public string ToString(string seperator) => $"{_min}{seperator}{_max}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user