Skip to content

Commit

Permalink
Merge pull request #5 from techno-dwarf-works/feature/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
uurha authored Apr 10, 2024
2 parents 0b04341 + 0712f09 commit 36291d9
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 17 deletions.
6 changes: 3 additions & 3 deletions Assets/BetterServices/Runtime/BetterServices.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "BetterServices.Runtime",
"rootNamespace": "Better.Services",
"rootNamespace": "Better.Services.Runtime",
"references": [
"GUID:441b78e90a9cf724ab41c6eed8c0b93d",
"GUID:a59e3daedde9ca94bba45364d4ead25f"
"GUID:8bd4b41f8da90144d9006c4d926c9679"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand All @@ -15,7 +15,7 @@
"versionDefines": [
{
"name": "com.uurha.bettervalidation",
"expression": "1.0.4",
"expression": "1.6.0",
"define": "BETTER_VALIDATION"
}
],
Expand Down
9 changes: 3 additions & 6 deletions Assets/BetterServices/Runtime/Services/MonoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ protected virtual void Awake()

async Task IService.InitializeAsync(CancellationToken cancellationToken)
{
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}");

if (Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized");
Debug.LogError("Service already initialized");
return;
}

Expand All @@ -38,18 +36,17 @@ async Task IService.InitializeAsync(CancellationToken cancellationToken)
}

Initialized = true;
Debug.Log("Service initialized");
}

Task IService.PostInitializeAsync(CancellationToken cancellationToken)
{
if (!Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized");
Debug.LogError("Service must be initialized");
return Task.CompletedTask;
}

Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}");

var linkedTokenSource = CancellationTokenSource.CreateLinkedTokenSource(DestroyCancellationToken, cancellationToken);
cancellationToken = linkedTokenSource.Token;

Expand Down
15 changes: 8 additions & 7 deletions Assets/BetterServices/Runtime/Services/PocoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Better.Services.Runtime.Interfaces;
using UnityEngine;

#if BETTER_VALIDATION
using Better.Validation.Runtime.Attributes;
#endif
Expand All @@ -16,28 +17,27 @@ public abstract class PocoService : IService

async Task IService.InitializeAsync(CancellationToken cancellationToken)
{
Debug.Log($"[{GetType().Name}] {nameof(IService.InitializeAsync)}");

if (Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.InitializeAsync)}: already initialized");
Debug.LogError("Service already initialized");
return;
}

Initialized = true;
await OnInitializeAsync(cancellationToken);
Initialized = !cancellationToken.IsCancellationRequested;

Debug.Log("Service initialized");
}

Task IService.PostInitializeAsync(CancellationToken cancellationToken)
{
if (!Initialized)
{
Debug.LogError($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}: not initialized");
Debug.LogError("Service must be initialized");
return Task.CompletedTask;
}

Debug.Log($"[{GetType().Name}] {nameof(IService.PostInitializeAsync)}");
return OnPostInitializeAsync(cancellationToken);
}

Expand All @@ -49,7 +49,7 @@ Task IService.PostInitializeAsync(CancellationToken cancellationToken)
public abstract class PocoService<TSettings> : PocoService where TSettings : ScriptableObject
{
#if BETTER_VALIDATION
[NotNull]
[NotNull]
#endif
[SerializeField] private TSettings _settings;

Expand All @@ -59,7 +59,8 @@ protected override Task OnInitializeAsync(CancellationToken cancellationToken)
{
if (Settings == null)
{
throw new NullReferenceException($"[{GetType().Name}] {nameof(OnInitializeAsync)}: {nameof(Settings)} cannot be null");
var exception = new NullReferenceException(nameof(Settings));
Debug.LogException(exception);
}

return Task.CompletedTask;
Expand Down
5 changes: 4 additions & 1 deletion Assets/BetterServices/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
{
"name": "com.tdw.better.services",
"displayName": "Better Services",
"version": "0.0.4",
"version": "0.1.0",
"unity": "2021.3",
"description": " ",
"dependencies": {
"com.tdw.better.internal.core": "0.0.2"
},
"author": {
"name": "Better Plugins",
"url": "https://github.com/techno-dwarf-works"
Expand Down
1 change: 1 addition & 0 deletions Packages/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"com.unity.timeline": "1.6.4",
"com.unity.ugui": "1.0.0",
"com.unity.visualscripting": "1.8.0",
"com.uurha.bettervalidation": "1.6.0",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",
Expand Down
48 changes: 48 additions & 0 deletions Packages/packages-lock.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,42 @@
{
"dependencies": {
"com.tdw.better.commons": {
"version": "0.0.2",
"depth": 1,
"source": "registry",
"dependencies": {
"com.tdw.better.internal.core": "0.0.2"
},
"url": "https://package.openupm.com"
},
"com.tdw.better.internal.core": {
"version": "0.0.2",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://package.openupm.com"
},
"com.tdw.better.projectsettings": {
"version": "0.1.1",
"depth": 1,
"source": "registry",
"dependencies": {
"com.tdw.better.singletons": "0.1.0",
"com.tdw.better.internal.core": "0.0.2",
"com.tdw.better.commons": "0.0.2"
},
"url": "https://package.openupm.com"
},
"com.tdw.better.singletons": {
"version": "0.1.0",
"depth": 2,
"source": "registry",
"dependencies": {
"com.tdw.better.commons": "0.0.2",
"com.tdw.better.internal.core": "0.0.2"
},
"url": "https://package.openupm.com"
},
"com.unity.collab-proxy": {
"version": "2.0.1",
"depth": 0,
Expand Down Expand Up @@ -135,6 +172,17 @@
},
"url": "https://packages.unity.com"
},
"com.uurha.bettervalidation": {
"version": "1.6.0",
"depth": 0,
"source": "registry",
"dependencies": {
"com.tdw.better.internal.core": "0.0.2",
"com.tdw.better.projectsettings": "0.1.1",
"com.tdw.better.commons": "0.0.2"
},
"url": "https://package.openupm.com"
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,
Expand Down

0 comments on commit 36291d9

Please sign in to comment.