Phosphor
Qt6 / Wayland library suite for window-management tools
 
Loading...
Searching...
No Matches
ScriptedAlgorithmLoader.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <phosphortiles_export.h>
8#include <QByteArray>
9#include <QHash>
10#include <QObject>
11#include <QString>
12
13#include <memory>
14
15namespace PhosphorScripting {
16class LuauEngine;
17class LuauWatchdog;
18}
19
20namespace PhosphorTiles {
21
22class ITileAlgorithmRegistry;
23
41class PHOSPHORTILES_EXPORT ScriptedAlgorithmLoader : public QObject
42{
43 Q_OBJECT
44
45public:
57 explicit ScriptedAlgorithmLoader(const QString& subdirectory, ITileAlgorithmRegistry* registry,
58 QObject* parent = nullptr);
60
85
90
97 QString userAlgorithmDir() const;
98
99Q_SIGNALS:
104
105private:
106 class LuauScanStrategy;
107 QStringList performScan(const QStringList& directoriesInScanOrder);
108
109 void loadFromDirectory(const QString& dir, bool isUserDir, const QString& canonicalUserDir);
110 QStringList algorithmDirectories() const;
111 QStringList validatedLuauFiles(const QString& dirPath, int maxFiles) const;
112
116 std::shared_ptr<PhosphorScripting::LuauEngine> ensureSharedEngine();
117
118 QString m_subdirectory;
119 ITileAlgorithmRegistry* m_registry = nullptr;
130 std::shared_ptr<PhosphorScripting::LuauWatchdog> m_watchdog;
137 std::shared_ptr<PhosphorScripting::LuauEngine> m_sharedEngine;
138 bool m_sharedEngineFailed = false;
139 std::unique_ptr<LuauScanStrategy> m_strategy;
140 std::unique_ptr<PhosphorFsLoader::WatchedDirectorySet> m_watcher;
141 QHash<QString, QString> m_scriptIdToPath;
148 QByteArray m_lastScriptSignature;
149};
150
151} // namespace PhosphorTiles
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Discovers, loads, and hot-reloads LuauTileAlgorithm instances.
Definition ScriptedAlgorithmLoader.h:42
void ensureUserDirectoryExists()
Create the user algorithm directory if it does not exist.
QString userAlgorithmDir() const
Writable user directory path for custom algorithms.
void algorithmsChanged()
Emitted after any add/remove/reload of scripted algorithms.
void scanAndRegister(PhosphorFsLoader::LiveReload liveReload=PhosphorFsLoader::LiveReload::On)
Discover and load all .luau algorithms from system + user dirs.
ScriptedAlgorithmLoader(const QString &subdirectory, ITileAlgorithmRegistry *registry, QObject *parent=nullptr)
Construct a loader for subdirectory under XDG data dirs.
LiveReload
Opt-in policy for directory watching.
Definition WatchedDirectorySet.h:34
Definition LuauTileAlgorithm.h:16
Definition AutotileEngine.h:46