mirror of
https://github.com/lubosz/overte.git
synced 2025-08-08 04:08:13 +02:00
Merge pull request #4325 from AndrewMeadows/bispinor
use strings for shapeType in JS Entity properties
This commit is contained in:
commit
af99a5d07b
5 changed files with 55 additions and 20 deletions
|
@ -122,7 +122,7 @@ function makeBalls(pos) {
|
||||||
gravity: { x: 0, y: GRAVITY, z: 0 },
|
gravity: { x: 0, y: GRAVITY, z: 0 },
|
||||||
ignoreCollisions: false,
|
ignoreCollisions: false,
|
||||||
damping: 0.50,
|
damping: 0.50,
|
||||||
shapeType: 2,
|
shapeType: "sphere",
|
||||||
collisionsWillMove: true }));
|
collisionsWillMove: true }));
|
||||||
ballPosition.z += (BALL_SIZE + BALL_GAP) * SCALE;
|
ballPosition.z += (BALL_SIZE + BALL_GAP) * SCALE;
|
||||||
ballNumber++;
|
ballNumber++;
|
||||||
|
@ -143,7 +143,7 @@ function makeBalls(pos) {
|
||||||
velocity: {x: 0, y: 0, z: 0 },
|
velocity: {x: 0, y: 0, z: 0 },
|
||||||
ignoreCollisions: false,
|
ignoreCollisions: false,
|
||||||
damping: 0.50,
|
damping: 0.50,
|
||||||
shapeType: 2,
|
shapeType: "sphere",
|
||||||
collisionsWillMove: true });
|
collisionsWillMove: true });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -406,7 +406,7 @@
|
||||||
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
|
elModelAnimationFrame.addEventListener('change', createEmitNumberPropertyUpdateFunction('animationFrameIndex'));
|
||||||
elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings'));
|
elModelAnimationSettings.addEventListener('change', createEmitTextPropertyUpdateFunction('animationSettings'));
|
||||||
elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
|
elModelTextures.addEventListener('change', createEmitTextPropertyUpdateFunction('textures'));
|
||||||
elModelShapeType.addEventListener('change', createEmitNumberPropertyUpdateFunction('shapeType'));
|
elModelShapeType.addEventListener('change', createEmitTextPropertyUpdateFunction('shapeType'));
|
||||||
|
|
||||||
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
|
elTextText.addEventListener('change', createEmitTextPropertyUpdateFunction('text'));
|
||||||
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
|
elTextLineHeight.addEventListener('change', createEmitNumberPropertyUpdateFunction('lineHeight'));
|
||||||
|
@ -671,9 +671,9 @@
|
||||||
<div class="label">Shape Type</div>
|
<div class="label">Shape Type</div>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
<select name="SelectShapeType" id="property-model-shape" name="SelectShapeType">
|
<select name="SelectShapeType" id="property-model-shape" name="SelectShapeType">
|
||||||
<option value=0>None</option>
|
<option value='none'>none</option>
|
||||||
<option value=1>Box</option>
|
<option value='box'>box</option>
|
||||||
<option value=2>Sphere</option>
|
<option value='sphere'>sphere</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtCore/QJsonDocument>
|
#include <QtCore/QJsonDocument>
|
||||||
|
|
||||||
|
@ -170,6 +171,31 @@ void EntityItemProperties::setLastEdited(quint64 usecTime) {
|
||||||
_lastEdited = usecTime > _created ? usecTime : _created;
|
_lastEdited = usecTime > _created ? usecTime : _created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const char* shapeTypeNames[] = {"none", "box", "sphere"};
|
||||||
|
|
||||||
|
QHash<QString, ShapeType> stringToShapeTypeLookup;
|
||||||
|
|
||||||
|
void buildStringToShapeTypeLookup() {
|
||||||
|
stringToShapeTypeLookup["none"] = SHAPE_TYPE_NONE;
|
||||||
|
stringToShapeTypeLookup["box"] = SHAPE_TYPE_BOX;
|
||||||
|
stringToShapeTypeLookup["sphere"] = SHAPE_TYPE_SPHERE;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString EntityItemProperties::getShapeTypeAsString() const {
|
||||||
|
return QString(shapeTypeNames[_shapeType]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityItemProperties::setShapeTypeFromString(const QString& shapeName) {
|
||||||
|
if (stringToShapeTypeLookup.empty()) {
|
||||||
|
buildStringToShapeTypeLookup();
|
||||||
|
}
|
||||||
|
auto shapeTypeItr = stringToShapeTypeLookup.find(shapeName.toLower());
|
||||||
|
if (shapeTypeItr != stringToShapeTypeLookup.end()) {
|
||||||
|
_shapeType = shapeTypeItr.value();
|
||||||
|
_shapeTypeChanged = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
|
EntityPropertyFlags EntityItemProperties::getChangedProperties() const {
|
||||||
EntityPropertyFlags changedProperties;
|
EntityPropertyFlags changedProperties;
|
||||||
|
|
||||||
|
@ -270,7 +296,7 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
|
||||||
COPY_PROPERTY_TO_QSCRIPTVALUE(lineHeight);
|
COPY_PROPERTY_TO_QSCRIPTVALUE(lineHeight);
|
||||||
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(textColor, getTextColor());
|
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(textColor, getTextColor());
|
||||||
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(backgroundColor, getBackgroundColor());
|
COPY_PROPERTY_TO_QSCRIPTVALUE_COLOR_GETTER(backgroundColor, getBackgroundColor());
|
||||||
COPY_PROPERTY_TO_QSCRIPTVALUE(shapeType);
|
COPY_PROPERTY_TO_QSCRIPTVALUE_GETTER(shapeType, getShapeTypeAsString());
|
||||||
|
|
||||||
// Sitting properties support
|
// Sitting properties support
|
||||||
QScriptValue sittingPoints = engine->newObject();
|
QScriptValue sittingPoints = engine->newObject();
|
||||||
|
@ -303,8 +329,6 @@ QScriptValue EntityItemProperties::copyToScriptValue(QScriptEngine* engine) cons
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
||||||
|
|
||||||
|
|
||||||
QScriptValue typeScriptValue = object.property("type");
|
QScriptValue typeScriptValue = object.property("type");
|
||||||
if (typeScriptValue.isValid()) {
|
if (typeScriptValue.isValid()) {
|
||||||
setType(typeScriptValue.toVariant().toString());
|
setType(typeScriptValue.toVariant().toString());
|
||||||
|
@ -350,7 +374,7 @@ void EntityItemProperties::copyFromScriptValue(const QScriptValue& object) {
|
||||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(lineHeight, setLineHeight);
|
COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(lineHeight, setLineHeight);
|
||||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(textColor, setTextColor);
|
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(textColor, setTextColor);
|
||||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(backgroundColor, setBackgroundColor);
|
COPY_PROPERTY_FROM_QSCRIPTVALUE_COLOR(backgroundColor, setBackgroundColor);
|
||||||
COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(shapeType, setShapeType, ShapeType);
|
COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(shapeType, ShapeType);
|
||||||
|
|
||||||
_lastEdited = usecTimestampNow();
|
_lastEdited = usecTimestampNow();
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ public:
|
||||||
DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float);
|
DEFINE_PROPERTY(PROP_LINE_HEIGHT, LineHeight, lineHeight, float);
|
||||||
DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor);
|
DEFINE_PROPERTY_REF(PROP_TEXT_COLOR, TextColor, textColor, xColor);
|
||||||
DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor);
|
DEFINE_PROPERTY_REF(PROP_BACKGROUND_COLOR, BackgroundColor, backgroundColor, xColor);
|
||||||
DEFINE_PROPERTY_REF(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
|
DEFINE_PROPERTY_REF_ENUM(PROP_SHAPE_TYPE, ShapeType, shapeType, ShapeType);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); }
|
float getMaxDimension() const { return glm::max(_dimensions.x, _dimensions.y, _dimensions.z); }
|
||||||
|
|
|
@ -180,15 +180,6 @@
|
||||||
#define COPY_PROPERTY_TO_QSCRIPTVALUE(P) \
|
#define COPY_PROPERTY_TO_QSCRIPTVALUE(P) \
|
||||||
properties.setProperty(#P, _##P);
|
properties.setProperty(#P, _##P);
|
||||||
|
|
||||||
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_ENUM(P, S, E) \
|
|
||||||
QScriptValue P = object.property(#P); \
|
|
||||||
if (P.isValid()) { \
|
|
||||||
E newValue = (E)(P.toVariant().toInt()); \
|
|
||||||
if (_defaultSettings || newValue != _##P) { \
|
|
||||||
S(newValue); \
|
|
||||||
} \
|
|
||||||
}
|
|
||||||
|
|
||||||
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(P, S) \
|
#define COPY_PROPERTY_FROM_QSCRIPTVALUE_FLOAT(P, S) \
|
||||||
QScriptValue P = object.property(#P); \
|
QScriptValue P = object.property(#P); \
|
||||||
if (P.isValid()) { \
|
if (P.isValid()) { \
|
||||||
|
@ -280,6 +271,15 @@
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define COPY_PROPERTY_FROM_QSCRITPTVALUE_ENUM(P, S) \
|
||||||
|
QScriptValue P = object.property(#P); \
|
||||||
|
if (P.isValid()) { \
|
||||||
|
QString newValue = P.toVariant().toString(); \
|
||||||
|
if (_defaultSettings || newValue != get##S##AsString()) { \
|
||||||
|
set##S##FromString(newValue); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
|
||||||
#define CONSTRUCT_PROPERTY(n, V) \
|
#define CONSTRUCT_PROPERTY(n, V) \
|
||||||
_##n(V), \
|
_##n(V), \
|
||||||
|
@ -321,6 +321,17 @@
|
||||||
T _##n; \
|
T _##n; \
|
||||||
bool _##n##Changed;
|
bool _##n##Changed;
|
||||||
|
|
||||||
|
#define DEFINE_PROPERTY_REF_ENUM(P, N, n, T) \
|
||||||
|
public: \
|
||||||
|
const T& get##N() const { return _##n; } \
|
||||||
|
void set##N(const T& value) { _##n = value; _##n##Changed = true; } \
|
||||||
|
bool n##Changed() const { return _##n##Changed; } \
|
||||||
|
QString get##N##AsString() const; \
|
||||||
|
void set##N##FromString(const QString& name); \
|
||||||
|
private: \
|
||||||
|
T _##n; \
|
||||||
|
bool _##n##Changed;
|
||||||
|
|
||||||
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
|
#define DEBUG_PROPERTY_IF_CHANGED(D, P, N, n, x) \
|
||||||
if (P.n##Changed()) { \
|
if (P.n##Changed()) { \
|
||||||
D << " " << #n << ":" << P.get##N() << x << "\n"; \
|
D << " " << #n << ":" << P.get##N() << x << "\n"; \
|
||||||
|
|
Loading…
Reference in a new issue