Moved isListOfStrings into shared/ScriptValueUtils

Also fixed some single line ifs.
This commit is contained in:
Anthony J. Thibault 2016-04-15 13:46:55 -07:00
parent 253e4cbb73
commit 38418d0169
3 changed files with 56 additions and 18 deletions

View file

@ -20,6 +20,7 @@
#include <GeometryUtil.h>
#include <NumericalConstants.h>
#include <DebugDraw.h>
#include <ScriptValueUtils.h>
#include <shared/NsightHelpers.h>
#include "AnimationLogging.h"
@ -783,24 +784,6 @@ void Rig::computeMotionAnimationState(float deltaTime, const glm::vec3& worldPos
_lastVelocity = workingVelocity;
}
static bool isListOfStrings(const QScriptValue& arg) {
if (!arg.isArray())
return false;
auto lengthProperty = arg.property("length");
if (!lengthProperty.isNumber())
return false;
int length = lengthProperty.toInt32();
for (int i = 0; i < length; i++) {
if (!arg.property(i).isString()) {
return false;
}
}
return true;
}
// Allow script to add/remove handlers and report results, from within their thread.
QScriptValue Rig::addAnimationStateHandler(QScriptValue handler, QScriptValue propertiesList) { // called in script thread

View file

@ -0,0 +1,34 @@
//
// ScriptValueUtils.cpp
// libraries/shared/src
//
// Created by Anthony Thibault on 4/15/16.
// Copyright 2016 High Fidelity, Inc.
//
// Utilities for working with QtScriptValues
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include "ScriptValueUtils.h"
bool isListOfStrings(const QScriptValue& arg) {
if (!arg.isArray()) {
return false;
}
auto lengthProperty = arg.property("length");
if (!lengthProperty.isNumber()) {
return false;
}
int length = lengthProperty.toInt32();
for (int i = 0; i < length; i++) {
if (!arg.property(i).isString()) {
return false;
}
}
return true;
}

View file

@ -0,0 +1,21 @@
//
// ScriptValueUtils.h
// libraries/shared/src
//
// Created by Anthony Thibault on 4/15/16.
// Copyright 2016 High Fidelity, Inc.
//
// Utilities for working with QtScriptValues
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_ScriptValueUtils_h
#define hifi_ScriptValueUtils_h
#include <QScriptValue>
bool isListOfStrings(const QScriptValue& value);
#endif // #define hifi_ScriptValueUtils_h