mirror of
https://github.com/muskit/H3VR-TNH-Quality-of-Life-Improvements.git
synced 2026-06-02 20:24:26 -07:00
update MeatKit (9a1a68ab68cd0650227af944ffa30d1166b9e056)
This commit is contained in:
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using AssetsTools.NET;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
@@ -18,6 +17,8 @@ namespace MeatKit
|
||||
[CreateAssetMenu(menuName = "MeatKit/Build Profile")]
|
||||
public class BuildProfile : ScriptableObject, IValidatable
|
||||
{
|
||||
private const string BaseOutputPath = "AssetBundles/";
|
||||
|
||||
[Header("Thunderstore Metadata")]
|
||||
public string PackageName = "";
|
||||
public string Author = "";
|
||||
@@ -31,10 +32,10 @@ namespace MeatKit
|
||||
[Header("Script Options")]
|
||||
public bool StripNamespaces = true;
|
||||
public string[] AdditionalNamespaces = new string[0];
|
||||
|
||||
public bool ApplyHarmonyPatches = true;
|
||||
|
||||
[Header("Export Options")]
|
||||
public BuildItem[] BuildItems = new BuildItem[0];
|
||||
public AssetBundleCompressionType BundleCompressionType = AssetBundleCompressionType.LZ4;
|
||||
public BuildAction BuildAction = BuildAction.JustBuildFiles;
|
||||
|
||||
[HideInInspector]
|
||||
@@ -49,6 +50,11 @@ namespace MeatKit
|
||||
messages["PackageName"] =
|
||||
BuildMessage.Error("Package name can only contain letters, numbers, and underscores.");
|
||||
|
||||
// Author needs to match regex
|
||||
if (!Regex.IsMatch(Author, @"^[a-zA-Z_0-9]+$"))
|
||||
messages["Author"] =
|
||||
BuildMessage.Error("Author can only contain letters, numbers, and underscores.");
|
||||
|
||||
// Make sure the version number is a valid x.x.x
|
||||
if (!Regex.IsMatch(Version, @"^\d+\.\d+\.\d+$"))
|
||||
messages["Version"] = BuildMessage.Error("Version number must be in format 'x.x.x'.");
|
||||
@@ -65,18 +71,8 @@ namespace MeatKit
|
||||
|
||||
if (!ReadMe)
|
||||
messages["ReadMe"] = BuildMessage.Error("Missing readme.");
|
||||
|
||||
switch (BundleCompressionType)
|
||||
{
|
||||
case AssetBundleCompressionType.NONE:
|
||||
messages["BundleCompressionType"] = BuildMessage.Warning(
|
||||
"Uncompressed bundles are not recommended for publication. They can and will be very large.");
|
||||
break;
|
||||
case AssetBundleCompressionType.LZMA:
|
||||
messages["BundleCompressionType"] = BuildMessage.Info(
|
||||
"LZMA can take longer to compress than LZ4, however it will result in smaller file sizes usually.");
|
||||
break;
|
||||
}
|
||||
else if (!AssetDatabase.GetAssetPath(ReadMe).EndsWith(".md", StringComparison.InvariantCultureIgnoreCase))
|
||||
messages["ReadMe"] = BuildMessage.Warning("Are you sure this is a Markdown file? It doesn't have the .md file extension.");
|
||||
|
||||
switch (BuildAction)
|
||||
{
|
||||
@@ -109,11 +105,32 @@ namespace MeatKit
|
||||
|
||||
public bool EnsureValidForEditor()
|
||||
{
|
||||
// Go over each build item
|
||||
BuildLog.WriteLine("Starting build profile check...");
|
||||
|
||||
// Check ourselves
|
||||
bool hasErrors = false, hasWarnings = false;
|
||||
foreach (var item in BuildItems)
|
||||
// Check if it has any validation messages
|
||||
foreach (var message in Validate().Values)
|
||||
{
|
||||
// Log them
|
||||
switch (message.Type)
|
||||
{
|
||||
case MessageType.Error:
|
||||
Debug.LogError(AssetDatabase.GetAssetPath(this) + ": " + message.Message);
|
||||
hasErrors = true;
|
||||
break;
|
||||
case MessageType.Warning:
|
||||
Debug.LogWarning(AssetDatabase.GetAssetPath(this) + ": " + message.Message);
|
||||
hasWarnings = true;
|
||||
break;
|
||||
}
|
||||
|
||||
BuildLog.WriteLine(" " + message.Type + ": " + this + ": " + message.Message);
|
||||
}
|
||||
|
||||
// Go over each build item and check for any validation messages
|
||||
foreach (var item in BuildItems.Where(x => x != null))
|
||||
foreach (var message in item.Validate().Values)
|
||||
{
|
||||
// Log them
|
||||
switch (message.Type)
|
||||
{
|
||||
@@ -125,45 +142,54 @@ namespace MeatKit
|
||||
Debug.LogWarning(AssetDatabase.GetAssetPath(item) + ": " + message.Message);
|
||||
hasWarnings = true;
|
||||
break;
|
||||
case MessageType.Info:
|
||||
Debug.Log(AssetDatabase.GetAssetPath(item) + ": " + message.Message);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
BuildLog.WriteLine(" " + message.Type + ": " + item + ": " + message.Message);
|
||||
}
|
||||
|
||||
|
||||
// If there's errors don't let anything continue
|
||||
if (hasErrors)
|
||||
{
|
||||
EditorUtility.DisplayDialog("Build errors",
|
||||
"There were errors validating your build items. Please check the console for more info.", "Ok.");
|
||||
BuildLog.SetCompletionStatus(true, "Build profile failed one or more checks", null);
|
||||
return false;
|
||||
}
|
||||
|
||||
// If there's only warnings, let the user decide if they want to continue
|
||||
if (hasWarnings)
|
||||
return EditorUtility.DisplayDialog("Build warnings",
|
||||
{
|
||||
var continueAnyway = EditorUtility.DisplayDialog("Build warnings",
|
||||
"Some build items validated with warnings. Continue with build anyway?", "Yes", "No");
|
||||
|
||||
// Otherwise continue
|
||||
return true;
|
||||
BuildLog.WriteLine("Build profile has one or more warnings.");
|
||||
BuildLog.WriteLine(" Continue anyway? " + continueAnyway);
|
||||
BuildLog.SetCompletionStatus(true, "User canceled build", null);
|
||||
|
||||
return continueAnyway;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise continue
|
||||
BuildLog.WriteLine(" Build profile passed all checks!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] GetRequiredDependencies()
|
||||
{
|
||||
return BuildItems
|
||||
.Where(x => x != null)
|
||||
.SelectMany(x => x.RequiredDependencies).ToArray();
|
||||
.SelectMany(x => x.RequiredDependencies)
|
||||
.Distinct().ToArray();
|
||||
}
|
||||
|
||||
public string MainNamespace
|
||||
{
|
||||
get
|
||||
{
|
||||
return Author + "." + PackageName;
|
||||
}
|
||||
get { return Author + "." + PackageName; }
|
||||
}
|
||||
|
||||
|
||||
public string[] GetRequiredNamespaces()
|
||||
{
|
||||
return new[] {MainNamespace};
|
||||
@@ -173,7 +199,12 @@ namespace MeatKit
|
||||
{
|
||||
return GetRequiredNamespaces().Concat(AdditionalNamespaces).ToArray();
|
||||
}
|
||||
|
||||
|
||||
public string ExportPath
|
||||
{
|
||||
get { return Path.Combine(BaseOutputPath, Path.Combine(PackageName, Version)) + Path.DirectorySeparatorChar; }
|
||||
}
|
||||
|
||||
public void WriteThunderstoreManifest(string location)
|
||||
{
|
||||
#if H3VR_IMPORTED
|
||||
@@ -187,7 +218,7 @@ namespace MeatKit
|
||||
// ReSharper disable once CoVariantArrayConversion
|
||||
obj["dependencies"] = new JArray(GetRequiredDependencies().Concat(AdditionalDependencies).ToArray());
|
||||
|
||||
File.WriteAllText(location, JsonConvert.SerializeObject(obj));
|
||||
File.WriteAllText(location, JsonConvert.SerializeObject(obj,Formatting.Indented));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -198,4 +229,4 @@ namespace MeatKit
|
||||
CopyToProfile,
|
||||
CreateThunderstorePackage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user