#include "scriptdocument.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "mainwindow.h" #include "objects/script.h" #include "datatypes/variant.h" #include #include QsciAPIs* makeApis(QsciLexer*); inline bool isDarkMode() { // https://stackoverflow.com/a/78854851/16255372 #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0) const auto scheme = QGuiApplication::styleHints()->colorScheme(); return scheme == Qt::ColorScheme::Dark; #else const QPalette defaultPalette; const auto text = defaultPalette.color(QPalette::WindowText); const auto window = defaultPalette.color(QPalette::Window); return text.lightness() > window.lightness(); #endif // QT_VERSION } std::map DARK_MODE_COLOR_SCHEME = {{ {QsciLexerLua::Comment, QColor("#808080")}, {QsciLexerLua::LineComment, QColor("#808080")}, {QsciLexerLua::Number, QColor("#6897BB")}, {QsciLexerLua::Keyword, QColor("#CC7832")}, {QsciLexerLua::String, QColor("#6A8759")}, {QsciLexerLua::Character, QColor("#6A8759")}, {QsciLexerLua::LiteralString, QColor("#6A8759")}, {QsciLexerLua::Preprocessor, QColor("#FF00FF")}, // Obsolete since Lua 4.0, but whatever {QsciLexerLua::Operator, QColor("#FFFFFF")}, {QsciLexerLua::Identifier, QColor("#FFFFFF")}, {QsciLexerLua::UnclosedString, QColor("#6A8759")}, {QsciLexerLua::BasicFunctions, QColor("#CC7832")}, {QsciLexerLua::StringTableMathsFunctions, QColor("#CC7832")}, {QsciLexerLua::CoroutinesIOSystemFacilities, QColor("#CC7832")}, {QsciLexerLua::Label, QColor("#FFFFFF")}, }}; class ObLuaLexer : public QsciLexerLua { const char * keywords(int set) const override { // Taken from qscilexerlua.cpp if (set == 1) // Keywords. return "and break do else elseif end false for function if " "in local nil not or repeat return then true until " "while"; if (set == 2) // Basic functions. return //"foreach foreachi getn " // Openblocks extensions "shared require game workspace " "_G _VERSION getfenv getmetatable ipairs loadstring " "next pairs pcall rawequal rawget rawset select " "setfenv setmetatable xpcall string table tonumber " "tostring type math newproxy coroutine io os"; if (set == 3) // String, table and maths functions. return // "abs acos asin atan atan2 ceil cos deg exp floor " // "format frexp gsub ldexp log log10 max min mod rad " // "random randomseed sin sqrt tan " "string.byte string.char string.dump string.find " "string.len string.lower string.rep string.sub " "string.upper string.format string.gfind string.gsub " "table.concat table.foreach table.foreachi table.getn " "table.sort table.insert table.remove table.setn " "math.abs math.acos math.asin math.atan math.atan2 " "math.ceil math.cos math.deg math.exp math.floor " "math.frexp math.ldexp math.log math.log10 math.max " "math.min math.mod math.pi math.rad math.random " "math.randomseed math.sin math.sqrt math.tan"; if (set == 4) // Coroutine, I/O and system facilities. return // "clock date difftime time " "coroutine.create coroutine.resume coroutine.status " "coroutine.wrap coroutine.yield os.clock os.date " "os.difftime os.time"; return 0; }; }; ScriptDocument::ScriptDocument(std::shared_ptr