-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TactFile.cs
70 lines (61 loc) · 2.3 KB
/
TactFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.IO;
using MelonLoader;
namespace GbHapticsIntegration
{
internal class TactFile
{
private string Identifier;
internal void Register(string identifier, string filename, string folderpath, string DefaultResourcesName)
{
Identifier = identifier;
string FolderPath = Path.Combine(GbHapticsIntegration.BaseUserDataDirectory, folderpath);
if (!Directory.Exists(FolderPath))
Directory.CreateDirectory(FolderPath);
string filepath = Path.Combine(FolderPath, filename);
try
{
#if DEBUG
bool is_file = true;
#endif
string json = null;
if (File.Exists(filepath))
{
json = File.ReadAllText(filepath);
if (string.IsNullOrEmpty(json))
throw new Exception($"Failed to Read JSON from File!");
}
else
{
#if DEBUG
is_file = false;
#endif
json = Properties.Resources.ResourceManager.GetString(DefaultResourcesName);
if (string.IsNullOrEmpty(json))
throw new Exception($"Failed to Read Default JSON ({DefaultResourcesName}) from Resources!");
}
bHaptics.RegisterFeedbackFromTactFile(Identifier, json);
#if DEBUG
Debug.LogTactFileRegister(Identifier, filepath, is_file);
#endif
}
catch (Exception ex)
{
GbHapticsIntegration.Logger.Error($"Failed to Register bHaptics Pattern [{Identifier}]\nfrom TactFile [{filepath}]:\n{ex}");
}
}
internal void Play()
=> Play(new bHaptics.ScaleOption());
internal void Play(bHaptics.ScaleOption scaleOption)
=> Play(scaleOption, new bHaptics.RotationOption(0, 0));
internal void Play(bHaptics.ScaleOption scaleOption, bHaptics.RotationOption rotationOption)
{
bHaptics.SubmitRegistered(Identifier, Identifier, scaleOption, rotationOption);
#if DEBUG
Debug.LogTactFilePlayback(Identifier, scaleOption, rotationOption);
#endif
}
internal bool IsPlaying()
=> bHaptics.IsPlaying(Identifier);
}
}