code format
This commit is contained in:
parent
3fdedb6240
commit
4610e71f42
@ -14,19 +14,19 @@ class Context
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
int contextId;
|
int contextId;
|
||||||
QString* source;
|
QString *source;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Driver* driver = NativeDriver::getInstance();
|
Driver *driver = NativeDriver::getInstance();
|
||||||
|
|
||||||
Context(int contextId, QString* source) {
|
Context(int contextId, QString *source) {
|
||||||
this->contextId = contextId;
|
this->contextId = contextId;
|
||||||
this->source = source;
|
this->source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
void show() {
|
void show() {
|
||||||
QString* method = new QString(Constant::DORIC_ENTITY_SHOW);
|
QString *method = new QString(Constant::DORIC_ENTITY_SHOW);
|
||||||
QVector<QString*>* arguments = new QVector<QString*>();
|
QVector<QString*> *arguments = new QVector<QString*>();
|
||||||
|
|
||||||
driver->invokeContextEntityMethod(contextId, method, nullptr);
|
driver->invokeContextEntityMethod(contextId, method, nullptr);
|
||||||
|
|
||||||
@ -35,12 +35,12 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void init(double width, double height) {
|
void init(double width, double height) {
|
||||||
QJsonObject* jsonObject = new QJsonObject();
|
QJsonObject *jsonObject = new QJsonObject();
|
||||||
jsonObject->insert("width", width);
|
jsonObject->insert("width", width);
|
||||||
jsonObject->insert("height", height);
|
jsonObject->insert("height", height);
|
||||||
|
|
||||||
QString* method = new QString(Constant::DORIC_ENTITY_INIT);
|
QString *method = new QString(Constant::DORIC_ENTITY_INIT);
|
||||||
QVariant* variant = new QVariant();
|
QVariant *variant = new QVariant();
|
||||||
variant->setValue(*jsonObject);
|
variant->setValue(*jsonObject);
|
||||||
|
|
||||||
driver->invokeContextEntityMethod(contextId, method, variant, nullptr);
|
driver->invokeContextEntityMethod(contextId, method, variant, nullptr);
|
||||||
|
@ -15,8 +15,8 @@ void NativeDriver::destroyContext(int contextId) {
|
|||||||
jsEngine->destroyContext(contextId);
|
jsEngine->destroyContext(contextId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeDriver::invokeContextEntityMethod(int contextId, QString* method, ...) {
|
void NativeDriver::invokeContextEntityMethod(int contextId, QString *method, ...) {
|
||||||
QJSValueList* arguments = new QJSValueList();
|
QJSValueList *arguments = new QJSValueList();
|
||||||
arguments->append(QJSValue(QString::number(contextId)));
|
arguments->append(QJSValue(QString::number(contextId)));
|
||||||
arguments->append(QJSValue(*method));
|
arguments->append(QJSValue(*method));
|
||||||
|
|
||||||
@ -25,8 +25,8 @@ void NativeDriver::invokeContextEntityMethod(int contextId, QString* method, ...
|
|||||||
auto argument = va_arg(vaList, QVariant*);
|
auto argument = va_arg(vaList, QVariant*);
|
||||||
while (argument != nullptr) {
|
while (argument != nullptr) {
|
||||||
if (QString(typeid(QJsonObject).name()).contains(QString(argument->typeName()))) {
|
if (QString(typeid(QJsonObject).name()).contains(QString(argument->typeName()))) {
|
||||||
QJsonObject* jsonObject = static_cast<QJsonObject*>(argument->data());
|
QJsonObject *jsonObject = static_cast<QJsonObject*>(argument->data());
|
||||||
QJsonValue* jsonValue = new QJsonValue(*jsonObject);
|
QJsonValue *jsonValue = new QJsonValue(*jsonObject);
|
||||||
QJSValue jsValue = Utility::convert(jsEngine->engine, *jsonValue);
|
QJSValue jsValue = Utility::convert(jsEngine->engine, *jsonValue);
|
||||||
delete jsonValue;
|
delete jsonValue;
|
||||||
arguments->append(jsValue);
|
arguments->append(jsValue);
|
||||||
|
@ -44,10 +44,10 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NativeLog* nativeLog = new NativeLog();
|
NativeLog *nativeLog = new NativeLog();
|
||||||
NativeTimer* nativeTimer = new NativeTimer(engine);
|
NativeTimer *nativeTimer = new NativeTimer(engine);
|
||||||
NativeEmpty* nativeEmpty = new NativeEmpty();
|
NativeEmpty *nativeEmpty = new NativeEmpty();
|
||||||
NativeBridge* nativeBridge = new NativeBridge();
|
NativeBridge *nativeBridge = new NativeBridge();
|
||||||
|
|
||||||
void initJSEngine() {
|
void initJSEngine() {
|
||||||
engine->installExtensions(QJSEngine::AllExtensions);
|
engine->installExtensions(QJSEngine::AllExtensions);
|
||||||
|
@ -29,7 +29,7 @@ int main(int argc, char *argv[])
|
|||||||
file->close();
|
file->close();
|
||||||
delete file;
|
delete file;
|
||||||
|
|
||||||
QString* source = new QString("Snake.js");
|
QString *source = new QString("Snake.js");
|
||||||
Context *context = ContextManager::getInstance()->createContext(&script, source);
|
Context *context = ContextManager::getInstance()->createContext(&script, source);
|
||||||
context->show();
|
context->show();
|
||||||
context->init(180, 320);
|
context->init(180, 320);
|
||||||
|
@ -7,5 +7,5 @@ Q_INVOKABLE void NativeBridge::function(int contextId, QString module, QString m
|
|||||||
"methodName: " + methodName + ", " +
|
"methodName: " + methodName + ", " +
|
||||||
"callbackId: " + callbackId + ", " +
|
"callbackId: " + callbackId + ", " +
|
||||||
"arguments: " + jsValue.toString();
|
"arguments: " + jsValue.toString();
|
||||||
Context* context = ContextManager::getInstance()->getContext(contextId);
|
Context *context = ContextManager::getInstance()->getContext(contextId);
|
||||||
}
|
}
|
||||||
|
@ -13,15 +13,15 @@ class NativeTimer : public QObject {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QSet<long> *deletedTimerIds = new QSet<long>();
|
QSet<long> *deletedTimerIds = new QSet<long>();
|
||||||
QJSEngine* engine;
|
QJSEngine *engine;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NativeTimer(QJSEngine* engine, QObject *parent = nullptr) : QObject(parent) {
|
NativeTimer(QJSEngine *engine, QObject *parent = nullptr) : QObject(parent) {
|
||||||
this->engine = engine;
|
this->engine = engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat) {
|
Q_INVOKABLE void setTimer(long timerId, int time, bool repeat) {
|
||||||
QTimer* timer = new QTimer(this);
|
QTimer *timer = new QTimer(this);
|
||||||
timer->setSingleShot(!repeat);
|
timer->setSingleShot(!repeat);
|
||||||
connect(timer, &QTimer::timeout, this, [=] () {
|
connect(timer, &QTimer::timeout, this, [=] () {
|
||||||
if (deletedTimerIds->contains(timerId)) {
|
if (deletedTimerIds->contains(timerId)) {
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
class ShaderPlugin : public ContextHolder {
|
class ShaderPlugin : public ContextHolder {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShaderPlugin(Context* context) : ContextHolder(context) {}
|
ShaderPlugin(Context *context) : ContextHolder(context) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SHADER_PLUGIN_H
|
#endif // SHADER_PLUGIN_H
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
class Utility {
|
class Utility {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static QJSValue convert(QJSEngine* jsEngine, QJsonValue jsonValue) {
|
static QJSValue convert(QJSEngine *jsEngine, QJsonValue jsonValue) {
|
||||||
if (jsonValue.isBool()) {
|
if (jsonValue.isBool()) {
|
||||||
return QJSValue(jsonValue.toBool());
|
return QJSValue(jsonValue.toBool());
|
||||||
} else if (jsonValue.isString()) {
|
} else if (jsonValue.isString()) {
|
||||||
|
Reference in New Issue
Block a user