refactor: move Godot packages into module repositories
Validate ShrinkSDK Workspace / unity (push) Failing after 5s

This commit is contained in:
2026-09-05 03:43:14 +08:00
parent 2695dcdbba
commit e9d8e93427
79 changed files with 92 additions and 1827 deletions
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
@@ -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>
+2 -2
View File
@@ -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
```
## 宿主节点
@@ -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
View File
@@ -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>
+6 -6
View File
@@ -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>