Skip to content

Commit e54f6b7

Browse files
committed
refactor: Namespace all Rivet plugin code (#13)
Closes UTY-32
1 parent 95e71d8 commit e54f6b7

8 files changed

Lines changed: 674 additions & 655 deletions

File tree

Assets/Rivet/Editor/BuildPipeline.cs

Lines changed: 38 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,52 @@
33
using UnityEngine;
44
using System.IO;
55

6-
public class BuildScript : IPreprocessBuildWithReport, IPostprocessBuildWithReport
6+
namespace Rivet
77
{
8-
public int callbackOrder { get { return 0; } }
9-
10-
public void OnPreprocessBuild(BuildReport report)
8+
public class BuildScript : IPreprocessBuildWithReport, IPostprocessBuildWithReport
119
{
12-
// Check if StreamingAssets folder exists and create it if it doesn't
13-
string streamingAssetsPath = Application.streamingAssetsPath;
14-
if (!Directory.Exists(streamingAssetsPath))
15-
{
16-
Directory.CreateDirectory(streamingAssetsPath);
17-
}
10+
public int callbackOrder { get { return 0; } }
1811

19-
// If either is null, add a build error
20-
if (string.IsNullOrEmpty(ExtensionData.ApiEndpoint))
12+
public void OnPreprocessBuild(BuildReport report)
2113
{
22-
Debug.LogError("Rivet API endpoint is not set. Please set the API endpoint in the Rivet settings.");
23-
}
14+
// Check if StreamingAssets folder exists and create it if it doesn't
15+
string streamingAssetsPath = Application.streamingAssetsPath;
16+
if (!Directory.Exists(streamingAssetsPath))
17+
{
18+
Directory.CreateDirectory(streamingAssetsPath);
19+
}
2420

25-
if (string.IsNullOrEmpty(ExtensionData.RivetToken))
26-
{
27-
Debug.LogError("Rivet token is not set. Please set the Rivet token in the Rivet settings.");
28-
}
21+
// If either is null, add a build error
22+
if (string.IsNullOrEmpty(ExtensionData.ApiEndpoint))
23+
{
24+
Debug.LogError("Rivet API endpoint is not set. Please set the API endpoint in the Rivet settings.");
25+
}
2926

30-
// Create the asset file before the build
31-
RivetSettings data = new RivetSettings
32-
{
33-
ApiEndpoint = ExtensionData.ApiEndpoint,
34-
RivetToken = ExtensionData.RivetToken
35-
};
27+
if (string.IsNullOrEmpty(ExtensionData.RivetToken))
28+
{
29+
Debug.LogError("Rivet token is not set. Please set the Rivet token in the Rivet settings.");
30+
}
3631

37-
string json = JsonUtility.ToJson(data);
38-
string filePath = Path.Combine(Application.streamingAssetsPath, "rivet_export.json");
39-
File.WriteAllText(filePath, json);
40-
}
32+
// Create the asset file before the build
33+
RivetSettings data = new RivetSettings
34+
{
35+
ApiEndpoint = ExtensionData.ApiEndpoint,
36+
RivetToken = ExtensionData.RivetToken
37+
};
4138

42-
public void OnPostprocessBuild(BuildReport report)
43-
{
44-
// Delete the asset file after the build
45-
string filePath = Path.Combine(Application.streamingAssetsPath, "rivet_export.json");
46-
if (File.Exists(filePath))
39+
string json = JsonUtility.ToJson(data);
40+
string filePath = Path.Combine(Application.streamingAssetsPath, "rivet_export.json");
41+
File.WriteAllText(filePath, json);
42+
}
43+
44+
public void OnPostprocessBuild(BuildReport report)
4745
{
48-
File.Delete(filePath);
46+
// Delete the asset file after the build
47+
string filePath = Path.Combine(Application.streamingAssetsPath, "rivet_export.json");
48+
if (File.Exists(filePath))
49+
{
50+
File.Delete(filePath);
51+
}
4952
}
5053
}
51-
}
54+
}

Assets/Rivet/Editor/Result.cs

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,101 @@
11
using System;
22
using System.Collections.Generic;
33

4-
// https://josef.codes/my-take-on-the-result-class-in-c-sharp/
5-
public abstract class Result
4+
namespace Rivet
65
{
7-
public bool Success { get; protected set; }
8-
public bool Failure => !Success;
9-
}
10-
11-
public abstract class Result<T> : Result
12-
{
13-
private T _data;
14-
15-
protected Result(T data)
6+
// https://josef.codes/my-take-on-the-result-class-in-c-sharp/
7+
public abstract class Result
168
{
17-
Data = data;
9+
public bool Success { get; protected set; }
10+
public bool Failure => !Success;
1811
}
1912

20-
public T Data
13+
public abstract class Result<T> : Result
2114
{
22-
get => Success ? _data : throw new Exception($"You can't access .{nameof(Data)} when .{nameof(Success)} is false");
23-
set => _data = value;
15+
private T _data;
16+
17+
protected Result(T data)
18+
{
19+
Data = data;
20+
}
21+
22+
public T Data
23+
{
24+
get => Success ? _data : throw new Exception($"You can't access .{nameof(Data)} when .{nameof(Success)} is false");
25+
set => _data = value;
26+
}
2427
}
25-
}
2628

27-
public class SuccessResult : Result
28-
{
29-
public SuccessResult()
29+
public class SuccessResult : Result
3030
{
31-
Success = true;
31+
public SuccessResult()
32+
{
33+
Success = true;
34+
}
3235
}
33-
}
3436

35-
public class SuccessResult<T> : Result<T>
36-
{
37-
public SuccessResult(T data) : base(data)
37+
public class SuccessResult<T> : Result<T>
3838
{
39-
Success = true;
39+
public SuccessResult(T data) : base(data)
40+
{
41+
Success = true;
42+
}
4043
}
41-
}
4244

43-
public class ErrorResult : Result, IErrorResult
44-
{
45-
public ErrorResult(string message) : this(message, Array.Empty<Error>())
45+
public class ErrorResult : Result, IErrorResult
4646
{
47+
public ErrorResult(string message) : this(message, Array.Empty<Error>())
48+
{
49+
}
50+
51+
public ErrorResult(string message, IReadOnlyCollection<Error> errors)
52+
{
53+
Message = message;
54+
Success = false;
55+
Errors = errors ?? Array.Empty<Error>();
56+
}
57+
58+
public string Message { get; }
59+
public IReadOnlyCollection<Error> Errors { get; }
4760
}
4861

49-
public ErrorResult(string message, IReadOnlyCollection<Error> errors)
62+
public class ErrorResult<T> : Result<T>, IErrorResult
5063
{
51-
Message = message;
52-
Success = false;
53-
Errors = errors ?? Array.Empty<Error>();
54-
}
55-
56-
public string Message { get; }
57-
public IReadOnlyCollection<Error> Errors { get; }
58-
}
59-
60-
public class ErrorResult<T> : Result<T>, IErrorResult
61-
{
62-
public ErrorResult(string message) : this(message, Array.Empty<Error>())
63-
{
64+
public ErrorResult(string message) : this(message, Array.Empty<Error>())
65+
{
66+
}
67+
68+
public ErrorResult(string message, IReadOnlyCollection<Error> errors) : base(default)
69+
{
70+
Message = message;
71+
Success = false;
72+
Errors = errors ?? Array.Empty<Error>();
73+
}
74+
75+
public string Message { get; set; }
76+
public IReadOnlyCollection<Error> Errors { get; }
6477
}
6578

66-
public ErrorResult(string message, IReadOnlyCollection<Error> errors) : base(default)
79+
public class Error
6780
{
68-
Message = message;
69-
Success = false;
70-
Errors = errors ?? Array.Empty<Error>();
71-
}
81+
public Error(string details) : this(null, details)
82+
{
7283

73-
public string Message { get; set; }
74-
public IReadOnlyCollection<Error> Errors { get; }
75-
}
84+
}
7685

77-
public class Error
78-
{
79-
public Error(string details) : this(null, details)
80-
{
86+
public Error(string code, string details)
87+
{
88+
Code = code;
89+
Details = details;
90+
}
8191

92+
public string Code { get; }
93+
public string Details { get; }
8294
}
8395

84-
public Error(string code, string details)
96+
internal interface IErrorResult
8597
{
86-
Code = code;
87-
Details = details;
98+
string Message { get; }
99+
IReadOnlyCollection<Error> Errors { get; }
88100
}
89-
90-
public string Code { get; }
91-
public string Details { get; }
92-
}
93-
94-
internal interface IErrorResult
95-
{
96-
string Message { get; }
97-
IReadOnlyCollection<Error> Errors { get; }
98-
}
101+
}

0 commit comments

Comments
 (0)