Compare commits
8
Commits
88ba3cdc48
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f92105c97d | ||
|
|
ddd55c0c58 | ||
|
|
2760dee6a7 | ||
|
|
bb12b8d02d | ||
|
|
6c90f9dc08
|
||
|
|
7debc0240c
|
||
|
|
e9d8e93427
|
||
|
|
2695dcdbba
|
@@ -4,7 +4,29 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
catalog:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker.m.daocloud.io/library/node:22-bookworm
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Validate submodules and version catalog
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
ref="${{ gitea.sha }}"
|
||||
git init .
|
||||
git remote add origin "https://git.crash.work/ShrinkSDK/Workspace.git"
|
||||
git fetch --depth=1 origin "$ref"
|
||||
git checkout --detach FETCH_HEAD
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
bash Tools/CI/Validate-Submodules.sh "$PWD"
|
||||
node Tools/Release/update-shrinksdk-versions.mjs --check
|
||||
|
||||
editmode:
|
||||
needs: catalog
|
||||
runs-on: unity-2022.3.62f3
|
||||
container:
|
||||
image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3
|
||||
@@ -27,8 +49,7 @@ jobs:
|
||||
git checkout --detach FETCH_HEAD
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
test "$(git submodule status --recursive | wc -l | tr -d ' ')" = "21"
|
||||
test -z "$(git submodule status --recursive | grep '^-')"
|
||||
bash Tools/CI/Validate-Submodules.sh "$PWD"
|
||||
|
||||
- name: Run every standalone package EditMode host
|
||||
shell: bash
|
||||
|
||||
@@ -7,7 +7,29 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
catalog:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: docker.m.daocloud.io/library/node:22-bookworm
|
||||
permissions:
|
||||
contents: read
|
||||
steps:
|
||||
- name: Validate submodules and version catalog
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
ref="${{ gitea.sha }}"
|
||||
git init .
|
||||
git remote add origin "https://git.crash.work/ShrinkSDK/Workspace.git"
|
||||
git fetch --depth=1 origin "$ref"
|
||||
git checkout --detach FETCH_HEAD
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
bash Tools/CI/Validate-Submodules.sh "$PWD"
|
||||
node Tools/Release/update-shrinksdk-versions.mjs --check
|
||||
|
||||
unity:
|
||||
needs: catalog
|
||||
runs-on: unity-2022.3.62f3
|
||||
container:
|
||||
image: docker.1panel.live/unityci/editor:ubuntu-2022.3.62f3-windows-mono-3
|
||||
@@ -30,10 +52,7 @@ jobs:
|
||||
git checkout --detach FETCH_HEAD
|
||||
git submodule sync --recursive
|
||||
git submodule update --init --recursive
|
||||
module_count="$(git submodule status --recursive | wc -l | tr -d ' ')"
|
||||
test "$module_count" = "21"
|
||||
test -z "$(git submodule status --recursive | grep '^-')"
|
||||
git submodule status --recursive
|
||||
bash Tools/CI/Validate-Submodules.sh "$PWD"
|
||||
|
||||
- name: Compile Workspace and validate package graph
|
||||
shell: bash
|
||||
|
||||
@@ -79,6 +79,8 @@ mono_crash.*
|
||||
# namespace-suffixed Unity Integration.App packages in source control.
|
||||
!Assets/Modules/*.Integration.App/
|
||||
!Assets/Modules/*.Integration.App/**
|
||||
!Godot/Packages/*.Integration.App/
|
||||
!Godot/Packages/*.Integration.App/**
|
||||
|
||||
# Crashlytics generated file
|
||||
crashlytics-build.properties
|
||||
|
||||
@@ -82,3 +82,11 @@
|
||||
path = Assets/Modules/ShrinkInstaller
|
||||
url = https://git.crash.work/ShrinkSDK/Installer.git
|
||||
branch = main
|
||||
[submodule "Assets/Modules/ShrinkRuntime.Abstractions"]
|
||||
path = Assets/Modules/ShrinkRuntime.Abstractions
|
||||
url = https://git.crash.work/ShrinkSDK/ShrinkRuntime.Abstractions.git
|
||||
branch = main
|
||||
[submodule "Godot/Packages/ShrinkSDK.Godot"]
|
||||
path = Godot/Packages/ShrinkSDK.Godot
|
||||
url = https://git.crash.work/ShrinkSDK/ShrinkGodot.git
|
||||
branch = main
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.RegularExpressions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@@ -13,30 +16,11 @@ namespace ShrinkSDK.WorkspaceValidation
|
||||
{
|
||||
public static class ShrinkSdkWorkspaceValidation
|
||||
{
|
||||
private static readonly ExpectedPackage[] ExpectedPackages =
|
||||
{
|
||||
new ExpectedPackage("ShrinkApp.Core", "com.cneicy.shrink-app-core", "0.1.4"),
|
||||
new ExpectedPackage("ShrinkApp.Starter.Basic", "com.cneicy.shrink-app-starter-basic", "0.2.2"),
|
||||
new ExpectedPackage("ShrinkCommand", "com.cneicy.shrink-command", "0.2.0"),
|
||||
new ExpectedPackage("ShrinkCommand.Integration.App", "com.cneicy.shrink-command-integration-app", "0.1.3"),
|
||||
new ExpectedPackage("ShrinkCommand.Integration.EventBus", "com.cneicy.shrink-command-integration-eventbus", "0.1.2"),
|
||||
new ExpectedPackage("ShrinkCommand.Integration.Network", "com.cneicy.shrink-command-integration-network", "0.1.1"),
|
||||
new ExpectedPackage("ShrinkContext.AppAdapter", "com.cneicy.shrink-context-app-adapter", "0.1.5"),
|
||||
new ExpectedPackage("ShrinkContext.Core", "com.cneicy.shrink-context-core", "0.1.0"),
|
||||
new ExpectedPackage("ShrinkContext.EventBusAdapter", "com.cneicy.shrink-context-eventbus-adapter", "0.1.1"),
|
||||
new ExpectedPackage("ShrinkDataSaver", "com.cneicy.shrink-datasaver", "2.2.2"),
|
||||
new ExpectedPackage("ShrinkDataSaver.Integration.App", "com.cneicy.shrink-datasaver-integration-app", "0.1.3"),
|
||||
new ExpectedPackage("ShrinkDataSaver.Integration.EventBus", "com.cneicy.shrink-datasaver-integration-eventbus", "2.1.3"),
|
||||
new ExpectedPackage("ShrinkEventBus", "com.cneicy.shrink-eventbus", "2.0.1"),
|
||||
new ExpectedPackage("ShrinkEventBus.Entities", "com.cneicy.shrink-eventbus-entities", "0.1.1"),
|
||||
new ExpectedPackage("ShrinkInstaller", "com.cneicy.shrink-installer", "0.2.4"),
|
||||
new ExpectedPackage("ShrinkModFramework", "com.cneicy.shrink-mod-framework", "0.2.4"),
|
||||
new ExpectedPackage("ShrinkNetwork", "com.cneicy.shrink-network", "0.2.1"),
|
||||
new ExpectedPackage("ShrinkNetwork.Integration.App", "com.cneicy.shrink-network-integration-app", "0.1.3"),
|
||||
new ExpectedPackage("ShrinkNetwork.Integration.EventBus", "com.cneicy.shrink-network-integration-eventbus", "0.1.3"),
|
||||
new ExpectedPackage("ShrinkShared.CodeGen", "com.cneicy.shrink-shared-codegen", "0.1.0"),
|
||||
new ExpectedPackage("ShrinkTutorial", "com.cneicy.shrink-tutorial", "0.1.4")
|
||||
};
|
||||
private const string InstallerPackageName = "com.cneicy.shrink-installer";
|
||||
private const string InstallerCatalogTypeName = "ShrinkSDK.Installer.ShrinkSdkPackageCatalog";
|
||||
private static readonly Regex SemanticVersion = new Regex(
|
||||
@"^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$",
|
||||
RegexOptions.CultureInvariant);
|
||||
|
||||
public static void Run()
|
||||
{
|
||||
@@ -45,6 +29,7 @@ namespace ShrinkSDK.WorkspaceValidation
|
||||
var workspaceRoot = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
|
||||
var packages = ReadPackages(workspaceRoot);
|
||||
ValidateGraph(packages);
|
||||
ValidateInstallerCatalog(packages);
|
||||
Debug.Log($"ShrinkSDK Workspace validation passed: packages={packages.Count}");
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
@@ -57,36 +42,97 @@ namespace ShrinkSDK.WorkspaceValidation
|
||||
|
||||
private static Dictionary<string, PackageDefinition> ReadPackages(string workspaceRoot)
|
||||
{
|
||||
var result = new Dictionary<string, PackageDefinition>(StringComparer.Ordinal);
|
||||
foreach (var expected in ExpectedPackages)
|
||||
var modulesRoot = Path.Combine(workspaceRoot, "Assets", "Modules");
|
||||
if (!Directory.Exists(modulesRoot))
|
||||
{
|
||||
var manifestPath = Path.Combine(workspaceRoot, "Assets", "Modules", expected.Directory, "package.json");
|
||||
throw new DirectoryNotFoundException($"Workspace package directory is missing: {modulesRoot}");
|
||||
}
|
||||
|
||||
var declaredDirectories = ReadDeclaredPackageDirectories(workspaceRoot);
|
||||
var manifestDirectories = Directory.EnumerateDirectories(modulesRoot)
|
||||
.Where(directory => File.Exists(Path.Combine(directory, "package.json")))
|
||||
.Select(Path.GetFullPath)
|
||||
.ToHashSet(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
var undeclared = manifestDirectories
|
||||
.Where(directory => !declaredDirectories.Contains(directory))
|
||||
.OrderBy(directory => directory, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
if (undeclared.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Package directories are not declared as submodules: " + string.Join(", ", undeclared));
|
||||
}
|
||||
|
||||
var result = new Dictionary<string, PackageDefinition>(StringComparer.Ordinal);
|
||||
foreach (var directory in declaredDirectories.OrderBy(value => value, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var manifestPath = Path.Combine(directory, "package.json");
|
||||
if (!File.Exists(manifestPath))
|
||||
{
|
||||
throw new FileNotFoundException($"Required package manifest is missing: {expected.Directory}", manifestPath);
|
||||
throw new FileNotFoundException("Declared package submodule has no package.json.", manifestPath);
|
||||
}
|
||||
|
||||
var manifest = JObject.Parse(File.ReadAllText(manifestPath));
|
||||
var packageName = manifest.Value<string>("name");
|
||||
var version = manifest.Value<string>("version");
|
||||
if (packageName == null || version == null || packageName.Length == 0 || version.Length == 0)
|
||||
if (string.IsNullOrWhiteSpace(packageName) || string.IsNullOrWhiteSpace(version))
|
||||
{
|
||||
throw new InvalidOperationException($"{expected.Directory} has no valid package name or version.");
|
||||
throw new InvalidOperationException($"{directory} has no valid package name or version.");
|
||||
}
|
||||
|
||||
if (!string.Equals(packageName, expected.Name, StringComparison.Ordinal) ||
|
||||
!string.Equals(version, expected.Version, StringComparison.Ordinal))
|
||||
var validPackageName = packageName!;
|
||||
var validVersion = version!;
|
||||
if (!SemanticVersion.IsMatch(validVersion))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"{expected.Directory} must be {expected.Name}@{expected.Version}, found {packageName}@{version}.");
|
||||
throw new InvalidOperationException($"{validPackageName} has an invalid semantic version: {validVersion}");
|
||||
}
|
||||
|
||||
if (result.ContainsKey(packageName))
|
||||
if (result.ContainsKey(validPackageName))
|
||||
{
|
||||
throw new InvalidOperationException($"Duplicate package manifest name: {packageName}");
|
||||
throw new InvalidOperationException($"Duplicate package manifest name: {validPackageName}");
|
||||
}
|
||||
|
||||
result.Add(packageName, new PackageDefinition(packageName, version, manifest));
|
||||
result.Add(validPackageName, new PackageDefinition(validPackageName, validVersion, manifest));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static HashSet<string> ReadDeclaredPackageDirectories(string workspaceRoot)
|
||||
{
|
||||
var gitModulesPath = Path.Combine(workspaceRoot, ".gitmodules");
|
||||
if (!File.Exists(gitModulesPath))
|
||||
{
|
||||
throw new FileNotFoundException("Workspace .gitmodules is missing.", gitModulesPath);
|
||||
}
|
||||
|
||||
var result = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var line in File.ReadLines(gitModulesPath))
|
||||
{
|
||||
var match = Regex.Match(line, @"^\s*path\s*=\s*(?<path>.+?)\s*$", RegexOptions.CultureInvariant);
|
||||
if (!match.Success)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var relativePath = match.Groups["path"].Value.Replace('\\', '/');
|
||||
if (!relativePath.StartsWith("Assets/Modules/", StringComparison.Ordinal) ||
|
||||
relativePath.Substring("Assets/Modules/".Length).Contains("/"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var fullPath = Path.GetFullPath(Path.Combine(workspaceRoot, relativePath));
|
||||
if (!result.Add(fullPath))
|
||||
{
|
||||
throw new InvalidOperationException($"Duplicate package submodule path: {relativePath}");
|
||||
}
|
||||
}
|
||||
|
||||
if (result.Count == 0)
|
||||
{
|
||||
throw new InvalidOperationException("No Assets/Modules package submodules are declared.");
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -158,6 +204,63 @@ namespace ShrinkSDK.WorkspaceValidation
|
||||
}
|
||||
}
|
||||
|
||||
private static void ValidateInstallerCatalog(IReadOnlyDictionary<string, PackageDefinition> packages)
|
||||
{
|
||||
var catalogType = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.Select(assembly => assembly.GetType(InstallerCatalogTypeName, false))
|
||||
.FirstOrDefault(type => type != null)
|
||||
?? throw new InvalidOperationException($"Installer catalog type was not loaded: {InstallerCatalogTypeName}");
|
||||
var packagesField = catalogType.GetField("Packages", BindingFlags.Static | BindingFlags.NonPublic)
|
||||
?? throw new InvalidOperationException("Installer catalog Packages field was not found.");
|
||||
var catalogItems = packagesField.GetValue(null) as IEnumerable
|
||||
?? throw new InvalidOperationException("Installer catalog Packages field is not enumerable.");
|
||||
|
||||
var catalog = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
foreach (var item in catalogItems)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
throw new InvalidOperationException("Installer catalog contains a null package entry.");
|
||||
}
|
||||
|
||||
var itemType = item.GetType();
|
||||
var packageName = itemType.GetProperty("PackageName")?.GetValue(item) as string;
|
||||
var version = itemType.GetProperty("Version")?.GetValue(item) as string;
|
||||
if (string.IsNullOrWhiteSpace(packageName) || string.IsNullOrWhiteSpace(version))
|
||||
{
|
||||
throw new InvalidOperationException("Installer catalog contains an invalid package entry.");
|
||||
}
|
||||
|
||||
var validPackageName = packageName!;
|
||||
var validVersion = version!;
|
||||
if (!catalog.TryAdd(validPackageName, validVersion))
|
||||
{
|
||||
throw new InvalidOperationException($"Installer catalog contains duplicate package: {validPackageName}");
|
||||
}
|
||||
}
|
||||
|
||||
var expectedNames = packages.Keys
|
||||
.Where(name => !string.Equals(name, InstallerPackageName, StringComparison.Ordinal))
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
var missing = expectedNames.Except(catalog.Keys).OrderBy(name => name, StringComparer.Ordinal).ToArray();
|
||||
var unexpected = catalog.Keys.Except(expectedNames).OrderBy(name => name, StringComparer.Ordinal).ToArray();
|
||||
if (missing.Length > 0 || unexpected.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Installer catalog package set differs from Workspace. Missing=[{string.Join(", ", missing)}], " +
|
||||
$"unexpected=[{string.Join(", ", unexpected)}]");
|
||||
}
|
||||
|
||||
foreach (var packageName in expectedNames)
|
||||
{
|
||||
if (!string.Equals(catalog[packageName], packages[packageName].Version, StringComparison.Ordinal))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Installer catalog requires {packageName} {catalog[packageName]}, but the Workspace provides {packages[packageName].Version}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class PackageDefinition
|
||||
{
|
||||
public PackageDefinition(string name, string version, JObject manifest)
|
||||
@@ -171,20 +274,6 @@ namespace ShrinkSDK.WorkspaceValidation
|
||||
public string Version { get; }
|
||||
public JObject Manifest { get; }
|
||||
}
|
||||
|
||||
private readonly struct ExpectedPackage
|
||||
{
|
||||
public ExpectedPackage(string directory, string name, string version)
|
||||
{
|
||||
Directory = directory;
|
||||
Name = name;
|
||||
Version = version;
|
||||
}
|
||||
|
||||
public string Directory { get; }
|
||||
public string Name { get; }
|
||||
public string Version { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Submodule Assets/Modules/ShrinkApp.Core updated: a5c5a70075...59d1a6c085
Submodule Assets/Modules/ShrinkApp.Starter.Basic updated: f8906faaec...c210428cb0
Submodule Assets/Modules/ShrinkCommand updated: 4ed7a91c79...5414a747e5
Submodule Assets/Modules/ShrinkCommand.Integration.App updated: 57246d5194...4b621a0ca2
Submodule Assets/Modules/ShrinkCommand.Integration.EventBus updated: 53720a3b71...2880c25888
Submodule Assets/Modules/ShrinkCommand.Integration.Network updated: bf315619f0...af97af183b
Submodule Assets/Modules/ShrinkContext.AppAdapter updated: 8b3121bc21...789aa2181b
Submodule Assets/Modules/ShrinkContext.Core updated: a4c78ea7a7...b93f3e6122
Submodule Assets/Modules/ShrinkContext.EventBusAdapter updated: 088a8f9606...254625e791
Submodule Assets/Modules/ShrinkDataSaver updated: 0030f5b794...d26f1a94ef
Submodule Assets/Modules/ShrinkDataSaver.Integration.App updated: e7da03273e...2b2b808aa3
Submodule Assets/Modules/ShrinkDataSaver.Integration.EventBus updated: 599b8e34c6...15b511feb6
Submodule Assets/Modules/ShrinkEventBus updated: 8aa4c79604...c44a7e6dda
Submodule Assets/Modules/ShrinkEventBus.Entities updated: 368870f0df...b888d8d247
Submodule Assets/Modules/ShrinkInstaller updated: 2abf367f36...30a6a11344
Submodule Assets/Modules/ShrinkModFramework updated: fea6ec56fc...af76458da0
Submodule Assets/Modules/ShrinkNetwork updated: 26241cb534...c7c45b26f8
Submodule Assets/Modules/ShrinkNetwork.Integration.App updated: 2cd552ef25...fa77a9ea96
Submodule Assets/Modules/ShrinkNetwork.Integration.EventBus updated: eb7fa55656...66f17aae85
+1
Submodule Assets/Modules/ShrinkRuntime.Abstractions added at 55bc7a4e75
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fdcff332146fc1d439fc0c82285637da
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"name": "ShrinkRuntime.Abstractions",
|
||||
"rootNamespace": "ShrinkSDK.Runtime",
|
||||
"autoReferenced": true
|
||||
}
|
||||
-7
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9285a23e48a9fd04ea5d3a7507010d2b
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,127 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ShrinkSDK.Runtime
|
||||
{
|
||||
public enum ShrinkLogLevel { Trace, Debug, Information, Warning, Error }
|
||||
|
||||
public interface IShrinkLogger
|
||||
{
|
||||
void Log(ShrinkLogLevel level, string message, Exception? exception = null);
|
||||
}
|
||||
|
||||
public interface IShrinkMainThreadDispatcher
|
||||
{
|
||||
bool IsMainThread { get; }
|
||||
bool TryPost(Action action);
|
||||
}
|
||||
|
||||
public interface IShrinkClock
|
||||
{
|
||||
DateTimeOffset UtcNow { get; }
|
||||
double UnscaledTimeSeconds { get; }
|
||||
}
|
||||
|
||||
public interface IShrinkPathProvider
|
||||
{
|
||||
string PersistentDataPath { get; }
|
||||
string TemporaryDataPath { get; }
|
||||
}
|
||||
|
||||
public interface IShrinkScreenshotProvider
|
||||
{
|
||||
ValueTask<byte[]> CapturePngAsync(CancellationToken cancellationToken = default);
|
||||
}
|
||||
|
||||
public interface IShrinkApplicationLifecycle
|
||||
{
|
||||
event Action? Paused;
|
||||
event Action? Resumed;
|
||||
event Action? Exiting;
|
||||
}
|
||||
|
||||
public static class ShrinkLoggerExtensions
|
||||
{
|
||||
public static void Error(this IShrinkLogger logger, string message, Exception? exception = null) =>
|
||||
logger.Log(ShrinkLogLevel.Error, message, exception);
|
||||
}
|
||||
|
||||
public static class ShrinkRuntimeServices
|
||||
{
|
||||
private static IShrinkLogger _logger = new ConsoleLogger();
|
||||
private static IShrinkMainThreadDispatcher _dispatcher = new InlineDispatcher();
|
||||
private static IShrinkClock _clock = new SystemClock();
|
||||
private static IShrinkPathProvider _paths = new SystemPaths();
|
||||
|
||||
public static IShrinkLogger Logger => _logger;
|
||||
public static IShrinkMainThreadDispatcher Dispatcher => _dispatcher;
|
||||
public static IShrinkClock Clock => _clock;
|
||||
public static IShrinkPathProvider Paths => _paths;
|
||||
public static IShrinkScreenshotProvider? Screenshots { get; private set; }
|
||||
public static IShrinkApplicationLifecycle? Lifecycle { get; private set; }
|
||||
|
||||
public static void Configure(IShrinkLogger logger, IShrinkMainThreadDispatcher dispatcher,
|
||||
IShrinkClock clock, IShrinkPathProvider paths,
|
||||
IShrinkScreenshotProvider? screenshots = null, IShrinkApplicationLifecycle? lifecycle = null)
|
||||
{
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
_clock = clock ?? throw new ArgumentNullException(nameof(clock));
|
||||
_paths = paths ?? throw new ArgumentNullException(nameof(paths));
|
||||
Screenshots = screenshots;
|
||||
Lifecycle = lifecycle;
|
||||
}
|
||||
|
||||
private sealed class ConsoleLogger : IShrinkLogger
|
||||
{
|
||||
public void Log(ShrinkLogLevel level, string message, Exception? exception = null)
|
||||
{
|
||||
Console.WriteLine($"[{level}] {message}");
|
||||
if (exception != null) Console.WriteLine(exception);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class InlineDispatcher : IShrinkMainThreadDispatcher
|
||||
{
|
||||
public bool IsMainThread => true;
|
||||
public bool TryPost(Action action)
|
||||
{
|
||||
if (action == null) return false;
|
||||
action();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class SystemClock : IShrinkClock
|
||||
{
|
||||
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
|
||||
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
|
||||
public double UnscaledTimeSeconds => _stopwatch.Elapsed.TotalSeconds;
|
||||
}
|
||||
|
||||
private sealed class SystemPaths : IShrinkPathProvider
|
||||
{
|
||||
public string PersistentDataPath => Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "ShrinkSDK");
|
||||
public string TemporaryDataPath => Path.GetTempPath();
|
||||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false)]
|
||||
public sealed class ShrinkCodeGenWovenAttribute : Attribute
|
||||
{
|
||||
public ShrinkCodeGenWovenAttribute(string weaverVersion, string inputMvid)
|
||||
{
|
||||
WeaverVersion = weaverVersion;
|
||||
InputMvid = inputMvid;
|
||||
}
|
||||
|
||||
public string WeaverVersion { get; }
|
||||
public string InputMvid { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f9b07df5ab1dc345be31f33e94077d2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"name": "com.cneicy.shrink-runtime-abstractions",
|
||||
"version": "0.1.0",
|
||||
"displayName": "ShrinkSDK Runtime Abstractions",
|
||||
"description": "Engine-neutral runtime services and CodeGen marker contracts.",
|
||||
"unity": "2022.3"
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2f07481a8e08f454fa1d85c5afe4c92d
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Submodule Assets/Modules/ShrinkShared.CodeGen updated: 5fd9b258d7...ab6617eda4
Submodule Assets/Modules/ShrinkTutorial updated: 5d66389bd6...1b638dbad5
@@ -65,7 +65,7 @@ ShrinkSDK 是以 Unity Package Manager 包为发布边界的 SDK Workspace,不
|
||||
|
||||
```text
|
||||
ShrinkSDK Workspace/
|
||||
|-- Assets/Modules/ 21 个同路径 Git submodule UPM 包
|
||||
|-- Assets/Modules/ .gitmodules 声明的同路径 Git submodule UPM 包
|
||||
|-- Assets/Modules/*.meta 根仓库追踪的 Unity 目录 GUID
|
||||
|-- Assets/Scenes/ 示例与验收场景
|
||||
|-- Assets/Resources/ 当前应用配置与组合 Profile
|
||||
@@ -73,6 +73,7 @@ ShrinkSDK Workspace/
|
||||
|-- GeneratedModSdk/ Mod SDK 导出物
|
||||
|-- Packages/ 根 Unity 工程依赖
|
||||
|-- Tools/UpmConsumerValidation/ 干净 UPM 消费工程验证
|
||||
|-- Tools/Release/ 包版本、依赖与目录同步工具
|
||||
|-- Tools/RepositoryMigration/ 子模块、发布仓库与独立宿主初始化脚本
|
||||
|-- Docs/Archive/ 已完成迁移与过期地图,仅供追溯
|
||||
|-- DESIGN.md 唯一当前架构文档
|
||||
@@ -84,27 +85,28 @@ ShrinkSDK Workspace/
|
||||
|
||||
| 包 | 版本 | 职责 |
|
||||
|---|---:|---|
|
||||
| `com.cneicy.shrink-eventbus` | 2.0.1 | 单一事件模型、多 Bus、生成特性订阅、可选 MonoBehaviour 生命周期织入、UniTask 调度与零 GC 热路径 |
|
||||
| `com.cneicy.shrink-eventbus-entities` | 0.1.1 | ShrinkEventBus 的 ECS/Burst NativeQueue writer 与 playback 适配 |
|
||||
| `com.cneicy.shrink-datasaver` | 2.2.2 | 多槽位存档、设置、迁移、加密、原子写入与备份 |
|
||||
| `com.cneicy.shrink-command` | 0.2.0 | 路径式命令、权限与同步/异步执行 |
|
||||
| `com.cneicy.shrink-network` | 0.2.1 | 消息、RPC、权限、诊断、TCP/KCP/Loopback 与服务器生成 |
|
||||
| `com.cneicy.shrink-mod-framework` | 0.2.4 | 模组发现、依赖、可逆生命周期、命名空间内容覆盖、外部 DLL revision 与 Harmony lease |
|
||||
| `com.cneicy.shrink-tutorial` | 0.1.3 | 数据驱动引导、遮罩、锚点、触发与持久化 |
|
||||
| `com.cneicy.shrink-context-core` | 0.1.0 | 可逆效应、coeffect、fiber、声明式 loader 与诊断 |
|
||||
| `com.cneicy.shrink-app-core` | 0.1.4 | App 设置、服务门面、ClassicHost 兼容面与宿主协议 |
|
||||
| `com.cneicy.shrink-app-starter-basic` | 0.2.2 | 默认 Context 组合根、配置资产和示例入口 |
|
||||
| `com.cneicy.shrink-context-app-adapter` | 0.1.5 | ContextLoader 宿主、Profile/JSON、诊断与基准 |
|
||||
| `com.cneicy.shrink-context-eventbus-adapter` | 0.1.1 | EventBus 生成绑定的可逆 EffectAttach 包装 |
|
||||
| `com.cneicy.shrink-datasaver-integration-eventbus` | 2.1.3 | DataSaver 事件桥 |
|
||||
| `com.cneicy.shrink-datasaver-integration-app` | 0.1.3 | DataSaver App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-command-integration-eventbus` | 0.1.2 | 命令请求与生命周期事件桥 |
|
||||
| `com.cneicy.shrink-command-integration-network` | 0.1.1 | `command/execute` RPC 桥 |
|
||||
| `com.cneicy.shrink-command-integration-app` | 0.1.3 | Command App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-network-integration-eventbus` | 0.1.3 | 网络事件广播、裁决结果与 delta 去重 |
|
||||
| `com.cneicy.shrink-network-integration-app` | 0.1.3 | Network App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-shared-codegen` | 0.1.0 | App、Command、Network 共用的 Editor-only IL 后处理注册表生成器 |
|
||||
| `com.cneicy.shrink-installer` | 0.2.4 | UI Toolkit 包管理器:显示真实安装状态,按 Context 分层提供固定版本单包与推荐组合 |
|
||||
| `com.cneicy.shrink-eventbus` | 2.1.0 | 单一事件模型、多 Bus、生成特性订阅、可选 MonoBehaviour 生命周期织入、UniTask 调度与零 GC 热路径 |
|
||||
| `com.cneicy.shrink-eventbus-entities` | 0.1.2 | ShrinkEventBus 的 ECS/Burst NativeQueue writer 与 playback 适配 |
|
||||
| `com.cneicy.shrink-datasaver` | 2.3.0 | 多槽位存档、设置、迁移、加密、原子写入与备份 |
|
||||
| `com.cneicy.shrink-command` | 0.3.0 | 路径式命令、权限与同步/异步执行 |
|
||||
| `com.cneicy.shrink-network` | 0.3.0 | 消息、RPC、权限、诊断、TCP/KCP/Loopback 与服务器生成 |
|
||||
| `com.cneicy.shrink-mod-framework` | 0.3.0 | 模组发现、依赖、可逆生命周期、命名空间内容覆盖、外部 DLL revision 与 Harmony lease |
|
||||
| `com.cneicy.shrink-tutorial` | 0.2.0 | 数据驱动引导、遮罩、锚点、触发与持久化 |
|
||||
| `com.cneicy.shrink-context-core` | 0.2.0 | 可逆效应、coeffect、fiber、声明式 loader 与诊断 |
|
||||
| `com.cneicy.shrink-app-core` | 0.2.0 | App 设置、服务门面、ClassicHost 兼容面与宿主协议 |
|
||||
| `com.cneicy.shrink-app-starter-basic` | 0.3.0 | 默认 Context 组合根、配置资产和示例入口 |
|
||||
| `com.cneicy.shrink-context-app-adapter` | 0.2.0 | ContextLoader 宿主、Profile/JSON、诊断与基准 |
|
||||
| `com.cneicy.shrink-context-eventbus-adapter` | 0.2.0 | EventBus 生成绑定的可逆 EffectAttach 包装 |
|
||||
| `com.cneicy.shrink-datasaver-integration-eventbus` | 2.2.0 | DataSaver 事件桥 |
|
||||
| `com.cneicy.shrink-datasaver-integration-app` | 0.2.0 | DataSaver App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-command-integration-eventbus` | 0.2.0 | 命令请求与生命周期事件桥 |
|
||||
| `com.cneicy.shrink-command-integration-network` | 0.2.0 | `command/execute` RPC 桥 |
|
||||
| `com.cneicy.shrink-command-integration-app` | 0.2.0 | Command App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-network-integration-eventbus` | 0.2.0 | 网络事件广播、裁决结果与 delta 去重 |
|
||||
| `com.cneicy.shrink-network-integration-app` | 0.2.0 | Network App installer/原生 Context 组件 |
|
||||
| `com.cneicy.shrink-shared-codegen` | 0.1.1 | App、Command、Network 共用的 Editor-only IL 后处理注册表生成器 |
|
||||
| `com.cneicy.shrink-runtime-abstractions` | 0.1.0 | Unity 与其他 .NET 宿主共用的平台服务合同 |
|
||||
| `com.cneicy.shrink-installer` | 0.2.6 | UI Toolkit 包管理器:显示真实安装状态,按 Context 分层提供固定版本单包与推荐组合 |
|
||||
|
||||
`ShrinkShared.CodeGen` 不反向引用业务 asmdef,只按程序集名与类型全名读取 Cecil 元数据,因此业务包可以依赖它而不形成包循环。
|
||||
|
||||
@@ -225,7 +227,7 @@ Mono 中已加载程序集不能真正卸载。系统只回滚组件实例与效
|
||||
1. 内部包图检查:全部 `com.cneicy.*` 依赖版本一致、无循环,普通主包不反向依赖 Integration 包。
|
||||
2. Unity 编译:目标 asmdef 和根项目无编译错误。
|
||||
3. EditMode 测试:功能测试、Context 生命周期、语义扫描和模板覆写保护。
|
||||
4. 真实 UPM 消费:`Tools/UpmConsumerValidation/Validate-UpmConsumer.ps1` 在递归 submodule 初始化后的 Workspace 中创建仓库外形态的临时 Unity 工程,通过 `file:` 安装全部 21 个包,启用 testables,验证包注册、程序集加载并运行 EditMode 测试。发布后还必须分别验证 registry、精确 Git URL 和 Installer 三种空白消费者工程路径。
|
||||
4. 真实 UPM 消费:`Tools/UpmConsumerValidation/Validate-UpmConsumer.ps1` 在递归 submodule 初始化后的 Workspace 中创建仓库外形态的临时 Unity 工程,通过 `file:` 安装全部包,启用 testables,验证包注册、程序集加载并运行 EditMode 测试。发布后还必须分别验证 registry、精确 Git URL 和 Installer 三种空白消费者工程路径。
|
||||
5. 独立宿主:生成工程与 RuntimeSmoke 按变更范围构建或运行。
|
||||
6. 涉及真实生命周期时,仍需在目标场景执行 Play Mode 验收;源码检查和 EditMode 不能替代该路径。
|
||||
|
||||
@@ -253,6 +255,8 @@ Mono 中已加载程序集不能真正卸载。系统只回滚组件实例与效
|
||||
|
||||
- 当前架构只更新本文。
|
||||
- 包级使用方式和 API 示例放在各包 README。
|
||||
- `Tools/Release/Update-ShrinkSdkVersions.ps1` 负责包版本递增,并同步受影响的精确依赖、对应 NuGet 项目、Installer 目录、本文版本表和 `Tools/Release/package-versions.json`;依赖清单变化会触发依赖方 patch 版本递增。
|
||||
- `Tools/UpmConsumerValidation/published-upm-versions.json` 只记录已经发布且要接受真实消费验证的版本,不随未打标签的 Workspace 版本提前更新。
|
||||
- 包源码、标签、独立开发宿主与包级 CI 位于 `https://git.crash.work/ShrinkSDK/<Package>`;发布版本只能由与 `package.json.version` 一致的 `vX.Y.Z` 标签产生。
|
||||
- `NETWORK_PITFALLS.md` 记录实现经验,不描述当前模块清单。
|
||||
- `Docs/Archive/CORDIS_MIGRATION.completed.md` 保存迁移论证、阶段记录和历史验收数据。
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
## Release 0.1.0
|
||||
|
||||
### New Rules
|
||||
|
||||
Rule ID | Category | Severity | Notes
|
||||
--------|----------|----------|-------
|
||||
SHRINK001 | ShrinkSDK.CodeGen | Error | Invalid event subscriber signature
|
||||
SHRINK002 | ShrinkSDK.CodeGen | Error | Duplicate network opcode and route
|
||||
SHRINK003 | ShrinkSDK.CodeGen | Error | Invalid application installer
|
||||
@@ -1,75 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Immutable;
|
||||
using System.Linq;
|
||||
using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.Diagnostics;
|
||||
|
||||
namespace ShrinkSDK.CodeGen.Analyzers;
|
||||
|
||||
[DiagnosticAnalyzer(LanguageNames.CSharp)]
|
||||
public sealed class ShrinkCodeGenAnalyzer : DiagnosticAnalyzer
|
||||
{
|
||||
private static readonly DiagnosticDescriptor InvalidEventHandler = new(
|
||||
"SHRINK001", "Invalid event subscriber signature",
|
||||
"Method '{0}' must use void(TEvent), UniTask(TEvent), or UniTask(TEvent, CancellationToken)",
|
||||
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
|
||||
private static readonly DiagnosticDescriptor DuplicateNetworkContract = new(
|
||||
"SHRINK002", "Duplicate network opcode and route",
|
||||
"Network opcode/route '{0}' is already declared by '{1}'",
|
||||
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
|
||||
private static readonly DiagnosticDescriptor InvalidInstaller = new(
|
||||
"SHRINK003", "Invalid application installer",
|
||||
"Type '{0}' has ShrinkAppModuleInstaller but does not implement IShrinkAppModuleInstaller",
|
||||
"ShrinkSDK.CodeGen", DiagnosticSeverity.Error, true);
|
||||
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics =>
|
||||
ImmutableArray.Create(InvalidEventHandler, DuplicateNetworkContract, InvalidInstaller);
|
||||
|
||||
public override void Initialize(AnalysisContext context)
|
||||
{
|
||||
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
|
||||
context.EnableConcurrentExecution();
|
||||
context.RegisterCompilationStartAction(start =>
|
||||
{
|
||||
var networkContracts = new ConcurrentDictionary<string, INamedTypeSymbol>(StringComparer.Ordinal);
|
||||
start.RegisterSymbolAction(symbolContext => AnalyzeMethod(symbolContext), SymbolKind.Method);
|
||||
start.RegisterSymbolAction(symbolContext => AnalyzeType(symbolContext, networkContracts), SymbolKind.NamedType);
|
||||
});
|
||||
}
|
||||
|
||||
private static void AnalyzeMethod(SymbolAnalysisContext context)
|
||||
{
|
||||
var method = (IMethodSymbol)context.Symbol;
|
||||
if (!HasAttribute(method, "ShrinkEventBus.ShrinkSubscribeAttribute")) return;
|
||||
var parametersValid = method.Parameters.Length == 1 ||
|
||||
method.Parameters.Length == 2 && method.Parameters[1].Type.ToDisplayString() == "System.Threading.CancellationToken";
|
||||
var returnName = method.ReturnType.ToDisplayString();
|
||||
var returnValid = method.Parameters.Length == 1 && (method.ReturnsVoid || returnName == "Cysharp.Threading.Tasks.UniTask") ||
|
||||
method.Parameters.Length == 2 && returnName == "Cysharp.Threading.Tasks.UniTask";
|
||||
if (!parametersValid || !returnValid)
|
||||
context.ReportDiagnostic(Diagnostic.Create(InvalidEventHandler, method.Locations.FirstOrDefault(), method.Name));
|
||||
}
|
||||
|
||||
private static void AnalyzeType(SymbolAnalysisContext context, ConcurrentDictionary<string, INamedTypeSymbol> networkContracts)
|
||||
{
|
||||
var type = (INamedTypeSymbol)context.Symbol;
|
||||
if (HasAttribute(type, "ShrinkApp.ShrinkAppModuleInstallerAttribute") &&
|
||||
!type.AllInterfaces.Any(item => item.ToDisplayString() == "ShrinkApp.IShrinkAppModuleInstaller"))
|
||||
context.ReportDiagnostic(Diagnostic.Create(InvalidInstaller, type.Locations.FirstOrDefault(), type.Name));
|
||||
|
||||
var network = type.GetAttributes().FirstOrDefault(attribute =>
|
||||
attribute.AttributeClass?.ToDisplayString() == "ShrinkNetwork.ShrinkNetworkMessageAttribute");
|
||||
if (network == null || network.ConstructorArguments.Length == 0) return;
|
||||
var opcode = network.ConstructorArguments[0].Value?.ToString() ?? string.Empty;
|
||||
var route = network.ConstructorArguments.Length > 1 ? network.ConstructorArguments[1].Value as string ?? string.Empty : string.Empty;
|
||||
var key = opcode + ":" + route;
|
||||
if (!networkContracts.TryAdd(key, type) && networkContracts.TryGetValue(key, out var previous))
|
||||
context.ReportDiagnostic(Diagnostic.Create(DuplicateNetworkContract, type.Locations.FirstOrDefault(), key, previous.Name));
|
||||
}
|
||||
|
||||
private static bool HasAttribute(ISymbol symbol, string fullName) =>
|
||||
symbol.GetAttributes().Any(attribute => attribute.AttributeClass?.ToDisplayString() == fullName);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.CodeGen.Analyzers</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.CodeGen.Analyzers</RootNamespace>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IncludeBuildOutput>false</IncludeBuildOutput>
|
||||
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.CodeGen.Core</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.CodeGen</RootNamespace>
|
||||
<PackageId>ShrinkSDK.CodeGen.Core</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<IsPackable>true</IsPackable>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\Editor\Core\*.cs" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.6" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,34 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.CodeGen.Task</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.CodeGen</RootNamespace>
|
||||
<PackageId>ShrinkSDK.CodeGen</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>MSBuild integration for ShrinkSDK Cecil weaving.</Description>
|
||||
<IsPackable>true</IsPackable>
|
||||
<BuildOutputTargetFolder>tools</BuildOutputTargetFolder>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
|
||||
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeShrinkCodeGenDependencies</TargetsForTfmSpecificBuildOutput>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShrinkSDK.CodeGen.Core\ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.CodeGen.Analyzers\ShrinkSDK.CodeGen.Analyzers.csproj" ReferenceOutputAssembly="false" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.6" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Build.Framework" Version="17.14.28" PrivateAssets="all" />
|
||||
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.14.28" PrivateAssets="all" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="buildTransitive\ShrinkSDK.CodeGen.props" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.props" />
|
||||
<None Include="buildTransitive\ShrinkSDK.CodeGen.targets" Pack="true" PackagePath="buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<None Include="..\ShrinkSDK.CodeGen.Analyzers\bin\$(Configuration)\netstandard2.0\ShrinkSDK.CodeGen.Analyzers.dll"
|
||||
Pack="true" PackagePath="analyzers\dotnet\cs\ShrinkSDK.CodeGen.Analyzers.dll" />
|
||||
</ItemGroup>
|
||||
<Target Name="IncludeShrinkCodeGenDependencies" DependsOnTargets="Build">
|
||||
<ItemGroup>
|
||||
<BuildOutputInPackage Include="$(OutputPath)ShrinkSDK.CodeGen.Core.dll" />
|
||||
<BuildOutputInPackage Include="$(OutputPath)Mono.Cecil.dll" />
|
||||
</ItemGroup>
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,98 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Framework;
|
||||
using Microsoft.Build.Utilities;
|
||||
|
||||
namespace ShrinkSDK.CodeGen;
|
||||
|
||||
public sealed class ShrinkWeaveTask : Task
|
||||
{
|
||||
[Required]
|
||||
public string AssemblyPath { get; set; } = string.Empty;
|
||||
|
||||
public string? PdbPath { get; set; }
|
||||
public ITaskItem[] ReferencePaths { get; set; } = Array.Empty<ITaskItem>();
|
||||
public string? StrongNameKeyFile { get; set; }
|
||||
|
||||
[Output] public bool Changed { get; private set; }
|
||||
[Output] public int InstanceSubscriberCount { get; private set; }
|
||||
[Output] public int StaticSubscriberCount { get; private set; }
|
||||
[Output] public int RegistryEntryCount { get; private set; }
|
||||
|
||||
public override bool Execute()
|
||||
{
|
||||
if (!File.Exists(AssemblyPath))
|
||||
{
|
||||
Log.LogError($"[ShrinkSDK.CodeGen] Intermediate assembly does not exist: {AssemblyPath}");
|
||||
return false;
|
||||
}
|
||||
|
||||
var assemblyDirectory = Path.GetDirectoryName(Path.GetFullPath(AssemblyPath))!;
|
||||
var temporaryAssembly = Path.Combine(assemblyDirectory, $".{Path.GetFileName(AssemblyPath)}.{Guid.NewGuid():N}.tmp");
|
||||
var hasPdb = !string.IsNullOrWhiteSpace(PdbPath) && File.Exists(PdbPath);
|
||||
var temporaryPdb = hasPdb
|
||||
? Path.Combine(assemblyDirectory, $".{Path.GetFileName(PdbPath)}.{Guid.NewGuid():N}.tmp")
|
||||
: null;
|
||||
try
|
||||
{
|
||||
var result = ShrinkAssemblyWeaver.Weave(
|
||||
AssemblyPath,
|
||||
hasPdb ? PdbPath : null,
|
||||
ReferencePaths.Select(item => item.ItemSpec),
|
||||
temporaryAssembly,
|
||||
temporaryPdb,
|
||||
ShrinkCodeGenPlatform.EngineNeutral,
|
||||
StrongNameKeyFile);
|
||||
foreach (var diagnostic in result.Diagnostics)
|
||||
{
|
||||
switch (diagnostic.Severity)
|
||||
{
|
||||
case ShrinkCodeGenDiagnosticSeverity.Warning:
|
||||
Log.LogWarning($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
case ShrinkCodeGenDiagnosticSeverity.Error:
|
||||
Log.LogError($"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
default:
|
||||
Log.LogMessage(MessageImportance.Low, $"[ShrinkSDK.CodeGen] {diagnostic.Message}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!result.Succeeded)
|
||||
return false;
|
||||
|
||||
Changed = result.Changed;
|
||||
InstanceSubscriberCount = result.InstanceSubscribers;
|
||||
StaticSubscriberCount = result.StaticSubscribers;
|
||||
RegistryEntryCount = result.RegistryEntries;
|
||||
if (Changed)
|
||||
{
|
||||
File.Move(temporaryAssembly, AssemblyPath, true);
|
||||
if (hasPdb && temporaryPdb != null)
|
||||
File.Move(temporaryPdb, PdbPath!, true);
|
||||
}
|
||||
Log.LogMessage(MessageImportance.High,
|
||||
$"[ShrinkSDK.CodeGen] {Path.GetFileName(AssemblyPath)} woven: instance={InstanceSubscriberCount}, static={StaticSubscriberCount}, registry={RegistryEntryCount}.");
|
||||
return true;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Log.LogErrorFromException(exception, true);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
TryDelete(temporaryAssembly);
|
||||
if (temporaryPdb != null) TryDelete(temporaryPdb);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TryDelete(string path)
|
||||
{
|
||||
try { if (File.Exists(path)) File.Delete(path); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<ShrinkCodeGenEnabled Condition="'$(ShrinkCodeGenEnabled)' == ''">true</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
<Project>
|
||||
<PropertyGroup>
|
||||
<_ShrinkCodeGenTaskAssembly Condition="'$(_ShrinkCodeGenTaskAssembly)' == ''">$(MSBuildThisFileDirectory)..\tools\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<UsingTask TaskName="ShrinkSDK.CodeGen.ShrinkWeaveTask" AssemblyFile="$(_ShrinkCodeGenTaskAssembly)" />
|
||||
<Target Name="ShrinkCodeGenWeave"
|
||||
AfterTargets="CoreCompile"
|
||||
BeforeTargets="CopyFilesToOutputDirectory"
|
||||
Condition="'$(ShrinkCodeGenEnabled)' == 'true' and '$(DesignTimeBuild)' != 'true'">
|
||||
<PropertyGroup>
|
||||
<_ShrinkCodeGenIntermediateAssembly>$(IntermediateOutputPath)$(TargetName).dll</_ShrinkCodeGenIntermediateAssembly>
|
||||
</PropertyGroup>
|
||||
<ShrinkWeaveTask AssemblyPath="$(_ShrinkCodeGenIntermediateAssembly)"
|
||||
PdbPath="$(IntermediateOutputPath)$(TargetName).pdb"
|
||||
ReferencePaths="@(ReferencePath)"
|
||||
StrongNameKeyFile="$(ShrinkCodeGenStrongNameKeyFile)" />
|
||||
</Target>
|
||||
</Project>
|
||||
@@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkSDK.Godot.Installer</AssemblyName>
|
||||
<PackageId>ShrinkSDK.Godot.Installer</PackageId>
|
||||
<Version>0.1.1</Version>
|
||||
<Description>Godot Editor package manager and CodeGen diagnostics for ShrinkSDK.</Description>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="addons\shrinksdk\*.cs" />
|
||||
<Compile Include="..\..\Assets\Modules\ShrinkInstaller\Editor\ShrinkPackageVersion.cs" Link="addons\shrinksdk\ShrinkPackageVersion.cs" />
|
||||
<PackageReference Include="GodotSharp" Version="4.6.3" />
|
||||
<PackageReference Include="GodotSharpEditor" Version="4.6.3" />
|
||||
<None Include="addons\shrinksdk\plugin.cfg" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\plugin.cfg" />
|
||||
<None Include="addons\shrinksdk\*.cs" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\" />
|
||||
<None Include="..\..\Assets\Modules\ShrinkInstaller\Editor\ShrinkPackageVersion.cs" Pack="true" PackagePath="contentFiles\any\any\addons\shrinksdk\ShrinkPackageVersion.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,133 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Godot;
|
||||
using ShrinkSDK.Installer;
|
||||
|
||||
namespace ShrinkSDK.Godot.Editor;
|
||||
|
||||
[Tool]
|
||||
public partial class ShrinkGodotInstallerPlugin : EditorPlugin
|
||||
{
|
||||
private EditorDock? _panel;
|
||||
private Label? _status;
|
||||
private RichTextLabel? _output;
|
||||
private readonly System.Collections.Generic.Dictionary<string, Button> _installActions =
|
||||
new(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly System.Collections.Generic.Dictionary<string, Button> _removeActions =
|
||||
new(StringComparer.OrdinalIgnoreCase);
|
||||
private string ProjectDirectory => ProjectSettings.GlobalizePath("res://");
|
||||
private string ProjectPath => Directory.GetFiles(ProjectDirectory, "*.csproj", SearchOption.TopDirectoryOnly).Single();
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
_panel = new EditorDock { Name = "ShrinkSDK", Title = "ShrinkSDK", DefaultSlot = EditorDock.DockSlot.LeftBr };
|
||||
var content = new VBoxContainer();
|
||||
_panel.AddChild(content);
|
||||
content.AddChild(new Label { Text = "ShrinkSDK Packages" });
|
||||
_installActions.Clear();
|
||||
_removeActions.Clear();
|
||||
foreach (var package in ShrinkProjectPackageEditor.RecommendedPackages)
|
||||
{
|
||||
var row = new HBoxContainer();
|
||||
row.AddChild(new Label { Text = $"{package.Key} {package.Value}", SizeFlagsHorizontal = Control.SizeFlags.ExpandFill });
|
||||
var install = new Button { Text = "Install / Update" };
|
||||
install.Pressed += () => ChangePackage(package.Key, package.Value);
|
||||
row.AddChild(install);
|
||||
_installActions[package.Key] = install;
|
||||
var remove = new Button { Text = "Remove" };
|
||||
remove.Pressed += () => ChangePackage(package.Key, null);
|
||||
row.AddChild(remove);
|
||||
_removeActions[package.Key] = remove;
|
||||
content.AddChild(row);
|
||||
}
|
||||
var restore = new Button { Text = "Restore and Build" };
|
||||
restore.Pressed += BuildProject;
|
||||
content.AddChild(restore);
|
||||
_status = new Label { Text = "CodeGen: not built" };
|
||||
content.AddChild(_status);
|
||||
_output = new RichTextLabel { FitContent = true, CustomMinimumSize = new Vector2(360, 180) };
|
||||
content.AddChild(_output);
|
||||
AddDock(_panel);
|
||||
RefreshInstalledState();
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_panel == null) return;
|
||||
RemoveDock(_panel);
|
||||
_panel.QueueFree();
|
||||
_panel = null;
|
||||
}
|
||||
|
||||
private async void ChangePackage(string packageId, string? version)
|
||||
{
|
||||
try
|
||||
{
|
||||
ShrinkProjectPackageEditor.EnsureShrinkFeed(Path.Combine(ProjectDirectory, "NuGet.Config"));
|
||||
ShrinkProjectPackageEditor.SetPackageReference(ProjectPath, packageId, version);
|
||||
await RunBuild("restore");
|
||||
}
|
||||
catch (Exception exception) { ShowFailure(exception); }
|
||||
}
|
||||
|
||||
private async void BuildProject()
|
||||
{
|
||||
try { await RunBuild("build"); }
|
||||
catch (Exception exception) { ShowFailure(exception); }
|
||||
}
|
||||
|
||||
private async System.Threading.Tasks.Task RunBuild(string command)
|
||||
{
|
||||
_status!.Text = $"CodeGen: running dotnet {command}";
|
||||
var result = await ShrinkProjectPackageEditor.RunDotnetAsync(ProjectDirectory, $"{command} \"{ProjectPath}\" /nr:false");
|
||||
_output!.Text = result.Output;
|
||||
var match = Regex.Matches(result.Output, @"\[ShrinkSDK\.CodeGen\].*woven: instance=(\d+), static=(\d+), registry=(\d+)").Cast<Match>().LastOrDefault();
|
||||
_status.Text = result.ExitCode == 0
|
||||
? match == null ? "CodeGen: build succeeded (no attributed registrations)" : $"CodeGen: woven; instance={match.Groups[1].Value}, static={match.Groups[2].Value}, registry={match.Groups[3].Value}"
|
||||
: "CodeGen: build failed";
|
||||
RefreshInstalledState();
|
||||
}
|
||||
|
||||
private void RefreshInstalledState()
|
||||
{
|
||||
if (_output == null) return;
|
||||
var installed = File.Exists(ProjectPath)
|
||||
? ShrinkProjectPackageEditor.ReadPackageReferences(ProjectPath)
|
||||
: new System.Collections.Generic.Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var package in ShrinkProjectPackageEditor.RecommendedPackages)
|
||||
{
|
||||
var hasInstalled = installed.TryGetValue(package.Key, out var installedVersion);
|
||||
var relation = hasInstalled
|
||||
? ShrinkPackageVersion.Classify(installedVersion, package.Value)
|
||||
: ShrinkPackageVersionRelation.Unknown;
|
||||
if (_installActions.TryGetValue(package.Key, out var install))
|
||||
{
|
||||
install.Text = !hasInstalled
|
||||
? $"Install {package.Value}"
|
||||
: relation switch
|
||||
{
|
||||
ShrinkPackageVersionRelation.Equal => $"Installed {installedVersion}",
|
||||
ShrinkPackageVersionRelation.Newer => $"Newer {installedVersion}",
|
||||
ShrinkPackageVersionRelation.Older => $"Upgrade {installedVersion} → {package.Value}",
|
||||
_ => $"Update {installedVersion} → {package.Value}"
|
||||
};
|
||||
install.Disabled = hasInstalled && relation is
|
||||
ShrinkPackageVersionRelation.Equal or ShrinkPackageVersionRelation.Newer;
|
||||
}
|
||||
if (_removeActions.TryGetValue(package.Key, out var remove))
|
||||
remove.Disabled = !hasInstalled;
|
||||
}
|
||||
_output.Text = "Direct packages: " + string.Join(", ", installed.Select(item => $"{item.Key}@{item.Value}"));
|
||||
}
|
||||
|
||||
private void ShowFailure(Exception exception)
|
||||
{
|
||||
_status!.Text = "CodeGen: operation failed";
|
||||
_output!.Text = exception.ToString();
|
||||
GD.PushError(exception.ToString());
|
||||
}
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace ShrinkSDK.Godot.Editor;
|
||||
|
||||
public static class ShrinkProjectPackageEditor
|
||||
{
|
||||
public static readonly IReadOnlyDictionary<string, string> RecommendedPackages =
|
||||
new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["ShrinkSDK.Godot"] = "0.1.0",
|
||||
["ShrinkSDK.EventBus"] = "2.1.0",
|
||||
["ShrinkSDK.Context.Core"] = "0.2.0",
|
||||
["ShrinkSDK.Command"] = "0.3.0",
|
||||
["ShrinkSDK.Command.Integration.EventBus"] = "0.2.0",
|
||||
["ShrinkSDK.Command.Integration.Network"] = "0.2.0",
|
||||
["ShrinkSDK.Command.Integration.App"] = "0.2.0",
|
||||
["ShrinkSDK.Network"] = "0.3.0",
|
||||
["ShrinkSDK.Network.Integration.EventBus"] = "0.2.0",
|
||||
["ShrinkSDK.Network.Integration.App"] = "0.2.0",
|
||||
["ShrinkSDK.DataSaver"] = "2.3.0",
|
||||
["ShrinkSDK.DataSaver.Integration.EventBus"] = "2.2.0",
|
||||
["ShrinkSDK.DataSaver.Integration.App"] = "0.2.0",
|
||||
["ShrinkSDK.App.Core"] = "0.2.0",
|
||||
["ShrinkSDK.Context.AppAdapter"] = "0.2.0",
|
||||
["ShrinkSDK.App.Starter.Basic"] = "0.3.0",
|
||||
["ShrinkSDK.ModFramework"] = "0.3.0",
|
||||
["ShrinkSDK.ModFramework.Godot"] = "0.1.0",
|
||||
["ShrinkSDK.Tutorial"] = "0.2.0",
|
||||
["ShrinkSDK.Tutorial.Godot"] = "0.1.0"
|
||||
};
|
||||
|
||||
public static IReadOnlyDictionary<string, string> ReadPackageReferences(string projectPath)
|
||||
{
|
||||
var document = XDocument.Load(projectPath, LoadOptions.PreserveWhitespace);
|
||||
return document.Descendants("PackageReference")
|
||||
.Select(element => new
|
||||
{
|
||||
Id = ((string?)element.Attribute("Include") ?? (string?)element.Attribute("Update"))?.Trim(),
|
||||
Version = ((string?)element.Attribute("Version") ??
|
||||
(string?)element.Attribute("VersionOverride") ??
|
||||
element.Element("Version")?.Value)?.Trim() ?? string.Empty
|
||||
})
|
||||
.Where(item => !string.IsNullOrWhiteSpace(item.Id))
|
||||
.GroupBy(item => item.Id!, StringComparer.OrdinalIgnoreCase)
|
||||
.ToDictionary(group => group.Key, group => group.First().Version, StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public static void SetPackageReference(string projectPath, string packageId, string? version)
|
||||
{
|
||||
var document = XDocument.Load(projectPath, LoadOptions.PreserveWhitespace);
|
||||
var root = document.Root ?? throw new InvalidDataException("The C# project has no root element.");
|
||||
var references = root.Descendants("PackageReference").Where(element =>
|
||||
string.Equals((string?)element.Attribute("Include"), packageId, StringComparison.OrdinalIgnoreCase)).ToArray();
|
||||
foreach (var duplicate in references.Skip(1)) duplicate.Remove();
|
||||
if (string.IsNullOrWhiteSpace(version))
|
||||
{
|
||||
foreach (var reference in references) reference.Remove();
|
||||
}
|
||||
else if (references.Length > 0)
|
||||
{
|
||||
var reference = references[0];
|
||||
if (reference.Attribute("VersionOverride") != null)
|
||||
reference.SetAttributeValue("VersionOverride", version);
|
||||
else if (reference.Attribute("Version") != null)
|
||||
reference.SetAttributeValue("Version", version);
|
||||
else if (reference.Element("Version") != null)
|
||||
reference.Element("Version")!.Value = version;
|
||||
else
|
||||
reference.SetAttributeValue("Version", version);
|
||||
}
|
||||
else
|
||||
{
|
||||
var group = root.Elements("ItemGroup").FirstOrDefault(element => element.Elements("PackageReference").Any());
|
||||
if (group == null)
|
||||
{
|
||||
group = new XElement("ItemGroup");
|
||||
root.Add(group);
|
||||
}
|
||||
group.Add(new XElement("PackageReference", new XAttribute("Include", packageId), new XAttribute("Version", version)));
|
||||
}
|
||||
WriteAtomically(projectPath, document);
|
||||
}
|
||||
|
||||
public static void EnsureShrinkFeed(string nugetConfigPath)
|
||||
{
|
||||
XDocument document;
|
||||
if (File.Exists(nugetConfigPath)) document = XDocument.Load(nugetConfigPath, LoadOptions.PreserveWhitespace);
|
||||
else document = new XDocument(new XDeclaration("1.0", "utf-8", null), new XElement("configuration"));
|
||||
var root = document.Root ?? throw new InvalidDataException("NuGet.Config has no root element.");
|
||||
var sources = root.Element("packageSources");
|
||||
if (sources == null)
|
||||
{
|
||||
sources = new XElement("packageSources");
|
||||
root.Add(sources);
|
||||
}
|
||||
var existing = sources.Elements("add").FirstOrDefault(element =>
|
||||
string.Equals((string?)element.Attribute("key"), "ShrinkSDK", StringComparison.OrdinalIgnoreCase));
|
||||
if (existing == null)
|
||||
sources.Add(new XElement("add", new XAttribute("key", "ShrinkSDK"),
|
||||
new XAttribute("value", "https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json")));
|
||||
else
|
||||
existing.SetAttributeValue("value", "https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json");
|
||||
WriteAtomically(nugetConfigPath, document);
|
||||
}
|
||||
|
||||
public static async Task<(int ExitCode, string Output)> RunDotnetAsync(string projectDirectory,
|
||||
string arguments, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var output = new StringBuilder();
|
||||
using var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo("dotnet", arguments)
|
||||
{
|
||||
WorkingDirectory = projectDirectory,
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
process.OutputDataReceived += (_, args) => { if (args.Data != null) output.AppendLine(args.Data); };
|
||||
process.ErrorDataReceived += (_, args) => { if (args.Data != null) output.AppendLine(args.Data); };
|
||||
process.Start();
|
||||
process.BeginOutputReadLine();
|
||||
process.BeginErrorReadLine();
|
||||
await process.WaitForExitAsync(cancellationToken);
|
||||
return (process.ExitCode, output.ToString());
|
||||
}
|
||||
|
||||
private static void WriteAtomically(string path, XDocument document)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path))!);
|
||||
var temporaryPath = path + ".shrinksdk.tmp";
|
||||
using (var writer = new StreamWriter(temporaryPath, false, new UTF8Encoding(false)))
|
||||
document.Save(writer, SaveOptions.DisableFormatting);
|
||||
File.Move(temporaryPath, path, true);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
[plugin]
|
||||
|
||||
name="ShrinkSDK Installer"
|
||||
description="Installs and diagnoses ShrinkSDK NuGet modules and CodeGen weaving."
|
||||
author="ShrinkSDK"
|
||||
version="0.1.1"
|
||||
script="ShrinkGodotInstallerPlugin.cs"
|
||||
@@ -1,137 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Cysharp.Threading.Tasks;
|
||||
|
||||
namespace ShrinkApp;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public sealed class ShrinkAppModuleInstallerAttribute : Attribute { }
|
||||
|
||||
public interface IShrinkAppModuleInstaller
|
||||
{
|
||||
string ModuleId { get; }
|
||||
int Order { get; }
|
||||
IReadOnlyList<string> DependsOn { get; }
|
||||
void RegisterServices(ShrinkAppContext context);
|
||||
UniTask InitializeAsync(ShrinkAppContext context);
|
||||
}
|
||||
|
||||
public interface IShrinkAppModuleShutdown
|
||||
{
|
||||
UniTask ShutdownAsync(ShrinkAppContext context);
|
||||
}
|
||||
|
||||
public sealed class ShrinkAppSettings
|
||||
{
|
||||
public bool VerboseLogging { get; set; }
|
||||
public string[] DisabledModuleIds { get; set; } = Array.Empty<string>();
|
||||
}
|
||||
|
||||
public sealed class ShrinkAppServices
|
||||
{
|
||||
private readonly Dictionary<Type, object> _services = new();
|
||||
public void Register<T>(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service));
|
||||
public bool TryGet<T>(out T? service) where T : class
|
||||
{
|
||||
service = _services.TryGetValue(typeof(T), out var value) ? value as T : null;
|
||||
return service != null;
|
||||
}
|
||||
public T GetRequired<T>() where T : class => TryGet<T>(out var value) ? value! : throw new InvalidOperationException($"Required service is not registered: {typeof(T).FullName}");
|
||||
public bool TryUnregister<T>(T service) where T : class => _services.TryGetValue(typeof(T), out var value) && ReferenceEquals(value, service) && _services.Remove(typeof(T));
|
||||
}
|
||||
|
||||
public sealed class ShrinkAppContext
|
||||
{
|
||||
public ShrinkAppContext(object? host, ShrinkAppSettings settings, ShrinkAppServices services)
|
||||
{
|
||||
Host = host;
|
||||
Settings = settings ?? throw new ArgumentNullException(nameof(settings));
|
||||
Services = services ?? throw new ArgumentNullException(nameof(services));
|
||||
}
|
||||
public object? Host { get; }
|
||||
public ShrinkAppSettings Settings { get; }
|
||||
public ShrinkAppServices Services { get; }
|
||||
public static ShrinkAppContext CreateStandalone(ShrinkAppServices services, ShrinkAppSettings? settings = null) => new(null, settings ?? new ShrinkAppSettings(), services);
|
||||
}
|
||||
|
||||
public sealed class ShrinkAppRuntime
|
||||
{
|
||||
private readonly List<IShrinkAppModuleInstaller> _started = new();
|
||||
public ShrinkAppRuntime(object? host = null, ShrinkAppSettings? settings = null, ShrinkAppServices? services = null)
|
||||
{
|
||||
Context = new ShrinkAppContext(host, settings ?? new ShrinkAppSettings(), services ?? new ShrinkAppServices());
|
||||
}
|
||||
public ShrinkAppContext Context { get; }
|
||||
public bool IsRunning { get; private set; }
|
||||
public IReadOnlyList<string> StartedModules => _started.Select(item => item.ModuleId).ToArray();
|
||||
|
||||
public async UniTask StartAsync()
|
||||
{
|
||||
if (IsRunning) return;
|
||||
var installers = Sort(CreateInstallers(), Context.Settings.DisabledModuleIds);
|
||||
try
|
||||
{
|
||||
foreach (var installer in installers) installer.RegisterServices(Context);
|
||||
foreach (var installer in installers)
|
||||
{
|
||||
await installer.InitializeAsync(Context);
|
||||
_started.Add(installer);
|
||||
}
|
||||
IsRunning = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await ShutdownStartedAsync();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask ShutdownAsync()
|
||||
{
|
||||
await ShutdownStartedAsync();
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
private async UniTask ShutdownStartedAsync()
|
||||
{
|
||||
for (var index = _started.Count - 1; index >= 0; index--)
|
||||
if (_started[index] is IShrinkAppModuleShutdown shutdown) await shutdown.ShutdownAsync(Context);
|
||||
_started.Clear();
|
||||
}
|
||||
|
||||
private static IReadOnlyList<IShrinkAppModuleInstaller> CreateInstallers() =>
|
||||
ShrinkAppInstallers.GetDiscoveredInstallerTypes().Select(type =>
|
||||
Activator.CreateInstance(type) as IShrinkAppModuleInstaller ?? throw new InvalidOperationException($"Failed to create installer: {type.FullName}"))
|
||||
.ToArray();
|
||||
|
||||
private static IReadOnlyList<IShrinkAppModuleInstaller> Sort(IEnumerable<IShrinkAppModuleInstaller> source, IEnumerable<string> disabledIds)
|
||||
{
|
||||
var disabled = new HashSet<string>(disabledIds ?? Array.Empty<string>(), StringComparer.OrdinalIgnoreCase);
|
||||
var byId = source.Where(item => !disabled.Contains(item.ModuleId)).ToDictionary(item => item.ModuleId, StringComparer.OrdinalIgnoreCase);
|
||||
var states = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
|
||||
var result = new List<IShrinkAppModuleInstaller>();
|
||||
foreach (var installer in byId.Values.OrderBy(item => item.Order).ThenBy(item => item.ModuleId, StringComparer.OrdinalIgnoreCase))
|
||||
Visit(installer, byId, states, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void Visit(IShrinkAppModuleInstaller installer, IReadOnlyDictionary<string, IShrinkAppModuleInstaller> byId,
|
||||
IDictionary<string, int> states, ICollection<IShrinkAppModuleInstaller> result)
|
||||
{
|
||||
var state = states.TryGetValue(installer.ModuleId, out var value) ? value : 0;
|
||||
if (state == 2) return;
|
||||
if (state == 1) throw new InvalidOperationException($"Circular installer dependency: {installer.ModuleId}");
|
||||
states[installer.ModuleId] = 1;
|
||||
foreach (var dependencyId in installer.DependsOn ?? Array.Empty<string>())
|
||||
{
|
||||
if (!byId.TryGetValue(dependencyId, out var dependency))
|
||||
throw new InvalidOperationException($"Installer dependency missing. Module={installer.ModuleId}, DependsOn={dependencyId}");
|
||||
Visit(dependency, byId, states, result);
|
||||
}
|
||||
states[installer.ModuleId] = 2;
|
||||
result.Add(installer);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkApp.Core.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkApp</RootNamespace>
|
||||
<PackageId>ShrinkSDK.App.Core</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>ShrinkSDK engine-neutral application composition runtime.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\ShrinkAppCore.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkApp.Core\Runtime\ShrinkAppGeneratedRegistry.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkApp.Core\Runtime\ShrinkAppInstallers.cs" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,34 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.Collections.Generic;
|
||||
using ShrinkApp;
|
||||
using ShrinkCommand.Integration.App;
|
||||
using ShrinkContext;
|
||||
using ShrinkContext.AppAdapter;
|
||||
using ShrinkDataSaver.Integration.App;
|
||||
using ShrinkNetwork.Integration.App;
|
||||
|
||||
namespace ShrinkApp.Starter.Basic;
|
||||
|
||||
public static class ShrinkBasicComposition
|
||||
{
|
||||
public static ShrinkContextAppHost CreateHost(ShrinkAppServices? services = null)
|
||||
{
|
||||
var host = new ShrinkContextAppHost(services);
|
||||
host.Register<ShrinkCommandAppComponent>("shrink.command");
|
||||
host.Register<ShrinkDataSaverAppComponent>("shrink.datasaver");
|
||||
host.Register<ShrinkNetworkAppComponent>("shrink.network");
|
||||
return host;
|
||||
}
|
||||
|
||||
public static IReadOnlyList<ShrinkLoaderEntry> CreateEntries(ShrinkAppServices services,
|
||||
ShrinkNetworkAppModuleConfig? network = null) => new[]
|
||||
{
|
||||
new ShrinkLoaderEntry("datasaver", "shrink.datasaver", services),
|
||||
new ShrinkLoaderEntry("command", "shrink.command", services),
|
||||
new ShrinkLoaderEntry("network", "shrink.network", network ?? new ShrinkNetworkAppModuleConfig
|
||||
{
|
||||
Services = services
|
||||
})
|
||||
};
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkApp.Starter.Basic</AssemblyName>
|
||||
<RootNamespace>ShrinkApp.Starter.Basic</RootNamespace>
|
||||
<PackageId>ShrinkSDK.App.Starter.Basic</PackageId>
|
||||
<Version>0.3.0</Version>
|
||||
<Description>Engine-neutral basic ShrinkApp composition.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.App.Core\ShrinkSDK.App.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.AppAdapter\ShrinkSDK.Context.AppAdapter.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Command.Integration.App\ShrinkSDK.Command.Integration.App.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.DataSaver.Integration.App\ShrinkSDK.DataSaver.Integration.App.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Network.Integration.App\ShrinkSDK.Network.Integration.App.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkCommand.Integration.EventBus</AssemblyName>
|
||||
<RootNamespace>ShrinkCommand.Integration</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Command.Integration.EventBus</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>ShrinkCommand and EventBus integration.</Description>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand.Integration.EventBus\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkCommand.Integration.Network</AssemblyName>
|
||||
<RootNamespace>ShrinkCommand.Integration</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Command.Integration.Network</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>ShrinkCommand and Network RPC integration.</Description>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand.Integration.Network\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,18 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkCommand.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkCommand</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Command</PackageId>
|
||||
<Version>0.3.0</Version>
|
||||
<Description>ShrinkSDK command parsing, permissions and execution runtime.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkCommand\Runtime\**\*.cs" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,31 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkApp;
|
||||
|
||||
namespace ShrinkContext.AppAdapter;
|
||||
|
||||
public sealed class ShrinkContextAppHost
|
||||
{
|
||||
private readonly ShrinkContextRuntime _runtime = new();
|
||||
private readonly ShrinkComponentCatalog _catalog = new();
|
||||
private readonly ShrinkContextLoader _loader;
|
||||
|
||||
public ShrinkContextAppHost(ShrinkAppServices? services = null)
|
||||
{
|
||||
Services = services ?? new ShrinkAppServices();
|
||||
_loader = new ShrinkContextLoader(_runtime, _catalog);
|
||||
}
|
||||
|
||||
public ShrinkAppServices Services { get; }
|
||||
public ShrinkContextRuntime Runtime => _runtime;
|
||||
public ShrinkLoaderTransactionDiagnostic? LastTransaction => _loader.LastTransaction;
|
||||
|
||||
public void Register(string name, Func<IShrinkComponent> factory) => _catalog.Register(name, factory);
|
||||
public void Register<TComponent>(string name) where TComponent : IShrinkComponent, new() =>
|
||||
_catalog.Register<TComponent>(name);
|
||||
public UniTask ApplyAsync(IReadOnlyList<ShrinkLoaderEntry> entries) => _loader.ApplyAsync(entries);
|
||||
public UniTask ShutdownAsync() => _runtime.ShutdownAsync();
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkContext.AppAdapter</AssemblyName>
|
||||
<RootNamespace>ShrinkContext.AppAdapter</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Context.AppAdapter</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>Engine-neutral ShrinkContext composition host for ShrinkApp.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.App.Core\ShrinkSDK.App.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,17 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkContext.Core.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkContext</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Context.Core</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>ShrinkSDK reversible context and fiber runtime.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkContext.Core\Runtime\**\*.cs" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkDataSaver.Integration.EventBus</AssemblyName>
|
||||
<RootNamespace>ShrinkDataSaver.Integration</RootNamespace>
|
||||
<PackageId>ShrinkSDK.DataSaver.Integration.EventBus</PackageId>
|
||||
<Version>2.2.0</Version>
|
||||
<Description>ShrinkDataSaver and EventBus integration.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver.Integration.EventBus\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.DataSaver\ShrinkSDK.DataSaver.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,43 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System.IO;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkSDK.Runtime;
|
||||
|
||||
namespace ShrinkDataSaver;
|
||||
|
||||
public sealed class ShrinkDataSaverRuntimeConfig
|
||||
{
|
||||
public string? RootPath { get; set; }
|
||||
public string SaveFileExtension { get; set; } = ".sav";
|
||||
public string SettingsFileName { get; set; } = "settings.json";
|
||||
public int CurrentSaveVersion { get; set; } = 1;
|
||||
public int MaxSlots { get; set; } = 3;
|
||||
public float SettingsWriteDebounceSeconds { get; set; } = 0.35f;
|
||||
public bool DontDestroyOnLoadDriver { get; set; }
|
||||
}
|
||||
|
||||
public static class ShrinkDataSaverRuntime
|
||||
{
|
||||
public static bool IsInitialized { get; private set; }
|
||||
|
||||
public static void Initialize(ShrinkDataSaverRuntimeConfig? config = null)
|
||||
{
|
||||
if (IsInitialized) return;
|
||||
config ??= new ShrinkDataSaverRuntimeConfig();
|
||||
var root = string.IsNullOrWhiteSpace(config.RootPath)
|
||||
? ShrinkRuntimeServices.Paths.PersistentDataPath
|
||||
: config.RootPath!;
|
||||
Directory.CreateDirectory(root);
|
||||
var storage = new LocalStorageProvider(root);
|
||||
ShrinkDataSaverPlatform.SettingsWriteDebounceSeconds = config.SettingsWriteDebounceSeconds;
|
||||
ShrinkDataSaverPlatform.MaxSlots = config.MaxSlots;
|
||||
ShrinkSettings.Initialize(storage, Path.Combine(root, config.SettingsFileName));
|
||||
ShrinkSave.Initialize(storage, Path.Combine(root, "saves"), config.SaveFileExtension,
|
||||
config.CurrentSaveVersion);
|
||||
ShrinkSettings.LoadAsync().Forget();
|
||||
IsInitialized = true;
|
||||
ShrinkRuntimeServices.Logger.Log(ShrinkLogLevel.Information,
|
||||
$"[ShrinkDataSaver] Runtime initialized. Root: {root}");
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkDataSaver.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkDataSaver</RootNamespace>
|
||||
<PackageId>ShrinkSDK.DataSaver</PackageId>
|
||||
<Version>2.3.0</Version>
|
||||
<Description>ShrinkSDK engine-neutral versioned save and settings runtime.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\ShrinkDataSaverRuntime.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\AssemblyInfo.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\DataSerializer.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\IStorageProvider.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\LocalStorageProvider.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\MigrationChain.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\SaveEncryptor.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\SaveTypes.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkDataSaverPlatform.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkSave.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkDataSaver\Runtime\ShrinkSettings.cs" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkEventBus.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkEventBus</RootNamespace>
|
||||
<PackageId>ShrinkSDK.EventBus</PackageId>
|
||||
<Version>2.1.0</Version>
|
||||
<Description>ShrinkSDK typed event bus runtime.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkEventBus\Runtime\**\*.cs"
|
||||
Exclude="..\..\..\Assets\Modules\ShrinkEventBus\Runtime\ShrinkMonoEventScope.cs" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
Submodule
+1
Submodule Godot/Packages/ShrinkSDK.Godot added at 77adb61b3b
@@ -1,154 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Godot;
|
||||
using ShrinkEventBus;
|
||||
using ShrinkDataSaver;
|
||||
using ShrinkApp;
|
||||
using ShrinkNetwork;
|
||||
using ShrinkSDK.Runtime;
|
||||
|
||||
namespace ShrinkSDK.Godot;
|
||||
|
||||
public partial class ShrinkGodotHost : Node, IShrinkMainThreadDispatcher,
|
||||
IShrinkLogger, IShrinkClock, IShrinkPathProvider, IShrinkScreenshotProvider,
|
||||
IShrinkApplicationLifecycle
|
||||
{
|
||||
private readonly ConcurrentQueue<Action> _dispatchQueue = new();
|
||||
private readonly Dictionary<ShrinkNetworkService, ShrinkNetworkDispatchQueue> _networkServices = new();
|
||||
private int _mainThreadId;
|
||||
private bool _networkPumpRunning;
|
||||
private ShrinkAppRuntime? _appRuntime;
|
||||
|
||||
public event Action? Paused;
|
||||
public event Action? Resumed;
|
||||
public event Action? Exiting;
|
||||
|
||||
[Export] public int DispatchBudgetPerFrame { get; set; } = 256;
|
||||
[Export] public int NetworkDispatchBudgetPerFrame { get; set; } = 256;
|
||||
|
||||
public bool IsMainThread => Thread.CurrentThread.ManagedThreadId == _mainThreadId;
|
||||
public DateTimeOffset UtcNow => DateTimeOffset.UtcNow;
|
||||
public double UnscaledTimeSeconds => Time.GetTicksMsec() / 1000d;
|
||||
public string PersistentDataPath => ProjectSettings.GlobalizePath("user://");
|
||||
public string TemporaryDataPath => OS.GetCacheDir();
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
_mainThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
ShrinkRuntimeServices.Configure(this, this, this, this, this, this);
|
||||
ShrinkEventBusRuntime.ConfigureMainThreadDispatcher(this);
|
||||
ShrinkDataSaverPlatform.Configure(this, this, this, this);
|
||||
SetProcess(true);
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var budget = Math.Max(1, DispatchBudgetPerFrame);
|
||||
while (budget-- > 0 && _dispatchQueue.TryDequeue(out var action))
|
||||
action();
|
||||
PumpNetworkAsync().Forget();
|
||||
}
|
||||
|
||||
public override void _Notification(int what)
|
||||
{
|
||||
switch ((long)what)
|
||||
{
|
||||
case NotificationApplicationPaused:
|
||||
case NotificationApplicationFocusOut:
|
||||
Paused?.Invoke();
|
||||
break;
|
||||
case NotificationApplicationResumed:
|
||||
case NotificationApplicationFocusIn:
|
||||
Resumed?.Invoke();
|
||||
break;
|
||||
case NotificationWMCloseRequest:
|
||||
case NotificationPredelete:
|
||||
Exiting?.Invoke();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public async UniTask<ShrinkAppRuntime> StartAppAsync(ShrinkAppSettings? settings = null, ShrinkAppServices? services = null)
|
||||
{
|
||||
if (_appRuntime?.IsRunning == true) return _appRuntime;
|
||||
_appRuntime = new ShrinkAppRuntime(this, settings, services);
|
||||
await _appRuntime.StartAsync();
|
||||
return _appRuntime;
|
||||
}
|
||||
|
||||
public async UniTask ShutdownAppAsync()
|
||||
{
|
||||
if (_appRuntime == null) return;
|
||||
await _appRuntime.ShutdownAsync();
|
||||
_appRuntime = null;
|
||||
}
|
||||
|
||||
public bool TryPost(Action action)
|
||||
{
|
||||
if (action == null) throw new ArgumentNullException(nameof(action));
|
||||
_dispatchQueue.Enqueue(action);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void AddNetworkService(ShrinkNetworkService service)
|
||||
{
|
||||
if (service == null) throw new ArgumentNullException(nameof(service));
|
||||
if (_networkServices.ContainsKey(service)) return;
|
||||
var queue = new ShrinkNetworkDispatchQueue(Math.Max(1, NetworkDispatchBudgetPerFrame * 4));
|
||||
service.DispatchScheduler = queue;
|
||||
_networkServices.Add(service, queue);
|
||||
}
|
||||
|
||||
public bool RemoveNetworkService(ShrinkNetworkService service)
|
||||
{
|
||||
if (!_networkServices.Remove(service, out var queue)) return false;
|
||||
service.DispatchScheduler = ShrinkNetworkDispatchSchedulers.Inline;
|
||||
queue.Dispose();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static ShrinkCodeGenWovenAttribute RequireWoven(Assembly assembly)
|
||||
{
|
||||
if (assembly == null) throw new ArgumentNullException(nameof(assembly));
|
||||
return assembly.GetCustomAttribute<ShrinkCodeGenWovenAttribute>() ??
|
||||
throw new InvalidOperationException(
|
||||
$"Assembly '{assembly.GetName().Name}' was not woven by ShrinkSDK.CodeGen. Ensure the package is installed and ShrinkCodeGenEnabled is not false.");
|
||||
}
|
||||
|
||||
public void Log(ShrinkLogLevel level, string message, Exception? exception = null)
|
||||
{
|
||||
var text = exception == null ? message : $"{message}{System.Environment.NewLine}{exception}";
|
||||
if (level >= ShrinkLogLevel.Error) GD.PushError(text);
|
||||
else if (level >= ShrinkLogLevel.Warning) GD.PushWarning(text);
|
||||
else GD.Print(text);
|
||||
}
|
||||
|
||||
public ValueTask<byte[]> CapturePngAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var image = GetViewport().GetTexture().GetImage();
|
||||
return ValueTask.FromResult(image.SavePngToBuffer());
|
||||
}
|
||||
|
||||
private async UniTaskVoid PumpNetworkAsync()
|
||||
{
|
||||
if (_networkPumpRunning) return;
|
||||
_networkPumpRunning = true;
|
||||
try
|
||||
{
|
||||
foreach (var queue in _networkServices.Values)
|
||||
await queue.PumpAsync(Math.Max(1, NetworkDispatchBudgetPerFrame));
|
||||
}
|
||||
finally
|
||||
{
|
||||
_networkPumpRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.Godot</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.Godot</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Godot</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>Godot 4.6 host and platform services for ShrinkSDK.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GodotSharp" Version="4.6.3" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.DataSaver\ShrinkSDK.DataSaver.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.App.Core\ShrinkSDK.App.Core.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,66 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
|
||||
namespace ShrinkModFramework.Godot;
|
||||
|
||||
public sealed class ShrinkGodotModLoader : IDisposable
|
||||
{
|
||||
private sealed record LoadedMod(AssemblyLoadContext LoadContext, WeakReference UnloadReference,
|
||||
ShrinkModContext Context, IReadOnlyList<IShrinkMod> Instances);
|
||||
private readonly Dictionary<string, LoadedMod> _loaded = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public IReadOnlyCollection<string> LoadedAssemblyPaths => _loaded.Keys;
|
||||
|
||||
public IReadOnlyList<IShrinkMod> Load(string assemblyPath)
|
||||
{
|
||||
assemblyPath = Path.GetFullPath(assemblyPath);
|
||||
if (_loaded.ContainsKey(assemblyPath)) throw new InvalidOperationException($"Mod assembly is already loaded: {assemblyPath}");
|
||||
var loadContext = new AssemblyLoadContext($"ShrinkMod:{Path.GetFileNameWithoutExtension(assemblyPath)}", true);
|
||||
loadContext.Resolving += (_, name) => ResolveDependency(loadContext, Path.GetDirectoryName(assemblyPath)!, name);
|
||||
try
|
||||
{
|
||||
var assembly = loadContext.LoadFromAssemblyPath(assemblyPath);
|
||||
var entries = assembly.GetTypes().Where(type => !type.IsAbstract && typeof(IShrinkMod).IsAssignableFrom(type) &&
|
||||
type.GetCustomAttribute<ShrinkModAttribute>() != null).OrderBy(type => type.GetCustomAttribute<ShrinkModAttribute>()!.LoadOrder).ToArray();
|
||||
var context = new ShrinkModContext(Path.GetDirectoryName(assemblyPath)!);
|
||||
var instances = entries.Select(type => (IShrinkMod)(Activator.CreateInstance(type) ??
|
||||
throw new InvalidOperationException($"Failed to create mod entry: {type.FullName}"))).ToArray();
|
||||
foreach (var mod in instances) mod.OnConstruct(context);
|
||||
foreach (var mod in instances) mod.OnRegisterContent(context);
|
||||
foreach (var mod in instances) mod.OnInitialize(context);
|
||||
foreach (var mod in instances) mod.OnReady(context);
|
||||
_loaded[assemblyPath] = new LoadedMod(loadContext, new WeakReference(loadContext), context, instances);
|
||||
return instances;
|
||||
}
|
||||
catch { loadContext.Unload(); throw; }
|
||||
}
|
||||
|
||||
public bool Unload(string assemblyPath)
|
||||
{
|
||||
assemblyPath = Path.GetFullPath(assemblyPath);
|
||||
if (!_loaded.Remove(assemblyPath, out var loaded)) return false;
|
||||
for (var index = loaded.Instances.Count - 1; index >= 0; index--)
|
||||
if (loaded.Instances[index] is IShrinkModUnload unload) unload.OnUnload(loaded.Context);
|
||||
loaded.LoadContext.Unload();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var path in _loaded.Keys.ToArray()) Unload(path);
|
||||
}
|
||||
|
||||
private static Assembly? ResolveDependency(AssemblyLoadContext context, string directory, AssemblyName name)
|
||||
{
|
||||
var shared = AssemblyLoadContext.Default.Assemblies.FirstOrDefault(assembly => assembly.GetName().Name == name.Name);
|
||||
if (shared != null) return shared;
|
||||
var path = Path.Combine(directory, name.Name + ".dll");
|
||||
return File.Exists(path) ? context.LoadFromAssemblyPath(path) : null;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkModFramework.Godot</AssemblyName>
|
||||
<RootNamespace>ShrinkModFramework.Godot</RootNamespace>
|
||||
<PackageId>ShrinkSDK.ModFramework.Godot</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>Collectible AssemblyLoadContext host for ShrinkSDK mods in Godot.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ShrinkSDK.ModFramework\ShrinkSDK.ModFramework.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Godot\ShrinkSDK.Godot.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,25 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ShrinkModFramework;
|
||||
|
||||
public sealed class ShrinkModContext
|
||||
{
|
||||
private readonly Dictionary<Type, object> _services = new();
|
||||
public ShrinkModContext(string modDirectory) => ModDirectory = modDirectory ?? throw new ArgumentNullException(nameof(modDirectory));
|
||||
public string ModDirectory { get; }
|
||||
public void RegisterService<T>(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service));
|
||||
public bool TryGetService<T>(out T? service) where T : class
|
||||
{
|
||||
service = _services.TryGetValue(typeof(T), out var value) ? value as T : null;
|
||||
return service != null;
|
||||
}
|
||||
public T GetRequiredService<T>() where T : class => TryGetService<T>(out var value) ? value! : throw new InvalidOperationException($"Service is not registered: {typeof(T).FullName}");
|
||||
}
|
||||
|
||||
public interface IShrinkModUnload
|
||||
{
|
||||
void OnUnload(ShrinkModContext context);
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkModFramework.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkModFramework</RootNamespace>
|
||||
<PackageId>ShrinkSDK.ModFramework</PackageId>
|
||||
<Version>0.3.0</Version>
|
||||
<Description>Engine-neutral ShrinkSDK mod contracts and lifecycle.</Description>
|
||||
<Nullable>disable</Nullable>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\ShrinkModContext.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkModFramework\Runtime\Core\IShrinkMod.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkModFramework\Runtime\Core\ShrinkModBase.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkModFramework\Runtime\Core\ShrinkModHandle.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkModFramework\Runtime\Metadata\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkNetwork.Integration.EventBus</AssemblyName>
|
||||
<RootNamespace>ShrinkNetwork.Integration</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Network.Integration.EventBus</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>ShrinkNetwork and EventBus generated bridge.</Description>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkNetwork.Integration.EventBus\*.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Context.Core\ShrinkSDK.Context.Core.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,22 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkNetwork.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkNetwork</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Network</PackageId>
|
||||
<Version>0.3.0</Version>
|
||||
<Description>ShrinkSDK messaging, RPC, permission and transport runtime.</Description>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkNetwork\Runtime\**\*.cs" />
|
||||
<PackageReference Include="Kcp-CSharp" Version="1.0.8" />
|
||||
<PackageReference Include="MessagePack" Version="3.1.8" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="UniTask" Version="2.5.10" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<PackageReference Include="ShrinkSDK.CodeGen" Version="0.1.0" PrivateAssets="compile;runtime;contentfiles;native" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,13 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<AssemblyName>ShrinkRuntime.Abstractions</AssemblyName>
|
||||
<RootNamespace>ShrinkSDK.Runtime</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Runtime.Abstractions</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>Engine-neutral ShrinkSDK runtime contracts.</Description>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkRuntime.Abstractions\Runtime\ShrinkRuntimeServices.cs" Link="Runtime\ShrinkRuntimeServices.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,89 +0,0 @@
|
||||
#nullable enable
|
||||
|
||||
using Godot;
|
||||
|
||||
namespace ShrinkTutorial.Godot;
|
||||
|
||||
public partial class ShrinkGodotTutorialOverlay : Control
|
||||
{
|
||||
private readonly Label _title = new();
|
||||
private readonly Label _body = new();
|
||||
private ShrinkTutorialRunner? _runner;
|
||||
private Control? _target;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
SetAnchorsAndOffsetsPreset(LayoutPreset.FullRect);
|
||||
MouseFilter = MouseFilterEnum.Stop;
|
||||
var panel = new PanelContainer { CustomMinimumSize = new Vector2(320, 100) };
|
||||
panel.Position = new Vector2(24, 24);
|
||||
var text = new VBoxContainer();
|
||||
text.AddChild(_title);
|
||||
text.AddChild(_body);
|
||||
panel.AddChild(text);
|
||||
AddChild(panel);
|
||||
}
|
||||
|
||||
public void Bind(ShrinkTutorialRunner runner)
|
||||
{
|
||||
if (_runner != null) _runner.StepChanged -= ShowStep;
|
||||
_runner = runner;
|
||||
_runner.StepChanged += ShowStep;
|
||||
if (_runner.CurrentStep != null) ShowStep(_runner.CurrentStep);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
if (_runner != null) _runner.StepChanged -= ShowStep;
|
||||
_runner = null;
|
||||
_target = null;
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_runner?.CurrentStep is not { } step) return;
|
||||
_target = ResolveTarget(step);
|
||||
QueueRedraw();
|
||||
}
|
||||
|
||||
public override void _Draw()
|
||||
{
|
||||
var viewport = GetViewportRect();
|
||||
if (_target == null)
|
||||
{
|
||||
DrawRect(viewport, new Color(0, 0, 0, 0.72f));
|
||||
return;
|
||||
}
|
||||
var hole = _target.GetGlobalRect().Grow(8);
|
||||
var shade = new Color(0, 0, 0, 0.72f);
|
||||
DrawRect(new Rect2(viewport.Position, new Vector2(viewport.Size.X, hole.Position.Y)), shade);
|
||||
DrawRect(new Rect2(new Vector2(0, hole.End.Y), new Vector2(viewport.Size.X, viewport.Size.Y - hole.End.Y)), shade);
|
||||
DrawRect(new Rect2(new Vector2(0, hole.Position.Y), new Vector2(hole.Position.X, hole.Size.Y)), shade);
|
||||
DrawRect(new Rect2(new Vector2(hole.End.X, hole.Position.Y), new Vector2(viewport.Size.X - hole.End.X, hole.Size.Y)), shade);
|
||||
}
|
||||
|
||||
public override void _GuiInput(InputEvent @event)
|
||||
{
|
||||
if (@event is not InputEventMouseButton { Pressed: true }) return;
|
||||
var step = _runner?.CurrentStep;
|
||||
if (step == null) return;
|
||||
if (step.CompleteCondition == ShrinkTutorialCompleteCondition.AnyClick ||
|
||||
step.CompleteCondition == ShrinkTutorialCompleteCondition.ClickTarget && _target?.GetGlobalRect().HasPoint(GetGlobalMousePosition()) == true)
|
||||
_runner!.CompleteStep();
|
||||
AcceptEvent();
|
||||
}
|
||||
|
||||
private void ShowStep(ShrinkTutorialStep step)
|
||||
{
|
||||
_title.Text = step.Title;
|
||||
_body.Text = step.Body;
|
||||
Visible = true;
|
||||
}
|
||||
|
||||
private Control? ResolveTarget(ShrinkTutorialStep step)
|
||||
{
|
||||
if (step.TargetMode == ShrinkTutorialTargetMode.Path) return GetTree().Root.GetNodeOrNull<Control>(step.Target);
|
||||
if (step.TargetMode == ShrinkTutorialTargetMode.AnchorId) return GetTree().GetFirstNodeInGroup("shrink_tutorial_" + step.Target) as Control;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<AssemblyName>ShrinkTutorial.Godot</AssemblyName>
|
||||
<RootNamespace>ShrinkTutorial.Godot</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Tutorial.Godot</PackageId>
|
||||
<Version>0.1.0</Version>
|
||||
<Description>Godot Control overlay and Resources for ShrinkSDK Tutorial.</Description>
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="GodotSharp" Version="4.6.3" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Tutorial\ShrinkSDK.Tutorial.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,76 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace ShrinkTutorial;
|
||||
|
||||
[Serializable]
|
||||
public sealed class ShrinkTutorialStep
|
||||
{
|
||||
public string StepId = string.Empty;
|
||||
public string Title = string.Empty;
|
||||
public string Body = string.Empty;
|
||||
public string Target = string.Empty;
|
||||
public ShrinkTutorialTargetMode TargetMode;
|
||||
public ShrinkTutorialCompleteCondition CompleteCondition = ShrinkTutorialCompleteCondition.ClickTarget;
|
||||
public ShrinkTutorialDialogAnchor DialogAnchor = ShrinkTutorialDialogAnchor.Auto;
|
||||
public ShrinkTutorialMaskShape MaskShape = ShrinkTutorialMaskShape.Rect;
|
||||
public string CustomEventName = string.Empty;
|
||||
public bool BlockInputOutsideTarget = true;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class ShrinkTutorialData
|
||||
{
|
||||
public string TutorialId = string.Empty;
|
||||
public List<ShrinkTutorialStep> Steps = new();
|
||||
}
|
||||
|
||||
public sealed class ShrinkTutorialRunner
|
||||
{
|
||||
private readonly IShrinkTutorialStorage _storage;
|
||||
private ShrinkTutorialProgress _progress;
|
||||
public ShrinkTutorialRunner(IShrinkTutorialStorage storage)
|
||||
{
|
||||
_storage = storage ?? throw new ArgumentNullException(nameof(storage));
|
||||
_progress = storage.Load() ?? new ShrinkTutorialProgress();
|
||||
}
|
||||
public ShrinkTutorialData Current { get; private set; }
|
||||
public int StepIndex { get; private set; } = -1;
|
||||
public ShrinkTutorialStep CurrentStep => Current != null && StepIndex >= 0 && StepIndex < Current.Steps.Count ? Current.Steps[StepIndex] : null;
|
||||
public event Action<ShrinkTutorialStep> StepChanged;
|
||||
public event Action<string> Completed;
|
||||
|
||||
public bool Start(ShrinkTutorialData tutorial)
|
||||
{
|
||||
if (tutorial == null || tutorial.Steps.Count == 0 || _progress.completedTutorials.Contains(tutorial.TutorialId)) return false;
|
||||
Current = tutorial;
|
||||
StepIndex = 0;
|
||||
StepChanged?.Invoke(CurrentStep);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool CompleteStep(string customEventName = null)
|
||||
{
|
||||
var step = CurrentStep;
|
||||
if (step == null) return false;
|
||||
if (step.CompleteCondition == ShrinkTutorialCompleteCondition.CustomEvent &&
|
||||
!string.Equals(step.CustomEventName, customEventName, StringComparison.Ordinal)) return false;
|
||||
StepIndex++;
|
||||
if (StepIndex < Current.Steps.Count) { StepChanged?.Invoke(CurrentStep); return true; }
|
||||
_progress.completedTutorials.Add(Current.TutorialId);
|
||||
_storage.Save(_progress);
|
||||
var id = Current.TutorialId;
|
||||
Current = null;
|
||||
StepIndex = -1;
|
||||
Completed?.Invoke(id);
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Current = null;
|
||||
StepIndex = -1;
|
||||
_storage.Reset();
|
||||
_progress = new ShrinkTutorialProgress();
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
<AssemblyName>ShrinkTutorial.Runtime</AssemblyName>
|
||||
<RootNamespace>ShrinkTutorial</RootNamespace>
|
||||
<PackageId>ShrinkSDK.Tutorial</PackageId>
|
||||
<Version>0.2.0</Version>
|
||||
<Description>Engine-neutral ShrinkSDK tutorial state and step runtime.</Description>
|
||||
<Nullable>disable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Runtime\ShrinkTutorialCore.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkTutorial\Runtime\Core\ShrinkTutorialEnums.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkTutorial\Runtime\Core\ShrinkTutorialLocalization.cs" />
|
||||
<Compile Include="..\..\..\Assets\Modules\ShrinkTutorial\Runtime\Storage\IShrinkTutorialStorage.cs" />
|
||||
<ProjectReference Include="..\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
+170
@@ -0,0 +1,170 @@
|
||||
# ShrinkSDK for Godot 4.6 C#
|
||||
|
||||
Godot 适配层使用共享 ShrinkSDK 运行时和 MSBuild/Cecil CodeGen。首期目标是 Godot 4.6.3 Mono、.NET 8,以及 Windows、Linux、macOS 桌面项目;不包含 Web、Android 和 iOS。
|
||||
|
||||
## 直接运行 Workspace 示例
|
||||
|
||||
使用 Godot 4.6.3 Mono 打开:
|
||||
|
||||
```text
|
||||
Godot/Samples/ShrinkSDK.Godot.Sample/project.godot
|
||||
```
|
||||
|
||||
首次打开前可以先完成导入和编译:
|
||||
|
||||
```powershell
|
||||
$godot = Join-Path $env:GODOT_HOME "godot_console.exe"
|
||||
& $godot --headless --editor --path .\Godot\Samples\ShrinkSDK.Godot.Sample --quit
|
||||
dotnet build .\Godot\Samples\ShrinkSDK.Godot.Sample\ShrinkSDK.Godot.Sample.csproj
|
||||
& $godot --headless --path .\Godot\Samples\ShrinkSDK.Godot.Sample
|
||||
```
|
||||
|
||||
`GODOT_HOME` 指向 Godot Mono 安装目录。成功运行时会输出 `SHRINK_GODOT_SMOKE_PASS`。
|
||||
|
||||
## 在现有 Godot C# 项目中安装
|
||||
|
||||
项目需要:
|
||||
|
||||
- Godot 4.6.3 Mono;
|
||||
- .NET 8 SDK;
|
||||
- `.csproj` 使用 `Godot.NET.Sdk/4.6.3`;
|
||||
- 项目级 `NuGet.Config` 保留既有源并加入 ShrinkSDK feed。
|
||||
|
||||
`NuGet.Config` 的最小增量如下:
|
||||
|
||||
```xml
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="ShrinkSDK" value="https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
安装 Godot 宿主和所需模块:
|
||||
|
||||
```powershell
|
||||
dotnet add package ShrinkSDK.Godot --version 0.1.0
|
||||
dotnet add package ShrinkSDK.EventBus --version 2.1.0
|
||||
dotnet add package ShrinkSDK.Command --version 0.3.0
|
||||
dotnet add package ShrinkSDK.Network --version 0.3.0
|
||||
dotnet add package ShrinkSDK.DataSaver --version 2.3.0
|
||||
dotnet restore
|
||||
dotnet build
|
||||
```
|
||||
|
||||
只有实际使用的模块需要安装。版本以 ShrinkSDK NuGet 源中的已发布版本为准,并保留命令中的固定版本号,不要改用浮动版本。
|
||||
|
||||
## Installer 插件
|
||||
|
||||
`ShrinkSDK.Godot.Installer` 的 nupkg 内包含完整的 `addons/shrinksdk`。取得 `0.1.3` 包后,将包内:
|
||||
|
||||
```text
|
||||
contentFiles/any/any/addons/shrinksdk
|
||||
```
|
||||
|
||||
复制到 Godot 项目的:
|
||||
|
||||
```text
|
||||
addons/shrinksdk
|
||||
```
|
||||
|
||||
然后在 Godot 中打开 `Project > Project Settings > Plugins`,启用 **ShrinkSDK Installer**。左侧 ShrinkSDK 面板可以:
|
||||
|
||||
- 查看项目直接安装的 ShrinkSDK NuGet 包及版本;
|
||||
- 安装、升级或移除模块;
|
||||
- 保留项目已有 NuGet 源和无关 `PackageReference`;
|
||||
- 执行 `dotnet restore/build`;
|
||||
- 查看 CodeGen 最后一次织入结果和生成的注册数量。
|
||||
|
||||
已安装版本高于面板目录版本时会显示 `Newer` 并禁用更新按钮,不会执行降级。
|
||||
|
||||
在 Workspace 中生成 Installer 包:
|
||||
|
||||
```powershell
|
||||
dotnet build .\Assets\Modules\ShrinkInstaller\Godot~\ShrinkSDK.Godot.Installer.csproj -c Release
|
||||
dotnet pack .\Assets\Modules\ShrinkInstaller\Godot~\ShrinkSDK.Godot.Installer.csproj -c Release --no-build -o .\Godot\Artifacts
|
||||
```
|
||||
|
||||
## 宿主节点
|
||||
|
||||
主场景根节点继承 `ShrinkGodotHost`,并在 `_Ready` 中先调用 `base._Ready()`:
|
||||
|
||||
```csharp
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkSDK.Godot;
|
||||
|
||||
public partial class GameRoot : ShrinkGodotHost
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
BootAsync().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid BootAsync()
|
||||
{
|
||||
RequireWoven(GetType().Assembly);
|
||||
await StartAppAsync();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
宿主负责日志、主线程派发、时间、`user://` 持久化路径、截图、应用生命周期和网络 dispatch queue。使用 `ShrinkNetworkService` 时,通过 `AddNetworkService(service)` 交给宿主逐帧泵送,释放前调用 `RemoveNetworkService(service)`。
|
||||
|
||||
## CodeGen 织入
|
||||
|
||||
EventBus、Command、Network 和 App 的特性注册由 `ShrinkSDK.CodeGen` 在构建时生成。项目正常引用这些模块后,`buildTransitive` 会默认设置:
|
||||
|
||||
```xml
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
```
|
||||
|
||||
执行:
|
||||
|
||||
```powershell
|
||||
dotnet build
|
||||
```
|
||||
|
||||
日志应出现类似:
|
||||
|
||||
```text
|
||||
[ShrinkSDK.CodeGen] ... woven: instance=1, static=1, registry=2
|
||||
```
|
||||
|
||||
运行时可以在启动阶段验证程序集:
|
||||
|
||||
```csharp
|
||||
ShrinkGodotHost.RequireWoven(GetType().Assembly);
|
||||
```
|
||||
|
||||
缺少织入时应修复 NuGet 引用或构建配置,不要增加运行时反射扫描兜底。只有明确采用手工注册的普通 .NET 宿主才设置 `<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>`。
|
||||
|
||||
## 特性声明示例
|
||||
|
||||
```csharp
|
||||
using ShrinkCommand;
|
||||
using ShrinkEventBus;
|
||||
using ShrinkNetwork;
|
||||
|
||||
public readonly struct PlayerReadyEvent : IShrinkEvent { }
|
||||
|
||||
[ShrinkEventSubscriber]
|
||||
public sealed class PlayerReadySubscriber
|
||||
{
|
||||
[ShrinkSubscribe]
|
||||
private void OnPlayerReady(PlayerReadyEvent value) { }
|
||||
}
|
||||
|
||||
[ShrinkCommandSubscriber]
|
||||
public static class GameCommands
|
||||
{
|
||||
[ShrinkCommand("game/status")]
|
||||
public static void Status() { }
|
||||
}
|
||||
|
||||
[ShrinkNetworkMessage(41001, "game/player-ready")]
|
||||
public sealed class PlayerReadyMessage : IShrinkNetworkMessage { }
|
||||
```
|
||||
|
||||
实例订阅者使用 `EventBus.Attach(instance)` 绑定;静态订阅、Command、Network 和 App registry 由织入代码自动注册。
|
||||
@@ -3,18 +3,18 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<EnableDynamicLoading>true</EnableDynamicLoading>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkRuntime.Abstractions\DotNet~\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkEventBus\DotNet~\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkCommand\DotNet~\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkNetwork\DotNet~\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Godot\ShrinkSDK.Godot.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.App.Starter.Basic\ShrinkSDK.App.Starter.Basic.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Tutorial\ShrinkSDK.Tutorial.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Tutorial.Godot\ShrinkSDK.Tutorial.Godot.csproj" />
|
||||
<ProjectReference Include="..\..\CodeGen\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkApp.Starter.Basic\DotNet~\ShrinkSDK.App.Starter.Basic.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkTutorial\DotNet~\ShrinkSDK.Tutorial.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkTutorial\Godot~\ShrinkSDK.Tutorial.Godot.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\CodeGen\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<Import Project="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
</Project>
|
||||
|
||||
+24
-24
@@ -1,31 +1,31 @@
|
||||
<Solution>
|
||||
<Folder Name="/Packages/">
|
||||
<Project Path="Packages/ShrinkSDK.Runtime.Abstractions/ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Context.Core/ShrinkSDK.Context.Core.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.EventBus/ShrinkSDK.EventBus.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Command/ShrinkSDK.Command.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Network/ShrinkSDK.Network.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Command.Integration.EventBus/ShrinkSDK.Command.Integration.EventBus.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Command.Integration.Network/ShrinkSDK.Command.Integration.Network.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Command.Integration.App/ShrinkSDK.Command.Integration.App.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.DataSaver.Integration.EventBus/ShrinkSDK.DataSaver.Integration.EventBus.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.DataSaver.Integration.App/ShrinkSDK.DataSaver.Integration.App.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Network.Integration.EventBus/ShrinkSDK.Network.Integration.EventBus.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Network.Integration.App/ShrinkSDK.Network.Integration.App.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.DataSaver/ShrinkSDK.DataSaver.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.App.Core/ShrinkSDK.App.Core.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Context.AppAdapter/ShrinkSDK.Context.AppAdapter.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.App.Starter.Basic/ShrinkSDK.App.Starter.Basic.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.ModFramework/ShrinkSDK.ModFramework.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.ModFramework.Godot/ShrinkSDK.ModFramework.Godot.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Tutorial/ShrinkSDK.Tutorial.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Tutorial.Godot/ShrinkSDK.Tutorial.Godot.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkRuntime.Abstractions/DotNet~/ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkContext.Core/DotNet~/ShrinkSDK.Context.Core.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkEventBus/DotNet~/ShrinkSDK.EventBus.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkCommand/DotNet~/ShrinkSDK.Command.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkNetwork/DotNet~/ShrinkSDK.Network.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkCommand.Integration.EventBus/DotNet~/ShrinkSDK.Command.Integration.EventBus.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkCommand.Integration.Network/DotNet~/ShrinkSDK.Command.Integration.Network.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkCommand.Integration.App/DotNet~/ShrinkSDK.Command.Integration.App.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkDataSaver.Integration.EventBus/DotNet~/ShrinkSDK.DataSaver.Integration.EventBus.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkDataSaver.Integration.App/DotNet~/ShrinkSDK.DataSaver.Integration.App.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkNetwork.Integration.EventBus/DotNet~/ShrinkSDK.Network.Integration.EventBus.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkNetwork.Integration.App/DotNet~/ShrinkSDK.Network.Integration.App.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkDataSaver/DotNet~/ShrinkSDK.DataSaver.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkApp.Core/DotNet~/ShrinkSDK.App.Core.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkContext.AppAdapter/DotNet~/ShrinkSDK.Context.AppAdapter.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkApp.Starter.Basic/DotNet~/ShrinkSDK.App.Starter.Basic.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkModFramework/DotNet~/ShrinkSDK.ModFramework.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkModFramework/Godot~/ShrinkSDK.ModFramework.Godot.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkTutorial/DotNet~/ShrinkSDK.Tutorial.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkTutorial/Godot~/ShrinkSDK.Tutorial.Godot.csproj" />
|
||||
<Project Path="Packages/ShrinkSDK.Godot/ShrinkSDK.Godot.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/CodeGen/">
|
||||
<Project Path="CodeGen/ShrinkSDK.CodeGen.Core/ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<Project Path="CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkSDK.CodeGen.Analyzers.csproj" />
|
||||
<Project Path="CodeGen/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkShared.CodeGen/DotNet~/ShrinkSDK.CodeGen.Core/ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkShared.CodeGen/DotNet~/ShrinkSDK.CodeGen.Analyzers/ShrinkSDK.CodeGen.Analyzers.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkShared.CodeGen/DotNet~/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/Tests/">
|
||||
<Project Path="Tests/CodeGenFixture/CodeGenFixture.csproj" />
|
||||
@@ -40,6 +40,6 @@
|
||||
<Project Path="Samples/ShrinkSDK.Godot.Sample/ShrinkSDK.Godot.Sample.csproj" />
|
||||
</Folder>
|
||||
<Folder Name="/Installer/">
|
||||
<Project Path="Installer/ShrinkSDK.Godot.Installer.csproj" />
|
||||
<Project Path="../Assets/Modules/ShrinkInstaller/Godot~/ShrinkSDK.Godot.Installer.csproj" />
|
||||
</Folder>
|
||||
</Solution>
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
<SignAssembly Condition="'$(FixtureSignAssembly)' == 'true'">true</SignAssembly>
|
||||
<AssemblyOriginatorKeyFile Condition="'$(FixtureSignAssembly)' == 'true'">$(FixtureStrongNameKeyFile)</AssemblyOriginatorKeyFile>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Network.Integration.EventBus\ShrinkSDK.Network.Integration.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\CodeGen\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkRuntime.Abstractions\DotNet~\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkEventBus\DotNet~\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkCommand\DotNet~\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkNetwork\DotNet~\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkNetwork.Integration.EventBus\DotNet~\ShrinkSDK.Network.Integration.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\CodeGen\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<Import Project="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
</Project>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\CodeGen\ShrinkSDK.CodeGen.Core\ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Core\ShrinkSDK.CodeGen.Core.csproj" />
|
||||
<PackageReference Include="Mono.Cecil" Version="0.11.6" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
<AssemblyName>ShrinkSDK.InstallerFixture</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Installer\ShrinkSDK.Godot.Installer.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkInstaller\Godot~\ShrinkSDK.Godot.Installer.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
<AssemblyName>ShrinkSDK.InvalidCodeGenFixture</AssemblyName>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
<RunAnalyzers>false</RunAnalyzers>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Network\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\CodeGen\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkRuntime.Abstractions\DotNet~\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkNetwork\DotNet~\ShrinkSDK.Network.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\ShrinkSDK.CodeGen.Task.csproj" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\CodeGen\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<Import Project="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
</Project>
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
<TargetFramework>netstandard2.1</TargetFramework>
|
||||
<AssemblyName>ShrinkSDK.ModFixture</AssemblyName>
|
||||
<ShrinkCodeGenEnabled>true</ShrinkCodeGenEnabled>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
<_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll</_ShrinkCodeGenTaskAssembly>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Runtime.Abstractions\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.ModFramework\ShrinkSDK.ModFramework.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkRuntime.Abstractions\DotNet~\ShrinkSDK.Runtime.Abstractions.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkModFramework\DotNet~\ShrinkSDK.ModFramework.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkEventBus\DotNet~\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkCommand\DotNet~\ShrinkSDK.Command.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="..\..\CodeGen\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
<Import Project="..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\buildTransitive\ShrinkSDK.CodeGen.targets" />
|
||||
</Project>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<ShrinkCodeGenEnabled>false</ShrinkCodeGenEnabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.ModFramework.Godot\ShrinkSDK.ModFramework.Godot.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.EventBus\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\Packages\ShrinkSDK.Command\ShrinkSDK.Command.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkModFramework\Godot~\ShrinkSDK.ModFramework.Godot.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkEventBus\DotNet~\ShrinkSDK.EventBus.csproj" />
|
||||
<ProjectReference Include="..\..\..\Assets\Modules\ShrinkCommand\DotNet~\ShrinkSDK.Command.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# ShrinkSDK Workspace
|
||||
|
||||
ShrinkSDK 的 Workspace 用于跨包集成、场景验证、生成器验证和 SDK 文档。每个 `Assets/Modules/<Module>` 是独立公开仓库的 Git submodule;根仓库保留相邻 `.meta`,因此不要删除或重新生成这些文件。
|
||||
ShrinkSDK 是一组可独立组合的 Unity / Godot C# 运行时模块。共享内核以 `netstandard2.1` 为最低目标;Unity 侧支持 Unity 2022.3,Godot 侧首期支持 Godot 4.6.3 Mono 和桌面平台。
|
||||
|
||||
Workspace 用于跨包集成、Unity 场景验证、Godot 消费者验证和 CodeGen 织入测试。每个 `Assets/Modules/<Module>` 是独立公开仓库的 Git submodule;根仓库保留相邻 `.meta`,不要删除或重新生成这些文件。
|
||||
|
||||
## 获取 Workspace
|
||||
|
||||
@@ -10,11 +12,23 @@ cd Workspace
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
所有模块都可以独立打开其 `Development~/UnityProject`。根 Workspace 仅用于跨包组合与验收。
|
||||
所有 Unity 模块都可以独立打开其 `Development~/UnityProject`。根 Workspace 用于跨包组合与验收;Godot 综合示例位于 `Godot/Samples/ShrinkSDK.Godot.Sample`。
|
||||
|
||||
## 安装 SDK
|
||||
## Unity 安装与使用
|
||||
|
||||
首选公开 Gitea NPM/UPM registry,在消费者项目的 `Packages/manifest.json` 中保留既有配置并加入:
|
||||
### 通过 Installer 安装
|
||||
|
||||
在 Unity Package Manager 中选择 **Add package from git URL**,添加:
|
||||
|
||||
```text
|
||||
https://git.crash.work/ShrinkSDK/Installer.git#main
|
||||
```
|
||||
|
||||
正式项目应在对应版本发布后把 `main` 换成固定 tag。安装完成后打开 `ShrinkSDK/包管理`,选择单个模块或推荐组合。Installer 会合并 ShrinkSDK scoped registry、安装精确版本依赖,并分别显示未安装、可升级、已安装和已安装较新版本;不会把较新版本降级到目录版本。
|
||||
|
||||
### 手工安装
|
||||
|
||||
也可以在消费者项目的 `Packages/manifest.json` 中保留原有内容并加入 registry:
|
||||
|
||||
```json
|
||||
{
|
||||
@@ -24,23 +38,82 @@ git submodule update --init --recursive
|
||||
"url": "https://git.crash.work/api/packages/ShrinkSDK/npm/",
|
||||
"scopes": ["com.cneicy"]
|
||||
}
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"com.cneicy.shrink-app-starter-basic": "0.3.0"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
然后按精确版本添加包,例如 `com.cneicy.shrink-app-starter-basic: 0.2.2`。Git 备用安装同样必须固定标签,例如:
|
||||
如果项目已经有 `scopedRegistries` 或 `dependencies`,只合并对应条目,不要覆盖原有配置。Git 安装同样建议固定 tag,例如:
|
||||
|
||||
```text
|
||||
https://git.crash.work/ShrinkSDK/ShrinkEventBus.git#v2.0.1
|
||||
https://git.crash.work/ShrinkSDK/ShrinkEventBus.git#v2.1.0
|
||||
```
|
||||
|
||||
也可先通过固定标签安装 Editor 引导包:
|
||||
### 快速开始
|
||||
|
||||
安装 `ShrinkApp.Starter.Basic` 后,执行 `ShrinkSDK/应用/基础起步/创建默认 Context 组合`。菜单会生成默认配置和入口场景;打开 `Assets/Scenes/ShrinkAppEntry.unity` 即可运行 Command、DataSaver、Network 和 App 的基础组合。
|
||||
|
||||
EventBus、Command、Network 和 App 的特性注册由 Unity ILPostProcessor 在编译期织入,不需要运行时反射扫描或手工维护注册表。修改带 ShrinkSDK 特性的代码后,等待 Unity 完成重新编译,再进入 Play Mode。
|
||||
|
||||
## Godot 4.6 C# 安装与使用
|
||||
|
||||
Godot 项目需要 Godot 4.6.3 Mono 和 .NET 8 SDK。使用现有 Workspace 验证时,直接用 Godot 打开:
|
||||
|
||||
```text
|
||||
https://git.crash.work/ShrinkSDK/Installer.git#v0.2.4
|
||||
Godot/Samples/ShrinkSDK.Godot.Sample/project.godot
|
||||
```
|
||||
|
||||
随后在 Unity 打开 `ShrinkSDK/包管理`。UI Toolkit 窗口会显示直接与间接依赖的真实安装状态,并按 Context 组合基础、应用宿主、独立功能和模块集成组织固定版本包与推荐组合。安装器只合并 `com.cneicy` registry 和依赖数据,不写认证信息,也不复制模板到 `Assets`。
|
||||
外部 Godot C# 项目通过 NuGet 使用 ShrinkSDK。先在项目级 `NuGet.Config` 中加入软件源:
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="ShrinkSDK" value="https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
```
|
||||
|
||||
然后为 Godot 的 `.csproj` 安装宿主和需要的模块,例如:
|
||||
|
||||
```powershell
|
||||
dotnet add package ShrinkSDK.Godot --version 0.1.0
|
||||
dotnet add package ShrinkSDK.App.Starter.Basic --version 0.3.0
|
||||
dotnet add package ShrinkSDK.EventBus --version 2.1.0
|
||||
dotnet restore
|
||||
dotnet build
|
||||
```
|
||||
|
||||
需要自动注册的包会传递引入 `ShrinkSDK.CodeGen`。CodeGen 默认在 `CoreCompile` 后织入当前项目程序集;构建日志应出现 `[ShrinkSDK.CodeGen]`,无需额外添加 Source Generator、反射扫描或手工注册表。
|
||||
|
||||
主场景根节点可继承 `ShrinkGodotHost`:
|
||||
|
||||
```csharp
|
||||
using Cysharp.Threading.Tasks;
|
||||
using ShrinkSDK.Godot;
|
||||
|
||||
public partial class GameRoot : ShrinkGodotHost
|
||||
{
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
StartAsync().Forget();
|
||||
}
|
||||
|
||||
private async UniTaskVoid StartAsync()
|
||||
{
|
||||
RequireWoven(GetType().Assembly);
|
||||
await StartAppAsync();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
`ShrinkGodotHost` 在 `_Ready` 中安装平台服务,在 `_Process` 中泵送主线程和网络队列,并转发暂停、恢复与退出生命周期。Godot Installer 插件的安装、包管理面板、CodeGen 状态和命令行验证方式见 [Godot/README.md](Godot/README.md)。
|
||||
|
||||
## 开发与发布
|
||||
|
||||
发布、子模块迁移和独立开发宿主生成规则位于 [Tools/RepositoryMigration/Initialize-ShrinkSdkPackageRepositories.ps1](Tools/RepositoryMigration/Initialize-ShrinkSdkPackageRepositories.ps1)。架构约束与跨包验证要求见 [DESIGN.md](DESIGN.md)。
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
workspace_root="${1:-$PWD}"
|
||||
workspace_root="$(cd "$workspace_root" && pwd)"
|
||||
cd "$workspace_root"
|
||||
|
||||
if [[ ! -f .gitmodules ]]; then
|
||||
echo "Workspace .gitmodules was not found: $workspace_root" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t declared_paths < <(
|
||||
git config --file .gitmodules --get-regexp '^submodule\..*\.path$' |
|
||||
awk '{ print $2 }'
|
||||
)
|
||||
|
||||
if [[ "${#declared_paths[@]}" -eq 0 ]]; then
|
||||
echo "No submodules are declared in .gitmodules." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t top_level_status < <(git submodule status)
|
||||
if [[ "${#top_level_status[@]}" -ne "${#declared_paths[@]}" ]]; then
|
||||
echo "Submodule count mismatch: declared=${#declared_paths[@]} status=${#top_level_status[@]}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for relative_path in "${declared_paths[@]}"; do
|
||||
if [[ ! -e "$relative_path/.git" ]]; then
|
||||
echo "Declared submodule is not initialized: $relative_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
recursive_status="$(git submodule status --recursive)"
|
||||
if grep -Eq '^[+-U]' <<<"$recursive_status"; then
|
||||
echo "One or more submodules are missing, conflicted, or not at the recorded revision:" >&2
|
||||
grep -E '^[+-U]' <<<"$recursive_status" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf '%s\n' "$recursive_status"
|
||||
echo "Submodule validation passed: declared=${#declared_paths[@]}"
|
||||
@@ -0,0 +1,44 @@
|
||||
[CmdletBinding(DefaultParameterSetName = 'Check')]
|
||||
param(
|
||||
[Parameter(Mandatory, ParameterSetName = 'Check')]
|
||||
[switch]$Check,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName = 'Bump')]
|
||||
[Parameter(Mandatory, ParameterSetName = 'Version')]
|
||||
[string]$Package,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName = 'Bump')]
|
||||
[ValidateSet('major', 'minor', 'patch')]
|
||||
[string]$Bump,
|
||||
|
||||
[Parameter(Mandatory, ParameterSetName = 'Version')]
|
||||
[ValidatePattern('^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$')]
|
||||
[string]$Version,
|
||||
|
||||
[Parameter(ParameterSetName = 'Bump')]
|
||||
[Parameter(ParameterSetName = 'Version')]
|
||||
[switch]$DryRun
|
||||
)
|
||||
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$scriptPath = Join-Path $PSScriptRoot 'update-shrinksdk-versions.mjs'
|
||||
$arguments = @($scriptPath)
|
||||
|
||||
if ($Check) {
|
||||
$arguments += '--check'
|
||||
} else {
|
||||
$arguments += @('--package', $Package)
|
||||
if ($PSCmdlet.ParameterSetName -eq 'Bump') {
|
||||
$arguments += @('--bump', $Bump)
|
||||
} else {
|
||||
$arguments += @('--version', $Version)
|
||||
}
|
||||
if ($DryRun) {
|
||||
$arguments += '--dry-run'
|
||||
}
|
||||
}
|
||||
|
||||
& node @arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "ShrinkSDK version tool failed with exit code $LASTEXITCODE."
|
||||
}
|
||||
@@ -0,0 +1,302 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"unityPackages": [
|
||||
{
|
||||
"directory": "ShrinkApp.Core",
|
||||
"name": "com.cneicy.shrink-app-core",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkApp.Core.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.App.Core",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkApp.Core/DotNet~/ShrinkSDK.App.Core.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkApp.Starter.Basic",
|
||||
"name": "com.cneicy.shrink-app-starter-basic",
|
||||
"version": "0.3.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkApp.Starter.Basic.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.App.Starter.Basic",
|
||||
"version": "0.3.0",
|
||||
"project": "Assets/Modules/ShrinkApp.Starter.Basic/DotNet~/ShrinkSDK.App.Starter.Basic.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkCommand",
|
||||
"name": "com.cneicy.shrink-command",
|
||||
"version": "0.3.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkCommand.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Command",
|
||||
"version": "0.3.0",
|
||||
"project": "Assets/Modules/ShrinkCommand/DotNet~/ShrinkSDK.Command.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkCommand.Integration.App",
|
||||
"name": "com.cneicy.shrink-command-integration-app",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.App.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Command.Integration.App",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkCommand.Integration.App/DotNet~/ShrinkSDK.Command.Integration.App.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkCommand.Integration.EventBus",
|
||||
"name": "com.cneicy.shrink-command-integration-eventbus",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.EventBus.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Command.Integration.EventBus",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkCommand.Integration.EventBus/DotNet~/ShrinkSDK.Command.Integration.EventBus.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkCommand.Integration.Network",
|
||||
"name": "com.cneicy.shrink-command-integration-network",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkCommand.Integration.Network.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Command.Integration.Network",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkCommand.Integration.Network/DotNet~/ShrinkSDK.Command.Integration.Network.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkContext.AppAdapter",
|
||||
"name": "com.cneicy.shrink-context-app-adapter",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkContext.AppAdapter.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Context.AppAdapter",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkContext.AppAdapter/DotNet~/ShrinkSDK.Context.AppAdapter.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkContext.Core",
|
||||
"name": "com.cneicy.shrink-context-core",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkContext.Core.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Context.Core",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkContext.Core/DotNet~/ShrinkSDK.Context.Core.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkContext.EventBusAdapter",
|
||||
"name": "com.cneicy.shrink-context-eventbus-adapter",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkContext.EventBusAdapter.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Context.EventBusAdapter",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkContext.EventBusAdapter/DotNet~/ShrinkSDK.Context.EventBusAdapter.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkDataSaver",
|
||||
"name": "com.cneicy.shrink-datasaver",
|
||||
"version": "2.3.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkDataSaver.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.DataSaver",
|
||||
"version": "2.3.0",
|
||||
"project": "Assets/Modules/ShrinkDataSaver/DotNet~/ShrinkSDK.DataSaver.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkDataSaver.Integration.App",
|
||||
"name": "com.cneicy.shrink-datasaver-integration-app",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkDataSaver.Integration.App.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.DataSaver.Integration.App",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkDataSaver.Integration.App/DotNet~/ShrinkSDK.DataSaver.Integration.App.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkDataSaver.Integration.EventBus",
|
||||
"name": "com.cneicy.shrink-datasaver-integration-eventbus",
|
||||
"version": "2.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkDataSaver.Integration.EventBus.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.DataSaver.Integration.EventBus",
|
||||
"version": "2.2.0",
|
||||
"project": "Assets/Modules/ShrinkDataSaver.Integration.EventBus/DotNet~/ShrinkSDK.DataSaver.Integration.EventBus.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkEventBus",
|
||||
"name": "com.cneicy.shrink-eventbus",
|
||||
"version": "2.1.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkEventBus.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.EventBus",
|
||||
"version": "2.1.0",
|
||||
"project": "Assets/Modules/ShrinkEventBus/DotNet~/ShrinkSDK.EventBus.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkEventBus.Entities",
|
||||
"name": "com.cneicy.shrink-eventbus-entities",
|
||||
"version": "0.1.2",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkEventBus.Entities.git"
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkInstaller",
|
||||
"name": "com.cneicy.shrink-installer",
|
||||
"version": "0.2.6",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/Installer.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Godot.Installer",
|
||||
"version": "0.1.3",
|
||||
"project": "Assets/Modules/ShrinkInstaller/Godot~/ShrinkSDK.Godot.Installer.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkModFramework",
|
||||
"name": "com.cneicy.shrink-mod-framework",
|
||||
"version": "0.3.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkModFramework.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.ModFramework",
|
||||
"version": "0.3.0",
|
||||
"project": "Assets/Modules/ShrinkModFramework/DotNet~/ShrinkSDK.ModFramework.csproj"
|
||||
},
|
||||
{
|
||||
"id": "ShrinkSDK.ModFramework.Godot",
|
||||
"version": "0.1.0",
|
||||
"project": "Assets/Modules/ShrinkModFramework/Godot~/ShrinkSDK.ModFramework.Godot.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkNetwork",
|
||||
"name": "com.cneicy.shrink-network",
|
||||
"version": "0.3.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkNetwork.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Network",
|
||||
"version": "0.3.0",
|
||||
"project": "Assets/Modules/ShrinkNetwork/DotNet~/ShrinkSDK.Network.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkNetwork.Integration.App",
|
||||
"name": "com.cneicy.shrink-network-integration-app",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkNetwork.Integration.App.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Network.Integration.App",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkNetwork.Integration.App/DotNet~/ShrinkSDK.Network.Integration.App.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkNetwork.Integration.EventBus",
|
||||
"name": "com.cneicy.shrink-network-integration-eventbus",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkNetwork.Integration.EventBus.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Network.Integration.EventBus",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkNetwork.Integration.EventBus/DotNet~/ShrinkSDK.Network.Integration.EventBus.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkRuntime.Abstractions",
|
||||
"name": "com.cneicy.shrink-runtime-abstractions",
|
||||
"version": "0.1.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkRuntime.Abstractions.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Runtime.Abstractions",
|
||||
"version": "0.1.0",
|
||||
"project": "Assets/Modules/ShrinkRuntime.Abstractions/DotNet~/ShrinkSDK.Runtime.Abstractions.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkShared.CodeGen",
|
||||
"name": "com.cneicy.shrink-shared-codegen",
|
||||
"version": "0.1.1",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkShared.CodeGen.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.CodeGen",
|
||||
"version": "0.1.0",
|
||||
"project": "Assets/Modules/ShrinkShared.CodeGen/DotNet~/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"directory": "ShrinkTutorial",
|
||||
"name": "com.cneicy.shrink-tutorial",
|
||||
"version": "0.2.0",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkTutorial.git",
|
||||
"nugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Tutorial",
|
||||
"version": "0.2.0",
|
||||
"project": "Assets/Modules/ShrinkTutorial/DotNet~/ShrinkSDK.Tutorial.csproj"
|
||||
},
|
||||
{
|
||||
"id": "ShrinkSDK.Tutorial.Godot",
|
||||
"version": "0.1.0",
|
||||
"project": "Assets/Modules/ShrinkTutorial/Godot~/ShrinkSDK.Tutorial.Godot.csproj"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"standaloneNugetPackages": [
|
||||
{
|
||||
"id": "ShrinkSDK.Godot",
|
||||
"version": "0.1.0",
|
||||
"project": "Godot/Packages/ShrinkSDK.Godot/ShrinkSDK.Godot.csproj",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkGodot.git"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,867 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptDirectory = path.dirname(fileURLToPath(import.meta.url));
|
||||
const workspaceRoot = path.resolve(scriptDirectory, '..', '..');
|
||||
const packageCatalogPath = path.join(scriptDirectory, 'package-versions.json');
|
||||
const installerPackageName = 'com.cneicy.shrink-installer';
|
||||
const semanticVersionPattern = '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*)(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?';
|
||||
const semanticVersion = new RegExp(`^${semanticVersionPattern}$`);
|
||||
|
||||
function usage(message) {
|
||||
if (message) {
|
||||
console.error(message);
|
||||
}
|
||||
console.error('Usage:');
|
||||
console.error(' node Tools/Release/update-shrinksdk-versions.mjs --check');
|
||||
console.error(' node Tools/Release/update-shrinksdk-versions.mjs --package <name> --bump <major|minor|patch> [--dry-run]');
|
||||
console.error(' node Tools/Release/update-shrinksdk-versions.mjs --package <name> --version <x.y.z> [--dry-run]');
|
||||
process.exitCode = 2;
|
||||
}
|
||||
|
||||
function parseArguments(argv) {
|
||||
const options = { check: false, dryRun: false, package: null, bump: null, version: null };
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const argument = argv[index];
|
||||
switch (argument) {
|
||||
case '--check':
|
||||
options.check = true;
|
||||
break;
|
||||
case '--dry-run':
|
||||
options.dryRun = true;
|
||||
break;
|
||||
case '--package':
|
||||
options.package = argv[++index] ?? null;
|
||||
break;
|
||||
case '--bump':
|
||||
options.bump = argv[++index] ?? null;
|
||||
break;
|
||||
case '--version':
|
||||
options.version = argv[++index] ?? null;
|
||||
break;
|
||||
case '--help':
|
||||
case '-h':
|
||||
return { help: true };
|
||||
default:
|
||||
throw new Error(`Unknown argument: ${argument}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.check) {
|
||||
if (options.package || options.bump || options.version || options.dryRun) {
|
||||
throw new Error('--check cannot be combined with update arguments.');
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
if (!options.package || Boolean(options.bump) === Boolean(options.version)) {
|
||||
throw new Error('An update requires --package and exactly one of --bump or --version.');
|
||||
}
|
||||
if (options.bump && !['major', 'minor', 'patch'].includes(options.bump)) {
|
||||
throw new Error(`Unsupported bump kind: ${options.bump}`);
|
||||
}
|
||||
if (options.version && !semanticVersion.test(options.version)) {
|
||||
throw new Error(`Invalid semantic version: ${options.version}`);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
function normalizeRelative(value) {
|
||||
return value.replaceAll('\\', '/').replace(/^\.\//, '');
|
||||
}
|
||||
|
||||
function relativeToWorkspace(absolutePath) {
|
||||
return normalizeRelative(path.relative(workspaceRoot, absolutePath));
|
||||
}
|
||||
|
||||
function escapeRegularExpression(value) {
|
||||
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
function readGitModules() {
|
||||
const gitModulesPath = path.join(workspaceRoot, '.gitmodules');
|
||||
if (!fs.existsSync(gitModulesPath)) {
|
||||
throw new Error(`Workspace .gitmodules was not found: ${gitModulesPath}`);
|
||||
}
|
||||
|
||||
const modules = [];
|
||||
let current = null;
|
||||
for (const line of fs.readFileSync(gitModulesPath, 'utf8').split(/\r?\n/)) {
|
||||
const section = line.match(/^\s*\[submodule\s+"(.+)"\]\s*$/);
|
||||
if (section) {
|
||||
current = { section: section[1], path: null, url: null };
|
||||
modules.push(current);
|
||||
continue;
|
||||
}
|
||||
if (!current) {
|
||||
continue;
|
||||
}
|
||||
const property = line.match(/^\s*(path|url)\s*=\s*(.*?)\s*$/);
|
||||
if (property) {
|
||||
current[property[1]] = property[1] === 'path' ? normalizeRelative(property[2]) : property[2];
|
||||
}
|
||||
}
|
||||
|
||||
const seenPaths = new Set();
|
||||
for (const module of modules) {
|
||||
if (!module.path || !module.url) {
|
||||
throw new Error(`Incomplete .gitmodules entry: ${module.section}`);
|
||||
}
|
||||
const key = module.path.toLowerCase();
|
||||
if (seenPaths.has(key)) {
|
||||
throw new Error(`Duplicate .gitmodules path: ${module.path}`);
|
||||
}
|
||||
seenPaths.add(key);
|
||||
}
|
||||
return modules;
|
||||
}
|
||||
|
||||
function walkFiles(directory, predicate) {
|
||||
if (!fs.existsSync(directory)) {
|
||||
return [];
|
||||
}
|
||||
const result = [];
|
||||
const visit = current => {
|
||||
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
||||
if (entry.name === '.git' || entry.name === 'bin' || entry.name === 'obj' || entry.name === 'Development~') {
|
||||
continue;
|
||||
}
|
||||
const fullPath = path.join(current, entry.name);
|
||||
if (entry.isDirectory()) {
|
||||
visit(fullPath);
|
||||
} else if (entry.isFile() && predicate(fullPath)) {
|
||||
result.push(fullPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
visit(directory);
|
||||
return result.sort((left, right) => left.localeCompare(right));
|
||||
}
|
||||
|
||||
function xmlElement(text, name) {
|
||||
return text.match(new RegExp(`<${name}>\\s*([^<]+?)\\s*</${name}>`, 'i'))?.[1]?.trim() ?? null;
|
||||
}
|
||||
|
||||
function xmlAttribute(text, name) {
|
||||
return text.match(new RegExp(`\\b${name}\\s*=\\s*"([^"]+)"`, 'i'))?.[1]?.trim() ?? null;
|
||||
}
|
||||
|
||||
function readPackageReferences(text) {
|
||||
const references = [];
|
||||
const elementPattern = /<PackageReference\b[\s\S]*?(?:\/>|<\/PackageReference>)/gi;
|
||||
for (const match of text.matchAll(elementPattern)) {
|
||||
const include = xmlAttribute(match[0], 'Include');
|
||||
const version = xmlAttribute(match[0], 'Version') ?? xmlElement(match[0], 'Version');
|
||||
if (include && version) {
|
||||
references.push({ id: include, version });
|
||||
}
|
||||
}
|
||||
return references;
|
||||
}
|
||||
|
||||
function readProject(projectPath, ownerModule, ownerUpmName) {
|
||||
const text = fs.readFileSync(projectPath, 'utf8');
|
||||
const id = xmlElement(text, 'PackageId');
|
||||
const version = xmlElement(text, 'Version');
|
||||
const isPackable = xmlElement(text, 'IsPackable');
|
||||
if (!id || !version || String(isPackable).toLowerCase() === 'false') {
|
||||
return null;
|
||||
}
|
||||
if (!semanticVersion.test(version)) {
|
||||
throw new Error(`${relativeToWorkspace(projectPath)} has an invalid package version: ${version}`);
|
||||
}
|
||||
|
||||
const relativeToOwner = normalizeRelative(path.relative(path.join(workspaceRoot, ownerModule.path), projectPath));
|
||||
const segments = relativeToOwner.split('/');
|
||||
return {
|
||||
id,
|
||||
version,
|
||||
path: projectPath,
|
||||
project: relativeToWorkspace(projectPath),
|
||||
repository: ownerModule.url,
|
||||
ownerModulePath: ownerModule.path,
|
||||
ownerUpmName,
|
||||
coupledToUpm: Boolean(ownerUpmName) && segments.length === 2 && segments[0] === 'DotNet~',
|
||||
references: readPackageReferences(text)
|
||||
};
|
||||
}
|
||||
|
||||
function buildModel() {
|
||||
const modules = readGitModules();
|
||||
const upmModules = modules.filter(module => /^Assets\/Modules\/[^/]+$/.test(module.path));
|
||||
const declaredPaths = new Set(upmModules.map(module => module.path.toLowerCase()));
|
||||
const modulesDirectory = path.join(workspaceRoot, 'Assets', 'Modules');
|
||||
const manifestDirectories = fs.readdirSync(modulesDirectory, { withFileTypes: true })
|
||||
.filter(entry => entry.isDirectory() && fs.existsSync(path.join(modulesDirectory, entry.name, 'package.json')))
|
||||
.map(entry => `Assets/Modules/${entry.name}`);
|
||||
const undeclared = manifestDirectories.filter(directory => !declaredPaths.has(directory.toLowerCase()));
|
||||
if (undeclared.length > 0) {
|
||||
throw new Error(`Package directories are not declared in .gitmodules: ${undeclared.join(', ')}`);
|
||||
}
|
||||
|
||||
const upmPackages = [];
|
||||
const upmByName = new Map();
|
||||
for (const module of upmModules) {
|
||||
const packagePath = path.join(workspaceRoot, module.path);
|
||||
const manifestPath = path.join(packagePath, 'package.json');
|
||||
if (!fs.existsSync(manifestPath)) {
|
||||
throw new Error(`Declared package submodule has no package.json: ${module.path}`);
|
||||
}
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
|
||||
if (typeof manifest.name !== 'string' || typeof manifest.version !== 'string' || !semanticVersion.test(manifest.version)) {
|
||||
throw new Error(`${module.path}/package.json has no valid name and semantic version.`);
|
||||
}
|
||||
if (upmByName.has(manifest.name)) {
|
||||
throw new Error(`Duplicate UPM package name: ${manifest.name}`);
|
||||
}
|
||||
const dependencies = Object.entries(manifest.dependencies ?? {})
|
||||
.filter(([name]) => name.startsWith('com.cneicy.'))
|
||||
.map(([name, version]) => ({ name, version: String(version) }));
|
||||
const record = {
|
||||
name: manifest.name,
|
||||
displayName: typeof manifest.displayName === 'string' ? manifest.displayName : '',
|
||||
version: manifest.version,
|
||||
directory: path.posix.basename(module.path),
|
||||
modulePath: module.path,
|
||||
packagePath,
|
||||
manifestPath,
|
||||
repository: module.url,
|
||||
dependencies,
|
||||
nugetPackages: []
|
||||
};
|
||||
upmPackages.push(record);
|
||||
upmByName.set(record.name, record);
|
||||
}
|
||||
|
||||
const nugetPackages = [];
|
||||
const nugetById = new Map();
|
||||
const addProject = record => {
|
||||
if (!record) {
|
||||
return;
|
||||
}
|
||||
if (nugetById.has(record.id)) {
|
||||
throw new Error(`Duplicate NuGet package id: ${record.id}`);
|
||||
}
|
||||
nugetPackages.push(record);
|
||||
nugetById.set(record.id, record);
|
||||
if (record.ownerUpmName) {
|
||||
upmByName.get(record.ownerUpmName).nugetPackages.push(record);
|
||||
}
|
||||
};
|
||||
|
||||
for (const upmPackage of upmPackages) {
|
||||
const ownerModule = upmModules.find(module => module.path === upmPackage.modulePath);
|
||||
for (const area of ['DotNet~', 'Godot~']) {
|
||||
const areaPath = path.join(upmPackage.packagePath, area);
|
||||
for (const projectPath of walkFiles(areaPath, candidate => candidate.toLowerCase().endsWith('.csproj'))) {
|
||||
addProject(readProject(projectPath, ownerModule, upmPackage.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const module of modules.filter(candidate => !declaredPaths.has(candidate.path.toLowerCase()))) {
|
||||
const moduleRoot = path.join(workspaceRoot, module.path);
|
||||
for (const projectPath of walkFiles(moduleRoot, candidate => candidate.toLowerCase().endsWith('.csproj'))) {
|
||||
addProject(readProject(projectPath, module, null));
|
||||
}
|
||||
}
|
||||
|
||||
for (const upmPackage of upmPackages) {
|
||||
const coupled = upmPackage.nugetPackages.filter(project => project.coupledToUpm);
|
||||
if (coupled.length > 1) {
|
||||
throw new Error(`${upmPackage.directory} has more than one directly coupled DotNet~ project.`);
|
||||
}
|
||||
}
|
||||
|
||||
const installer = upmByName.get(installerPackageName);
|
||||
if (!installer) {
|
||||
throw new Error(`Installer package was not found: ${installerPackageName}`);
|
||||
}
|
||||
const installerUpmCatalogPath = path.join(installer.packagePath, 'Editor', 'ShrinkSdkPackageCatalog.cs');
|
||||
const installerNugetCatalogPath = path.join(installer.packagePath, 'Godot~', 'addons', 'shrinksdk', 'ShrinkProjectPackageEditor.cs');
|
||||
|
||||
return {
|
||||
modules,
|
||||
upmPackages: upmPackages.sort((left, right) => left.name.localeCompare(right.name)),
|
||||
upmByName,
|
||||
nugetPackages: nugetPackages.sort((left, right) => left.id.localeCompare(right.id)),
|
||||
nugetById,
|
||||
installer,
|
||||
installerUpmCatalogPath,
|
||||
installerNugetCatalogPath,
|
||||
designPath: path.join(workspaceRoot, 'DESIGN.md')
|
||||
};
|
||||
}
|
||||
|
||||
function parseVersion(value) {
|
||||
const match = value.match(/^(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?(?:\+[0-9A-Za-z.-]+)?$/);
|
||||
if (!match) {
|
||||
throw new Error(`Cannot parse semantic version: ${value}`);
|
||||
}
|
||||
return { major: Number(match[1]), minor: Number(match[2]), patch: Number(match[3]), prerelease: match[4] ?? null };
|
||||
}
|
||||
|
||||
function compareVersions(leftValue, rightValue) {
|
||||
const left = parseVersion(leftValue);
|
||||
const right = parseVersion(rightValue);
|
||||
for (const key of ['major', 'minor', 'patch']) {
|
||||
if (left[key] !== right[key]) {
|
||||
return left[key] < right[key] ? -1 : 1;
|
||||
}
|
||||
}
|
||||
if (left.prerelease === right.prerelease) {
|
||||
return 0;
|
||||
}
|
||||
if (left.prerelease === null) {
|
||||
return 1;
|
||||
}
|
||||
if (right.prerelease === null) {
|
||||
return -1;
|
||||
}
|
||||
const leftParts = left.prerelease.split('.');
|
||||
const rightParts = right.prerelease.split('.');
|
||||
const length = Math.max(leftParts.length, rightParts.length);
|
||||
for (let index = 0; index < length; index += 1) {
|
||||
if (leftParts[index] === undefined) return -1;
|
||||
if (rightParts[index] === undefined) return 1;
|
||||
if (leftParts[index] === rightParts[index]) continue;
|
||||
const leftNumeric = /^[0-9]+$/.test(leftParts[index]);
|
||||
const rightNumeric = /^[0-9]+$/.test(rightParts[index]);
|
||||
if (leftNumeric && rightNumeric) return Number(leftParts[index]) < Number(rightParts[index]) ? -1 : 1;
|
||||
if (leftNumeric !== rightNumeric) return leftNumeric ? -1 : 1;
|
||||
return leftParts[index].localeCompare(rightParts[index]);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
function bumpVersion(value, kind) {
|
||||
const parsed = parseVersion(value);
|
||||
if (parsed.prerelease) {
|
||||
throw new Error(`Automatic ${kind} bump requires a stable version: ${value}`);
|
||||
}
|
||||
if (kind === 'major') return `${parsed.major + 1}.0.0`;
|
||||
if (kind === 'minor') return `${parsed.major}.${parsed.minor + 1}.0`;
|
||||
return `${parsed.major}.${parsed.minor}.${parsed.patch + 1}`;
|
||||
}
|
||||
|
||||
function parseUpmCatalog(model) {
|
||||
const text = fs.readFileSync(model.installerUpmCatalogPath, 'utf8');
|
||||
const entries = new Map();
|
||||
const pattern = new RegExp(`"(com\\.cneicy\\.[^"]+)"\\s*,\\s*"(${semanticVersionPattern})"\\s*,\\s*ShrinkSdkPackageLayer`, 'g');
|
||||
for (const match of text.matchAll(pattern)) {
|
||||
if (entries.has(match[1])) throw new Error(`Duplicate Installer UPM catalog entry: ${match[1]}`);
|
||||
entries.set(match[1], match[2]);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
function parseNugetCatalog(model) {
|
||||
const text = fs.readFileSync(model.installerNugetCatalogPath, 'utf8');
|
||||
const entries = new Map();
|
||||
const pattern = new RegExp(`\\["(ShrinkSDK\\.[^"]+)"\\]\\s*=\\s*"(${semanticVersionPattern})"`, 'g');
|
||||
for (const match of text.matchAll(pattern)) {
|
||||
if (entries.has(match[1])) throw new Error(`Duplicate Installer NuGet catalog entry: ${match[1]}`);
|
||||
entries.set(match[1], match[2]);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
function parseDesignVersions(model) {
|
||||
const text = fs.readFileSync(model.designPath, 'utf8');
|
||||
const entries = new Map();
|
||||
const pattern = new RegExp('^\\|\\s*`(com\\.cneicy\\.[^`]+)`\\s*\\|\\s*(' + semanticVersionPattern + ')\\s*\\|', 'gm');
|
||||
for (const match of text.matchAll(pattern)) {
|
||||
if (entries.has(match[1])) throw new Error(`Duplicate DESIGN.md package row: ${match[1]}`);
|
||||
entries.set(match[1], match[2]);
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
function finalUpmVersion(record, upmPlan = new Map()) {
|
||||
return upmPlan.get(record.name) ?? record.version;
|
||||
}
|
||||
|
||||
function finalNugetVersion(record, nugetPlan = new Map()) {
|
||||
return nugetPlan.get(record.id) ?? record.version;
|
||||
}
|
||||
|
||||
function generatePackageCatalog(model, upmPlan = new Map(), nugetPlan = new Map()) {
|
||||
const unityPackages = model.upmPackages.map(record => {
|
||||
const entry = {
|
||||
directory: record.directory,
|
||||
name: record.name,
|
||||
version: finalUpmVersion(record, upmPlan),
|
||||
repository: record.repository
|
||||
};
|
||||
if (record.nugetPackages.length > 0) {
|
||||
entry.nugetPackages = record.nugetPackages
|
||||
.map(project => ({ id: project.id, version: finalNugetVersion(project, nugetPlan), project: project.project }))
|
||||
.sort((left, right) => left.id.localeCompare(right.id));
|
||||
}
|
||||
return entry;
|
||||
});
|
||||
const standaloneNugetPackages = model.nugetPackages
|
||||
.filter(record => !record.ownerUpmName)
|
||||
.map(record => ({
|
||||
id: record.id,
|
||||
version: finalNugetVersion(record, nugetPlan),
|
||||
project: record.project,
|
||||
repository: record.repository
|
||||
}));
|
||||
return `${JSON.stringify({ schemaVersion: 1, unityPackages, standaloneNugetPackages }, null, 2)}\n`;
|
||||
}
|
||||
|
||||
function collectValidationErrors(model) {
|
||||
const errors = [];
|
||||
const upmCatalog = parseUpmCatalog(model);
|
||||
const nugetCatalog = parseNugetCatalog(model);
|
||||
const designVersions = parseDesignVersions(model);
|
||||
|
||||
for (const record of model.upmPackages) {
|
||||
for (const dependency of record.dependencies) {
|
||||
const target = model.upmByName.get(dependency.name);
|
||||
if (!target) continue;
|
||||
if (dependency.version !== target.version) {
|
||||
errors.push(`${record.name} requires ${dependency.name} ${dependency.version}, Workspace has ${target.version}`);
|
||||
}
|
||||
const canDependOnIntegration = record.name.includes('-integration-') || record.name.includes('-starter-');
|
||||
if (dependency.name.includes('-integration-') && !canDependOnIntegration) {
|
||||
errors.push(`${record.name} must not depend on integration package ${dependency.name}`);
|
||||
}
|
||||
}
|
||||
|
||||
const coupled = record.nugetPackages.filter(project => project.coupledToUpm);
|
||||
for (const project of coupled) {
|
||||
if (project.version !== record.version) {
|
||||
errors.push(`${project.project} version ${project.version} differs from ${record.name} ${record.version}`);
|
||||
}
|
||||
}
|
||||
|
||||
const designVersion = designVersions.get(record.name);
|
||||
if (!designVersion) {
|
||||
errors.push(`DESIGN.md is missing package ${record.name}`);
|
||||
} else if (designVersion !== record.version) {
|
||||
errors.push(`DESIGN.md lists ${record.name} ${designVersion}, Workspace has ${record.version}`);
|
||||
}
|
||||
}
|
||||
|
||||
const expectedCatalogNames = new Set(model.upmPackages
|
||||
.filter(record => record.name !== installerPackageName)
|
||||
.map(record => record.name));
|
||||
for (const name of expectedCatalogNames) {
|
||||
const record = model.upmByName.get(name);
|
||||
if (!upmCatalog.has(name)) {
|
||||
errors.push(`Installer UPM catalog is missing ${name}`);
|
||||
} else if (upmCatalog.get(name) !== record.version) {
|
||||
errors.push(`Installer UPM catalog lists ${name} ${upmCatalog.get(name)}, Workspace has ${record.version}`);
|
||||
}
|
||||
}
|
||||
for (const name of upmCatalog.keys()) {
|
||||
if (!expectedCatalogNames.has(name)) errors.push(`Installer UPM catalog has unknown package ${name}`);
|
||||
}
|
||||
|
||||
for (const [id, version] of nugetCatalog) {
|
||||
const record = model.nugetById.get(id);
|
||||
if (!record) {
|
||||
errors.push(`Installer NuGet catalog has unknown package ${id}`);
|
||||
} else if (version !== record.version) {
|
||||
errors.push(`Installer NuGet catalog lists ${id} ${version}, project has ${record.version}`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const project of model.nugetPackages) {
|
||||
for (const reference of project.references) {
|
||||
const target = model.nugetById.get(reference.id);
|
||||
if (target && reference.version !== target.version) {
|
||||
errors.push(`${project.project} references ${reference.id} ${reference.version}, Workspace has ${target.version}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const dependencies = new Map(model.upmPackages.map(record => [
|
||||
record.name,
|
||||
new Set(record.dependencies.filter(dependency => model.upmByName.has(dependency.name)).map(dependency => dependency.name))
|
||||
]));
|
||||
const resolved = new Set();
|
||||
let progress = true;
|
||||
while (progress) {
|
||||
progress = false;
|
||||
for (const [name, values] of dependencies) {
|
||||
if (!resolved.has(name) && [...values].every(dependency => resolved.has(dependency))) {
|
||||
resolved.add(name);
|
||||
progress = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (resolved.size !== model.upmPackages.length) {
|
||||
const blocked = [...dependencies]
|
||||
.filter(([name]) => !resolved.has(name))
|
||||
.map(([name, values]) => `${name} -> ${[...values].filter(value => !resolved.has(value)).join(', ')}`);
|
||||
errors.push(`Circular UPM dependencies: ${blocked.join('; ')}`);
|
||||
}
|
||||
|
||||
const expectedCatalog = generatePackageCatalog(model);
|
||||
if (!fs.existsSync(packageCatalogPath)) {
|
||||
errors.push(`Generated package catalog is missing: ${relativeToWorkspace(packageCatalogPath)}`);
|
||||
} else {
|
||||
const actualCatalog = fs.readFileSync(packageCatalogPath, 'utf8').replaceAll('\r\n', '\n');
|
||||
if (actualCatalog !== expectedCatalog) {
|
||||
errors.push(`${relativeToWorkspace(packageCatalogPath)} is out of date`);
|
||||
}
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
function resolveTarget(model, requested) {
|
||||
const key = requested.toLowerCase();
|
||||
const upmMatches = model.upmPackages.filter(record =>
|
||||
[record.name, record.directory, record.displayName].some(value => value && value.toLowerCase() === key));
|
||||
const nugetMatches = model.nugetPackages.filter(record => record.id.toLowerCase() === key);
|
||||
const matches = [...upmMatches.map(record => ({ kind: 'upm', record })), ...nugetMatches.map(record => ({ kind: 'nuget', record }))];
|
||||
if (matches.length === 0) {
|
||||
throw new Error(`Package was not found: ${requested}`);
|
||||
}
|
||||
if (matches.length > 1) {
|
||||
throw new Error(`Package name is ambiguous: ${requested}`);
|
||||
}
|
||||
return matches[0];
|
||||
}
|
||||
|
||||
function createPlan(model, options) {
|
||||
const upmPlan = new Map();
|
||||
const nugetPlan = new Map();
|
||||
const reasons = new Map();
|
||||
const reasonKey = (kind, name) => `${kind}:${name}`;
|
||||
const addReason = (kind, name, reason) => {
|
||||
const key = reasonKey(kind, name);
|
||||
const values = reasons.get(key) ?? [];
|
||||
if (!values.includes(reason)) values.push(reason);
|
||||
reasons.set(key, values);
|
||||
};
|
||||
const setUpm = (record, version, reason) => {
|
||||
const existing = upmPlan.get(record.name);
|
||||
if (existing && existing !== version) throw new Error(`Conflicting versions planned for ${record.name}: ${existing} and ${version}`);
|
||||
addReason('upm', record.name, reason);
|
||||
if (existing) return false;
|
||||
upmPlan.set(record.name, version);
|
||||
return true;
|
||||
};
|
||||
const setNuget = (record, version, reason) => {
|
||||
const existing = nugetPlan.get(record.id);
|
||||
if (existing && existing !== version) throw new Error(`Conflicting versions planned for ${record.id}: ${existing} and ${version}`);
|
||||
addReason('nuget', record.id, reason);
|
||||
if (existing) return false;
|
||||
nugetPlan.set(record.id, version);
|
||||
return true;
|
||||
};
|
||||
const ensureUpmPatch = (record, reason) => setUpm(record, bumpVersion(record.version, 'patch'), reason);
|
||||
const ensureNugetPatch = (record, reason) => {
|
||||
if (record.coupledToUpm) return ensureUpmPatch(model.upmByName.get(record.ownerUpmName), reason);
|
||||
const changed = setNuget(record, bumpVersion(record.version, 'patch'), reason);
|
||||
if (record.ownerUpmName) ensureUpmPatch(model.upmByName.get(record.ownerUpmName), `${record.id} content changed`);
|
||||
return changed;
|
||||
};
|
||||
|
||||
const target = resolveTarget(model, options.package);
|
||||
const currentVersion = target.record.version;
|
||||
const requestedVersion = options.version ?? bumpVersion(currentVersion, options.bump);
|
||||
if (compareVersions(requestedVersion, currentVersion) <= 0) {
|
||||
throw new Error(`Requested version must be newer than ${currentVersion}: ${requestedVersion}`);
|
||||
}
|
||||
if (target.kind === 'upm') {
|
||||
setUpm(target.record, requestedVersion, 'requested update');
|
||||
} else if (target.record.coupledToUpm) {
|
||||
setUpm(model.upmByName.get(target.record.ownerUpmName), requestedVersion, `requested through ${target.record.id}`);
|
||||
} else {
|
||||
setNuget(target.record, requestedVersion, 'requested update');
|
||||
if (target.record.ownerUpmName) {
|
||||
ensureUpmPatch(model.upmByName.get(target.record.ownerUpmName), `${target.record.id} content changed`);
|
||||
}
|
||||
}
|
||||
|
||||
for (const record of model.upmPackages) {
|
||||
for (const dependency of record.dependencies) {
|
||||
const targetRecord = model.upmByName.get(dependency.name);
|
||||
if (targetRecord && dependency.version !== targetRecord.version) {
|
||||
ensureUpmPatch(record, `repair ${dependency.name} dependency`);
|
||||
}
|
||||
}
|
||||
for (const project of record.nugetPackages.filter(candidate => candidate.coupledToUpm)) {
|
||||
if (project.version !== record.version) ensureUpmPatch(record, `repair ${project.id} version`);
|
||||
}
|
||||
}
|
||||
for (const project of model.nugetPackages) {
|
||||
for (const reference of project.references) {
|
||||
const targetRecord = model.nugetById.get(reference.id);
|
||||
if (targetRecord && reference.version !== targetRecord.version) {
|
||||
ensureNugetPatch(project, `repair ${reference.id} reference`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const upmCatalog = parseUpmCatalog(model);
|
||||
const nugetCatalog = parseNugetCatalog(model);
|
||||
let changed = true;
|
||||
while (changed) {
|
||||
changed = false;
|
||||
|
||||
for (const record of model.upmPackages) {
|
||||
if (!upmPlan.has(record.name)) continue;
|
||||
for (const project of record.nugetPackages.filter(candidate => candidate.coupledToUpm)) {
|
||||
changed = setNuget(project, upmPlan.get(record.name), `coupled to ${record.name}`) || changed;
|
||||
}
|
||||
}
|
||||
for (const project of model.nugetPackages.filter(candidate => candidate.coupledToUpm && nugetPlan.has(candidate.id))) {
|
||||
changed = setUpm(model.upmByName.get(project.ownerUpmName), nugetPlan.get(project.id), `coupled to ${project.id}`) || changed;
|
||||
}
|
||||
|
||||
for (const record of model.upmPackages) {
|
||||
for (const dependency of record.dependencies) {
|
||||
const targetRecord = model.upmByName.get(dependency.name);
|
||||
if (!targetRecord) continue;
|
||||
const targetVersion = finalUpmVersion(targetRecord, upmPlan);
|
||||
if (dependency.version !== targetVersion) {
|
||||
changed = ensureUpmPatch(record, `${dependency.name} becomes ${targetVersion}`) || changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const project of model.nugetPackages) {
|
||||
for (const reference of project.references) {
|
||||
const targetRecord = model.nugetById.get(reference.id);
|
||||
if (!targetRecord) continue;
|
||||
const targetVersion = finalNugetVersion(targetRecord, nugetPlan);
|
||||
if (reference.version !== targetVersion) {
|
||||
changed = ensureNugetPatch(project, `${reference.id} becomes ${targetVersion}`) || changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const project of model.nugetPackages.filter(candidate => nugetPlan.has(candidate.id) && candidate.ownerUpmName && !candidate.coupledToUpm)) {
|
||||
changed = ensureUpmPatch(model.upmByName.get(project.ownerUpmName), `${project.id} content changed`) || changed;
|
||||
}
|
||||
|
||||
for (const record of model.upmPackages.filter(candidate => candidate.name !== installerPackageName)) {
|
||||
if (upmCatalog.get(record.name) !== finalUpmVersion(record, upmPlan)) {
|
||||
changed = ensureUpmPatch(model.installer, `${record.name} catalog changed`) || changed;
|
||||
}
|
||||
}
|
||||
for (const [id, catalogVersion] of nugetCatalog) {
|
||||
const project = model.nugetById.get(id);
|
||||
if (project && catalogVersion !== finalNugetVersion(project, nugetPlan)) {
|
||||
changed = ensureUpmPatch(model.installer, `${id} catalog changed`) || changed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { upmPlan, nugetPlan, reasons };
|
||||
}
|
||||
|
||||
function replaceSingle(text, pattern, replacer, description) {
|
||||
const countPattern = new RegExp(pattern.source, pattern.flags.includes('g') ? pattern.flags : `${pattern.flags}g`);
|
||||
const matches = [...text.matchAll(countPattern)];
|
||||
if (matches.length !== 1) {
|
||||
throw new Error(`${description}: expected one match, found ${matches.length}`);
|
||||
}
|
||||
return text.replace(pattern, replacer);
|
||||
}
|
||||
|
||||
function replaceManifestVersion(text, version, manifestPath) {
|
||||
return replaceSingle(
|
||||
text,
|
||||
/^(\s*"version"\s*:\s*")([^"]+)(")/m,
|
||||
`$1${version}$3`,
|
||||
`${relativeToWorkspace(manifestPath)} top-level version`
|
||||
);
|
||||
}
|
||||
|
||||
function replaceJsonValue(text, name, version, filePath) {
|
||||
const pattern = new RegExp(`("${escapeRegularExpression(name)}"\\s*:\\s*")([^"]+)(")`, 'g');
|
||||
return replaceSingle(text, pattern, `$1${version}$3`, `${relativeToWorkspace(filePath)} ${name}`);
|
||||
}
|
||||
|
||||
function replaceProjectVersion(text, version, projectPath) {
|
||||
return replaceSingle(
|
||||
text,
|
||||
/(<Version>\s*)([^<]+?)(\s*<\/Version>)/i,
|
||||
`$1${version}$3`,
|
||||
`${relativeToWorkspace(projectPath)} Version`
|
||||
);
|
||||
}
|
||||
|
||||
function replacePackageReferenceVersion(text, id, version, projectPath) {
|
||||
const elementPattern = /<PackageReference\b[\s\S]*?(?:\/>|<\/PackageReference>)/gi;
|
||||
const elements = [...text.matchAll(elementPattern)].filter(match => xmlAttribute(match[0], 'Include') === id);
|
||||
if (elements.length !== 1) {
|
||||
throw new Error(`${relativeToWorkspace(projectPath)} ${id} reference: expected one match, found ${elements.length}`);
|
||||
}
|
||||
const original = elements[0][0];
|
||||
let replacement;
|
||||
if (/\bVersion\s*=\s*"[^"]+"/i.test(original)) {
|
||||
replacement = original.replace(/(\bVersion\s*=\s*")([^"]+)(")/i, `$1${version}$3`);
|
||||
} else {
|
||||
replacement = replaceSingle(original, /(<Version>\s*)([^<]+?)(\s*<\/Version>)/i, `$1${version}$3`, `${id} nested Version`);
|
||||
}
|
||||
return `${text.slice(0, elements[0].index)}${replacement}${text.slice(elements[0].index + original.length)}`;
|
||||
}
|
||||
|
||||
function buildUpdatedContents(model, plan) {
|
||||
const contents = new Map();
|
||||
const read = filePath => contents.get(filePath) ?? fs.readFileSync(filePath, 'utf8');
|
||||
const write = (filePath, text) => contents.set(filePath, text);
|
||||
|
||||
for (const record of model.upmPackages.filter(candidate => plan.upmPlan.has(candidate.name))) {
|
||||
let text = read(record.manifestPath);
|
||||
text = replaceManifestVersion(text, plan.upmPlan.get(record.name), record.manifestPath);
|
||||
for (const dependency of record.dependencies) {
|
||||
const target = model.upmByName.get(dependency.name);
|
||||
if (!target) continue;
|
||||
const targetVersion = finalUpmVersion(target, plan.upmPlan);
|
||||
if (dependency.version !== targetVersion) {
|
||||
text = replaceJsonValue(text, dependency.name, targetVersion, record.manifestPath);
|
||||
}
|
||||
}
|
||||
write(record.manifestPath, text);
|
||||
}
|
||||
|
||||
for (const project of model.nugetPackages.filter(candidate => plan.nugetPlan.has(candidate.id))) {
|
||||
let text = read(project.path);
|
||||
text = replaceProjectVersion(text, plan.nugetPlan.get(project.id), project.path);
|
||||
for (const reference of project.references) {
|
||||
const target = model.nugetById.get(reference.id);
|
||||
if (!target) continue;
|
||||
const targetVersion = finalNugetVersion(target, plan.nugetPlan);
|
||||
if (reference.version !== targetVersion) {
|
||||
text = replacePackageReferenceVersion(text, reference.id, targetVersion, project.path);
|
||||
}
|
||||
}
|
||||
write(project.path, text);
|
||||
}
|
||||
|
||||
let upmCatalogText = read(model.installerUpmCatalogPath);
|
||||
const upmCatalog = parseUpmCatalog(model);
|
||||
for (const record of model.upmPackages.filter(candidate => candidate.name !== installerPackageName)) {
|
||||
const version = finalUpmVersion(record, plan.upmPlan);
|
||||
if (upmCatalog.get(record.name) !== version) {
|
||||
const pattern = new RegExp(`("${escapeRegularExpression(record.name)}"\\s*,\\s*")([^"]+)(")`, 'g');
|
||||
upmCatalogText = replaceSingle(upmCatalogText, pattern, `$1${version}$3`, `Installer UPM catalog ${record.name}`);
|
||||
}
|
||||
}
|
||||
write(model.installerUpmCatalogPath, upmCatalogText);
|
||||
|
||||
let nugetCatalogText = read(model.installerNugetCatalogPath);
|
||||
const nugetCatalog = parseNugetCatalog(model);
|
||||
for (const [id, currentVersion] of nugetCatalog) {
|
||||
const project = model.nugetById.get(id);
|
||||
if (!project) continue;
|
||||
const version = finalNugetVersion(project, plan.nugetPlan);
|
||||
if (currentVersion !== version) {
|
||||
const pattern = new RegExp(`(\\["${escapeRegularExpression(id)}"\\]\\s*=\\s*")([^"]+)(")`, 'g');
|
||||
nugetCatalogText = replaceSingle(nugetCatalogText, pattern, `$1${version}$3`, `Installer NuGet catalog ${id}`);
|
||||
}
|
||||
}
|
||||
write(model.installerNugetCatalogPath, nugetCatalogText);
|
||||
|
||||
let designText = read(model.designPath);
|
||||
const designVersions = parseDesignVersions(model);
|
||||
for (const record of model.upmPackages) {
|
||||
const version = finalUpmVersion(record, plan.upmPlan);
|
||||
if (!designVersions.has(record.name)) {
|
||||
throw new Error(`DESIGN.md is missing package ${record.name}`);
|
||||
}
|
||||
if (designVersions.get(record.name) !== version) {
|
||||
const pattern = new RegExp('^(\\|\\s*`' + escapeRegularExpression(record.name) + '`\\s*\\|\\s*)[^|]+?(\\s*\\|)', 'm');
|
||||
designText = replaceSingle(designText, pattern, `$1${version}$2`, `DESIGN.md ${record.name}`);
|
||||
}
|
||||
}
|
||||
write(model.designPath, designText);
|
||||
write(packageCatalogPath, generatePackageCatalog(model, plan.upmPlan, plan.nugetPlan));
|
||||
|
||||
for (const [filePath, text] of [...contents]) {
|
||||
if (fs.existsSync(filePath) && fs.readFileSync(filePath, 'utf8') === text) {
|
||||
contents.delete(filePath);
|
||||
}
|
||||
}
|
||||
return contents;
|
||||
}
|
||||
|
||||
function printPlan(model, plan, contents, dryRun) {
|
||||
console.log(dryRun ? 'Dry-run version plan:' : 'Applied version plan:');
|
||||
for (const record of model.upmPackages.filter(candidate => plan.upmPlan.has(candidate.name))) {
|
||||
const reasons = plan.reasons.get(`upm:${record.name}`) ?? [];
|
||||
console.log(` UPM ${record.name}: ${record.version} -> ${plan.upmPlan.get(record.name)} (${reasons.join('; ')})`);
|
||||
}
|
||||
for (const record of model.nugetPackages.filter(candidate => plan.nugetPlan.has(candidate.id))) {
|
||||
const reasons = plan.reasons.get(`nuget:${record.id}`) ?? [];
|
||||
console.log(` NuGet ${record.id}: ${record.version} -> ${plan.nugetPlan.get(record.id)} (${reasons.join('; ')})`);
|
||||
}
|
||||
console.log('Files:');
|
||||
for (const filePath of [...contents.keys()].sort((left, right) => left.localeCompare(right))) {
|
||||
console.log(` ${relativeToWorkspace(filePath)}`);
|
||||
}
|
||||
}
|
||||
|
||||
function applyContents(contents) {
|
||||
const originals = new Map();
|
||||
try {
|
||||
for (const [filePath, text] of contents) {
|
||||
originals.set(filePath, fs.existsSync(filePath) ? fs.readFileSync(filePath) : null);
|
||||
fs.mkdirSync(path.dirname(filePath), { recursive: true });
|
||||
fs.writeFileSync(filePath, text, 'utf8');
|
||||
}
|
||||
const refreshed = buildModel();
|
||||
const errors = collectValidationErrors(refreshed);
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`Post-update validation failed:\n${errors.map(error => ` - ${error}`).join('\n')}`);
|
||||
}
|
||||
} catch (error) {
|
||||
for (const [filePath, original] of originals) {
|
||||
if (original === null) fs.rmSync(filePath, { force: true });
|
||||
else fs.writeFileSync(filePath, original);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
let options;
|
||||
try {
|
||||
options = parseArguments(process.argv.slice(2));
|
||||
} catch (error) {
|
||||
usage(error.message);
|
||||
return;
|
||||
}
|
||||
if (options.help) {
|
||||
usage();
|
||||
process.exitCode = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const model = buildModel();
|
||||
if (options.check) {
|
||||
const errors = collectValidationErrors(model);
|
||||
if (errors.length > 0) {
|
||||
throw new Error(`ShrinkSDK version validation failed:\n${errors.map(error => ` - ${error}`).join('\n')}`);
|
||||
}
|
||||
console.log(`ShrinkSDK version validation passed: UPM=${model.upmPackages.length}, NuGet=${model.nugetPackages.length}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const plan = createPlan(model, options);
|
||||
const contents = buildUpdatedContents(model, plan);
|
||||
printPlan(model, plan, contents, options.dryRun);
|
||||
if (!options.dryRun) {
|
||||
applyContents(contents);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error.stack ?? error.message);
|
||||
process.exitCode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
main();
|
||||
@@ -5,6 +5,7 @@ workspace_root="${1:-$PWD}"
|
||||
workspace_root="$(cd "$workspace_root" && pwd)"
|
||||
unity_bin="${UNITY_EDITOR_PATH:-$(command -v unity-editor || command -v unity || command -v Unity || true)}"
|
||||
consumer_root="$workspace_root/Temp/PublishedUpmConsumerValidation"
|
||||
published_catalog="$workspace_root/Tools/UpmConsumerValidation/published-upm-versions.json"
|
||||
|
||||
if [[ ! -f "$workspace_root/ProjectSettings/ProjectVersion.txt" ]]; then
|
||||
echo "Workspace ProjectVersion.txt was not found: $workspace_root" >&2
|
||||
@@ -16,6 +17,60 @@ if [[ -z "$unity_bin" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$published_catalog" ]]; then
|
||||
echo "Published package catalog was not found: $published_catalog" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
published_value() {
|
||||
local package_name="$1"
|
||||
local property_name="$2"
|
||||
local value
|
||||
value="$(awk -v package_name="$package_name" -v property_name="$property_name" '
|
||||
index($0, "\"" package_name "\"") {
|
||||
in_package = 1
|
||||
next
|
||||
}
|
||||
in_package && index($0, "\"" property_name "\"") {
|
||||
value = $0
|
||||
sub(/^[^:]*:[[:space:]]*"/, "", value)
|
||||
sub(/".*$/, "", value)
|
||||
print value
|
||||
found = 1
|
||||
exit
|
||||
}
|
||||
in_package && /^[[:space:]]*}/ {
|
||||
exit
|
||||
}
|
||||
END {
|
||||
if (!found) exit 1
|
||||
}
|
||||
' "$published_catalog")" || {
|
||||
echo "Published catalog value is missing: ${package_name}.${property_name}" >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
if [[ -z "$value" ]]; then
|
||||
echo "Published catalog value is empty: ${package_name}.${property_name}" >&2
|
||||
return 1
|
||||
fi
|
||||
if [[ "$property_name" == "version" && ! "$value" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)$ ]]; then
|
||||
echo "Published catalog version is invalid: ${package_name}=${value}" >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
printf '%s' "$value"
|
||||
}
|
||||
|
||||
export SHRINKSDK_PUBLISHED_STARTER_VERSION="$(published_value com.cneicy.shrink-app-starter-basic version)"
|
||||
export SHRINKSDK_PUBLISHED_CONTEXT_APP_VERSION="$(published_value com.cneicy.shrink-context-app-adapter version)"
|
||||
export SHRINKSDK_PUBLISHED_CONTEXT_EVENTBUS_VERSION="$(published_value com.cneicy.shrink-context-eventbus-adapter version)"
|
||||
export SHRINKSDK_PUBLISHED_MOD_VERSION="$(published_value com.cneicy.shrink-mod-framework version)"
|
||||
export SHRINKSDK_PUBLISHED_TUTORIAL_VERSION="$(published_value com.cneicy.shrink-tutorial version)"
|
||||
export SHRINKSDK_PUBLISHED_INSTALLER_VERSION="$(published_value com.cneicy.shrink-installer version)"
|
||||
export SHRINKSDK_PUBLISHED_MOD_REPOSITORY="$(published_value com.cneicy.shrink-mod-framework repository)"
|
||||
export SHRINKSDK_PUBLISHED_INSTALLER_REPOSITORY="$(published_value com.cneicy.shrink-installer repository)"
|
||||
|
||||
case "$consumer_root" in
|
||||
"$workspace_root"/Temp/*) ;;
|
||||
*) echo "Consumer project must stay under the workspace Temp directory." >&2; exit 1 ;;
|
||||
@@ -42,19 +97,28 @@ public static class PublishedUpmConsumerValidator
|
||||
{
|
||||
private const string RegistryUrl = "https://git.crash.work/api/packages/ShrinkSDK/npm/";
|
||||
private const string UniTaskUrl = "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#7c0f199fe0d3fc528024488ccd671e6c7b27745b";
|
||||
private static readonly string StarterVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_STARTER_VERSION");
|
||||
private static readonly string ContextAppVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_CONTEXT_APP_VERSION");
|
||||
private static readonly string ContextEventBusVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_CONTEXT_EVENTBUS_VERSION");
|
||||
private static readonly string ModVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_MOD_VERSION");
|
||||
private static readonly string TutorialVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_TUTORIAL_VERSION");
|
||||
private static readonly string InstallerVersion = RequiredEnvironment("SHRINKSDK_PUBLISHED_INSTALLER_VERSION");
|
||||
private static readonly string ModRepository = RequiredEnvironment("SHRINKSDK_PUBLISHED_MOD_REPOSITORY");
|
||||
private static readonly string InstallerRepository = RequiredEnvironment("SHRINKSDK_PUBLISHED_INSTALLER_REPOSITORY");
|
||||
|
||||
public static void VerifyRegistry()
|
||||
{
|
||||
Run(() =>
|
||||
{
|
||||
VerifyPackage("com.cneicy.shrink-app-starter-basic", "0.2.2", "ShrinkApp.Starter.Basic.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-app-adapter", "0.1.5", "ShrinkContext.AppAdapter.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-eventbus-adapter", "0.1.1", "ShrinkContext.EventBusAdapter.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-mod-framework", "0.2.4", "ShrinkModFramework.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-tutorial", "0.1.3", "ShrinkTutorial.Runtime");
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", "0.2.2");
|
||||
RequireManifestValue("com.cneicy.shrink-context-eventbus-adapter", "0.1.1");
|
||||
RequireManifestValue("com.cneicy.shrink-mod-framework", "0.2.4");
|
||||
RequireManifestValue("com.cneicy.shrink-tutorial", "0.1.3");
|
||||
VerifyPackage("com.cneicy.shrink-app-starter-basic", StarterVersion, "ShrinkApp.Starter.Basic.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-app-adapter", ContextAppVersion, "ShrinkContext.AppAdapter.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-eventbus-adapter", ContextEventBusVersion, "ShrinkContext.EventBusAdapter.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-mod-framework", ModVersion, "ShrinkModFramework.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-tutorial", TutorialVersion, "ShrinkTutorial.Runtime");
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", StarterVersion);
|
||||
RequireManifestValue("com.cneicy.shrink-context-eventbus-adapter", ContextEventBusVersion);
|
||||
RequireManifestValue("com.cneicy.shrink-mod-framework", ModVersion);
|
||||
RequireManifestValue("com.cneicy.shrink-tutorial", TutorialVersion);
|
||||
RequireManifestValue("com.cysharp.unitask", UniTaskUrl);
|
||||
RequireRegistry("com.cneicy", RegistryUrl);
|
||||
});
|
||||
@@ -64,10 +128,10 @@ public static class PublishedUpmConsumerValidator
|
||||
{
|
||||
Run(() =>
|
||||
{
|
||||
VerifyPackage("com.cneicy.shrink-mod-framework", "0.2.4", "ShrinkModFramework.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-mod-framework", ModVersion, "ShrinkModFramework.Runtime");
|
||||
RequireManifestValue(
|
||||
"com.cneicy.shrink-mod-framework",
|
||||
"https://git.crash.work/ShrinkSDK/ShrinkModFramework.git#v0.2.4");
|
||||
ModRepository + "#v" + ModVersion);
|
||||
RequireManifestValue("com.cysharp.unitask", UniTaskUrl);
|
||||
RequireRegistry("com.cneicy", RegistryUrl);
|
||||
});
|
||||
@@ -77,10 +141,10 @@ public static class PublishedUpmConsumerValidator
|
||||
{
|
||||
try
|
||||
{
|
||||
VerifyPackage("com.cneicy.shrink-installer", "0.2.4", "ShrinkInstaller.Editor");
|
||||
VerifyPackage("com.cneicy.shrink-installer", InstallerVersion, "ShrinkInstaller.Editor");
|
||||
RequireManifestValue(
|
||||
"com.cneicy.shrink-installer",
|
||||
"https://git.crash.work/ShrinkSDK/Installer.git#v0.2.4");
|
||||
InstallerRepository + "#v" + InstallerVersion);
|
||||
|
||||
var catalog = FindType("ShrinkSDK.Installer.ShrinkSdkPackageCatalog");
|
||||
var starter = catalog.GetField("StarterBasic", BindingFlags.Static | BindingFlags.NonPublic)
|
||||
@@ -94,7 +158,7 @@ public static class PublishedUpmConsumerValidator
|
||||
roots.SetValue(starter, 0);
|
||||
install.Invoke(null, new object[] { roots });
|
||||
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", "0.2.2");
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", StarterVersion);
|
||||
RequireManifestValue("com.cysharp.unitask", UniTaskUrl);
|
||||
RequireRegistry("com.cneicy", RegistryUrl);
|
||||
RequireRegistry("com.example", "https://registry.npmjs.org/");
|
||||
@@ -110,10 +174,10 @@ public static class PublishedUpmConsumerValidator
|
||||
{
|
||||
Run(() =>
|
||||
{
|
||||
VerifyPackage("com.cneicy.shrink-installer", "0.2.4", "ShrinkInstaller.Editor");
|
||||
VerifyPackage("com.cneicy.shrink-app-starter-basic", "0.2.2", "ShrinkApp.Starter.Basic.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-app-adapter", "0.1.5", "ShrinkContext.AppAdapter.Runtime");
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", "0.2.2");
|
||||
VerifyPackage("com.cneicy.shrink-installer", InstallerVersion, "ShrinkInstaller.Editor");
|
||||
VerifyPackage("com.cneicy.shrink-app-starter-basic", StarterVersion, "ShrinkApp.Starter.Basic.Runtime");
|
||||
VerifyPackage("com.cneicy.shrink-context-app-adapter", ContextAppVersion, "ShrinkContext.AppAdapter.Runtime");
|
||||
RequireManifestValue("com.cneicy.shrink-app-starter-basic", StarterVersion);
|
||||
RequireManifestValue("com.cysharp.unitask", UniTaskUrl);
|
||||
RequireRegistry("com.cneicy", RegistryUrl);
|
||||
RequireRegistry("com.example", "https://registry.npmjs.org/");
|
||||
@@ -133,6 +197,12 @@ public static class PublishedUpmConsumerValidator
|
||||
}
|
||||
}
|
||||
|
||||
private static string RequiredEnvironment(string name)
|
||||
{
|
||||
return Environment.GetEnvironmentVariable(name)
|
||||
?? throw new InvalidOperationException("Required environment variable is missing: " + name);
|
||||
}
|
||||
|
||||
private static void VerifyPackage(string packageName, string version, string assemblyName)
|
||||
{
|
||||
var package = PackageInfo.GetAllRegisteredPackages()
|
||||
@@ -261,7 +331,7 @@ rm -rf "$consumer_root"
|
||||
mkdir -p "$consumer_root"
|
||||
|
||||
registry_project="$(prepare_consumer registry)"
|
||||
write_manifest "$registry_project" '{
|
||||
registry_manifest='{
|
||||
"scopedRegistries": [
|
||||
{
|
||||
"name": "ShrinkSDK",
|
||||
@@ -270,18 +340,23 @@ write_manifest "$registry_project" '{
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"com.cneicy.shrink-app-starter-basic": "0.2.2",
|
||||
"com.cneicy.shrink-context-eventbus-adapter": "0.1.1",
|
||||
"com.cneicy.shrink-mod-framework": "0.2.4",
|
||||
"com.cneicy.shrink-tutorial": "0.1.3",
|
||||
"com.cneicy.shrink-app-starter-basic": "__STARTER_VERSION__",
|
||||
"com.cneicy.shrink-context-eventbus-adapter": "__CONTEXT_EVENTBUS_VERSION__",
|
||||
"com.cneicy.shrink-mod-framework": "__MOD_VERSION__",
|
||||
"com.cneicy.shrink-tutorial": "__TUTORIAL_VERSION__",
|
||||
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#7c0f199fe0d3fc528024488ccd671e6c7b27745b",
|
||||
"com.unity.nuget.newtonsoft-json": "3.2.2"
|
||||
}
|
||||
}'
|
||||
registry_manifest="${registry_manifest//__STARTER_VERSION__/$SHRINKSDK_PUBLISHED_STARTER_VERSION}"
|
||||
registry_manifest="${registry_manifest//__CONTEXT_EVENTBUS_VERSION__/$SHRINKSDK_PUBLISHED_CONTEXT_EVENTBUS_VERSION}"
|
||||
registry_manifest="${registry_manifest//__MOD_VERSION__/$SHRINKSDK_PUBLISHED_MOD_VERSION}"
|
||||
registry_manifest="${registry_manifest//__TUTORIAL_VERSION__/$SHRINKSDK_PUBLISHED_TUTORIAL_VERSION}"
|
||||
write_manifest "$registry_project" "$registry_manifest"
|
||||
run_unity "$registry_project" PublishedUpmConsumerValidator.VerifyRegistry "$registry_project/registry.log" false
|
||||
|
||||
git_project="$(prepare_consumer git-tag)"
|
||||
write_manifest "$git_project" '{
|
||||
git_manifest='{
|
||||
"scopedRegistries": [
|
||||
{
|
||||
"name": "ShrinkSDK",
|
||||
@@ -290,15 +365,18 @@ write_manifest "$git_project" '{
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"com.cneicy.shrink-mod-framework": "https://git.crash.work/ShrinkSDK/ShrinkModFramework.git#v0.2.4",
|
||||
"com.cneicy.shrink-mod-framework": "__MOD_REPOSITORY__#v__MOD_VERSION__",
|
||||
"com.cysharp.unitask": "https://github.com/Cysharp/UniTask.git?path=src/UniTask/Assets/Plugins/UniTask#7c0f199fe0d3fc528024488ccd671e6c7b27745b",
|
||||
"com.unity.nuget.newtonsoft-json": "3.2.2"
|
||||
}
|
||||
}'
|
||||
git_manifest="${git_manifest//__MOD_REPOSITORY__/$SHRINKSDK_PUBLISHED_MOD_REPOSITORY}"
|
||||
git_manifest="${git_manifest//__MOD_VERSION__/$SHRINKSDK_PUBLISHED_MOD_VERSION}"
|
||||
write_manifest "$git_project" "$git_manifest"
|
||||
run_unity "$git_project" PublishedUpmConsumerValidator.VerifyGitTag "$git_project/git-tag.log" false
|
||||
|
||||
installer_project="$(prepare_consumer installer)"
|
||||
write_manifest "$installer_project" '{
|
||||
installer_manifest='{
|
||||
"scopedRegistries": [
|
||||
{
|
||||
"name": "Existing Registry",
|
||||
@@ -307,11 +385,14 @@ write_manifest "$installer_project" '{
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"com.cneicy.shrink-installer": "https://git.crash.work/ShrinkSDK/Installer.git#v0.2.4",
|
||||
"com.cneicy.shrink-installer": "__INSTALLER_REPOSITORY__#v__INSTALLER_VERSION__",
|
||||
"com.unity.nuget.newtonsoft-json": "3.2.2",
|
||||
"com.unity.test-framework": "1.1.33"
|
||||
}
|
||||
}'
|
||||
installer_manifest="${installer_manifest//__INSTALLER_REPOSITORY__/$SHRINKSDK_PUBLISHED_INSTALLER_REPOSITORY}"
|
||||
installer_manifest="${installer_manifest//__INSTALLER_VERSION__/$SHRINKSDK_PUBLISHED_INSTALLER_VERSION}"
|
||||
write_manifest "$installer_project" "$installer_manifest"
|
||||
run_unity "$installer_project" PublishedUpmConsumerValidator.ApplyInstaller "$installer_project/installer-apply.log" false
|
||||
run_unity "$installer_project" PublishedUpmConsumerValidator.VerifyInstallerResult "$installer_project/installer-result.log" false
|
||||
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"schemaVersion": 1,
|
||||
"packages": {
|
||||
"com.cneicy.shrink-app-starter-basic": {
|
||||
"version": "0.3.0",
|
||||
"assembly": "ShrinkApp.Starter.Basic.Runtime"
|
||||
},
|
||||
"com.cneicy.shrink-context-app-adapter": {
|
||||
"version": "0.2.0",
|
||||
"assembly": "ShrinkContext.AppAdapter.Runtime"
|
||||
},
|
||||
"com.cneicy.shrink-context-eventbus-adapter": {
|
||||
"version": "0.2.0",
|
||||
"assembly": "ShrinkContext.EventBusAdapter.Runtime"
|
||||
},
|
||||
"com.cneicy.shrink-mod-framework": {
|
||||
"version": "0.3.0",
|
||||
"assembly": "ShrinkModFramework.Runtime",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/ShrinkModFramework.git"
|
||||
},
|
||||
"com.cneicy.shrink-tutorial": {
|
||||
"version": "0.2.0",
|
||||
"assembly": "ShrinkTutorial.Runtime"
|
||||
},
|
||||
"com.cneicy.shrink-installer": {
|
||||
"version": "0.2.5",
|
||||
"assembly": "ShrinkInstaller.Editor",
|
||||
"repository": "https://git.crash.work/ShrinkSDK/Installer.git"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user