Overte C++ Documentation
ScriptMessage.h
1 //
2 // ScriptMessage.h
3 // libraries/script-engine/src/v8/FastScriptValueUtils.cpp
4 //
5 // Created by dr Karol Suprynowicz on 2023/09/24.
6 // Copyright 2023 Overte e.V.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef OVERTE_SCRIPTMESSAGE_H
13 #define OVERTE_SCRIPTMESSAGE_H
14 
15 // Used to store script messages on entity script server before transmitting them to clients who subscribed to them.
16 // EntityServerScriptLog packet type is used.
17 // In the future will also be used for storing assignment client script messages before transmission
18 
19 #include <QString>
20 #include <QJsonObject>
21 #include "EntityItemID.h"
22 
23 // SEVERITY_ERROR is defined as a macro in winerror.h
24 #undef SEVERITY_ERROR
25 
26 class ScriptMessage {
27 public:
28  enum class ScriptType {
29  TYPE_NONE,
30  TYPE_ENTITY_SCRIPT
31  };
32  enum class Severity {
33  SEVERITY_NONE,
34  SEVERITY_PRINT,
35  SEVERITY_INFO,
36  SEVERITY_DEBUG,
37  SEVERITY_WARNING,
38  SEVERITY_ERROR
39  };
40 
41  ScriptMessage() {};
42  ScriptMessage(const QString &messageContent, const QString &fileName, int lineNumber, const EntityItemID& entityID, ScriptType scriptType, Severity severity)
43  : _messageContent(messageContent), _fileName(fileName), _lineNumber(lineNumber), _entityID(entityID), _scriptType(scriptType), _severity(severity) {}
44 
45  QJsonObject toJson();
46  bool fromJson(const QJsonObject &object);
47 
48  QString getMessage() { return _messageContent; }
49  QString getFileName() { return _fileName; }
50  int getLineNumber() { return _lineNumber; }
51  ScriptType getScriptType() { return _scriptType; }
52  Severity getSeverity() { return _severity; }
53  EntityItemID getEntityID() { return _entityID; }
54 
55 private:
56  QString _messageContent;
57  QString _fileName;
58  int _lineNumber {-1};
59  EntityItemID _entityID;
60  ScriptType _scriptType {ScriptType::TYPE_NONE};
61  Severity _severity {Severity::SEVERITY_NONE};
62 };
63 
64 #endif //OVERTE_SCRIPTMESSAGE_H
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28