mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
added example for the new Scripts functions:
example\misc\scriptsExample.js
This commit is contained in:
parent
a783f03025
commit
af34add63c
2 changed files with 43 additions and 2 deletions
41
examples/example/misc/scriptsExample.js
Normal file
41
examples/example/misc/scriptsExample.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
//
|
||||
// scriptsExample.js
|
||||
// examples/example/misc
|
||||
//
|
||||
// Created by Thijs Wenker on 7 Apr 2015
|
||||
// Copyright 2015 High Fidelity, Inc.
|
||||
//
|
||||
// Outputs the running, public and local scripts to the console.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var runningScripts = Scripts.getRunning();
|
||||
print("Running Scripts:");
|
||||
for (var i = 0; i < runningScripts.length; i++) {
|
||||
print(" - " + runningScripts[i].name + (runningScripts[i].local ? "[Local]" : "") + " {" + runningScripts[i].url + "}");
|
||||
}
|
||||
|
||||
var localScripts = Scripts.getLocal();
|
||||
print("Local Scripts:");
|
||||
for (var i = 0; i < localScripts.length; i++) {
|
||||
print(" - " + localScripts[i].name + " {" + localScripts[i].path + "}");
|
||||
}
|
||||
|
||||
// recursive function to walk through all folders in public scripts
|
||||
// adding 2 spaces to the prefix per depth level
|
||||
function displayPublicScriptFolder(nodes, prefix) {
|
||||
for (var i = 0; i < nodes.length; i++) {
|
||||
if (nodes[i].type == "folder") {
|
||||
print(prefix + "<" + nodes[i].name + ">");
|
||||
displayPublicScriptFolder(nodes[i].children, " " + prefix);
|
||||
continue;
|
||||
}
|
||||
print(prefix + nodes[i].name + " {" + nodes[i].url + "}");
|
||||
}
|
||||
}
|
||||
|
||||
var publicScripts = Scripts.getPublic();
|
||||
print("Public Scripts:");
|
||||
displayPublicScriptFolder(publicScripts, " - ");
|
|
@ -29,7 +29,7 @@ QVariantList ScriptsScriptingInterface::getRunning() {
|
|||
}
|
||||
QVariantMap resultNode;
|
||||
resultNode.insert("name", runningScriptURL.fileName());
|
||||
resultNode.insert("path", runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
resultNode.insert("url", runningScriptURL.toDisplayString(QUrl::FormattingOptions(QUrl::FullyEncoded)));
|
||||
resultNode.insert("local", runningScriptURL.isLocalFile());
|
||||
result.append(resultNode);
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ QVariantList ScriptsScriptingInterface::getPublicChildNodes(TreeNodeFolder* pare
|
|||
QVariantMap resultNode;
|
||||
resultNode.insert("name", node->getName());
|
||||
resultNode.insert("type", "script");
|
||||
resultNode.insert("path", script->getFullPath());
|
||||
resultNode.insert("url", script->getFullPath());
|
||||
result.append(resultNode);
|
||||
}
|
||||
return result;
|
||||
|
|
Loading…
Reference in a new issue