Skip to content

Commit

Permalink
Use separate plugins folder for lua scripts
Browse files Browse the repository at this point in the history
[CI BUILD]
  • Loading branch information
andybak committed Jul 4, 2023
1 parent 88e3935 commit 14ee747
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Assets/Editor/LuaDocsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static void GenerateDocs()
LuaManager.Instance.CopyLuaModules(); // Update the copy in User docs (also done on app start)

// Generate markdown docs
string docsPath = Path.Join(ApiManager.Instance.UserScriptsPath(), "LuaDocs");
string docsPath = Path.Join(LuaManager.Instance.UserPluginsPath(), "LuaDocs");
if (!Directory.Exists(docsPath)) Directory.CreateDirectory(docsPath);
foreach (var klass in LuaDocsRegistration.ApiDocClasses)
{
Expand Down
18 changes: 13 additions & 5 deletions Assets/Scripts/API/Lua/LuaManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public class LuaManager : MonoBehaviour
private static LuaManager m_Instance;
private ApiManager apiManager;
private static readonly string LuaFileSearchPattern = "*.lua";
private string m_UserPluginsPath;

public string UserPluginsPath() { return m_UserPluginsPath; }

public List<LuaApiCategory> ApiCategories => Enum.GetValues(typeof(LuaApiCategory)).Cast<LuaApiCategory>().ToList();
public int ScriptedWaveformSampleRate = 16000;
Expand All @@ -99,7 +102,7 @@ public class LuaManager : MonoBehaviour

private LinkedList<LuaWebRequest> m_WebRequests;

public string LuaModulesPath => Path.Join(ApiManager.Instance.UserScriptsPath(), "LuaModules");
public string LuaModulesPath => Path.Join(UserPluginsPath(), "LuaModules");

public struct ScriptTrTransform
{
Expand All @@ -116,6 +119,11 @@ public ScriptTrTransform(TrTransform transform, ScriptCoordSpace space)
void Awake()
{
m_Instance = this;
m_UserPluginsPath = Path.Combine(App.UserPath(), "Plugins");
if (!Directory.Exists(m_UserPluginsPath))
{
Directory.CreateDirectory(m_UserPluginsPath);
}
Init();
}

Expand Down Expand Up @@ -161,9 +169,9 @@ public void Init()
ConfigureScriptButton(LuaApiCategory.SymmetryScript);
ConfigureScriptButton(LuaApiCategory.ToolScript);

if (Directory.Exists(ApiManager.Instance.UserScriptsPath()))
if (Directory.Exists(UserPluginsPath()))
{
m_FileWatcher = new FileWatcher(ApiManager.Instance.UserScriptsPath(), "*.lua");
m_FileWatcher = new FileWatcher(UserPluginsPath(), "*.lua");
m_FileWatcher.NotifyFilter = NotifyFilters.LastWrite;
m_FileWatcher.FileChanged += OnScriptsDirectoryChanged;
m_FileWatcher.FileCreated += OnScriptsDirectoryChanged;
Expand Down Expand Up @@ -304,7 +312,7 @@ private void Update()

public void LoadUserScripts()
{
string[] files = Directory.GetFiles(ApiManager.Instance.UserScriptsPath(), LuaFileSearchPattern, SearchOption.AllDirectories);
string[] files = Directory.GetFiles(UserPluginsPath(), LuaFileSearchPattern, SearchOption.AllDirectories);
foreach (string scriptPath in files)
{
LoadScriptFromPath(scriptPath);
Expand Down Expand Up @@ -961,7 +969,7 @@ public bool CopyActiveScriptToUserScriptFolder(LuaApiCategory category)
public bool CopyScriptToUserScriptFolder(LuaApiCategory category, string scriptName)
{
var originalFilename = $"{category}.{scriptName}";
var newFilename = Path.Join(ApiManager.Instance.UserScriptsPath(), $"{originalFilename}.lua");
var newFilename = Path.Join(UserPluginsPath(), $"{originalFilename}.lua");
if (!File.Exists(newFilename))
{
FileUtils.WriteTextFromResources($"LuaScriptExamples/{originalFilename}", newFilename);
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/API/Lua/Wrappers/AppApiWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static string ReadFile(string path)
valid = !Path.IsPathRooted(path);
if (valid)
{
path = Path.Join(ApiManager.Instance.UserScriptsPath(), path);
path = Path.Join(LuaManager.Instance.UserPluginsPath(), path);
// Check path is a subdirectory of User folder
valid = _IsSubdirectory(path, App.UserPath());
}
Expand Down
12 changes: 11 additions & 1 deletion Assets/Scripts/Sharing/DriveSync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,17 @@ private async Task SetupSyncFoldersAsync(CancellationToken token)
SyncedFolderType.Scripts,
token,
recursive: true,
includeExtensions: new[] { ".lua", ".html" }));
includeExtensions: new[] { ".html" }));

folderSyncs.Add(AddSyncedFolderAsync(
"Plugins",
LuaManager.Instance.UserPluginsPath(),
deviceRootId,
SyncType.UploadAndDownload,
SyncedFolderType.Scripts,
token,
recursive: true,
includeExtensions: new[] { ".lua" }));
}

if (!App.Config.IsMobileHardware)
Expand Down

0 comments on commit 14ee747

Please sign in to comment.