April 2018
Beginner
714 pages
18h 21m
English
Before we move on to executing the players' scripts, we need to create a QJSEngine and insert some information into its global object. The scripts will use this information to decide the optimal move.
First, we add the QJSEngine m_jsEngine private field to the Scene class. Next, we create a new SceneProxy class and derive it from QObject. This class will expose the permitted API of Scene to the scripts. We pass a pointer to the Scene object to the constructor of the SceneProxy object and store it in a private variable:
SceneProxy::SceneProxy(Scene *scene) :
QObject(scene), m_scene(scene)
{
}
Add two invokable methods to the class declaration:
Q_INVOKABLE QSize size() const; Q_INVOKABLE ...
Read now
Unlock full access