Showing the changes to libraries/script-engine/src/ScriptValueUtils.cpp (1 of 170 files). Show all
Unified · Split
| @@ -28,19 +28,19 @@ · 27 unmodified lines | |||
| 28 | #include "ScriptEngineCast.h" | 28 | #include "ScriptEngineCast.h" |
| 29 | #include "ScriptValueIterator.h" | 29 | #include "ScriptValueIterator.h" |
| 30 | 30 | ||
| 31 | bool isListOfStrings(const ScriptValuePointer& arg) { | 31 | bool isListOfStrings(const ScriptValue& arg) { |
| 32 | if (!arg->isArray()) { | 32 | if (!arg.isArray()) { |
| 33 | return false; | 33 | return false; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | auto lengthProperty = arg->property("length"); | 36 | auto lengthProperty = arg.property("length"); |
| 37 | if (!lengthProperty->isNumber()) { | 37 | if (!lengthProperty.isNumber()) { |
| 38 | return false; | 38 | return false; |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | int length = lengthProperty->toInt32(); | 41 | int length = lengthProperty.toInt32(); |
| 42 | for (int i = 0; i < length; i++) { | 42 | for (int i = 0; i < length; i++) { |
| 43 | if (!arg->property(i)->isString()) { | 43 | if (!arg.property(i).isString()) { |
| 44 | return false; | 44 | return false; |
| 45 | } | 45 | } |
| 46 | } | 46 | } |
| @@ -80,9 +80,9 @@ void registerMetaTypes(ScriptEngine* engine) { · 33 unmodified lines | |||
| 80 | scriptRegisterSequenceMetaType<QVector<unsigned int>>(engine); | 80 | scriptRegisterSequenceMetaType<QVector<unsigned int>>(engine); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | ScriptValuePointer vec2ToScriptValue(ScriptEngine* engine, const glm::vec2& vec2) { | 83 | ScriptValue vec2ToScriptValue(ScriptEngine* engine, const glm::vec2& vec2) { |
| 84 | auto prototype = engine->globalObject()->property("__hifi_vec2__"); | 84 | auto prototype = engine->globalObject().property("__hifi_vec2__"); |
| 85 | if (!prototype->property("defined")->toBool()) { | 85 | if (!prototype.property("defined").toBool()) { |
| 86 | prototype = engine->evaluate( | 86 | prototype = engine->evaluate( |
| 87 | "__hifi_vec2__ = Object.defineProperties({}, { " | 87 | "__hifi_vec2__ = Object.defineProperties({}, { " |
| 88 | "defined: { value: true }," | 88 | "defined: { value: true }," |
| @@ -92,41 +92,41 @@ ScriptValuePointer vec2ToScriptValue(ScriptEngine* engine, const glm::vec2& vec2 · 3 unmodified lines | |||
| 92 | "v: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } }" | 92 | "v: { set: function(nv) { return this.y = nv; }, get: function() { return this.y; } }" |
| 93 | "})"); | 93 | "})"); |
| 94 | } | 94 | } |
| 95 | ScriptValuePointer value = engine->newObject(); | 95 | ScriptValue value = engine->newObject(); |
| 96 | value->setProperty("x", vec2.x); | 96 | value.setProperty("x", vec2.x); |
| 97 | value->setProperty("y", vec2.y); | 97 | value.setProperty("y", vec2.y); |
| 98 | value->setPrototype(prototype); | 98 | value.setPrototype(prototype); |
| 99 | return value; | 99 | return value; |
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | void vec2FromScriptValue(const ScriptValuePointer& object, glm::vec2& vec2) { | 102 | void vec2FromScriptValue(const ScriptValue& object, glm::vec2& vec2) { |
| 103 | if (object->isNumber()) { | 103 | if (object.isNumber()) { |
| 104 | vec2 = glm::vec2(object->toVariant().toFloat()); | 104 | vec2 = glm::vec2(object.toVariant().toFloat()); |
| 105 | } else if (object->isArray()) { | 105 | } else if (object.isArray()) { |
| 106 | QVariantList list = object->toVariant().toList(); | 106 | QVariantList list = object.toVariant().toList(); |
| 107 | if (list.length() == 2) { | 107 | if (list.length() == 2) { |
| 108 | vec2.x = list[0].toFloat(); | 108 | vec2.x = list[0].toFloat(); |
| 109 | vec2.y = list[1].toFloat(); | 109 | vec2.y = list[1].toFloat(); |
| 110 | } | 110 | } |
| 111 | } else { | 111 | } else { |
| 112 | ScriptValuePointer x = object->property("x"); | 112 | ScriptValue x = object.property("x"); |
| 113 | if (!x->isValid()) { | 113 | if (!x.isValid()) { |
| 114 | x = object->property("u"); | 114 | x = object.property("u"); |
| 115 | } | 115 | } |
| 116 | 116 | ||
| 117 | ScriptValuePointer y = object->property("y"); | 117 | ScriptValue y = object.property("y"); |
| 118 | if (!y->isValid()) { | 118 | if (!y.isValid()) { |
| 119 | y = object->property("v"); | 119 | y = object.property("v"); |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | vec2.x = x->toVariant().toFloat(); | 122 | vec2.x = x.toVariant().toFloat(); |
| 123 | vec2.y = y->toVariant().toFloat(); | 123 | vec2.y = y.toVariant().toFloat(); |
| 124 | } | 124 | } |
| 125 | } | 125 | } |
| 126 | 126 | ||
| 127 | ScriptValuePointer vec3ToScriptValue(ScriptEngine* engine, const glm::vec3& vec3) { | 127 | ScriptValue vec3ToScriptValue(ScriptEngine* engine, const glm::vec3& vec3) { |
| 128 | auto prototype = engine->globalObject()->property("__hifi_vec3__"); | 128 | auto prototype = engine->globalObject().property("__hifi_vec3__"); |
| 129 | if (!prototype->property("defined")->toBool()) { | 129 | if (!prototype.property("defined").toBool()) { |
| 130 | prototype = engine->evaluate( | 130 | prototype = engine->evaluate( |
| 131 | "__hifi_vec3__ = Object.defineProperties({}, { " | 131 | "__hifi_vec3__ = Object.defineProperties({}, { " |
| 132 | "defined: { value: true }," | 132 | "defined: { value: true }," |
| @@ -141,17 +141,17 @@ ScriptValuePointer vec3ToScriptValue(ScriptEngine* engine, const glm::vec3& vec3 · 8 unmodified lines | |||
| 141 | "blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }" | 141 | "blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }" |
| 142 | "})"); | 142 | "})"); |
| 143 | } | 143 | } |
| 144 | ScriptValuePointer value = engine->newObject(); | 144 | ScriptValue value = engine->newObject(); |
| 145 | value->setProperty("x", vec3.x); | 145 | value.setProperty("x", vec3.x); |
| 146 | value->setProperty("y", vec3.y); | 146 | value.setProperty("y", vec3.y); |
| 147 | value->setProperty("z", vec3.z); | 147 | value.setProperty("z", vec3.z); |
| 148 | value->setPrototype(prototype); | 148 | value.setPrototype(prototype); |
| 149 | return value; | 149 | return value; |
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | ScriptValuePointer vec3ColorToScriptValue(ScriptEngine* engine, const glm::vec3& vec3) { | 152 | ScriptValue vec3ColorToScriptValue(ScriptEngine* engine, const glm::vec3& vec3) { |
| 153 | auto prototype = engine->globalObject()->property("__hifi_vec3_color__"); | 153 | auto prototype = engine->globalObject().property("__hifi_vec3_color__"); |
| 154 | if (!prototype->property("defined")->toBool()) { | 154 | if (!prototype.property("defined").toBool()) { |
| 155 | prototype = engine->evaluate( | 155 | prototype = engine->evaluate( |
| 156 | "__hifi_vec3_color__ = Object.defineProperties({}, { " | 156 | "__hifi_vec3_color__ = Object.defineProperties({}, { " |
| 157 | "defined: { value: true }," | 157 | "defined: { value: true }," |
| @@ -166,65 +166,65 @@ ScriptValuePointer vec3ColorToScriptValue(ScriptEngine* engine, const glm::vec3& · 8 unmodified lines | |||
| 166 | "z: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }" | 166 | "z: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }" |
| 167 | "})"); | 167 | "})"); |
| 168 | } | 168 | } |
| 169 | ScriptValuePointer value = engine->newObject(); | 169 | ScriptValue value = engine->newObject(); |
| 170 | value->setProperty("red", vec3.x); | 170 | value.setProperty("red", vec3.x); |
| 171 | value->setProperty("green", vec3.y); | 171 | value.setProperty("green", vec3.y); |
| 172 | value->setProperty("blue", vec3.z); | 172 | value.setProperty("blue", vec3.z); |
| 173 | value->setPrototype(prototype); | 173 | value.setPrototype(prototype); |
| 174 | return value; | 174 | return value; |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | void vec3FromScriptValue(const ScriptValuePointer& object, glm::vec3& vec3) { | 177 | void vec3FromScriptValue(const ScriptValue& object, glm::vec3& vec3) { |
| 178 | if (object->isNumber()) { | 178 | if (object.isNumber()) { |
| 179 | vec3 = glm::vec3(object->toVariant().toFloat()); | 179 | vec3 = glm::vec3(object.toVariant().toFloat()); |
| 180 | } else if (object->isString()) { | 180 | } else if (object.isString()) { |
| 181 | QColor qColor(object->toString()); | 181 | QColor qColor(object.toString()); |
| 182 | if (qColor.isValid()) { | 182 | if (qColor.isValid()) { |
| 183 | vec3.x = qColor.red(); | 183 | vec3.x = qColor.red(); |
| 184 | vec3.y = qColor.green(); | 184 | vec3.y = qColor.green(); |
| 185 | vec3.z = qColor.blue(); | 185 | vec3.z = qColor.blue(); |
| 186 | } | 186 | } |
| 187 | } else if (object->isArray()) { | 187 | } else if (object.isArray()) { |
| 188 | QVariantList list = object->toVariant().toList(); | 188 | QVariantList list = object.toVariant().toList(); |
| 189 | if (list.length() == 3) { | 189 | if (list.length() == 3) { |
| 190 | vec3.x = list[0].toFloat(); | 190 | vec3.x = list[0].toFloat(); |
| 191 | vec3.y = list[1].toFloat(); | 191 | vec3.y = list[1].toFloat(); |
| 192 | vec3.z = list[2].toFloat(); | 192 | vec3.z = list[2].toFloat(); |
| 193 | } | 193 | } |
| 194 | } else { | 194 | } else { |
| 195 | ScriptValuePointer x = object->property("x"); | 195 | ScriptValue x = object.property("x"); |
| 196 | if (!x->isValid()) { | 196 | if (!x.isValid()) { |
| 197 | x = object->property("r"); | 197 | x = object.property("r"); |
| 198 | } | 198 | } |
| 199 | if (!x->isValid()) { | 199 | if (!x.isValid()) { |
| 200 | x = object->property("red"); | 200 | x = object.property("red"); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | ScriptValuePointer y = object->property("y"); | 203 | ScriptValue y = object.property("y"); |
| 204 | if (!y->isValid()) { | 204 | if (!y.isValid()) { |
| 205 | y = object->property("g"); | 205 | y = object.property("g"); |
| 206 | } | 206 | } |
| 207 | if (!y->isValid()) { | 207 | if (!y.isValid()) { |
| 208 | y = object->property("green"); | 208 | y = object.property("green"); |
| 209 | } | 209 | } |
| 210 | 210 | ||
| 211 | ScriptValuePointer z = object->property("z"); | 211 | ScriptValue z = object.property("z"); |
| 212 | if (!z->isValid()) { | 212 | if (!z.isValid()) { |
| 213 | z = object->property("b"); | 213 | z = object.property("b"); |
| 214 | } | 214 | } |
| 215 | if (!z->isValid()) { | 215 | if (!z.isValid()) { |
| 216 | z = object->property("blue"); | 216 | z = object.property("blue"); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| 219 | vec3.x = x->toVariant().toFloat(); | 219 | vec3.x = x.toVariant().toFloat(); |
| 220 | vec3.y = y->toVariant().toFloat(); | 220 | vec3.y = y.toVariant().toFloat(); |
| 221 | vec3.z = z->toVariant().toFloat(); | 221 | vec3.z = z.toVariant().toFloat(); |
| 222 | } | 222 | } |
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | ScriptValuePointer u8vec3ToScriptValue(ScriptEngine* engine, const glm::u8vec3& vec3) { | 225 | ScriptValue u8vec3ToScriptValue(ScriptEngine* engine, const glm::u8vec3& vec3) { |
| 226 | auto prototype = engine->globalObject()->property("__hifi_u8vec3__"); | 226 | auto prototype = engine->globalObject().property("__hifi_u8vec3__"); |
| 227 | if (!prototype->property("defined")->toBool()) { | 227 | if (!prototype.property("defined").toBool()) { |
| 228 | prototype = engine->evaluate( | 228 | prototype = engine->evaluate( |
| 229 | "__hifi_u8vec3__ = Object.defineProperties({}, { " | 229 | "__hifi_u8vec3__ = Object.defineProperties({}, { " |
| 230 | "defined: { value: true }," | 230 | "defined: { value: true }," |
| @@ -239,17 +239,17 @@ ScriptValuePointer u8vec3ToScriptValue(ScriptEngine* engine, const glm::u8vec3& · 8 unmodified lines | |||
| 239 | "blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }" | 239 | "blue: { set: function(nv) { return this.z = nv; }, get: function() { return this.z; } }" |
| 240 | "})"); | 240 | "})"); |
| 241 | } | 241 | } |
| 242 | ScriptValuePointer value = engine->newObject(); | 242 | ScriptValue value = engine->newObject(); |
| 243 | value->setProperty("x", vec3.x); | 243 | value.setProperty("x", vec3.x); |
| 244 | value->setProperty("y", vec3.y); | 244 | value.setProperty("y", vec3.y); |
| 245 | value->setProperty("z", vec3.z); | 245 | value.setProperty("z", vec3.z); |
| 246 | value->setPrototype(prototype); | 246 | value.setPrototype(prototype); |
| 247 | return value; | 247 | return value; |
| 248 | } | 248 | } |
| 249 | 249 | ||
| 250 | ScriptValuePointer u8vec3ColorToScriptValue(ScriptEngine* engine, const glm::u8vec3& vec3) { | 250 | ScriptValue u8vec3ColorToScriptValue(ScriptEngine* engine, const glm::u8vec3& vec3) { |
| 251 | auto prototype = engine->globalObject()->property("__hifi_u8vec3_color__"); | 251 | auto prototype = engine->globalObject().property("__hifi_u8vec3_color__"); |
| 252 | if (!prototype->property("defined")->toBool()) { | 252 | if (!prototype.property("defined").toBool()) { |
| 253 | prototype = engine->evaluate( | 253 | prototype = engine->evaluate( |
| 254 | "__hifi_u8vec3_color__ = Object.defineProperties({}, { " | 254 | "__hifi_u8vec3_color__ = Object.defineProperties({}, { " |
| 255 | "defined: { value: true }," | 255 | "defined: { value: true }," |
| @@ -264,174 +264,174 @@ ScriptValuePointer u8vec3ColorToScriptValue(ScriptEngine* engine, const glm::u8v · 8 unmodified lines | |||
| 264 | "z: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }" | 264 | "z: { set: function(nv) { return this.blue = nv; }, get: function() { return this.blue; } }" |
| 265 | "})"); | 265 | "})"); |
| 266 | } | 266 | } |
| 267 | ScriptValuePointer value = engine->newObject(); | 267 | ScriptValue value = engine->newObject(); |
| 268 | value->setProperty("red", vec3.x); | 268 | value.setProperty("red", vec3.x); |
| 269 | value->setProperty("green", vec3.y); | 269 | value.setProperty("green", vec3.y); |
| 270 | value->setProperty("blue", vec3.z); | 270 | value.setProperty("blue", vec3.z); |
| 271 | value->setPrototype(prototype); | 271 | value.setPrototype(prototype); |
| 272 | return value; | 272 | return value; |
| 273 | } | 273 | } |
| 274 | 274 | ||
| 275 | void u8vec3FromScriptValue(const ScriptValuePointer& object, glm::u8vec3& vec3) { | 275 | void u8vec3FromScriptValue(const ScriptValue& object, glm::u8vec3& vec3) { |
| 276 | if (object->isNumber()) { | 276 | if (object.isNumber()) { |
| 277 | vec3 = glm::vec3(object->toVariant().toUInt()); | 277 | vec3 = glm::vec3(object.toVariant().toUInt()); |
| 278 | } else if (object->isString()) { | 278 | } else if (object.isString()) { |
| 279 | QColor qColor(object->toString()); | 279 | QColor qColor(object.toString()); |
| 280 | if (qColor.isValid()) { | 280 | if (qColor.isValid()) { |
| 281 | vec3.x = (uint8_t)qColor.red(); | 281 | vec3.x = (uint8_t)qColor.red(); |
| 282 | vec3.y = (uint8_t)qColor.green(); | 282 | vec3.y = (uint8_t)qColor.green(); |
| 283 | vec3.z = (uint8_t)qColor.blue(); | 283 | vec3.z = (uint8_t)qColor.blue(); |
| 284 | } | 284 | } |
| 285 | } else if (object->isArray()) { | 285 | } else if (object.isArray()) { |
| 286 | QVariantList list = object->toVariant().toList(); | 286 | QVariantList list = object.toVariant().toList(); |
| 287 | if (list.length() == 3) { | 287 | if (list.length() == 3) { |
| 288 | vec3.x = list[0].toUInt(); | 288 | vec3.x = list[0].toUInt(); |
| 289 | vec3.y = list[1].toUInt(); | 289 | vec3.y = list[1].toUInt(); |
| 290 | vec3.z = list[2].toUInt(); | 290 | vec3.z = list[2].toUInt(); |
| 291 | } | 291 | } |
| 292 | } else { | 292 | } else { |
| 293 | ScriptValuePointer x = object->property("x"); | 293 | ScriptValue x = object.property("x"); |
| 294 | if (!x->isValid()) { | 294 | if (!x.isValid()) { |
| 295 | x = object->property("r"); | 295 | x = object.property("r"); |
| 296 | } | 296 | } |
| 297 | if (!x->isValid()) { | 297 | if (!x.isValid()) { |
| 298 | x = object->property("red"); | 298 | x = object.property("red"); |
| 299 | } | 299 | } |
| 300 | 300 | ||
| 301 | ScriptValuePointer y = object->property("y"); | 301 | ScriptValue y = object.property("y"); |
| 302 | if (!y->isValid()) { | 302 | if (!y.isValid()) { |
| 303 | y = object->property("g"); | 303 | y = object.property("g"); |
| 304 | } | 304 | } |
| 305 | if (!y->isValid()) { | 305 | if (!y.isValid()) { |
| 306 | y = object->property("green"); | 306 | y = object.property("green"); |
| 307 | } | 307 | } |
| 308 | 308 | ||
| 309 | ScriptValuePointer z = object->property("z"); | 309 | ScriptValue z = object.property("z"); |
| 310 | if (!z->isValid()) { | 310 | if (!z.isValid()) { |
| 311 | z = object->property("b"); | 311 | z = object.property("b"); |
| 312 | } | 312 | } |
| 313 | if (!z->isValid()) { | 313 | if (!z.isValid()) { |
| 314 | z = object->property("blue"); | 314 | z = object.property("blue"); |
| 315 | } | 315 | } |
| 316 | 316 | ||
| 317 | vec3.x = x->toVariant().toUInt(); | 317 | vec3.x = x.toVariant().toUInt(); |
| 318 | vec3.y = y->toVariant().toUInt(); | 318 | vec3.y = y.toVariant().toUInt(); |
| 319 | vec3.z = z->toVariant().toUInt(); | 319 | vec3.z = z.toVariant().toUInt(); |
| 320 | } | 320 | } |
| 321 | } | 321 | } |
| 322 | 322 | ||
| 323 | ScriptValuePointer vec4toScriptValue(ScriptEngine* engine, const glm::vec4& vec4) { | 323 | ScriptValue vec4toScriptValue(ScriptEngine* engine, const glm::vec4& vec4) { |
| 324 | ScriptValuePointer obj = engine->newObject(); | 324 | ScriptValue obj = engine->newObject(); |
| 325 | obj->setProperty("x", vec4.x); | 325 | obj.setProperty("x", vec4.x); |
| 326 | obj->setProperty("y", vec4.y); | 326 | obj.setProperty("y", vec4.y); |
| 327 | obj->setProperty("z", vec4.z); | 327 | obj.setProperty("z", vec4.z); |
| 328 | obj->setProperty("w", vec4.w); | 328 | obj.setProperty("w", vec4.w); |
| 329 | return obj; | 329 | return obj; |
| 330 | } | 330 | } |
| 331 | 331 | ||
| 332 | void vec4FromScriptValue(const ScriptValuePointer& object, glm::vec4& vec4) { | 332 | void vec4FromScriptValue(const ScriptValue& object, glm::vec4& vec4) { |
| 333 | vec4.x = object->property("x")->toVariant().toFloat(); | 333 | vec4.x = object.property("x").toVariant().toFloat(); |
| 334 | vec4.y = object->property("y")->toVariant().toFloat(); | 334 | vec4.y = object.property("y").toVariant().toFloat(); |
| 335 | vec4.z = object->property("z")->toVariant().toFloat(); | 335 | vec4.z = object.property("z").toVariant().toFloat(); |
| 336 | vec4.w = object->property("w")->toVariant().toFloat(); | 336 | vec4.w = object.property("w").toVariant().toFloat(); |
| 337 | } | 337 | } |
| 338 | 338 | ||
| 339 | ScriptValuePointer mat4toScriptValue(ScriptEngine* engine, const glm::mat4& mat4) { | 339 | ScriptValue mat4toScriptValue(ScriptEngine* engine, const glm::mat4& mat4) { |
| 340 | ScriptValuePointer obj = engine->newObject(); | 340 | ScriptValue obj = engine->newObject(); |
| 341 | obj->setProperty("r0c0", mat4[0][0]); | 341 | obj.setProperty("r0c0", mat4[0][0]); |
| 342 | obj->setProperty("r1c0", mat4[0][1]); | 342 | obj.setProperty("r1c0", mat4[0][1]); |
| 343 | obj->setProperty("r2c0", mat4[0][2]); | 343 | obj.setProperty("r2c0", mat4[0][2]); |
| 344 | obj->setProperty("r3c0", mat4[0][3]); | 344 | obj.setProperty("r3c0", mat4[0][3]); |
| 345 | obj->setProperty("r0c1", mat4[1][0]); | 345 | obj.setProperty("r0c1", mat4[1][0]); |
| 346 | obj->setProperty("r1c1", mat4[1][1]); | 346 | obj.setProperty("r1c1", mat4[1][1]); |
| 347 | obj->setProperty("r2c1", mat4[1][2]); | 347 | obj.setProperty("r2c1", mat4[1][2]); |
| 348 | obj->setProperty("r3c1", mat4[1][3]); | 348 | obj.setProperty("r3c1", mat4[1][3]); |
| 349 | obj->setProperty("r0c2", mat4[2][0]); | 349 | obj.setProperty("r0c2", mat4[2][0]); |
| 350 | obj->setProperty("r1c2", mat4[2][1]); | 350 | obj.setProperty("r1c2", mat4[2][1]); |
| 351 | obj->setProperty("r2c2", mat4[2][2]); | 351 | obj.setProperty("r2c2", mat4[2][2]); |
| 352 | obj->setProperty("r3c2", mat4[2][3]); | 352 | obj.setProperty("r3c2", mat4[2][3]); |
| 353 | obj->setProperty("r0c3", mat4[3][0]); | 353 | obj.setProperty("r0c3", mat4[3][0]); |
| 354 | obj->setProperty("r1c3", mat4[3][1]); | 354 | obj.setProperty("r1c3", mat4[3][1]); |
| 355 | obj->setProperty("r2c3", mat4[3][2]); | 355 | obj.setProperty("r2c3", mat4[3][2]); |
| 356 | obj->setProperty("r3c3", mat4[3][3]); | 356 | obj.setProperty("r3c3", mat4[3][3]); |
| 357 | return obj; | 357 | return obj; |
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | void mat4FromScriptValue(const ScriptValuePointer& object, glm::mat4& mat4) { | 360 | void mat4FromScriptValue(const ScriptValue& object, glm::mat4& mat4) { |
| 361 | mat4[0][0] = object->property("r0c0")->toVariant().toFloat(); | 361 | mat4[0][0] = object.property("r0c0").toVariant().toFloat(); |
| 362 | mat4[0][1] = object->property("r1c0")->toVariant().toFloat(); | 362 | mat4[0][1] = object.property("r1c0").toVariant().toFloat(); |
| 363 | mat4[0][2] = object->property("r2c0")->toVariant().toFloat(); | 363 | mat4[0][2] = object.property("r2c0").toVariant().toFloat(); |
| 364 | mat4[0][3] = object->property("r3c0")->toVariant().toFloat(); | 364 | mat4[0][3] = object.property("r3c0").toVariant().toFloat(); |
| 365 | mat4[1][0] = object->property("r0c1")->toVariant().toFloat(); | 365 | mat4[1][0] = object.property("r0c1").toVariant().toFloat(); |
| 366 | mat4[1][1] = object->property("r1c1")->toVariant().toFloat(); | 366 | mat4[1][1] = object.property("r1c1").toVariant().toFloat(); |
| 367 | mat4[1][2] = object->property("r2c1")->toVariant().toFloat(); | 367 | mat4[1][2] = object.property("r2c1").toVariant().toFloat(); |
| 368 | mat4[1][3] = object->property("r3c1")->toVariant().toFloat(); | 368 | mat4[1][3] = object.property("r3c1").toVariant().toFloat(); |
| 369 | mat4[2][0] = object->property("r0c2")->toVariant().toFloat(); | 369 | mat4[2][0] = object.property("r0c2").toVariant().toFloat(); |
| 370 | mat4[2][1] = object->property("r1c2")->toVariant().toFloat(); | 370 | mat4[2][1] = object.property("r1c2").toVariant().toFloat(); |
| 371 | mat4[2][2] = object->property("r2c2")->toVariant().toFloat(); | 371 | mat4[2][2] = object.property("r2c2").toVariant().toFloat(); |
| 372 | mat4[2][3] = object->property("r3c2")->toVariant().toFloat(); | 372 | mat4[2][3] = object.property("r3c2").toVariant().toFloat(); |
| 373 | mat4[3][0] = object->property("r0c3")->toVariant().toFloat(); | 373 | mat4[3][0] = object.property("r0c3").toVariant().toFloat(); |
| 374 | mat4[3][1] = object->property("r1c3")->toVariant().toFloat(); | 374 | mat4[3][1] = object.property("r1c3").toVariant().toFloat(); |
| 375 | mat4[3][2] = object->property("r2c3")->toVariant().toFloat(); | 375 | mat4[3][2] = object.property("r2c3").toVariant().toFloat(); |
| 376 | mat4[3][3] = object->property("r3c3")->toVariant().toFloat(); | 376 | mat4[3][3] = object.property("r3c3").toVariant().toFloat(); |
| 377 | } | 377 | } |
| 378 | 378 | ||
| 379 | ScriptValuePointer qVectorVec3ColorToScriptValue(ScriptEngine* engine, const QVector<glm::vec3>& vector) { | 379 | ScriptValue qVectorVec3ColorToScriptValue(ScriptEngine* engine, const QVector<glm::vec3>& vector) { |
| 380 | ScriptValuePointer array = engine->newArray(); | 380 | ScriptValue array = engine->newArray(); |
| 381 | for (int i = 0; i < vector.size(); i++) { | 381 | for (int i = 0; i < vector.size(); i++) { |
| 382 | array->setProperty(i, vec3ColorToScriptValue(engine, vector.at(i))); | 382 | array.setProperty(i, vec3ColorToScriptValue(engine, vector.at(i))); |
| 383 | } | 383 | } |
| 384 | return array; | 384 | return array; |
| 385 | } | 385 | } |
| 386 | 386 | ||
| 387 | ScriptValuePointer qVectorVec3ToScriptValue(ScriptEngine* engine, const QVector<glm::vec3>& vector) { | 387 | ScriptValue qVectorVec3ToScriptValue(ScriptEngine* engine, const QVector<glm::vec3>& vector) { |
| 388 | ScriptValuePointer array = engine->newArray(); | 388 | ScriptValue array = engine->newArray(); |
| 389 | for (int i = 0; i < vector.size(); i++) { | 389 | for (int i = 0; i < vector.size(); i++) { |
| 390 | array->setProperty(i, vec3ToScriptValue(engine, vector.at(i))); | 390 | array.setProperty(i, vec3ToScriptValue(engine, vector.at(i))); |
| 391 | } | 391 | } |
| 392 | return array; | 392 | return array; |
| 393 | } | 393 | } |
| 394 | 394 | ||
| 395 | QVector<glm::vec3> qVectorVec3FromScriptValue(const ScriptValuePointer& array) { | 395 | QVector<glm::vec3> qVectorVec3FromScriptValue(const ScriptValue& array) { |
| 396 | QVector<glm::vec3> newVector; | 396 | QVector<glm::vec3> newVector; |
| 397 | int length = array->property("length")->toInteger(); | 397 | int length = array.property("length").toInteger(); |
| 398 | 398 | ||
| 399 | for (int i = 0; i < length; i++) { | 399 | for (int i = 0; i < length; i++) { |
| 400 | glm::vec3 newVec3 = glm::vec3(); | 400 | glm::vec3 newVec3 = glm::vec3(); |
| 401 | vec3FromScriptValue(array->property(i), newVec3); | 401 | vec3FromScriptValue(array.property(i), newVec3); |
| 402 | newVector << newVec3; | 402 | newVector << newVec3; |
| 403 | } | 403 | } |
| 404 | return newVector; | 404 | return newVector; |
| 405 | } | 405 | } |
| 406 | 406 | ||
| 407 | void qVectorVec3FromScriptValue(const ScriptValuePointer& array, QVector<glm::vec3>& vector) { | 407 | void qVectorVec3FromScriptValue(const ScriptValue& array, QVector<glm::vec3>& vector) { |
| 408 | int length = array->property("length")->toInteger(); | 408 | int length = array.property("length").toInteger(); |
| 409 | 409 | ||
| 410 | for (int i = 0; i < length; i++) { | 410 | for (int i = 0; i < length; i++) { |
| 411 | glm::vec3 newVec3 = glm::vec3(); | 411 | glm::vec3 newVec3 = glm::vec3(); |
| 412 | vec3FromScriptValue(array->property(i), newVec3); | 412 | vec3FromScriptValue(array.property(i), newVec3); |
| 413 | vector << newVec3; | 413 | vector << newVec3; |
| 414 | } | 414 | } |
| 415 | } | 415 | } |
| 416 | 416 | ||
| 417 | ScriptValuePointer quatToScriptValue(ScriptEngine* engine, const glm::quat& quat) { | 417 | ScriptValue quatToScriptValue(ScriptEngine* engine, const glm::quat& quat) { |
| 418 | ScriptValuePointer obj = engine->newObject(); | 418 | ScriptValue obj = engine->newObject(); |
| 419 | if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z || quat.w != quat.w) { | 419 | if (quat.x != quat.x || quat.y != quat.y || quat.z != quat.z || quat.w != quat.w) { |
| 420 | // if quat contains a NaN don't try to convert it | 420 | // if quat contains a NaN don't try to convert it |
| 421 | return obj; | 421 | return obj; |
| 422 | } | 422 | } |
| 423 | obj->setProperty("x", quat.x); | 423 | obj.setProperty("x", quat.x); |
| 424 | obj->setProperty("y", quat.y); | 424 | obj.setProperty("y", quat.y); |
| 425 | obj->setProperty("z", quat.z); | 425 | obj.setProperty("z", quat.z); |
| 426 | obj->setProperty("w", quat.w); | 426 | obj.setProperty("w", quat.w); |
| 427 | return obj; | 427 | return obj; |
| 428 | } | 428 | } |
| 429 | 429 | ||
| 430 | void quatFromScriptValue(const ScriptValuePointer& object, glm::quat& quat) { | 430 | void quatFromScriptValue(const ScriptValue& object, glm::quat& quat) { |
| 431 | quat.x = object->property("x")->toVariant().toFloat(); | 431 | quat.x = object.property("x").toVariant().toFloat(); |
| 432 | quat.y = object->property("y")->toVariant().toFloat(); | 432 | quat.y = object.property("y").toVariant().toFloat(); |
| 433 | quat.z = object->property("z")->toVariant().toFloat(); | 433 | quat.z = object.property("z").toVariant().toFloat(); |
| 434 | quat.w = object->property("w")->toVariant().toFloat(); | 434 | quat.w = object.property("w").toVariant().toFloat(); |
| 435 | 435 | ||
| 436 | // enforce normalized quaternion | 436 | // enforce normalized quaternion |
| 437 | float length = glm::length(quat); | 437 | float length = glm::length(quat); |
| @@ -442,181 +442,181 @@ void quatFromScriptValue(const ScriptValuePointer& object, glm::quat& quat) { · 4 unmodified lines | |||
| 442 | } | 442 | } |
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | ScriptValuePointer qVectorQuatToScriptValue(ScriptEngine* engine, const QVector<glm::quat>& vector) { | 445 | ScriptValue qVectorQuatToScriptValue(ScriptEngine* engine, const QVector<glm::quat>& vector) { |
| 446 | ScriptValuePointer array = engine->newArray(); | 446 | ScriptValue array = engine->newArray(); |
| 447 | for (int i = 0; i < vector.size(); i++) { | 447 | for (int i = 0; i < vector.size(); i++) { |
| 448 | array->setProperty(i, quatToScriptValue(engine, vector.at(i))); | 448 | array.setProperty(i, quatToScriptValue(engine, vector.at(i))); |
| 449 | } | 449 | } |
| 450 | return array; | 450 | return array; |
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | ScriptValuePointer qVectorBoolToScriptValue(ScriptEngine* engine, const QVector<bool>& vector) { | 453 | ScriptValue qVectorBoolToScriptValue(ScriptEngine* engine, const QVector<bool>& vector) { |
| 454 | ScriptValuePointer array = engine->newArray(); | 454 | ScriptValue array = engine->newArray(); |
| 455 | for (int i = 0; i < vector.size(); i++) { | 455 | for (int i = 0; i < vector.size(); i++) { |
| 456 | array->setProperty(i, vector.at(i)); | 456 | array.setProperty(i, vector.at(i)); |
| 457 | } | 457 | } |
| 458 | return array; | 458 | return array; |
| 459 | } | 459 | } |
| 460 | 460 | ||
| 461 | QVector<float> qVectorFloatFromScriptValue(const ScriptValuePointer& array) { | 461 | QVector<float> qVectorFloatFromScriptValue(const ScriptValue& array) { |
| 462 | if (!array->isArray()) { | 462 | if (!array.isArray()) { |
| 463 | return QVector<float>(); | 463 | return QVector<float>(); |
| 464 | } | 464 | } |
| 465 | QVector<float> newVector; | 465 | QVector<float> newVector; |
| 466 | int length = array->property("length")->toInteger(); | 466 | int length = array.property("length").toInteger(); |
| 467 | newVector.reserve(length); | 467 | newVector.reserve(length); |
| 468 | for (int i = 0; i < length; i++) { | 468 | for (int i = 0; i < length; i++) { |
| 469 | if (array->property(i)->isNumber()) { | 469 | if (array.property(i).isNumber()) { |
| 470 | newVector << array->property(i)->toNumber(); | 470 | newVector << array.property(i).toNumber(); |
| 471 | } | 471 | } |
| 472 | } | 472 | } |
| 473 | 473 | ||
| 474 | return newVector; | 474 | return newVector; |
| 475 | } | 475 | } |
| 476 | 476 | ||
| 477 | ScriptValuePointer qVectorQUuidToScriptValue(ScriptEngine* engine, const QVector<QUuid>& vector) { | 477 | ScriptValue qVectorQUuidToScriptValue(ScriptEngine* engine, const QVector<QUuid>& vector) { |
| 478 | ScriptValuePointer array = engine->newArray(); | 478 | ScriptValue array = engine->newArray(); |
| 479 | for (int i = 0; i < vector.size(); i++) { | 479 | for (int i = 0; i < vector.size(); i++) { |
| 480 | array->setProperty(i, quuidToScriptValue(engine, vector.at(i))); | 480 | array.setProperty(i, quuidToScriptValue(engine, vector.at(i))); |
| 481 | } | 481 | } |
| 482 | return array; | 482 | return array; |
| 483 | } | 483 | } |
| 484 | 484 | ||
| 485 | void qVectorQUuidFromScriptValue(const ScriptValuePointer& array, QVector<QUuid>& vector) { | 485 | void qVectorQUuidFromScriptValue(const ScriptValue& array, QVector<QUuid>& vector) { |
| 486 | int length = array->property("length")->toInteger(); | 486 | int length = array.property("length").toInteger(); |
| 487 | 487 | ||
| 488 | for (int i = 0; i < length; i++) { | 488 | for (int i = 0; i < length; i++) { |
| 489 | vector << array->property(i)->toVariant().toUuid(); | 489 | vector << array.property(i).toVariant().toUuid(); |
| 490 | } | 490 | } |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | QVector<QUuid> qVectorQUuidFromScriptValue(const ScriptValuePointer& array) { | 493 | QVector<QUuid> qVectorQUuidFromScriptValue(const ScriptValue& array) { |
| 494 | if (!array->isArray()) { | 494 | if (!array.isArray()) { |
| 495 | return QVector<QUuid>(); | 495 | return QVector<QUuid>(); |
| 496 | } | 496 | } |
| 497 | QVector<QUuid> newVector; | 497 | QVector<QUuid> newVector; |
| 498 | int length = array->property("length")->toInteger(); | 498 | int length = array.property("length").toInteger(); |
| 499 | newVector.reserve(length); | 499 | newVector.reserve(length); |
| 500 | for (int i = 0; i < length; i++) { | 500 | for (int i = 0; i < length; i++) { |
| 501 | QString uuidAsString = array->property(i)->toString(); | 501 | QString uuidAsString = array.property(i).toString(); |
| 502 | QUuid fromString(uuidAsString); | 502 | QUuid fromString(uuidAsString); |
| 503 | newVector << fromString; | 503 | newVector << fromString; |
| 504 | } | 504 | } |
| 505 | return newVector; | 505 | return newVector; |
| 506 | } | 506 | } |
| 507 | 507 | ||
| 508 | ScriptValuePointer qVectorFloatToScriptValue(ScriptEngine* engine, const QVector<float>& vector) { | 508 | ScriptValue qVectorFloatToScriptValue(ScriptEngine* engine, const QVector<float>& vector) { |
| 509 | ScriptValuePointer array = engine->newArray(); | 509 | ScriptValue array = engine->newArray(); |
| 510 | for (int i = 0; i < vector.size(); i++) { | 510 | for (int i = 0; i < vector.size(); i++) { |
| 511 | float num = vector.at(i); | 511 | float num = vector.at(i); |
| 512 | array->setProperty(i, engine->newValue(num)); | 512 | array.setProperty(i, engine->newValue(num)); |
| 513 | } | 513 | } |
| 514 | return array; | 514 | return array; |
| 515 | } | 515 | } |
| 516 | 516 | ||
| 517 | ScriptValuePointer qVectorIntToScriptValue(ScriptEngine* engine, const QVector<uint32_t>& vector) { | 517 | ScriptValue qVectorIntToScriptValue(ScriptEngine* engine, const QVector<uint32_t>& vector) { |
| 518 | ScriptValuePointer array = engine->newArray(); | 518 | ScriptValue array = engine->newArray(); |
| 519 | for (int i = 0; i < vector.size(); i++) { | 519 | for (int i = 0; i < vector.size(); i++) { |
| 520 | int num = vector.at(i); | 520 | int num = vector.at(i); |
| 521 | array->setProperty(i, engine->newValue(num)); | 521 | array.setProperty(i, engine->newValue(num)); |
| 522 | } | 522 | } |
| 523 | return array; | 523 | return array; |
| 524 | } | 524 | } |
| 525 | 525 | ||
| 526 | void qVectorFloatFromScriptValue(const ScriptValuePointer& array, QVector<float>& vector) { | 526 | void qVectorFloatFromScriptValue(const ScriptValue& array, QVector<float>& vector) { |
| 527 | int length = array->property("length")->toInteger(); | 527 | int length = array.property("length").toInteger(); |
| 528 | 528 | ||
| 529 | for (int i = 0; i < length; i++) { | 529 | for (int i = 0; i < length; i++) { |
| 530 | vector << array->property(i)->toVariant().toFloat(); | 530 | vector << array.property(i).toVariant().toFloat(); |
| 531 | } | 531 | } |
| 532 | } | 532 | } |
| 533 | 533 | ||
| 534 | void qVectorIntFromScriptValue(const ScriptValuePointer& array, QVector<uint32_t>& vector) { | 534 | void qVectorIntFromScriptValue(const ScriptValue& array, QVector<uint32_t>& vector) { |
| 535 | int length = array->property("length")->toInteger(); | 535 | int length = array.property("length").toInteger(); |
| 536 | 536 | ||
| 537 | for (int i = 0; i < length; i++) { | 537 | for (int i = 0; i < length; i++) { |
| 538 | vector << array->property(i)->toVariant().toInt(); | 538 | vector << array.property(i).toVariant().toInt(); |
| 539 | } | 539 | } |
| 540 | } | 540 | } |
| 541 | 541 | ||
| 542 | QVector<glm::quat> qVectorQuatFromScriptValue(const ScriptValuePointer& array) { | 542 | QVector<glm::quat> qVectorQuatFromScriptValue(const ScriptValue& array) { |
| 543 | QVector<glm::quat> newVector; | 543 | QVector<glm::quat> newVector; |
| 544 | int length = array->property("length")->toInteger(); | 544 | int length = array.property("length").toInteger(); |
| 545 | 545 | ||
| 546 | for (int i = 0; i < length; i++) { | 546 | for (int i = 0; i < length; i++) { |
| 547 | glm::quat newQuat = glm::quat(); | 547 | glm::quat newQuat = glm::quat(); |
| 548 | quatFromScriptValue(array->property(i), newQuat); | 548 | quatFromScriptValue(array.property(i), newQuat); |
| 549 | newVector << newQuat; | 549 | newVector << newQuat; |
| 550 | } | 550 | } |
| 551 | return newVector; | 551 | return newVector; |
| 552 | } | 552 | } |
| 553 | 553 | ||
| 554 | void qVectorQuatFromScriptValue(const ScriptValuePointer& array, QVector<glm::quat>& vector) { | 554 | void qVectorQuatFromScriptValue(const ScriptValue& array, QVector<glm::quat>& vector) { |
| 555 | int length = array->property("length")->toInteger(); | 555 | int length = array.property("length").toInteger(); |
| 556 | 556 | ||
| 557 | for (int i = 0; i < length; i++) { | 557 | for (int i = 0; i < length; i++) { |
| 558 | glm::quat newQuat = glm::quat(); | 558 | glm::quat newQuat = glm::quat(); |
| 559 | quatFromScriptValue(array->property(i), newQuat); | 559 | quatFromScriptValue(array.property(i), newQuat); |
| 560 | vector << newQuat; | 560 | vector << newQuat; |
| 561 | } | 561 | } |
| 562 | } | 562 | } |
| 563 | 563 | ||
| 564 | QVector<bool> qVectorBoolFromScriptValue(const ScriptValuePointer& array) { | 564 | QVector<bool> qVectorBoolFromScriptValue(const ScriptValue& array) { |
| 565 | QVector<bool> newVector; | 565 | QVector<bool> newVector; |
| 566 | int length = array->property("length")->toInteger(); | 566 | int length = array.property("length").toInteger(); |
| 567 | 567 | ||
| 568 | for (int i = 0; i < length; i++) { | 568 | for (int i = 0; i < length; i++) { |
| 569 | newVector << array->property(i)->toBool(); | 569 | newVector << array.property(i).toBool(); |
| 570 | } | 570 | } |
| 571 | return newVector; | 571 | return newVector; |
| 572 | } | 572 | } |
| 573 | 573 | ||
| 574 | void qVectorBoolFromScriptValue(const ScriptValuePointer& array, QVector<bool>& vector) { | 574 | void qVectorBoolFromScriptValue(const ScriptValue& array, QVector<bool>& vector) { |
| 575 | int length = array->property("length")->toInteger(); | 575 | int length = array.property("length").toInteger(); |
| 576 | 576 | ||
| 577 | for (int i = 0; i < length; i++) { | 577 | for (int i = 0; i < length; i++) { |
| 578 | vector << array->property(i)->toBool(); | 578 | vector << array.property(i).toBool(); |
| 579 | } | 579 | } |
| 580 | } | 580 | } |
| 581 | 581 | ||
| 582 | ScriptValuePointer qRectToScriptValue(ScriptEngine* engine, const QRect& rect) { | 582 | ScriptValue qRectToScriptValue(ScriptEngine* engine, const QRect& rect) { |
| 583 | ScriptValuePointer obj = engine->newObject(); | 583 | ScriptValue obj = engine->newObject(); |
| 584 | obj->setProperty("x", rect.x()); | 584 | obj.setProperty("x", rect.x()); |
| 585 | obj->setProperty("y", rect.y()); | 585 | obj.setProperty("y", rect.y()); |
| 586 | obj->setProperty("width", rect.width()); | 586 | obj.setProperty("width", rect.width()); |
| 587 | obj->setProperty("height", rect.height()); | 587 | obj.setProperty("height", rect.height()); |
| 588 | return obj; | 588 | return obj; |
| 589 | } | 589 | } |
| 590 | 590 | ||
| 591 | void qRectFromScriptValue(const ScriptValuePointer& object, QRect& rect) { | 591 | void qRectFromScriptValue(const ScriptValue& object, QRect& rect) { |
| 592 | rect.setX(object->property("x")->toVariant().toInt()); | 592 | rect.setX(object.property("x").toVariant().toInt()); |
| 593 | rect.setY(object->property("y")->toVariant().toInt()); | 593 | rect.setY(object.property("y").toVariant().toInt()); |
| 594 | rect.setWidth(object->property("width")->toVariant().toInt()); | 594 | rect.setWidth(object.property("width").toVariant().toInt()); |
| 595 | rect.setHeight(object->property("height")->toVariant().toInt()); | 595 | rect.setHeight(object.property("height").toVariant().toInt()); |
| 596 | } | 596 | } |
| 597 | 597 | ||
| 598 | ScriptValuePointer qRectFToScriptValue(ScriptEngine* engine, const QRectF& rect) { | 598 | ScriptValue qRectFToScriptValue(ScriptEngine* engine, const QRectF& rect) { |
| 599 | ScriptValuePointer obj = engine->newObject(); | 599 | ScriptValue obj = engine->newObject(); |
| 600 | obj->setProperty("x", rect.x()); | 600 | obj.setProperty("x", rect.x()); |
| 601 | obj->setProperty("y", rect.y()); | 601 | obj.setProperty("y", rect.y()); |
| 602 | obj->setProperty("width", rect.width()); | 602 | obj.setProperty("width", rect.width()); |
| 603 | obj->setProperty("height", rect.height()); | 603 | obj.setProperty("height", rect.height()); |
| 604 | return obj; | 604 | return obj; |
| 605 | } | 605 | } |
| 606 | 606 | ||
| 607 | void qRectFFromScriptValue(const ScriptValuePointer& object, QRectF& rect) { | 607 | void qRectFFromScriptValue(const ScriptValue& object, QRectF& rect) { |
| 608 | rect.setX(object->property("x")->toVariant().toFloat()); | 608 | rect.setX(object.property("x").toVariant().toFloat()); |
| 609 | rect.setY(object->property("y")->toVariant().toFloat()); | 609 | rect.setY(object.property("y").toVariant().toFloat()); |
| 610 | rect.setWidth(object->property("width")->toVariant().toFloat()); | 610 | rect.setWidth(object.property("width").toVariant().toFloat()); |
| 611 | rect.setHeight(object->property("height")->toVariant().toFloat()); | 611 | rect.setHeight(object.property("height").toVariant().toFloat()); |
| 612 | } | 612 | } |
| 613 | 613 | ||
| 614 | ScriptValuePointer qColorToScriptValue(ScriptEngine* engine, const QColor& color) { | 614 | ScriptValue qColorToScriptValue(ScriptEngine* engine, const QColor& color) { |
| 615 | ScriptValuePointer object = engine->newObject(); | 615 | ScriptValue object = engine->newObject(); |
| 616 | object->setProperty("red", color.red()); | 616 | object.setProperty("red", color.red()); |
| 617 | object->setProperty("green", color.green()); | 617 | object.setProperty("green", color.green()); |
| 618 | object->setProperty("blue", color.blue()); | 618 | object.setProperty("blue", color.blue()); |
| 619 | object->setProperty("alpha", color.alpha()); | 619 | object.setProperty("alpha", color.alpha()); |
| 620 | return object; | 620 | return object; |
| 621 | } | 621 | } |
| 622 | 622 | ||
| @@ -629,78 +629,78 @@ ScriptValuePointer qColorToScriptValue(ScriptEngine* engine, const QColor& color · 6 unmodified lines | |||
| 629 | * @property {number} z - Z coordinate of the brn corner of the cube. | 629 | * @property {number} z - Z coordinate of the brn corner of the cube. |
| 630 | * @property {number} scale - The dimensions of each side of the cube. | 630 | * @property {number} scale - The dimensions of each side of the cube. |
| 631 | */ | 631 | */ |
| 632 | ScriptValuePointer aaCubeToScriptValue(ScriptEngine* engine, const AACube& aaCube) { | 632 | ScriptValue aaCubeToScriptValue(ScriptEngine* engine, const AACube& aaCube) { |
| 633 | ScriptValuePointer obj = engine->newObject(); | 633 | ScriptValue obj = engine->newObject(); |
| 634 | const glm::vec3& corner = aaCube.getCorner(); | 634 | const glm::vec3& corner = aaCube.getCorner(); |
| 635 | obj->setProperty("x", corner.x); | 635 | obj.setProperty("x", corner.x); |
| 636 | obj->setProperty("y", corner.y); | 636 | obj.setProperty("y", corner.y); |
| 637 | obj->setProperty("z", corner.z); | 637 | obj.setProperty("z", corner.z); |
| 638 | obj->setProperty("scale", aaCube.getScale()); | 638 | obj.setProperty("scale", aaCube.getScale()); |
| 639 | return obj; | 639 | return obj; |
| 640 | } | 640 | } |
| 641 | 641 | ||
| 642 | void aaCubeFromScriptValue(const ScriptValuePointer& object, AACube& aaCube) { | 642 | void aaCubeFromScriptValue(const ScriptValue& object, AACube& aaCube) { |
| 643 | glm::vec3 corner; | 643 | glm::vec3 corner; |
| 644 | corner.x = object->property("x")->toVariant().toFloat(); | 644 | corner.x = object.property("x").toVariant().toFloat(); |
| 645 | corner.y = object->property("y")->toVariant().toFloat(); | 645 | corner.y = object.property("y").toVariant().toFloat(); |
| 646 | corner.z = object->property("z")->toVariant().toFloat(); | 646 | corner.z = object.property("z").toVariant().toFloat(); |
| 647 | float scale = object->property("scale")->toVariant().toFloat(); | 647 | float scale = object.property("scale").toVariant().toFloat(); |
| 648 | 648 | ||
| 649 | aaCube.setBox(corner, scale); | 649 | aaCube.setBox(corner, scale); |
| 650 | } | 650 | } |
| 651 | 651 | ||
| 652 | void qColorFromScriptValue(const ScriptValuePointer& object, QColor& color) { | 652 | void qColorFromScriptValue(const ScriptValue& object, QColor& color) { |
| 653 | if (object->isNumber()) { | 653 | if (object.isNumber()) { |
| 654 | color.setRgb(object->toUInt32()); | 654 | color.setRgb(object.toUInt32()); |
| 655 | 655 | ||
| 656 | } else if (object->isString()) { | 656 | } else if (object.isString()) { |
| 657 | color.setNamedColor(object->toString()); | 657 | color.setNamedColor(object.toString()); |
| 658 | 658 | ||
| 659 | } else { | 659 | } else { |
| 660 | ScriptValuePointer alphaValue = object->property("alpha"); | 660 | ScriptValue alphaValue = object.property("alpha"); |
| 661 | color.setRgb(object->property("red")->toInt32(), object->property("green")->toInt32(), object->property("blue")->toInt32(), | 661 | color.setRgb(object.property("red").toInt32(), object.property("green").toInt32(), object.property("blue").toInt32(), |
| 662 | alphaValue->isNumber() ? alphaValue->toInt32() : 255); | 662 | alphaValue.isNumber() ? alphaValue.toInt32() : 255); |
| 663 | } | 663 | } |
| 664 | } | 664 | } |
| 665 | 665 | ||
| 666 | ScriptValuePointer qURLToScriptValue(ScriptEngine* engine, const QUrl& url) { | 666 | ScriptValue qURLToScriptValue(ScriptEngine* engine, const QUrl& url) { |
| 667 | return engine->newValue(url.toString()); | 667 | return engine->newValue(url.toString()); |
| 668 | } | 668 | } |
| 669 | 669 | ||
| 670 | void qURLFromScriptValue(const ScriptValuePointer& object, QUrl& url) { | 670 | void qURLFromScriptValue(const ScriptValue& object, QUrl& url) { |
| 671 | url = object->toString(); | 671 | url = object.toString(); |
| 672 | } | 672 | } |
| 673 | 673 | ||
| 674 | ScriptValuePointer pickRayToScriptValue(ScriptEngine* engine, const PickRay& pickRay) { | 674 | ScriptValue pickRayToScriptValue(ScriptEngine* engine, const PickRay& pickRay) { |
| 675 | ScriptValuePointer obj = engine->newObject(); | 675 | ScriptValue obj = engine->newObject(); |
| 676 | ScriptValuePointer origin = vec3ToScriptValue(engine, pickRay.origin); | 676 | ScriptValue origin = vec3ToScriptValue(engine, pickRay.origin); |
| 677 | obj->setProperty("origin", origin); | 677 | obj.setProperty("origin", origin); |
| 678 | ScriptValuePointer direction = vec3ToScriptValue(engine, pickRay.direction); | 678 | ScriptValue direction = vec3ToScriptValue(engine, pickRay.direction); |
| 679 | obj->setProperty("direction", direction); | 679 | obj.setProperty("direction", direction); |
| 680 | return obj; | 680 | return obj; |
| 681 | } | 681 | } |
| 682 | 682 | ||
| 683 | void pickRayFromScriptValue(const ScriptValuePointer& object, PickRay& pickRay) { | 683 | void pickRayFromScriptValue(const ScriptValue& object, PickRay& pickRay) { |
| 684 | ScriptValuePointer originValue = object->property("origin"); | 684 | ScriptValue originValue = object.property("origin"); |
| 685 | if (originValue->isValid()) { | 685 | if (originValue.isValid()) { |
| 686 | auto x = originValue->property("x"); | 686 | auto x = originValue.property("x"); |
| 687 | auto y = originValue->property("y"); | 687 | auto y = originValue.property("y"); |
| 688 | auto z = originValue->property("z"); | 688 | auto z = originValue.property("z"); |
| 689 | if (x->isValid() && y->isValid() && z->isValid()) { | 689 | if (x.isValid() && y.isValid() && z.isValid()) { |
| 690 | pickRay.origin.x = x->toVariant().toFloat(); | 690 | pickRay.origin.x = x.toVariant().toFloat(); |
| 691 | pickRay.origin.y = y->toVariant().toFloat(); | 691 | pickRay.origin.y = y.toVariant().toFloat(); |
| 692 | pickRay.origin.z = z->toVariant().toFloat(); | 692 | pickRay.origin.z = z.toVariant().toFloat(); |
| 693 | } | 693 | } |
| 694 | } | 694 | } |
| 695 | ScriptValuePointer directionValue = object->property("direction"); | 695 | ScriptValue directionValue = object.property("direction"); |
| 696 | if (directionValue->isValid()) { | 696 | if (directionValue.isValid()) { |
| 697 | auto x = directionValue->property("x"); | 697 | auto x = directionValue.property("x"); |
| 698 | auto y = directionValue->property("y"); | 698 | auto y = directionValue.property("y"); |
| 699 | auto z = directionValue->property("z"); | 699 | auto z = directionValue.property("z"); |
| 700 | if (x->isValid() && y->isValid() && z->isValid()) { | 700 | if (x.isValid() && y.isValid() && z.isValid()) { |
| 701 | pickRay.direction.x = x->toVariant().toFloat(); | 701 | pickRay.direction.x = x.toVariant().toFloat(); |
| 702 | pickRay.direction.y = y->toVariant().toFloat(); | 702 | pickRay.direction.y = y.toVariant().toFloat(); |
| 703 | pickRay.direction.z = z->toVariant().toFloat(); | 703 | pickRay.direction.z = z.toVariant().toFloat(); |
| 704 | } | 704 | } |
| 705 | } | 705 | } |
| 706 | } | 706 | } |
| @@ -715,35 +715,35 @@ void pickRayFromScriptValue(const ScriptValuePointer& object, PickRay& pickRay) · 8 unmodified lines | |||
| 715 | * @property {Vec3} contactPoint - The point of contact. | 715 | * @property {Vec3} contactPoint - The point of contact. |
| 716 | * @property {Vec3} velocityChange - The change in relative velocity of the two items, in m/s. | 716 | * @property {Vec3} velocityChange - The change in relative velocity of the two items, in m/s. |
| 717 | */ | 717 | */ |
| 718 | ScriptValuePointer collisionToScriptValue(ScriptEngine* engine, const Collision& collision) { | 718 | ScriptValue collisionToScriptValue(ScriptEngine* engine, const Collision& collision) { |
| 719 | ScriptValuePointer obj = engine->newObject(); | 719 | ScriptValue obj = engine->newObject(); |
| 720 | obj->setProperty("type", collision.type); | 720 | obj.setProperty("type", collision.type); |
| 721 | obj->setProperty("idA", quuidToScriptValue(engine, collision.idA)); | 721 | obj.setProperty("idA", quuidToScriptValue(engine, collision.idA)); |
| 722 | obj->setProperty("idB", quuidToScriptValue(engine, collision.idB)); | 722 | obj.setProperty("idB", quuidToScriptValue(engine, collision.idB)); |
| 723 | obj->setProperty("penetration", vec3ToScriptValue(engine, collision.penetration)); | 723 | obj.setProperty("penetration", vec3ToScriptValue(engine, collision.penetration)); |
| 724 | obj->setProperty("contactPoint", vec3ToScriptValue(engine, collision.contactPoint)); | 724 | obj.setProperty("contactPoint", vec3ToScriptValue(engine, collision.contactPoint)); |
| 725 | obj->setProperty("velocityChange", vec3ToScriptValue(engine, collision.velocityChange)); | 725 | obj.setProperty("velocityChange", vec3ToScriptValue(engine, collision.velocityChange)); |
| 726 | return obj; | 726 | return obj; |
| 727 | } | 727 | } |
| 728 | 728 | ||
| 729 | void collisionFromScriptValue(const ScriptValuePointer& object, Collision& collision) { | 729 | void collisionFromScriptValue(const ScriptValue& object, Collision& collision) { |
| 730 | // TODO: implement this when we know what it means to accept collision events from JS | 730 | // TODO: implement this when we know what it means to accept collision events from JS |
| 731 | } | 731 | } |
| 732 | 732 | ||
| 733 | ScriptValuePointer quuidToScriptValue(ScriptEngine* engine, const QUuid& uuid) { | 733 | ScriptValue quuidToScriptValue(ScriptEngine* engine, const QUuid& uuid) { |
| 734 | if (uuid.isNull()) { | 734 | if (uuid.isNull()) { |
| 735 | return engine->nullValue(); | 735 | return engine->nullValue(); |
| 736 | } | 736 | } |
| 737 | ScriptValuePointer obj(engine->newValue(uuid.toString())); | 737 | ScriptValue obj(engine->newValue(uuid.toString())); |
| 738 | return obj; | 738 | return obj; |
| 739 | } | 739 | } |
| 740 | 740 | ||
| 741 | void quuidFromScriptValue(const ScriptValuePointer& object, QUuid& uuid) { | 741 | void quuidFromScriptValue(const ScriptValue& object, QUuid& uuid) { |
| 742 | if (object.isNull()) { | 742 | if (object.isNull()) { |
| 743 | uuid = QUuid(); | 743 | uuid = QUuid(); |
| 744 | return; | 744 | return; |
| 745 | } | 745 | } |
| 746 | QString uuidAsString = object->toVariant().toString(); | 746 | QString uuidAsString = object.toVariant().toString(); |
| 747 | QUuid fromString(uuidAsString); | 747 | QUuid fromString(uuidAsString); |
| 748 | uuid = fromString; | 748 | uuid = fromString; |
| 749 | } | 749 | } |
| @@ -754,16 +754,16 @@ void quuidFromScriptValue(const ScriptValuePointer& object, QUuid& uuid) { · 4 unmodified lines | |||
| 754 | * @property {number} height - The height value. | 754 | * @property {number} height - The height value. |
| 755 | * @property {number} width - The width value. | 755 | * @property {number} width - The width value. |
| 756 | */ | 756 | */ |
| 757 | ScriptValuePointer qSizeFToScriptValue(ScriptEngine* engine, const QSizeF& qSizeF) { | 757 | ScriptValue qSizeFToScriptValue(ScriptEngine* engine, const QSizeF& qSizeF) { |
| 758 | ScriptValuePointer obj = engine->newObject(); | 758 | ScriptValue obj = engine->newObject(); |
| 759 | obj->setProperty("width", qSizeF.width()); | 759 | obj.setProperty("width", qSizeF.width()); |
| 760 | obj->setProperty("height", qSizeF.height()); | 760 | obj.setProperty("height", qSizeF.height()); |
| 761 | return obj; | 761 | return obj; |
| 762 | } | 762 | } |
| 763 | 763 | ||
| 764 | void qSizeFFromScriptValue(const ScriptValuePointer& object, QSizeF& qSizeF) { | 764 | void qSizeFFromScriptValue(const ScriptValue& object, QSizeF& qSizeF) { |
| 765 | qSizeF.setWidth(object->property("width")->toVariant().toFloat()); | 765 | qSizeF.setWidth(object.property("width").toVariant().toFloat()); |
| 766 | qSizeF.setHeight(object->property("height")->toVariant().toFloat()); | 766 | qSizeF.setHeight(object.property("height").toVariant().toFloat()); |
| 767 | } | 767 | } |
| 768 | 768 | ||
| 769 | /**jsdoc | 769 | /**jsdoc |
| @@ -785,47 +785,47 @@ void qSizeFFromScriptValue(const ScriptValuePointer& object, QSizeF& qSizeF) { · 15 unmodified lines | |||
| 785 | * @property {boolean} startAutomatically - <em>Not used.</em> | 785 | * @property {boolean} startAutomatically - <em>Not used.</em> |
| 786 | * @property {boolean} allowTranslation - <em>Not used.</em> | 786 | * @property {boolean} allowTranslation - <em>Not used.</em> |
| 787 | */ | 787 | */ |
| 788 | ScriptValuePointer animationDetailsToScriptValue(ScriptEngine* engine, const AnimationDetails& details) { | 788 | ScriptValue animationDetailsToScriptValue(ScriptEngine* engine, const AnimationDetails& details) { |
| 789 | ScriptValuePointer obj = engine->newObject(); | 789 | ScriptValue obj = engine->newObject(); |
| 790 | obj->setProperty("role", details.role); | 790 | obj.setProperty("role", details.role); |
| 791 | obj->setProperty("url", details.url.toString()); | 791 | obj.setProperty("url", details.url.toString()); |
| 792 | obj->setProperty("fps", details.fps); | 792 | obj.setProperty("fps", details.fps); |
| 793 | obj->setProperty("priority", details.priority); | 793 | obj.setProperty("priority", details.priority); |
| 794 | obj->setProperty("loop", details.loop); | 794 | obj.setProperty("loop", details.loop); |
| 795 | obj->setProperty("hold", details.hold); | 795 | obj.setProperty("hold", details.hold); |
| 796 | obj->setProperty("startAutomatically", details.startAutomatically); | 796 | obj.setProperty("startAutomatically", details.startAutomatically); |
| 797 | obj->setProperty("firstFrame", details.firstFrame); | 797 | obj.setProperty("firstFrame", details.firstFrame); |
| 798 | obj->setProperty("lastFrame", details.lastFrame); | 798 | obj.setProperty("lastFrame", details.lastFrame); |
| 799 | obj->setProperty("running", details.running); | 799 | obj.setProperty("running", details.running); |
| 800 | obj->setProperty("currentFrame", details.currentFrame); | 800 | obj.setProperty("currentFrame", details.currentFrame); |
| 801 | obj->setProperty("allowTranslation", details.allowTranslation); | 801 | obj.setProperty("allowTranslation", details.allowTranslation); |
| 802 | return obj; | 802 | return obj; |
| 803 | } | 803 | } |
| 804 | 804 | ||
| 805 | void animationDetailsFromScriptValue(const ScriptValuePointer& object, AnimationDetails& details) { | 805 | void animationDetailsFromScriptValue(const ScriptValue& object, AnimationDetails& details) { |
| 806 | // nothing for now... | 806 | // nothing for now... |
| 807 | } | 807 | } |
| 808 | 808 | ||
| 809 | ScriptValuePointer meshToScriptValue(ScriptEngine* engine, MeshProxy* const& in) { | 809 | ScriptValue meshToScriptValue(ScriptEngine* engine, MeshProxy* const& in) { |
| 810 | return engine->newQObject(in, ScriptEngine::QtOwnership); | 810 | return engine->newQObject(in, ScriptEngine::QtOwnership); |
| 811 | } | 811 | } |
| 812 | 812 | ||
| 813 | void meshFromScriptValue(const ScriptValuePointer& value, MeshProxy*& out) { | 813 | void meshFromScriptValue(const ScriptValue& value, MeshProxy*& out) { |
| 814 | out = qobject_cast<MeshProxy*>(value->toQObject()); | 814 | out = qobject_cast<MeshProxy*>(value.toQObject()); |
| 815 | } | 815 | } |
| 816 | 816 | ||
| 817 | ScriptValuePointer meshesToScriptValue(ScriptEngine* engine, const MeshProxyList& in) { | 817 | ScriptValue meshesToScriptValue(ScriptEngine* engine, const MeshProxyList& in) { |
| 818 | // ScriptValueList result; | 818 | // ScriptValueList result; |
| 819 | ScriptValuePointer result = engine->newArray(); | 819 | ScriptValue result = engine->newArray(); |
| 820 | int i = 0; | 820 | int i = 0; |
| 821 | foreach (MeshProxy* const meshProxy, in) { result->setProperty(i++, meshToScriptValue(engine, meshProxy)); } | 821 | foreach (MeshProxy* const meshProxy, in) { result.setProperty(i++, meshToScriptValue(engine, meshProxy)); } |
| 822 | return result; | 822 | return result; |
| 823 | } | 823 | } |
| 824 | 824 | ||
| 825 | void meshesFromScriptValue(const ScriptValuePointer& value, MeshProxyList& out) { | 825 | void meshesFromScriptValue(const ScriptValue& value, MeshProxyList& out) { |
| 826 | ScriptValueIteratorPointer itr(value->newIterator()); | 826 | ScriptValueIteratorPointer itr(value.newIterator()); |
| 827 | 827 | ||
| 828 | qDebug() << "in meshesFromScriptValue, value.length =" << value->property("length")->toInt32(); | 828 | qDebug() << "in meshesFromScriptValue, value.length =" << value.property("length").toInt32(); |
| 829 | 829 | ||
| 830 | while (itr->hasNext()) { | 830 | while (itr->hasNext()) { |
| 831 | itr->next(); | 831 | itr->next(); |
| @@ -843,67 +843,67 @@ void meshesFromScriptValue(const ScriptValuePointer& value, MeshProxyList& out) · 11 unmodified lines | |||
| 843 | * @typedef {object} MeshFace | 843 | * @typedef {object} MeshFace |
| 844 | * @property {number[]} vertices - The indexes of the three vertices that make up the face. | 844 | * @property {number[]} vertices - The indexes of the three vertices that make up the face. |
| 845 | */ | 845 | */ |
| 846 | ScriptValuePointer meshFaceToScriptValue(ScriptEngine* engine, const MeshFace& meshFace) { | 846 | ScriptValue meshFaceToScriptValue(ScriptEngine* engine, const MeshFace& meshFace) { |
| 847 | ScriptValuePointer obj = engine->newObject(); | 847 | ScriptValue obj = engine->newObject(); |
| 848 | obj->setProperty("vertices", qVectorIntToScriptValue(engine, meshFace.vertexIndices)); | 848 | obj.setProperty("vertices", qVectorIntToScriptValue(engine, meshFace.vertexIndices)); |
| 849 | return obj; | 849 | return obj; |
| 850 | } | 850 | } |
| 851 | 851 | ||
| 852 | void meshFaceFromScriptValue(const ScriptValuePointer& object, MeshFace& meshFaceResult) { | 852 | void meshFaceFromScriptValue(const ScriptValue& object, MeshFace& meshFaceResult) { |
| 853 | qVectorIntFromScriptValue(object->property("vertices"), meshFaceResult.vertexIndices); | 853 | qVectorIntFromScriptValue(object.property("vertices"), meshFaceResult.vertexIndices); |
| 854 | } | 854 | } |
| 855 | 855 | ||
| 856 | ScriptValuePointer qVectorMeshFaceToScriptValue(ScriptEngine* engine, const QVector<MeshFace>& vector) { | 856 | ScriptValue qVectorMeshFaceToScriptValue(ScriptEngine* engine, const QVector<MeshFace>& vector) { |
| 857 | ScriptValuePointer array = engine->newArray(); | 857 | ScriptValue array = engine->newArray(); |
| 858 | for (int i = 0; i < vector.size(); i++) { | 858 | for (int i = 0; i < vector.size(); i++) { |
| 859 | array->setProperty(i, meshFaceToScriptValue(engine, vector.at(i))); | 859 | array.setProperty(i, meshFaceToScriptValue(engine, vector.at(i))); |
| 860 | } | 860 | } |
| 861 | return array; | 861 | return array; |
| 862 | } | 862 | } |
| 863 | 863 | ||
| 864 | void qVectorMeshFaceFromScriptValue(const ScriptValuePointer& array, QVector<MeshFace>& result) { | 864 | void qVectorMeshFaceFromScriptValue(const ScriptValue& array, QVector<MeshFace>& result) { |
| 865 | int length = array->property("length")->toInteger(); | 865 | int length = array.property("length").toInteger(); |
| 866 | result.clear(); | 866 | result.clear(); |
| 867 | 867 | ||
| 868 | for (int i = 0; i < length; i++) { | 868 | for (int i = 0; i < length; i++) { |
| 869 | MeshFace meshFace = MeshFace(); | 869 | MeshFace meshFace = MeshFace(); |
| 870 | meshFaceFromScriptValue(array->property(i), meshFace); | 870 | meshFaceFromScriptValue(array.property(i), meshFace); |
| 871 | result << meshFace; | 871 | result << meshFace; |
| 872 | } | 872 | } |
| 873 | } | 873 | } |
| 874 | 874 | ||
| 875 | ScriptValuePointer stencilMaskModeToScriptValue(ScriptEngine* engine, const StencilMaskMode& stencilMode) { | 875 | ScriptValue stencilMaskModeToScriptValue(ScriptEngine* engine, const StencilMaskMode& stencilMode) { |
| 876 | return engine->newValue((int)stencilMode); | 876 | return engine->newValue((int)stencilMode); |
| 877 | } | 877 | } |
| 878 | 878 | ||
| 879 | void stencilMaskModeFromScriptValue(const ScriptValuePointer& object, StencilMaskMode& stencilMode) { | 879 | void stencilMaskModeFromScriptValue(const ScriptValue& object, StencilMaskMode& stencilMode) { |
| 880 | stencilMode = StencilMaskMode(object->toVariant().toInt()); | 880 | stencilMode = StencilMaskMode(object.toVariant().toInt()); |
| 881 | } | 881 | } |
| 882 | 882 | ||
| 883 | void promiseFromScriptValue(const ScriptValuePointer& object, std::shared_ptr<MiniPromise>& promise) { | 883 | void promiseFromScriptValue(const ScriptValue& object, std::shared_ptr<MiniPromise>& promise) { |
| 884 | Q_ASSERT(false); | 884 | Q_ASSERT(false); |
| 885 | } | 885 | } |
| 886 | ScriptValuePointer promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise) { | 886 | ScriptValue promiseToScriptValue(ScriptEngine* engine, const std::shared_ptr<MiniPromise>& promise) { |
| 887 | return engine->newQObject(promise.get()); | 887 | return engine->newQObject(promise.get()); |
| 888 | } | 888 | } |
| 889 | 889 | ||
| 890 | ScriptValuePointer EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& id) { | 890 | ScriptValue EntityItemIDtoScriptValue(ScriptEngine* engine, const EntityItemID& id) { |
| 891 | return quuidToScriptValue(engine, id); | 891 | return quuidToScriptValue(engine, id); |
| 892 | } | 892 | } |
| 893 | 893 | ||
| 894 | void EntityItemIDfromScriptValue(const ScriptValuePointer &object, EntityItemID& id) { | 894 | void EntityItemIDfromScriptValue(const ScriptValue &object, EntityItemID& id) { |
| 895 | quuidFromScriptValue(object, id); | 895 | quuidFromScriptValue(object, id); |
| 896 | } | 896 | } |
| 897 | 897 | ||
| 898 | QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValuePointer& array) { | 898 | QVector<EntityItemID> qVectorEntityItemIDFromScriptValue(const ScriptValue& array) { |
| 899 | if (!array->isArray()) { | 899 | if (!array.isArray()) { |
| 900 | return QVector<EntityItemID>(); | 900 | return QVector<EntityItemID>(); |
| 901 | } | 901 | } |
| 902 | QVector<EntityItemID> newVector; | 902 | QVector<EntityItemID> newVector; |
| 903 | int length = array->property("length")->toInteger(); | 903 | int length = array.property("length").toInteger(); |
| 904 | newVector.reserve(length); | 904 | newVector.reserve(length); |
| 905 | for (int i = 0; i < length; i++) { | 905 | for (int i = 0; i < length; i++) { |
| 906 | QString uuidAsString = array->property(i)->toString(); | 906 | QString uuidAsString = array.property(i).toString(); |
| 907 | EntityItemID fromString(uuidAsString); | 907 | EntityItemID fromString(uuidAsString); |
| 908 | newVector << fromString; | 908 | newVector << fromString; |
| 909 | } | 909 | } |