Skip to content

Commit

Permalink
[v0.2.3] Cleaning; Add github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed Dec 15, 2023
1 parent 209543b commit 55ec265
Show file tree
Hide file tree
Showing 33 changed files with 219 additions and 143 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Each line is a file pattern followed by one or more owners.
# Owners will be requested for review when someone opens a pull request.

* @Depra-Inc/api-developers
27 changes: 27 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
name: Bug report
about: Create a report to help us improve
title: '[Bug Report Title]'
labels: 'bug'
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: '[Feature Request Title]'
labels: 'enhancement'
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Description

Please include a summary of the change and which issue is fixed or what was added to the project.

# How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration.

# Checklist

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] I have added tests that demonstrate the new feature or bugfix
- [ ] New and existing unit and integrations tests pass locally with my changes
14 changes: 14 additions & 0 deletions .github/workflows/cd-github.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CD GitHub Packages

on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
uses: Depra-Inc/Workflows/.github/workflows/cd-github.yml@main
secrets:
node_auth_token: ${{secrets.GITHUB_TOKEN}}
discord_webhook: ${{secrets.DISCORD_WEBHOOK}}
14 changes: 14 additions & 0 deletions .github/workflows/cd-npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: CD NPM

on:
workflow_dispatch:
push:
branches:
- main

jobs:
deploy:
uses: Depra-Inc/Workflows/.github/workflows/cd-npm.yml@main
secrets:
node_auth_token: ${{secrets.NPM_AUTH_TOKEN}}
discord_webhook: ${{secrets.DISCORD_WEBHOOK}}
8 changes: 5 additions & 3 deletions Editor/Depra.Assets.Editor.asmdef
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Depra.Assets.Editor",
"rootNamespace": "",
"rootNamespace": "Depra.Assets",
"references": [
"GUID:ce2ab5ef472b35f498b9d47a89be9396"
],
Expand All @@ -9,8 +9,10 @@
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"overrideReferences": true,
"precompiledReferences": [
"Depra.Assets.dll"
],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
Expand Down
11 changes: 5 additions & 6 deletions Editor/Extensions/SerializedPropertyExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ private static object ElementAtOrDefault(this IEnumerable self, int index)
private static FieldInfo FieldRecursive(this Type self, string fieldName)
{
var field = self.Field(fieldName);
if (field != null)
{
return field;
}

return self.BaseType == typeof(object) ? null : self.BaseType.FieldRecursive(fieldName);
return field != null
? field
: self.BaseType == typeof(object)
? null
: self.BaseType.FieldRecursive(fieldName);
}

private static FieldInfo Field(this Type self, string fieldName)
Expand Down
2 changes: 1 addition & 1 deletion Editor/Files/PreloadedAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class PreloadedAsset<TAsset> : IAssetFile<TAsset>, IDisposable whe

public PreloadedAsset(IAssetFile<TAsset> asset)
{
Guard.AgainstNull(asset, () => new ArgumentNullException(nameof(asset)));
Guard.AgainstNull(asset, nameof(asset));

_asset = asset;
_assetType = typeof(TAsset);
Expand Down
3 changes: 0 additions & 3 deletions Runtime/Common/AssetTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ public static class AssetTypes
{
public const string META = ".meta";
public const string BASE = ".asset";
public const string SPRITE = ".sprite";
public const string MATERIAL = ".material";
public const string ASSET_BUNDLE = ".unity3d";
}
}
2 changes: 1 addition & 1 deletion Runtime/Common/UnityProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class UnityProject

internal const string SLASH = "/";

internal static string DataPathByPlatform
public static string DataPathByPlatform
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Depra.Assets.Runtime.asmdef
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Depra.Assets.Runtime",
"rootNamespace": "",
"rootNamespace": "Depra.Assets",
"references": [],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
29 changes: 22 additions & 7 deletions Runtime/Exceptions/Guard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ namespace Depra.Assets.Exceptions
{
internal static class Guard
{
private const string CONDITION = "DEBUG";

[Conditional(CONDITION)]
[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void Against(bool condition, Func<Exception> exception)
{
Expand All @@ -22,24 +20,41 @@ public static void Against(bool condition, Func<Exception> exception)
}
}

[Conditional(CONDITION)]
[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstNull<TObject>(TObject asset, Func<Exception> exception) =>
Against(asset == null, exception);

[Conditional(CONDITION)]
[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstNull<TObject>(TObject asset, string argumentName) =>
Against(asset == null, () => new ArgumentNullException(argumentName));

[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstEqual<T>(IEquatable<T> value, IEquatable<T> other, Func<Exception> exception) =>
Against(value.Equals(other), exception);

[Conditional(CONDITION)]
[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstFileNotFound(string filePath) =>
Against(File.Exists(filePath) == false, () => new FileNotFoundException(filePath));

[Conditional(CONDITION)]
[Conditional(Conditional.ENSURE)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AgainstEmptyString(string value, Func<Exception> exception) =>
Against(string.IsNullOrEmpty(value), exception);

private static class Conditional
{
private const string TRUE = "DEBUG";
private const string FALSE = "THIS_IS_JUST_SOME_RANDOM_STRING_THAT_IS_NEVER_DEFINED";

#if DEBUG || DEV_BUILD
public const string ENSURE = TRUE;
#else
public const string ENSURE = FALSE;
#endif
}
}
}
19 changes: 9 additions & 10 deletions Runtime/Extensions/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@

using System;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;

namespace Depra.Assets.Extensions
{
internal static class ATask
{
public static void Void(Func<Task> taskFactory) => taskFactory().Forget();

public static IEnumerator ToCoroutine(Func<Task> taskFactory, Action<Exception> exception = null) =>
taskFactory().ToCoroutine(exception);
}

internal static class TaskExtensions
{
public static IEnumerator ToCoroutine(this Task self, Action<Exception> exception = null) =>
new ToCoroutineEnumerator(self, exception);

public static void Forget([SuppressMessage("ReSharper", "UnusedParameter.Global")] this Task self) { }
public static void Forget(this Task _) { }

private sealed record ToCoroutineEnumerator : IEnumerator
{
Expand Down Expand Up @@ -85,4 +76,12 @@ bool IEnumerator.MoveNext()
void IEnumerator.Reset() { }
}
}

internal static class ATask
{
public static void Void(Func<Task> taskFactory) => taskFactory().Forget();

public static IEnumerator ToCoroutine(Func<Task> taskFactory, Action<Exception> exception = null) =>
taskFactory().ToCoroutine(exception);
}
}
12 changes: 4 additions & 8 deletions Runtime/Files.Bundles/Extensions/AssetBundleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,18 @@ where fileInfo.Exists
[SuppressMessage("ReSharper", "InconsistentNaming")]
private static FileSize SizeInRAM(this Object assetBundle)
{
var sizes = new Dictionary<Type, long>();
var serializedObject = new SerializedObject(assetBundle);
var serializedProperty = serializedObject.FindProperty("m_PreloadTable");
var sizes = new Dictionary<Type, long>();
for (var i = 0; i < serializedProperty.arraySize; i++)
for (var index = 0; index < serializedProperty.arraySize; index++)
{
var objectReference = serializedProperty.GetArrayElementAtIndex(i).objectReferenceValue;
var objectReference = serializedProperty.GetArrayElementAtIndex(index).objectReferenceValue;
var type = objectReference.GetType();
var size = Profiler.GetRuntimeMemorySizeLong(objectReference);
if (sizes.ContainsKey(type))
if (sizes.TryAdd(type, size) == false)
{
sizes[type] += size;
}
else
{
sizes.Add(type, size);
}
}

return new FileSize(sizes.Sum(x => x.Value));
Expand Down
15 changes: 0 additions & 15 deletions Runtime/Files.Bundles/Extensions/AssetBundleFileExtensions.cs

This file was deleted.

This file was deleted.

13 changes: 6 additions & 7 deletions Runtime/Files.Bundles/Extensions/AssetBundleRequestExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ namespace Depra.Assets.Files.Bundles.Extensions
{
internal static class AssetBundleRequestExtensions
{
public static Task<Object> ToTask(this AssetBundleRequest self,
Action<float> onProgress = null, CancellationToken cancellationToken = default) =>
cancellationToken.IsCancellationRequested
? Task.FromCanceled<Object>(cancellationToken)
: self.isDone
? Task.FromResult(self.asset)
: AwaitWithProgress(self, onProgress, cancellationToken);
public static Task<Object> ToTask(this AssetBundleRequest self, Action<float> onProgress = null,
CancellationToken cancellationToken = default) => cancellationToken.IsCancellationRequested
? Task.FromCanceled<Object>(cancellationToken)
: self.isDone
? Task.FromResult(self.asset)
: AwaitWithProgress(self, onProgress, cancellationToken);

private async static Task<Object> AwaitWithProgress(this AssetBundleRequest self,
Action<float> onProgress, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading;
using System.Threading.Tasks;
using Depra.Assets.Files.Bundles.Exceptions;
using Depra.Assets.Files.Bundles.Sources;
using UnityEngine.Networking;

namespace Depra.Assets.Files.Bundles.Extensions
Expand Down
9 changes: 5 additions & 4 deletions Runtime/Files.Bundles/Files/AssetBundleAssetFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,15 @@ public sealed class AssetBundleAssetFile<TAsset> : IAssetFile<TAsset>, IDisposab

public AssetBundleAssetFile(AssetName name, AssetBundle assetBundle)
{
Guard.AgainstNull(name, () => new ArgumentNullException(nameof(name)));
Guard.AgainstNull(assetBundle, () => new ArgumentNullException(nameof(assetBundle)));
Guard.AgainstNull(name, nameof(name));
Guard.AgainstNull(assetBundle, nameof(assetBundle));

_assetBundle = assetBundle;
Metadata = new AssetMetadata(name, FileSize.Unknown);
}

public AssetMetadata Metadata { get; }
public bool IsLoaded => _loadedAsset != null;

private string Name => Metadata.Uri.Relative;

public TAsset Load()
Expand Down Expand Up @@ -70,7 +69,7 @@ public async Task<TAsset> LoadAsync(DownloadProgressDelegate onProgress = null,

var loadedAsset = await _assetBundle
.LoadAssetAsync<TAsset>(Name)
.ToTask(progress => onProgress?.Invoke(new DownloadProgress(progress)), cancellationToken);
.ToTask(OnProgress, cancellationToken);

Guard.AgainstNull(loadedAsset, () => new AssetBundleFileNotLoaded(Name, _assetBundle.name));

Expand All @@ -79,6 +78,8 @@ public async Task<TAsset> LoadAsync(DownloadProgressDelegate onProgress = null,
Metadata.Size = UnityFileSize.FromProfiler(_loadedAsset);

return _loadedAsset;

void OnProgress(float progress) => onProgress?.Invoke(new DownloadProgress(progress));
}

void IDisposable.Dispose() => Unload();
Expand Down
Loading

0 comments on commit 55ec265

Please sign in to comment.