From 76f395dce53f83255675aaf9e8b02eae48a39d84 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Tue, 11 Mar 2025 15:02:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mROA/Abstract/IRemoteObjectFactory.cs | 9 ++++++ .../Implementation/ComplexObjectIdentifier.cs | 3 +- mROA/Implementation/RemoteObjectFactory.cs | 31 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 mROA/Abstract/IRemoteObjectFactory.cs create mode 100644 mROA/Implementation/RemoteObjectFactory.cs diff --git a/mROA/Abstract/IRemoteObjectFactory.cs b/mROA/Abstract/IRemoteObjectFactory.cs new file mode 100644 index 0000000..e68fb0f --- /dev/null +++ b/mROA/Abstract/IRemoteObjectFactory.cs @@ -0,0 +1,9 @@ +using mROA.Implementation; + +namespace mROA.Abstract +{ + public interface IRemoteObjectFactory : IInjectableModule + { + T Produce(ComplexObjectIdentifier id); + } +} \ No newline at end of file diff --git a/mROA/Implementation/ComplexObjectIdentifier.cs b/mROA/Implementation/ComplexObjectIdentifier.cs index 35652ee..15ede59 100644 --- a/mROA/Implementation/ComplexObjectIdentifier.cs +++ b/mROA/Implementation/ComplexObjectIdentifier.cs @@ -12,9 +12,10 @@ namespace mROA.Implementation { ContextId = contextId; OwnerId = ownerId; - } + public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId }; + public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 }; public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat }; diff --git a/mROA/Implementation/RemoteObjectFactory.cs b/mROA/Implementation/RemoteObjectFactory.cs new file mode 100644 index 0000000..fad21e3 --- /dev/null +++ b/mROA/Implementation/RemoteObjectFactory.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using mROA.Abstract; + +namespace mROA.Implementation +{ + public class RemoteObjectFactory : IRemoteObjectFactory + { + public static Dictionary RemoteTypes = new(); + private IRepresentationModuleProducer? _representationProducer; + + public T Produce(ComplexObjectIdentifier id) + { + if (_representationProducer == null) + throw new NullReferenceException("representation producer is not initialized"); + + if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException(); + var representationModule = + _representationProducer.Produce(TransmissionConfig.OwnershipRepository.GetOwnershipId()); + var remote = (T)Activator.CreateInstance(remoteType, id.ContextId, + representationModule)!; + return remote; + } + + public void Inject(T dependency) + { + if (dependency is IRepresentationModuleProducer serialisationModule) + _representationProducer = serialisationModule; + } + } +} \ No newline at end of file