mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-04 10:13:12 +02:00
scripts save on exit and load on entry
This commit is contained in:
parent
19793a9a4a
commit
0eed041deb
6 changed files with 69 additions and 19 deletions
|
@ -232,6 +232,7 @@ Application::Application(int& argc, char** argv, timeval &startup_time) :
|
|||
_window->setCentralWidget(_glWidget);
|
||||
|
||||
restoreSizeAndPosition();
|
||||
loadScripts();
|
||||
_window->setVisible(true);
|
||||
_glWidget->setFocusPolicy(Qt::StrongFocus);
|
||||
_glWidget->setFocus();
|
||||
|
@ -270,7 +271,7 @@ Application::~Application() {
|
|||
_audio.thread()->wait();
|
||||
|
||||
storeSizeAndPosition();
|
||||
|
||||
saveScripts();
|
||||
_sharedVoxelSystem.changeTree(new VoxelTree);
|
||||
|
||||
VoxelTreeElement::removeDeleteHook(&_voxels); // we don't need to do this processing on shutdown
|
||||
|
@ -4237,13 +4238,38 @@ void Application::packetSentNotification(ssize_t length) {
|
|||
_bandwidthMeter.outputStream(BandwidthMeter::VOXELS).updateValue(length);
|
||||
}
|
||||
|
||||
void Application::loadScript() {
|
||||
// shut down and stop any existing script
|
||||
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
QString suggestedName = desktopLocation.append("/script.js");
|
||||
void Application::loadScripts(){
|
||||
// loads all saved scripts
|
||||
QSettings* settings = new QSettings(this);
|
||||
int size = settings->beginReadArray("Settings");
|
||||
for(int i=0; i<size; ++i){
|
||||
settings->setArrayIndex(i);
|
||||
QString string = settings->value("script").toString();
|
||||
loadScript(string);
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName,
|
||||
tr("JavaScript Files (*.js)"));
|
||||
}
|
||||
|
||||
void Application::saveScripts(){
|
||||
// saves all current running scripts
|
||||
QSettings* settings = new QSettings(this);
|
||||
settings->beginWriteArray("Settings");
|
||||
for(int i=0; i<_activeScripts.size(); ++i){
|
||||
settings->setArrayIndex(i);
|
||||
settings->setValue("script", _activeScripts.at(i));
|
||||
}
|
||||
settings->endArray();
|
||||
|
||||
}
|
||||
|
||||
void Application::removeScriptName(const QString& fileNameString)
|
||||
{
|
||||
_activeScripts.removeOne(fileNameString);
|
||||
}
|
||||
|
||||
void Application::loadScript(const QString& fileNameString){
|
||||
_activeScripts.append(fileNameString);
|
||||
QByteArray fileNameAscii = fileNameString.toLocal8Bit();
|
||||
const char* fileName = fileNameAscii.data();
|
||||
|
||||
|
@ -4270,9 +4296,7 @@ void Application::loadScript() {
|
|||
// start the script on a new thread...
|
||||
bool wantMenuItems = true; // tells the ScriptEngine object to add menu items for itself
|
||||
|
||||
|
||||
ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(),
|
||||
&_controllerScriptingInterface);
|
||||
ScriptEngine* scriptEngine = new ScriptEngine(script, wantMenuItems, fileName, Menu::getInstance(), &_controllerScriptingInterface);
|
||||
scriptEngine->setupMenuItems();
|
||||
|
||||
// setup the packet senders and jurisdiction listeners of the script engine's scripting interfaces so
|
||||
|
@ -4286,8 +4310,9 @@ void Application::loadScript() {
|
|||
connect(workerThread, SIGNAL(started()), scriptEngine, SLOT(run()));
|
||||
|
||||
// when the thread is terminated, add both scriptEngine and thread to the deleteLater queue
|
||||
connect(scriptEngine, SIGNAL(finished()), scriptEngine, SLOT(deleteLater()));
|
||||
connect(scriptEngine, SIGNAL(finished(const QString&)), scriptEngine, SLOT(deleteLater()));
|
||||
connect(workerThread, SIGNAL(finished()), workerThread, SLOT(deleteLater()));
|
||||
connect(scriptEngine, SIGNAL(finished(const QString&)), this, SLOT(removeScriptName(const QString&)));
|
||||
|
||||
// when the application is about to quit, stop our script engine so it unwinds properly
|
||||
connect(this, SIGNAL(aboutToQuit()), scriptEngine, SLOT(stop()));
|
||||
|
@ -4301,6 +4326,17 @@ void Application::loadScript() {
|
|||
_window->activateWindow();
|
||||
}
|
||||
|
||||
void Application::loadDialog() {
|
||||
// shut down and stop any existing script
|
||||
QString desktopLocation = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
|
||||
QString suggestedName = desktopLocation.append("/script.js");
|
||||
|
||||
QString fileNameString = QFileDialog::getOpenFileName(_glWidget, tr("Open Script"), suggestedName,
|
||||
tr("JavaScript Files (*.js)"));
|
||||
|
||||
loadScript(fileNameString);
|
||||
}
|
||||
|
||||
void Application::toggleLogDialog() {
|
||||
if (! _logDialog) {
|
||||
_logDialog = new LogDialog(_glWidget, getLogger());
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <QSettings>
|
||||
#include <QTouchEvent>
|
||||
#include <QList>
|
||||
#include <QStringList>
|
||||
#include <QPointer>
|
||||
|
||||
#include <NetworkPacket.h>
|
||||
|
@ -103,7 +104,10 @@ public:
|
|||
~Application();
|
||||
|
||||
void restoreSizeAndPosition();
|
||||
void loadScript(const QString& fileNameString);
|
||||
void loadScripts();
|
||||
void storeSizeAndPosition();
|
||||
void saveScripts();
|
||||
void initializeGL();
|
||||
void paintGL();
|
||||
void resizeGL(int width, int height);
|
||||
|
@ -221,7 +225,7 @@ public slots:
|
|||
void doKillLocalVoxels();
|
||||
void decreaseVoxelSize();
|
||||
void increaseVoxelSize();
|
||||
void loadScript();
|
||||
void loadDialog();
|
||||
void toggleLogDialog();
|
||||
void initAvatarAndViewFrustum();
|
||||
|
||||
|
@ -250,6 +254,8 @@ private slots:
|
|||
void shrinkMirrorView();
|
||||
void resetSensors();
|
||||
|
||||
void removeScriptName(const QString& fileNameString);
|
||||
|
||||
private:
|
||||
void resetCamerasOnResizeGL(Camera& camera, int width, int height);
|
||||
void updateProjectionMatrix();
|
||||
|
@ -373,6 +379,7 @@ private:
|
|||
Faceshift _faceshift;
|
||||
|
||||
SixenseManager _sixenseManager;
|
||||
QStringList _activeScripts;
|
||||
|
||||
Camera _myCamera; // My view onto the world
|
||||
Camera _viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <QtCore/QObject>
|
||||
|
||||
#include <AbstractControllerScriptingInterface.h>
|
||||
class PalmData;
|
||||
|
||||
/// handles scripting of input controller commands from JS
|
||||
class ControllerScriptingInterface : public AbstractControllerScriptingInterface {
|
||||
|
|
|
@ -91,7 +91,7 @@ Menu::Menu() :
|
|||
SLOT(login())));
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Scripts");
|
||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadScript()));
|
||||
addActionToQMenuAndActionHash(fileMenu, MenuOption::LoadScript, Qt::CTRL | Qt::Key_O, appInstance, SLOT(loadDialog()));
|
||||
_activeScriptsMenu = fileMenu->addMenu("Running Scripts");
|
||||
|
||||
addDisabledActionAndSeparator(fileMenu, "Voxels");
|
||||
|
|
|
@ -38,17 +38,20 @@ static QScriptValue soundConstructor(QScriptContext* context, QScriptEngine* eng
|
|||
return soundScriptValue;
|
||||
}
|
||||
|
||||
ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems,
|
||||
const char* scriptMenuName, AbstractMenuInterface* menu,
|
||||
ScriptEngine::ScriptEngine(const QString& scriptContents, bool wantMenuItems, const QString& fileNameString, AbstractMenuInterface* menu,
|
||||
AbstractControllerScriptingInterface* controllerScriptingInterface) {
|
||||
_scriptContents = scriptContents;
|
||||
_isFinished = false;
|
||||
_isRunning = false;
|
||||
_isInitialized = false;
|
||||
_fileNameString = fileNameString;
|
||||
|
||||
QByteArray fileNameAscii = fileNameString.toLocal8Bit();
|
||||
const char* scriptMenuName = fileNameAscii.data();
|
||||
|
||||
// some clients will use these menu features
|
||||
_wantMenuItems = wantMenuItems;
|
||||
if (scriptMenuName) {
|
||||
if (!fileNameString.isEmpty()) {
|
||||
_scriptMenuName = "Stop ";
|
||||
_scriptMenuName.append(scriptMenuName);
|
||||
_scriptMenuName.append(QString(" [%1]").arg(_scriptNumber));
|
||||
|
@ -233,9 +236,11 @@ void ScriptEngine::run() {
|
|||
thread()->quit();
|
||||
}
|
||||
|
||||
emit finished();
|
||||
emit finished(_fileNameString);
|
||||
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
void ScriptEngine::stop() {
|
||||
_isFinished = true;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ class ScriptEngine : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
ScriptEngine(const QString& scriptContents = NO_SCRIPT, bool wantMenuItems = false,
|
||||
const char* scriptMenuName = NULL, AbstractMenuInterface* menu = NULL,
|
||||
const QString& scriptMenuName = QString(""), AbstractMenuInterface* menu = NULL,
|
||||
AbstractControllerScriptingInterface* controllerScriptingInterface = NULL);
|
||||
|
||||
~ScriptEngine();
|
||||
|
@ -58,7 +58,7 @@ signals:
|
|||
void willSendAudioDataCallback();
|
||||
void willSendVisualDataCallback();
|
||||
void scriptEnding();
|
||||
void finished();
|
||||
void finished(const QString& fileNameString);
|
||||
|
||||
protected:
|
||||
QString _scriptContents;
|
||||
|
@ -74,6 +74,7 @@ private:
|
|||
AudioScriptingInterface _audioScriptingInterface;
|
||||
bool _wantMenuItems;
|
||||
QString _scriptMenuName;
|
||||
QString _fileNameString;
|
||||
AbstractMenuInterface* _menu;
|
||||
static int _scriptNumber;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue