diff --git a/.gitignore b/.gitignore index 72438ca..526f409 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.gitmodules b/.gitmodules index e53d03a..a6da8bc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/Assets/Modules/ShrinkApp.Core b/Assets/Modules/ShrinkApp.Core index a5c5a70..f077a32 160000 --- a/Assets/Modules/ShrinkApp.Core +++ b/Assets/Modules/ShrinkApp.Core @@ -1 +1 @@ -Subproject commit a5c5a700754a317308aedffd6c7576b41f113685 +Subproject commit f077a32e3ee7a379aab4326b1af62cbb1bd66989 diff --git a/Assets/Modules/ShrinkApp.Starter.Basic b/Assets/Modules/ShrinkApp.Starter.Basic index f8906fa..dcbecea 160000 --- a/Assets/Modules/ShrinkApp.Starter.Basic +++ b/Assets/Modules/ShrinkApp.Starter.Basic @@ -1 +1 @@ -Subproject commit f8906faaec430a593656ccc541bb673a54c133d0 +Subproject commit dcbecea0f1db67558a9b218c076da545f3b48811 diff --git a/Assets/Modules/ShrinkCommand b/Assets/Modules/ShrinkCommand index 4ed7a91..9d66781 160000 --- a/Assets/Modules/ShrinkCommand +++ b/Assets/Modules/ShrinkCommand @@ -1 +1 @@ -Subproject commit 4ed7a91c79bdcc0d53155d7410472deef6e3b1dc +Subproject commit 9d66781ddfeb24bc5bee5d2e53dab4c1e72a3507 diff --git a/Assets/Modules/ShrinkCommand.Integration.App b/Assets/Modules/ShrinkCommand.Integration.App index 57246d5..d2642d5 160000 --- a/Assets/Modules/ShrinkCommand.Integration.App +++ b/Assets/Modules/ShrinkCommand.Integration.App @@ -1 +1 @@ -Subproject commit 57246d51949636d5f7e7e19d08676de94d06192f +Subproject commit d2642d56debc5b55d4990fad47d193f4c7da285d diff --git a/Assets/Modules/ShrinkCommand.Integration.EventBus b/Assets/Modules/ShrinkCommand.Integration.EventBus index 53720a3..302acba 160000 --- a/Assets/Modules/ShrinkCommand.Integration.EventBus +++ b/Assets/Modules/ShrinkCommand.Integration.EventBus @@ -1 +1 @@ -Subproject commit 53720a3b717d1978f18582f32a99fa90eb9f75b5 +Subproject commit 302acba9bdc71289b71e51ef43775be32a4c2df4 diff --git a/Assets/Modules/ShrinkCommand.Integration.Network b/Assets/Modules/ShrinkCommand.Integration.Network index bf31561..9f128c0 160000 --- a/Assets/Modules/ShrinkCommand.Integration.Network +++ b/Assets/Modules/ShrinkCommand.Integration.Network @@ -1 +1 @@ -Subproject commit bf315619f080e0949361041900e9ee17251d3d4a +Subproject commit 9f128c0432287bb95f6f249a820938ebef0e1e30 diff --git a/Assets/Modules/ShrinkContext.AppAdapter b/Assets/Modules/ShrinkContext.AppAdapter index 8b3121b..3c08d07 160000 --- a/Assets/Modules/ShrinkContext.AppAdapter +++ b/Assets/Modules/ShrinkContext.AppAdapter @@ -1 +1 @@ -Subproject commit 8b3121bc21798ff39503366653e57f534e40c6ca +Subproject commit 3c08d076c5cfcde0e3cfcb8bd1b4e9685a65549b diff --git a/Assets/Modules/ShrinkContext.Core b/Assets/Modules/ShrinkContext.Core index a4c78ea..63fb328 160000 --- a/Assets/Modules/ShrinkContext.Core +++ b/Assets/Modules/ShrinkContext.Core @@ -1 +1 @@ -Subproject commit a4c78ea7a71470bcb5234b4b4cbfe705a3d18128 +Subproject commit 63fb328bedc9d76a40557dad1aeb511325424f33 diff --git a/Assets/Modules/ShrinkContext.EventBusAdapter b/Assets/Modules/ShrinkContext.EventBusAdapter index 088a8f9..06ce2b7 160000 --- a/Assets/Modules/ShrinkContext.EventBusAdapter +++ b/Assets/Modules/ShrinkContext.EventBusAdapter @@ -1 +1 @@ -Subproject commit 088a8f96063d43586f44a421b2a1a1d67a0c43f2 +Subproject commit 06ce2b718869de440225c156971bcc3ae17208c0 diff --git a/Assets/Modules/ShrinkDataSaver b/Assets/Modules/ShrinkDataSaver index 0030f5b..422cf9a 160000 --- a/Assets/Modules/ShrinkDataSaver +++ b/Assets/Modules/ShrinkDataSaver @@ -1 +1 @@ -Subproject commit 0030f5b794dc2f6730f193579acac861a852c5d7 +Subproject commit 422cf9a48b758ee2e5e6ac70a792a3ce59adae0e diff --git a/Assets/Modules/ShrinkDataSaver.Integration.App b/Assets/Modules/ShrinkDataSaver.Integration.App index e7da032..b202507 160000 --- a/Assets/Modules/ShrinkDataSaver.Integration.App +++ b/Assets/Modules/ShrinkDataSaver.Integration.App @@ -1 +1 @@ -Subproject commit e7da03273edf1af4eb8e2f5c883541c28f5ee61d +Subproject commit b2025072fcaac01e2022606292282dbd5d0ebf44 diff --git a/Assets/Modules/ShrinkDataSaver.Integration.EventBus b/Assets/Modules/ShrinkDataSaver.Integration.EventBus index 599b8e3..663e46f 160000 --- a/Assets/Modules/ShrinkDataSaver.Integration.EventBus +++ b/Assets/Modules/ShrinkDataSaver.Integration.EventBus @@ -1 +1 @@ -Subproject commit 599b8e34c6975cff4807cd182128205940d03299 +Subproject commit 663e46f2d7f2dd198c6779f7869704947dd0374b diff --git a/Assets/Modules/ShrinkEventBus b/Assets/Modules/ShrinkEventBus index 8aa4c79..64ce75a 160000 --- a/Assets/Modules/ShrinkEventBus +++ b/Assets/Modules/ShrinkEventBus @@ -1 +1 @@ -Subproject commit 8aa4c796043651fa6641804d6ae620d954e2610d +Subproject commit 64ce75a3411ed99869b1445cc2b1c9a1f568e302 diff --git a/Assets/Modules/ShrinkInstaller b/Assets/Modules/ShrinkInstaller index e97692e..b505c5e 160000 --- a/Assets/Modules/ShrinkInstaller +++ b/Assets/Modules/ShrinkInstaller @@ -1 +1 @@ -Subproject commit e97692e7683cfaaaaa2486e49cc0b0a0bf8edc0e +Subproject commit b505c5ebb1602a66f6a3a654981dc4a0cb16e9de diff --git a/Assets/Modules/ShrinkModFramework b/Assets/Modules/ShrinkModFramework index fea6ec5..2c48d24 160000 --- a/Assets/Modules/ShrinkModFramework +++ b/Assets/Modules/ShrinkModFramework @@ -1 +1 @@ -Subproject commit fea6ec56fcef6cd72d67ba3948deca384c5c8145 +Subproject commit 2c48d247b892fbe65e3daf28b1dd9a3302c5b91f diff --git a/Assets/Modules/ShrinkNetwork b/Assets/Modules/ShrinkNetwork index 26241cb..f573c8e 160000 --- a/Assets/Modules/ShrinkNetwork +++ b/Assets/Modules/ShrinkNetwork @@ -1 +1 @@ -Subproject commit 26241cb5347a33d30da4dce246eff29b9778fe4f +Subproject commit f573c8e742a76c94f98edf610a97eba5d9cbd44b diff --git a/Assets/Modules/ShrinkNetwork.Integration.App b/Assets/Modules/ShrinkNetwork.Integration.App index 2cd552e..a970bb4 160000 --- a/Assets/Modules/ShrinkNetwork.Integration.App +++ b/Assets/Modules/ShrinkNetwork.Integration.App @@ -1 +1 @@ -Subproject commit 2cd552ef2571aebe3f7cd8ee5c2af8316aa9c66e +Subproject commit a970bb475a9af418ad20a35dfcf0c2f63c8741cc diff --git a/Assets/Modules/ShrinkNetwork.Integration.EventBus b/Assets/Modules/ShrinkNetwork.Integration.EventBus index eb7fa55..3a1dc91 160000 --- a/Assets/Modules/ShrinkNetwork.Integration.EventBus +++ b/Assets/Modules/ShrinkNetwork.Integration.EventBus @@ -1 +1 @@ -Subproject commit eb7fa55656ac954cd3ab528aac384a4a12261b53 +Subproject commit 3a1dc91c85f0a35fe92ddb6ce34ce809002ec1d9 diff --git a/Assets/Modules/ShrinkRuntime.Abstractions b/Assets/Modules/ShrinkRuntime.Abstractions new file mode 160000 index 0000000..ce8efad --- /dev/null +++ b/Assets/Modules/ShrinkRuntime.Abstractions @@ -0,0 +1 @@ +Subproject commit ce8efad5b38d277615588da322bac9cef45f7b18 diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime.meta b/Assets/Modules/ShrinkRuntime.Abstractions/Runtime.meta deleted file mode 100644 index a4cfb82..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: fdcff332146fc1d439fc0c82285637da -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef b/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef deleted file mode 100644 index e191c12..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "ShrinkRuntime.Abstractions", - "rootNamespace": "ShrinkSDK.Runtime", - "autoReferenced": true -} diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef.meta b/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef.meta deleted file mode 100644 index 8cd5fd9..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntime.Abstractions.asmdef.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 9285a23e48a9fd04ea5d3a7507010d2b -AssemblyDefinitionImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs b/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs deleted file mode 100644 index afcb260..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs +++ /dev/null @@ -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 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; } - } -} diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs.meta b/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs.meta deleted file mode 100644 index d660e28..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/Runtime/ShrinkRuntimeServices.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 9f9b07df5ab1dc345be31f33e94077d2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/package.json b/Assets/Modules/ShrinkRuntime.Abstractions/package.json deleted file mode 100644 index 50f75d9..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/package.json +++ /dev/null @@ -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" -} diff --git a/Assets/Modules/ShrinkRuntime.Abstractions/package.json.meta b/Assets/Modules/ShrinkRuntime.Abstractions/package.json.meta deleted file mode 100644 index 8d8096e..0000000 --- a/Assets/Modules/ShrinkRuntime.Abstractions/package.json.meta +++ /dev/null @@ -1,7 +0,0 @@ -fileFormatVersion: 2 -guid: 2f07481a8e08f454fa1d85c5afe4c92d -TextScriptImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Modules/ShrinkShared.CodeGen b/Assets/Modules/ShrinkShared.CodeGen index 5fd9b25..371e880 160000 --- a/Assets/Modules/ShrinkShared.CodeGen +++ b/Assets/Modules/ShrinkShared.CodeGen @@ -1 +1 @@ -Subproject commit 5fd9b258d78a4eccff03b1da12ffd9f9a62526a4 +Subproject commit 371e880b846ba2a32c7f47199b2dde6fa32aed86 diff --git a/Assets/Modules/ShrinkTutorial b/Assets/Modules/ShrinkTutorial index 5d66389..8898221 160000 --- a/Assets/Modules/ShrinkTutorial +++ b/Assets/Modules/ShrinkTutorial @@ -1 +1 @@ -Subproject commit 5d66389bd6c7e3a2e4cd7b1893c14c92a0deeddc +Subproject commit 88982211981f03cbce9c8bed255e1d8b40b3ee8d diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/AnalyzerReleases.Shipped.md b/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/AnalyzerReleases.Shipped.md deleted file mode 100644 index 332da7f..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/AnalyzerReleases.Shipped.md +++ /dev/null @@ -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 diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkCodeGenAnalyzer.cs b/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkCodeGenAnalyzer.cs deleted file mode 100644 index 64ae6e9..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkCodeGenAnalyzer.cs +++ /dev/null @@ -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 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(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 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); -} diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkSDK.CodeGen.Analyzers.csproj b/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkSDK.CodeGen.Analyzers.csproj deleted file mode 100644 index 78c53ff..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Analyzers/ShrinkSDK.CodeGen.Analyzers.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - netstandard2.0 - ShrinkSDK.CodeGen.Analyzers - ShrinkSDK.CodeGen.Analyzers - false - false - true - - - - - diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Core/ShrinkSDK.CodeGen.Core.csproj b/Godot/CodeGen/ShrinkSDK.CodeGen.Core/ShrinkSDK.CodeGen.Core.csproj deleted file mode 100644 index 6656b11..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Core/ShrinkSDK.CodeGen.Core.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - net8.0 - ShrinkSDK.CodeGen.Core - ShrinkSDK.CodeGen - ShrinkSDK.CodeGen.Core - 0.1.0 - true - false - - - - - - diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj b/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj deleted file mode 100644 index d89da22..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkSDK.CodeGen.Task.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - net8.0 - ShrinkSDK.CodeGen.Task - ShrinkSDK.CodeGen - ShrinkSDK.CodeGen - 0.1.0 - MSBuild integration for ShrinkSDK Cecil weaving. - true - tools - true - true - $(TargetsForTfmSpecificBuildOutput);IncludeShrinkCodeGenDependencies - - - - - - - - - - - - - - - - - - - - diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkWeaveTask.cs b/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkWeaveTask.cs deleted file mode 100644 index a7a8639..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/ShrinkWeaveTask.cs +++ /dev/null @@ -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(); - 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 { } - } -} diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.props b/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.props deleted file mode 100644 index 54942f1..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.props +++ /dev/null @@ -1,5 +0,0 @@ - - - true - - diff --git a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.targets b/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.targets deleted file mode 100644 index 307f232..0000000 --- a/Godot/CodeGen/ShrinkSDK.CodeGen.Task/buildTransitive/ShrinkSDK.CodeGen.targets +++ /dev/null @@ -1,18 +0,0 @@ - - - <_ShrinkCodeGenTaskAssembly Condition="'$(_ShrinkCodeGenTaskAssembly)' == ''">$(MSBuildThisFileDirectory)..\tools\net8.0\ShrinkSDK.CodeGen.Task.dll - - - - - <_ShrinkCodeGenIntermediateAssembly>$(IntermediateOutputPath)$(TargetName).dll - - - - diff --git a/Godot/Installer/ShrinkSDK.Godot.Installer.csproj b/Godot/Installer/ShrinkSDK.Godot.Installer.csproj deleted file mode 100644 index a82c48f..0000000 --- a/Godot/Installer/ShrinkSDK.Godot.Installer.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - net8.0 - false - ShrinkSDK.Godot.Installer - ShrinkSDK.Godot.Installer - 0.1.1 - Godot Editor package manager and CodeGen diagnostics for ShrinkSDK. - - - - - - - - - - - diff --git a/Godot/Installer/addons/shrinksdk/ShrinkGodotInstallerPlugin.cs b/Godot/Installer/addons/shrinksdk/ShrinkGodotInstallerPlugin.cs deleted file mode 100644 index ec1cc0a..0000000 --- a/Godot/Installer/addons/shrinksdk/ShrinkGodotInstallerPlugin.cs +++ /dev/null @@ -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 _installActions = - new(StringComparer.OrdinalIgnoreCase); - private readonly System.Collections.Generic.Dictionary _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().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(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()); - } -} diff --git a/Godot/Installer/addons/shrinksdk/ShrinkProjectPackageEditor.cs b/Godot/Installer/addons/shrinksdk/ShrinkProjectPackageEditor.cs deleted file mode 100644 index 7397f76..0000000 --- a/Godot/Installer/addons/shrinksdk/ShrinkProjectPackageEditor.cs +++ /dev/null @@ -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 RecommendedPackages = - new Dictionary(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 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); - } -} diff --git a/Godot/Installer/addons/shrinksdk/plugin.cfg b/Godot/Installer/addons/shrinksdk/plugin.cfg deleted file mode 100644 index 1715616..0000000 --- a/Godot/Installer/addons/shrinksdk/plugin.cfg +++ /dev/null @@ -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" diff --git a/Godot/Packages/ShrinkSDK.App.Core/Runtime/ShrinkAppCore.cs b/Godot/Packages/ShrinkSDK.App.Core/Runtime/ShrinkAppCore.cs deleted file mode 100644 index e9d112b..0000000 --- a/Godot/Packages/ShrinkSDK.App.Core/Runtime/ShrinkAppCore.cs +++ /dev/null @@ -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 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(); -} - -public sealed class ShrinkAppServices -{ - private readonly Dictionary _services = new(); - public void Register(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service)); - public bool TryGet(out T? service) where T : class - { - service = _services.TryGetValue(typeof(T), out var value) ? value as T : null; - return service != null; - } - public T GetRequired() where T : class => TryGet(out var value) ? value! : throw new InvalidOperationException($"Required service is not registered: {typeof(T).FullName}"); - public bool TryUnregister(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 _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 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 CreateInstallers() => - ShrinkAppInstallers.GetDiscoveredInstallerTypes().Select(type => - Activator.CreateInstance(type) as IShrinkAppModuleInstaller ?? throw new InvalidOperationException($"Failed to create installer: {type.FullName}")) - .ToArray(); - - private static IReadOnlyList Sort(IEnumerable source, IEnumerable disabledIds) - { - var disabled = new HashSet(disabledIds ?? Array.Empty(), StringComparer.OrdinalIgnoreCase); - var byId = source.Where(item => !disabled.Contains(item.ModuleId)).ToDictionary(item => item.ModuleId, StringComparer.OrdinalIgnoreCase); - var states = new Dictionary(StringComparer.OrdinalIgnoreCase); - var result = new List(); - 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 byId, - IDictionary states, ICollection 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()) - { - 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); - } -} diff --git a/Godot/Packages/ShrinkSDK.App.Core/ShrinkSDK.App.Core.csproj b/Godot/Packages/ShrinkSDK.App.Core/ShrinkSDK.App.Core.csproj deleted file mode 100644 index 490f95d..0000000 --- a/Godot/Packages/ShrinkSDK.App.Core/ShrinkSDK.App.Core.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.1 - false - ShrinkApp.Core.Runtime - ShrinkApp - ShrinkSDK.App.Core - 0.2.0 - ShrinkSDK engine-neutral application composition runtime. - false - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.App.Starter.Basic/Runtime/ShrinkBasicComposition.cs b/Godot/Packages/ShrinkSDK.App.Starter.Basic/Runtime/ShrinkBasicComposition.cs deleted file mode 100644 index 813b350..0000000 --- a/Godot/Packages/ShrinkSDK.App.Starter.Basic/Runtime/ShrinkBasicComposition.cs +++ /dev/null @@ -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("shrink.command"); - host.Register("shrink.datasaver"); - host.Register("shrink.network"); - return host; - } - - public static IReadOnlyList 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 - }) - }; -} diff --git a/Godot/Packages/ShrinkSDK.App.Starter.Basic/ShrinkSDK.App.Starter.Basic.csproj b/Godot/Packages/ShrinkSDK.App.Starter.Basic/ShrinkSDK.App.Starter.Basic.csproj deleted file mode 100644 index 29c6f67..0000000 --- a/Godot/Packages/ShrinkSDK.App.Starter.Basic/ShrinkSDK.App.Starter.Basic.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - netstandard2.1 - false - ShrinkApp.Starter.Basic - ShrinkApp.Starter.Basic - ShrinkSDK.App.Starter.Basic - 0.3.0 - Engine-neutral basic ShrinkApp composition. - false - - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Command.Integration.EventBus/ShrinkSDK.Command.Integration.EventBus.csproj b/Godot/Packages/ShrinkSDK.Command.Integration.EventBus/ShrinkSDK.Command.Integration.EventBus.csproj deleted file mode 100644 index a278416..0000000 --- a/Godot/Packages/ShrinkSDK.Command.Integration.EventBus/ShrinkSDK.Command.Integration.EventBus.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.1 - false - ShrinkCommand.Integration.EventBus - ShrinkCommand.Integration - ShrinkSDK.Command.Integration.EventBus - 0.2.0 - ShrinkCommand and EventBus integration. - true - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Command.Integration.Network/ShrinkSDK.Command.Integration.Network.csproj b/Godot/Packages/ShrinkSDK.Command.Integration.Network/ShrinkSDK.Command.Integration.Network.csproj deleted file mode 100644 index 8274b48..0000000 --- a/Godot/Packages/ShrinkSDK.Command.Integration.Network/ShrinkSDK.Command.Integration.Network.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.1 - false - ShrinkCommand.Integration.Network - ShrinkCommand.Integration - ShrinkSDK.Command.Integration.Network - 0.2.0 - ShrinkCommand and Network RPC integration. - true - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Command/ShrinkSDK.Command.csproj b/Godot/Packages/ShrinkSDK.Command/ShrinkSDK.Command.csproj deleted file mode 100644 index 34600a7..0000000 --- a/Godot/Packages/ShrinkSDK.Command/ShrinkSDK.Command.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - netstandard2.1 - false - ShrinkCommand.Runtime - ShrinkCommand - ShrinkSDK.Command - 0.3.0 - ShrinkSDK command parsing, permissions and execution runtime. - false - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Context.AppAdapter/Runtime/ShrinkContextAppHost.cs b/Godot/Packages/ShrinkSDK.Context.AppAdapter/Runtime/ShrinkContextAppHost.cs deleted file mode 100644 index 1053589..0000000 --- a/Godot/Packages/ShrinkSDK.Context.AppAdapter/Runtime/ShrinkContextAppHost.cs +++ /dev/null @@ -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 factory) => _catalog.Register(name, factory); - public void Register(string name) where TComponent : IShrinkComponent, new() => - _catalog.Register(name); - public UniTask ApplyAsync(IReadOnlyList entries) => _loader.ApplyAsync(entries); - public UniTask ShutdownAsync() => _runtime.ShutdownAsync(); -} diff --git a/Godot/Packages/ShrinkSDK.Context.AppAdapter/ShrinkSDK.Context.AppAdapter.csproj b/Godot/Packages/ShrinkSDK.Context.AppAdapter/ShrinkSDK.Context.AppAdapter.csproj deleted file mode 100644 index ff4c6c4..0000000 --- a/Godot/Packages/ShrinkSDK.Context.AppAdapter/ShrinkSDK.Context.AppAdapter.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - netstandard2.1 - false - ShrinkContext.AppAdapter - ShrinkContext.AppAdapter - ShrinkSDK.Context.AppAdapter - 0.2.0 - Engine-neutral ShrinkContext composition host for ShrinkApp. - false - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Context.Core/ShrinkSDK.Context.Core.csproj b/Godot/Packages/ShrinkSDK.Context.Core/ShrinkSDK.Context.Core.csproj deleted file mode 100644 index 6baa9c0..0000000 --- a/Godot/Packages/ShrinkSDK.Context.Core/ShrinkSDK.Context.Core.csproj +++ /dev/null @@ -1,17 +0,0 @@ - - - netstandard2.1 - false - ShrinkContext.Core.Runtime - ShrinkContext - ShrinkSDK.Context.Core - 0.2.0 - ShrinkSDK reversible context and fiber runtime. - false - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.DataSaver.Integration.EventBus/ShrinkSDK.DataSaver.Integration.EventBus.csproj b/Godot/Packages/ShrinkSDK.DataSaver.Integration.EventBus/ShrinkSDK.DataSaver.Integration.EventBus.csproj deleted file mode 100644 index 7e6de31..0000000 --- a/Godot/Packages/ShrinkSDK.DataSaver.Integration.EventBus/ShrinkSDK.DataSaver.Integration.EventBus.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.1 - false - ShrinkDataSaver.Integration.EventBus - ShrinkDataSaver.Integration - ShrinkSDK.DataSaver.Integration.EventBus - 2.2.0 - ShrinkDataSaver and EventBus integration. - false - disable - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.DataSaver/Runtime/ShrinkDataSaverRuntime.cs b/Godot/Packages/ShrinkSDK.DataSaver/Runtime/ShrinkDataSaverRuntime.cs deleted file mode 100644 index 8cc5d94..0000000 --- a/Godot/Packages/ShrinkSDK.DataSaver/Runtime/ShrinkDataSaverRuntime.cs +++ /dev/null @@ -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}"); - } -} diff --git a/Godot/Packages/ShrinkSDK.DataSaver/ShrinkSDK.DataSaver.csproj b/Godot/Packages/ShrinkSDK.DataSaver/ShrinkSDK.DataSaver.csproj deleted file mode 100644 index b4cce88..0000000 --- a/Godot/Packages/ShrinkSDK.DataSaver/ShrinkSDK.DataSaver.csproj +++ /dev/null @@ -1,29 +0,0 @@ - - - netstandard2.1 - false - ShrinkDataSaver.Runtime - ShrinkDataSaver - ShrinkSDK.DataSaver - 2.3.0 - ShrinkSDK engine-neutral versioned save and settings runtime. - false - disable - - - - - - - - - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.EventBus/ShrinkSDK.EventBus.csproj b/Godot/Packages/ShrinkSDK.EventBus/ShrinkSDK.EventBus.csproj deleted file mode 100644 index 633c90e..0000000 --- a/Godot/Packages/ShrinkSDK.EventBus/ShrinkSDK.EventBus.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - netstandard2.1 - false - ShrinkEventBus.Runtime - ShrinkEventBus - ShrinkSDK.EventBus - 2.1.0 - ShrinkSDK typed event bus runtime. - false - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Godot b/Godot/Packages/ShrinkSDK.Godot new file mode 160000 index 0000000..a24f39d --- /dev/null +++ b/Godot/Packages/ShrinkSDK.Godot @@ -0,0 +1 @@ +Subproject commit a24f39d4fda86835bc71dd64dc172612f652802f diff --git a/Godot/Packages/ShrinkSDK.Godot/ShrinkGodotHost.cs b/Godot/Packages/ShrinkSDK.Godot/ShrinkGodotHost.cs deleted file mode 100644 index 60ffcbd..0000000 --- a/Godot/Packages/ShrinkSDK.Godot/ShrinkGodotHost.cs +++ /dev/null @@ -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 _dispatchQueue = new(); - private readonly Dictionary _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 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() ?? - 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 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; - } - } -} diff --git a/Godot/Packages/ShrinkSDK.Godot/ShrinkSDK.Godot.csproj b/Godot/Packages/ShrinkSDK.Godot/ShrinkSDK.Godot.csproj deleted file mode 100644 index 61b34a6..0000000 --- a/Godot/Packages/ShrinkSDK.Godot/ShrinkSDK.Godot.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - net8.0 - ShrinkSDK.Godot - ShrinkSDK.Godot - ShrinkSDK.Godot - 0.1.0 - Godot 4.6 host and platform services for ShrinkSDK. - false - - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkGodotModLoader.cs b/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkGodotModLoader.cs deleted file mode 100644 index 93d29c3..0000000 --- a/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkGodotModLoader.cs +++ /dev/null @@ -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 Instances); - private readonly Dictionary _loaded = new(StringComparer.OrdinalIgnoreCase); - - public IReadOnlyCollection LoadedAssemblyPaths => _loaded.Keys; - - public IReadOnlyList 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() != null).OrderBy(type => type.GetCustomAttribute()!.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; - } -} diff --git a/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkSDK.ModFramework.Godot.csproj b/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkSDK.ModFramework.Godot.csproj deleted file mode 100644 index 7863adb..0000000 --- a/Godot/Packages/ShrinkSDK.ModFramework.Godot/ShrinkSDK.ModFramework.Godot.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - net8.0 - ShrinkModFramework.Godot - ShrinkModFramework.Godot - ShrinkSDK.ModFramework.Godot - 0.1.0 - Collectible AssemblyLoadContext host for ShrinkSDK mods in Godot. - false - - - - - - diff --git a/Godot/Packages/ShrinkSDK.ModFramework/Runtime/ShrinkModContext.cs b/Godot/Packages/ShrinkSDK.ModFramework/Runtime/ShrinkModContext.cs deleted file mode 100644 index e38807e..0000000 --- a/Godot/Packages/ShrinkSDK.ModFramework/Runtime/ShrinkModContext.cs +++ /dev/null @@ -1,25 +0,0 @@ -#nullable enable - -using System; -using System.Collections.Generic; - -namespace ShrinkModFramework; - -public sealed class ShrinkModContext -{ - private readonly Dictionary _services = new(); - public ShrinkModContext(string modDirectory) => ModDirectory = modDirectory ?? throw new ArgumentNullException(nameof(modDirectory)); - public string ModDirectory { get; } - public void RegisterService(T service) where T : class => _services[typeof(T)] = service ?? throw new ArgumentNullException(nameof(service)); - public bool TryGetService(out T? service) where T : class - { - service = _services.TryGetValue(typeof(T), out var value) ? value as T : null; - return service != null; - } - public T GetRequiredService() where T : class => TryGetService(out var value) ? value! : throw new InvalidOperationException($"Service is not registered: {typeof(T).FullName}"); -} - -public interface IShrinkModUnload -{ - void OnUnload(ShrinkModContext context); -} diff --git a/Godot/Packages/ShrinkSDK.ModFramework/ShrinkSDK.ModFramework.csproj b/Godot/Packages/ShrinkSDK.ModFramework/ShrinkSDK.ModFramework.csproj deleted file mode 100644 index baa6894..0000000 --- a/Godot/Packages/ShrinkSDK.ModFramework/ShrinkSDK.ModFramework.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - netstandard2.1 - false - ShrinkModFramework.Runtime - ShrinkModFramework - ShrinkSDK.ModFramework - 0.3.0 - Engine-neutral ShrinkSDK mod contracts and lifecycle. - disable - false - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Network.Integration.EventBus/ShrinkSDK.Network.Integration.EventBus.csproj b/Godot/Packages/ShrinkSDK.Network.Integration.EventBus/ShrinkSDK.Network.Integration.EventBus.csproj deleted file mode 100644 index 225c06b..0000000 --- a/Godot/Packages/ShrinkSDK.Network.Integration.EventBus/ShrinkSDK.Network.Integration.EventBus.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - netstandard2.1 - false - ShrinkNetwork.Integration.EventBus - ShrinkNetwork.Integration - ShrinkSDK.Network.Integration.EventBus - 0.2.0 - ShrinkNetwork and EventBus generated bridge. - true - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Network/ShrinkSDK.Network.csproj b/Godot/Packages/ShrinkSDK.Network/ShrinkSDK.Network.csproj deleted file mode 100644 index fd08cae..0000000 --- a/Godot/Packages/ShrinkSDK.Network/ShrinkSDK.Network.csproj +++ /dev/null @@ -1,22 +0,0 @@ - - - netstandard2.1 - false - ShrinkNetwork.Runtime - ShrinkNetwork - ShrinkSDK.Network - 0.3.0 - ShrinkSDK messaging, RPC, permission and transport runtime. - true - false - - - - - - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Runtime.Abstractions/ShrinkSDK.Runtime.Abstractions.csproj b/Godot/Packages/ShrinkSDK.Runtime.Abstractions/ShrinkSDK.Runtime.Abstractions.csproj deleted file mode 100644 index 47f22ff..0000000 --- a/Godot/Packages/ShrinkSDK.Runtime.Abstractions/ShrinkSDK.Runtime.Abstractions.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - netstandard2.1 - ShrinkRuntime.Abstractions - ShrinkSDK.Runtime - ShrinkSDK.Runtime.Abstractions - 0.1.0 - Engine-neutral ShrinkSDK runtime contracts. - - - - - diff --git a/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkGodotTutorialOverlay.cs b/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkGodotTutorialOverlay.cs deleted file mode 100644 index be5aa04..0000000 --- a/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkGodotTutorialOverlay.cs +++ /dev/null @@ -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(step.Target); - if (step.TargetMode == ShrinkTutorialTargetMode.AnchorId) return GetTree().GetFirstNodeInGroup("shrink_tutorial_" + step.Target) as Control; - return null; - } -} diff --git a/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkSDK.Tutorial.Godot.csproj b/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkSDK.Tutorial.Godot.csproj deleted file mode 100644 index f021c73..0000000 --- a/Godot/Packages/ShrinkSDK.Tutorial.Godot/ShrinkSDK.Tutorial.Godot.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - net8.0 - ShrinkTutorial.Godot - ShrinkTutorial.Godot - ShrinkSDK.Tutorial.Godot - 0.1.0 - Godot Control overlay and Resources for ShrinkSDK Tutorial. - false - - - - - - diff --git a/Godot/Packages/ShrinkSDK.Tutorial/Runtime/ShrinkTutorialCore.cs b/Godot/Packages/ShrinkSDK.Tutorial/Runtime/ShrinkTutorialCore.cs deleted file mode 100644 index 886c88f..0000000 --- a/Godot/Packages/ShrinkSDK.Tutorial/Runtime/ShrinkTutorialCore.cs +++ /dev/null @@ -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 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 StepChanged; - public event Action 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(); - } -} diff --git a/Godot/Packages/ShrinkSDK.Tutorial/ShrinkSDK.Tutorial.csproj b/Godot/Packages/ShrinkSDK.Tutorial/ShrinkSDK.Tutorial.csproj deleted file mode 100644 index d2bce51..0000000 --- a/Godot/Packages/ShrinkSDK.Tutorial/ShrinkSDK.Tutorial.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - netstandard2.1 - false - ShrinkTutorial.Runtime - ShrinkTutorial - ShrinkSDK.Tutorial - 0.2.0 - Engine-neutral ShrinkSDK tutorial state and step runtime. - disable - - - - - - - - - diff --git a/Godot/README.md b/Godot/README.md index c50fe0b..a202353 100644 --- a/Godot/README.md +++ b/Godot/README.md @@ -82,8 +82,8 @@ addons/shrinksdk 在 Workspace 中生成 Installer 包: ```powershell -dotnet build .\Godot\Installer\ShrinkSDK.Godot.Installer.csproj -c Release -dotnet pack .\Godot\Installer\ShrinkSDK.Godot.Installer.csproj -c Release --no-build -o .\Godot\Artifacts --include-symbols --include-source +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 --include-symbols --include-source ``` ## 宿主节点 diff --git a/Godot/Samples/ShrinkSDK.Godot.Sample/ShrinkSDK.Godot.Sample.csproj b/Godot/Samples/ShrinkSDK.Godot.Sample/ShrinkSDK.Godot.Sample.csproj index 0dc47e7..16cfb49 100644 --- a/Godot/Samples/ShrinkSDK.Godot.Sample/ShrinkSDK.Godot.Sample.csproj +++ b/Godot/Samples/ShrinkSDK.Godot.Sample/ShrinkSDK.Godot.Sample.csproj @@ -3,18 +3,18 @@ net8.0 true true - <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll + <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll - - - - + + + + - - - - + + + + - + diff --git a/Godot/ShrinkSDK.Godot.slnx b/Godot/ShrinkSDK.Godot.slnx index d6698d4..127c076 100644 --- a/Godot/ShrinkSDK.Godot.slnx +++ b/Godot/ShrinkSDK.Godot.slnx @@ -1,31 +1,31 @@ - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - + + + @@ -40,6 +40,6 @@ - + diff --git a/Godot/Tests/CodeGenFixture/CodeGenFixture.csproj b/Godot/Tests/CodeGenFixture/CodeGenFixture.csproj index 2fb62d1..db16cae 100644 --- a/Godot/Tests/CodeGenFixture/CodeGenFixture.csproj +++ b/Godot/Tests/CodeGenFixture/CodeGenFixture.csproj @@ -6,15 +6,15 @@ true true $(FixtureStrongNameKeyFile) - <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll + <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll - - - - - - + + + + + + - + diff --git a/Godot/Tests/CodeGenValidation/CodeGenValidation.csproj b/Godot/Tests/CodeGenValidation/CodeGenValidation.csproj index f9fd7d9..c122892 100644 --- a/Godot/Tests/CodeGenValidation/CodeGenValidation.csproj +++ b/Godot/Tests/CodeGenValidation/CodeGenValidation.csproj @@ -6,7 +6,7 @@ false - + diff --git a/Godot/Tests/InstallerFixture/InstallerFixture.csproj b/Godot/Tests/InstallerFixture/InstallerFixture.csproj index 2831408..abc7d53 100644 --- a/Godot/Tests/InstallerFixture/InstallerFixture.csproj +++ b/Godot/Tests/InstallerFixture/InstallerFixture.csproj @@ -5,6 +5,6 @@ ShrinkSDK.InstallerFixture - + diff --git a/Godot/Tests/InvalidCodeGenFixture/InvalidCodeGenFixture.csproj b/Godot/Tests/InvalidCodeGenFixture/InvalidCodeGenFixture.csproj index ad7888f..75b0ab3 100644 --- a/Godot/Tests/InvalidCodeGenFixture/InvalidCodeGenFixture.csproj +++ b/Godot/Tests/InvalidCodeGenFixture/InvalidCodeGenFixture.csproj @@ -4,12 +4,12 @@ ShrinkSDK.InvalidCodeGenFixture true false - <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll + <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll - - - + + + - + diff --git a/Godot/Tests/ModFixture/ModFixture.csproj b/Godot/Tests/ModFixture/ModFixture.csproj index 866771b..1b52bbc 100644 --- a/Godot/Tests/ModFixture/ModFixture.csproj +++ b/Godot/Tests/ModFixture/ModFixture.csproj @@ -3,13 +3,13 @@ netstandard2.1 ShrinkSDK.ModFixture true - <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\CodeGen\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll + <_ShrinkCodeGenTaskAssembly>$(MSBuildThisFileDirectory)..\..\..\Assets\Modules\ShrinkShared.CodeGen\DotNet~\ShrinkSDK.CodeGen.Task\bin\$(Configuration)\net8.0\ShrinkSDK.CodeGen.Task.dll - - - - + + + + - + diff --git a/Godot/Tests/ModHostFixture/ModHostFixture.csproj b/Godot/Tests/ModHostFixture/ModHostFixture.csproj index adf1ac4..14dcc7e 100644 --- a/Godot/Tests/ModHostFixture/ModHostFixture.csproj +++ b/Godot/Tests/ModHostFixture/ModHostFixture.csproj @@ -6,8 +6,8 @@ false - - - + + +