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>
7
9
10#include <QByteArray>
11#include <QHash>
12#include <QObject>
13#include <QSet>
14#include <QString>
15#include <QStringList>
16
17#include <memory>
18
19namespace PhosphorScripting {
20class LuauEngine;
21class LuauWatchdog;
22}
23
24namespace PhosphorTiles {
25
26class ITileAlgorithmRegistry;
27
49class PHOSPHORTILES_EXPORT ScriptedAlgorithmLoader : public QObject
50{
51 Q_OBJECT
52
53public:
60 static constexpr int MaxWatchedFilesPerDir = 100;
61
68 static constexpr int MaxScripts = 10'000;
69
81 explicit ScriptedAlgorithmLoader(const QString& subdirectory, ITileAlgorithmRegistry* registry,
82 QObject* parent = nullptr);
84
116
121
128 QString userAlgorithmDir() const;
129
130Q_SIGNALS:
135
136private:
137 class LuauScanStrategy;
138 QStringList performScan(const QStringList& directoriesInScanOrder);
139
143 struct ScriptStamp
144 {
145 QString id;
146 qint64 size = -1;
147 qint64 mtimeMs = -1;
154 bool isUser = false;
155 };
156
157 void loadFromDirectory(const QString& dir, bool isUserDir, const QString& canonicalUserDir,
158 const QHash<QString, ScriptStamp>& prevStamps);
159 QStringList algorithmDirectories() const;
160 QStringList validatedLuauFiles(const QString& dirPath, int maxFiles) const;
161
165 std::shared_ptr<PhosphorScripting::LuauEngine> ensureSharedEngine();
166
167 QString m_subdirectory;
168 ITileAlgorithmRegistry* m_registry = nullptr;
179 std::shared_ptr<PhosphorScripting::LuauWatchdog> m_watchdog;
186 std::shared_ptr<PhosphorScripting::LuauEngine> m_sharedEngine;
187 bool m_sharedEngineFailed = false;
188 std::unique_ptr<LuauScanStrategy> m_strategy;
189 std::unique_ptr<PhosphorFsLoader::WatchedDirectorySet> m_watcher;
190 QHash<QString, QString> m_scriptIdToPath;
196 QSet<QString> m_refusedFilePaths;
205 QHash<QString, ScriptStamp> m_scriptStamps;
212 QByteArray m_lastScriptSignature;
213};
214
215} // namespace PhosphorTiles
Abstract contract for a tiling-algorithm registry.
Definition ITileAlgorithmRegistry.h:41
Discovers, loads, and hot-reloads LuauTileAlgorithm instances.
Definition ScriptedAlgorithmLoader.h:50
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:17
Definition AutotileEngine.h:59