2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/* variant_op.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
2017-08-27 12:11:45 +00:00
|
|
|
/* https://godotengine.org */
|
2014-02-10 01:10:30 +00:00
|
|
|
/*************************************************************************/
|
2018-01-02 10:27:24 +00:00
|
|
|
/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
|
2014-02-10 01:10:30 +00:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "core_string_names.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "object.h"
|
|
|
|
#include "script_language.h"
|
2017-03-18 23:36:26 +00:00
|
|
|
#include "variant.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
Variant::operator bool() const {
|
|
|
|
|
|
|
|
bool b;
|
|
|
|
return booleanize(b);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Variant::booleanize(bool &r_valid) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = true;
|
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case NIL: return false;
|
|
|
|
case BOOL: return _data._bool;
|
|
|
|
case INT: return _data._int;
|
|
|
|
case REAL: return _data._real;
|
2017-03-18 23:36:26 +00:00
|
|
|
case STRING: return (*reinterpret_cast<const String *>(_data._mem)) != "";
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR2:
|
|
|
|
case RECT2:
|
|
|
|
case MATRIX32:
|
|
|
|
case VECTOR3:
|
|
|
|
case PLANE:
|
|
|
|
case _AABB:
|
|
|
|
case QUAT:
|
|
|
|
case MATRIX3:
|
|
|
|
case TRANSFORM:
|
|
|
|
case COLOR:
|
2017-03-18 23:36:26 +00:00
|
|
|
case IMAGE: r_valid = false; return false;
|
|
|
|
case _RID: return (*reinterpret_cast<const RID *>(_data._mem)).is_valid();
|
|
|
|
case OBJECT: return _get_obj().obj;
|
|
|
|
case NODE_PATH: return (*reinterpret_cast<const NodePath *>(_data._mem)) != NodePath();
|
2014-02-10 01:10:30 +00:00
|
|
|
case INPUT_EVENT:
|
|
|
|
case DICTIONARY:
|
|
|
|
case ARRAY:
|
|
|
|
case RAW_ARRAY:
|
|
|
|
case INT_ARRAY:
|
|
|
|
case REAL_ARRAY:
|
|
|
|
case STRING_ARRAY:
|
|
|
|
case VECTOR2_ARRAY:
|
|
|
|
case VECTOR3_ARRAY:
|
|
|
|
case COLOR_ARRAY:
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define _RETURN(m_what) \
|
|
|
|
{ \
|
|
|
|
r_ret = m_what; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_NUM(m_op, m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case BOOL: _RETURN(p_a._data.m_type m_op p_b._data._bool); \
|
|
|
|
case INT: _RETURN(p_a._data.m_type m_op p_b._data._int); \
|
|
|
|
case REAL: _RETURN(p_a._data.m_type m_op p_b._data._real); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_OP_NUM_NEG(m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
\
|
|
|
|
_RETURN(-p_a._data.m_type); \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_OP_NUM_VEC(m_op, m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case BOOL: _RETURN(p_a._data.m_type m_op p_b._data._bool); \
|
|
|
|
case INT: _RETURN(p_a._data.m_type m_op p_b._data._int); \
|
|
|
|
case REAL: _RETURN(p_a._data.m_type m_op p_b._data._real); \
|
|
|
|
case VECTOR2: _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector2 *>(p_b._data._mem)); \
|
|
|
|
case VECTOR3: _RETURN(p_a._data.m_type m_op *reinterpret_cast<const Vector3 *>(p_b._data._mem)); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_OP_STR(m_op, m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case STRING: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const String *>(p_b._data._mem)); \
|
|
|
|
case NODE_PATH: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const NodePath *>(p_b._data._mem)); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_OP_LOCALMEM(m_op, m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case m_name: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM_NEG(m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
_RETURN(-*reinterpret_cast<const m_type *>(p_a._data._mem)); \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_LOCALMEM_NUM(m_op, m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case m_name: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op *reinterpret_cast<const m_type *>(p_b._data._mem)); \
|
|
|
|
case BOOL: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._bool); \
|
|
|
|
case INT: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._int); \
|
|
|
|
case REAL: _RETURN(*reinterpret_cast<const m_type *>(p_a._data._mem) m_op p_b._data._real); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_PTR(m_op, m_name, m_sub) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case m_name: _RETURN(p_a._data.m_sub m_op p_b._data.m_sub); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_PTRREF(m_op, m_name, m_sub) \
|
|
|
|
case m_name: { \
|
|
|
|
switch (p_b.type) { \
|
|
|
|
case m_name: _RETURN(*p_a._data.m_sub m_op *p_b._data.m_sub); \
|
|
|
|
default: {} \
|
|
|
|
} \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_EQ(m_name, m_type) \
|
|
|
|
DEFAULT_OP_ARRAY_OP(m_name, m_type, !=, !=, true, false, false)
|
|
|
|
|
|
|
|
#define DEFAULT_OP_ARRAY_LT(m_name, m_type) \
|
|
|
|
DEFAULT_OP_ARRAY_OP(m_name, m_type, <, !=, false, a_len < array_b.size(), true)
|
|
|
|
|
|
|
|
#define DEFAULT_OP_ARRAY_OP(m_name, m_type, m_opa, m_opb, m_ret_def, m_ret_s, m_ret_f) \
|
|
|
|
case m_name: { \
|
|
|
|
if (p_a.type != p_b.type) { \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
const DVector<m_type> &array_a = *reinterpret_cast<const DVector<m_type> *>(p_a._data._mem); \
|
|
|
|
const DVector<m_type> &array_b = *reinterpret_cast<const DVector<m_type> *>(p_b._data._mem); \
|
|
|
|
\
|
|
|
|
int a_len = array_a.size(); \
|
|
|
|
if (a_len m_opa array_b.size()) { \
|
|
|
|
_RETURN(m_ret_s); \
|
|
|
|
} else { \
|
|
|
|
\
|
|
|
|
DVector<m_type>::Read ra = array_a.read(); \
|
|
|
|
DVector<m_type>::Read rb = array_b.read(); \
|
|
|
|
\
|
|
|
|
for (int i = 0; i < a_len; i++) { \
|
|
|
|
if (ra[i] m_opb rb[i]) \
|
|
|
|
_RETURN(m_ret_f); \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
_RETURN(m_ret_def); \
|
|
|
|
} \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_ADD(m_name, m_type) \
|
|
|
|
case m_name: { \
|
|
|
|
if (p_a.type != p_b.type) { \
|
|
|
|
r_valid = false; \
|
|
|
|
_RETURN(NIL); \
|
|
|
|
} \
|
|
|
|
const DVector<m_type> &array_a = *reinterpret_cast<const DVector<m_type> *>(p_a._data._mem); \
|
|
|
|
const DVector<m_type> &array_b = *reinterpret_cast<const DVector<m_type> *>(p_b._data._mem); \
|
|
|
|
DVector<m_type> sum = array_a; \
|
|
|
|
sum.append_array(array_b); \
|
|
|
|
_RETURN(sum); \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_FAIL(m_name) \
|
|
|
|
case m_name: { \
|
|
|
|
r_valid = false; \
|
|
|
|
return; \
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Variant::evaluate(const Operator &p_op, const Variant &p_a, const Variant &p_b, Variant &r_ret, bool &r_valid) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_op) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case OP_EQUAL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if ((int(p_a.type) * int(p_b.type)) == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//null case is an exception, one of both is null
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == p_b.type) //null against null is true
|
2014-02-10 01:10:30 +00:00
|
|
|
_RETURN(true);
|
|
|
|
//only against object is allowed
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == Variant::OBJECT) {
|
|
|
|
_RETURN(p_a._get_obj().obj == NULL);
|
|
|
|
} else if (p_b.type == Variant::OBJECT) {
|
|
|
|
_RETURN(p_b._get_obj().obj == NULL);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
//otherwise, always false
|
|
|
|
_RETURN(false);
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case NIL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_b.type == NIL || (p_b.type == Variant::OBJECT && !p_b._get_obj().obj));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(==, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM(==, INT, _int);
|
|
|
|
DEFAULT_OP_NUM(==, REAL, _real);
|
|
|
|
DEFAULT_OP_STR(==, STRING, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, VECTOR2, Vector2);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, RECT2, Rect2);
|
|
|
|
DEFAULT_OP_PTRREF(==, MATRIX32, _matrix32);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, VECTOR3, Vector3);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, PLANE, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, QUAT, Quat);
|
|
|
|
DEFAULT_OP_PTRREF(==, _AABB, _aabb);
|
|
|
|
DEFAULT_OP_PTRREF(==, MATRIX3, _matrix3);
|
|
|
|
DEFAULT_OP_PTRREF(==, TRANSFORM, _transform);
|
|
|
|
|
|
|
|
DEFAULT_OP_LOCALMEM(==, COLOR, Color);
|
|
|
|
DEFAULT_OP_PTRREF(==, IMAGE, _image);
|
|
|
|
DEFAULT_OP_STR(==, NODE_PATH, NodePath);
|
|
|
|
DEFAULT_OP_LOCALMEM(==, _RID, RID);
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == OBJECT)
|
|
|
|
_RETURN((p_a._get_obj().obj == p_b._get_obj().obj));
|
|
|
|
if (p_b.type == NIL)
|
|
|
|
_RETURN(!p_a._get_obj().obj);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_PTRREF(==, INPUT_EVENT, _input_event);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type != DICTIONARY)
|
|
|
|
_RETURN(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *arr_a = reinterpret_cast<const Dictionary *>(p_a._data._mem);
|
|
|
|
const Dictionary *arr_b = reinterpret_cast<const Dictionary *>(p_b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*arr_a == *arr_b);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type != ARRAY)
|
|
|
|
_RETURN(false);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int l = arr_a->size();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (arr_b->size() != l)
|
|
|
|
_RETURN(false);
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (!((*arr_a)[i] == (*arr_b)[i])) {
|
|
|
|
_RETURN(false);
|
2015-04-26 15:12:53 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(true);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_ARRAY_EQ(RAW_ARRAY, uint8_t);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(INT_ARRAY, int);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(REAL_ARRAY, real_t);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(VECTOR2_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_EQ(COLOR_ARRAY, Color);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OP_NOT_EQUAL: {
|
|
|
|
Variant res;
|
2017-03-18 23:36:26 +00:00
|
|
|
evaluate(OP_EQUAL, p_a, p_b, res, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!r_valid)
|
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (res.type == BOOL)
|
|
|
|
res._data._bool = !res._data._bool;
|
|
|
|
_RETURN(res);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_LESS: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(NIL);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(<, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM(<, INT, _int);
|
|
|
|
DEFAULT_OP_NUM(<, REAL, _real);
|
|
|
|
DEFAULT_OP_STR(<, STRING, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(<, VECTOR2, Vector2);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(<, VECTOR3, Vector3);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
|
|
|
DEFAULT_OP_FAIL(QUAT);
|
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(<, _RID, RID);
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == OBJECT)
|
|
|
|
_RETURN((p_a._get_obj().obj < p_b._get_obj().obj));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
2015-05-01 00:53:41 +00:00
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type != ARRAY)
|
|
|
|
_RETURN(false);
|
2015-05-01 00:53:41 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr_a = reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array *arr_b = reinterpret_cast<const Array *>(p_b._data._mem);
|
2015-05-01 00:53:41 +00:00
|
|
|
|
|
|
|
int l = arr_a->size();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (arr_b->size() < l)
|
|
|
|
_RETURN(false);
|
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (!((*arr_a)[i] < (*arr_b)[i])) {
|
|
|
|
_RETURN(true);
|
2015-05-01 00:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(false);
|
2015-05-01 00:53:41 +00:00
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_ARRAY_LT(RAW_ARRAY, uint8_t);
|
|
|
|
DEFAULT_OP_ARRAY_LT(INT_ARRAY, int);
|
|
|
|
DEFAULT_OP_ARRAY_LT(REAL_ARRAY, real_t);
|
|
|
|
DEFAULT_OP_ARRAY_LT(STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_LT(VECTOR2_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_LT(VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_LT(COLOR_ARRAY, Color);
|
2014-02-10 01:10:30 +00:00
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_LESS_EQUAL: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(NIL);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(<=, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM(<=, INT, _int);
|
|
|
|
DEFAULT_OP_NUM(<=, REAL, _real);
|
|
|
|
DEFAULT_OP_STR(<=, STRING, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(<=, VECTOR2, Vector2);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(<=, VECTOR3, Vector3);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
|
|
|
DEFAULT_OP_FAIL(QUAT);
|
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(<=, _RID, RID);
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == OBJECT)
|
|
|
|
_RETURN((p_a._get_obj().obj <= p_b._get_obj().obj));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
|
|
|
DEFAULT_OP_FAIL(ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(RAW_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(INT_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(REAL_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(STRING_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR2_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR3_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(COLOR_ARRAY);
|
2014-02-10 01:10:30 +00:00
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_GREATER: {
|
|
|
|
|
|
|
|
Variant res;
|
2017-03-18 23:36:26 +00:00
|
|
|
evaluate(OP_LESS, p_b, p_a, res, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
_RETURN(res);
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_GREATER_EQUAL: {
|
|
|
|
|
|
|
|
Variant res;
|
2017-03-18 23:36:26 +00:00
|
|
|
evaluate(OP_LESS_EQUAL, p_b, p_a, res, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!r_valid)
|
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(res);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
//mathematic
|
|
|
|
case OP_ADD: {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(NIL);
|
|
|
|
DEFAULT_OP_NUM(+, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM(+, INT, _int);
|
|
|
|
DEFAULT_OP_NUM(+, REAL, _real);
|
|
|
|
DEFAULT_OP_STR(+, STRING, String);
|
|
|
|
DEFAULT_OP_LOCALMEM(+, VECTOR2, Vector2);
|
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
|
|
|
DEFAULT_OP_LOCALMEM(+, VECTOR3, Vector3);
|
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
|
|
|
DEFAULT_OP_LOCALMEM(+, QUAT, Quat);
|
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
|
|
|
DEFAULT_OP_FAIL(_RID);
|
|
|
|
DEFAULT_OP_FAIL(OBJECT);
|
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
case ARRAY: {
|
|
|
|
if (p_a.type != p_b.type) {
|
|
|
|
r_valid = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const Array &array_a = *reinterpret_cast<const Array *>(p_a._data._mem);
|
|
|
|
const Array &array_b = *reinterpret_cast<const Array *>(p_b._data._mem);
|
|
|
|
Array sum(array_a.is_shared() || array_b.is_shared());
|
|
|
|
int asize = array_a.size();
|
|
|
|
int bsize = array_b.size();
|
|
|
|
sum.resize(asize + bsize);
|
|
|
|
for (int i = 0; i < asize; i++)
|
|
|
|
sum[i] = array_a[i];
|
|
|
|
for (int i = 0; i < bsize; i++)
|
|
|
|
sum[i + asize] = array_b[i];
|
|
|
|
_RETURN(sum);
|
|
|
|
}
|
|
|
|
DEFAULT_OP_ARRAY_ADD(RAW_ARRAY, uint8_t);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(INT_ARRAY, int);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(REAL_ARRAY, real_t);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(STRING_ARRAY, String);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(VECTOR2_ARRAY, Vector2);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(VECTOR3_ARRAY, Vector3);
|
|
|
|
DEFAULT_OP_ARRAY_ADD(COLOR_ARRAY, Color);
|
|
|
|
case VARIANT_MAX: {
|
|
|
|
r_valid = false;
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case OP_SUBSTRACT: {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(NIL);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(-, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM(-, INT, _int);
|
|
|
|
DEFAULT_OP_NUM(-, REAL, _real);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(STRING);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(-, VECTOR2, Vector2);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(-, VECTOR3, Vector3);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
2016-06-21 21:26:38 +00:00
|
|
|
DEFAULT_OP_LOCALMEM(-, QUAT, Quat);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
|
|
|
DEFAULT_OP_FAIL(_RID);
|
|
|
|
DEFAULT_OP_FAIL(OBJECT);
|
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
|
|
|
DEFAULT_OP_FAIL(ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(RAW_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(INT_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(REAL_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(STRING_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR2_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR3_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(COLOR_ARRAY);
|
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OP_MULTIPLY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(NIL);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(*, BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM_VEC(*, INT, _int);
|
|
|
|
DEFAULT_OP_NUM_VEC(*, REAL, _real);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(STRING);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(*, VECTOR2, Vector2);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
2014-02-21 02:01:44 +00:00
|
|
|
case MATRIX32: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == MATRIX32) {
|
|
|
|
_RETURN(*p_a._data._matrix32 * *p_b._data._matrix32);
|
2014-02-21 02:01:44 +00:00
|
|
|
};
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == VECTOR2) {
|
|
|
|
_RETURN(p_a._data._matrix32->xform(*(const Vector2 *)p_b._data._mem));
|
2015-03-02 03:54:10 +00:00
|
|
|
};
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-21 02:01:44 +00:00
|
|
|
return;
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_LOCALMEM_NUM(*, VECTOR3, Vector3);
|
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
2015-11-11 14:30:55 +00:00
|
|
|
case QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_b.type) {
|
2015-11-11 14:30:55 +00:00
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(reinterpret_cast<const Quat *>(p_a._data._mem)->xform(*(const Vector3 *)p_b._data._mem));
|
2015-11-11 14:30:55 +00:00
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * *reinterpret_cast<const Quat *>(p_b._data._mem));
|
2015-11-11 14:30:55 +00:00
|
|
|
} break;
|
2016-06-21 21:26:38 +00:00
|
|
|
case REAL: {
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._real);
|
2016-06-21 21:26:38 +00:00
|
|
|
} break;
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2015-11-11 14:30:55 +00:00
|
|
|
};
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2015-11-11 14:30:55 +00:00
|
|
|
return;
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
2014-02-10 01:10:30 +00:00
|
|
|
case MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_b.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a._data._matrix3->xform(*(const Vector3 *)p_b._data._mem));
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
case MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*p_a._data._matrix3 * *p_b._data._matrix3);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2017-03-18 23:36:26 +00:00
|
|
|
};
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_b.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a._data._transform->xform(*(const Vector3 *)p_b._data._mem));
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
case TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*p_a._data._transform * *p_b._data._transform);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2017-03-18 23:36:26 +00:00
|
|
|
};
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
|
|
|
DEFAULT_OP_FAIL(_RID);
|
|
|
|
DEFAULT_OP_FAIL(OBJECT);
|
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
|
|
|
DEFAULT_OP_FAIL(ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(RAW_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(INT_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(REAL_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(STRING_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR2_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR3_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(COLOR_ARRAY);
|
2014-02-10 01:10:30 +00:00
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case OP_DIVIDE: {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2016-03-08 23:00:52 +00:00
|
|
|
DEFAULT_OP_FAIL(NIL);
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(/, BOOL, _bool);
|
2014-02-10 01:10:30 +00:00
|
|
|
case INT: {
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (p_b.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case BOOL: {
|
|
|
|
int b = p_b._data._bool;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (b == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
|
|
|
_RETURN("Division By False");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a._data._int / b);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case INT: {
|
|
|
|
int b = p_b._data._int;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (b == 0) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
|
|
|
_RETURN("Division By Zero");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a._data._int / b);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case REAL: _RETURN(p_a._data._int / p_b._data._real);
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
};
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_NUM(/, REAL, _real);
|
|
|
|
DEFAULT_OP_FAIL(STRING);
|
|
|
|
DEFAULT_OP_LOCALMEM_NUM(/, VECTOR2, Vector2);
|
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
|
|
|
DEFAULT_OP_LOCALMEM_NUM(/, VECTOR3, Vector3);
|
|
|
|
DEFAULT_OP_FAIL(PLANE);
|
2016-06-21 21:26:38 +00:00
|
|
|
case QUAT: {
|
|
|
|
if (p_b.type != REAL) {
|
|
|
|
r_valid = false;
|
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) / p_b._data._real);
|
2016-06-21 21:26:38 +00:00
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
|
|
|
DEFAULT_OP_FAIL(_RID);
|
|
|
|
DEFAULT_OP_FAIL(OBJECT);
|
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
|
|
|
DEFAULT_OP_FAIL(ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(RAW_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(INT_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(REAL_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(STRING_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR2_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR3_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(COLOR_ARRAY);
|
|
|
|
case VARIANT_MAX: {
|
|
|
|
r_valid = false;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_NEGATE: {
|
|
|
|
switch (p_a.type) {
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(NIL);
|
|
|
|
DEFAULT_OP_NUM_NEG(BOOL, _bool);
|
|
|
|
DEFAULT_OP_NUM_NEG(INT, _int);
|
|
|
|
DEFAULT_OP_NUM_NEG(REAL, _real);
|
|
|
|
DEFAULT_OP_FAIL(STRING);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(VECTOR2, Vector2);
|
|
|
|
DEFAULT_OP_FAIL(RECT2);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX32);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(VECTOR3, Vector3);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(PLANE, Plane);
|
|
|
|
DEFAULT_OP_LOCALMEM_NEG(QUAT, Quat);
|
2014-02-10 01:10:30 +00:00
|
|
|
DEFAULT_OP_FAIL(_AABB);
|
|
|
|
DEFAULT_OP_FAIL(MATRIX3);
|
|
|
|
DEFAULT_OP_FAIL(TRANSFORM);
|
|
|
|
|
|
|
|
DEFAULT_OP_FAIL(COLOR);
|
|
|
|
DEFAULT_OP_FAIL(IMAGE);
|
|
|
|
DEFAULT_OP_FAIL(NODE_PATH);
|
|
|
|
DEFAULT_OP_FAIL(_RID);
|
|
|
|
DEFAULT_OP_FAIL(OBJECT);
|
|
|
|
DEFAULT_OP_FAIL(INPUT_EVENT);
|
|
|
|
DEFAULT_OP_FAIL(DICTIONARY);
|
|
|
|
DEFAULT_OP_FAIL(ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(RAW_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(INT_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(REAL_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(STRING_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR2_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(VECTOR3_ARRAY);
|
|
|
|
DEFAULT_OP_FAIL(COLOR_ARRAY);
|
|
|
|
case VARIANT_MAX: {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_MODULE: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b._data._int == 0) {
|
|
|
|
r_valid = false;
|
|
|
|
_RETURN("Division By Zero");
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a._data._int % p_b._data._int);
|
2016-03-08 23:00:52 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_a.type == STRING) {
|
|
|
|
const String *format = reinterpret_cast<const String *>(p_a._data._mem);
|
2015-01-10 20:44:20 +00:00
|
|
|
|
2015-02-19 15:45:49 +00:00
|
|
|
String result;
|
|
|
|
bool error;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_b.type == ARRAY) {
|
2015-01-10 20:44:20 +00:00
|
|
|
// e.g. "frog %s %d" % ["fish", 12]
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *args = reinterpret_cast<const Array *>(p_b._data._mem);
|
|
|
|
result = format->sprintf(*args, &error);
|
2015-01-10 20:44:20 +00:00
|
|
|
} else {
|
|
|
|
// e.g. "frog %d" % 12
|
2015-02-19 15:45:49 +00:00
|
|
|
Array args;
|
|
|
|
args.push_back(p_b);
|
2017-03-18 23:36:26 +00:00
|
|
|
result = format->sprintf(args, &error);
|
2015-01-10 20:44:20 +00:00
|
|
|
}
|
2015-02-19 15:45:49 +00:00
|
|
|
r_valid = !error;
|
|
|
|
_RETURN(result);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_STRING_CONCAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_a.operator String() + p_b.operator String());
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
//bitwise
|
|
|
|
case OP_SHIFT_LEFT: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT)
|
|
|
|
_RETURN(p_a._data._int << p_b._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_SHIFT_RIGHT: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT)
|
|
|
|
_RETURN(p_a._data._int >> p_b._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_BIT_AND: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT)
|
|
|
|
_RETURN(p_a._data._int & p_b._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_BIT_OR: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT)
|
|
|
|
_RETURN(p_a._data._int | p_b._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_BIT_XOR: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT && p_b.type == INT)
|
|
|
|
_RETURN(p_a._data._int ^ p_b._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_BIT_NEGATE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_a.type == INT)
|
|
|
|
_RETURN(~p_a._data._int);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
//logic
|
|
|
|
case OP_AND: {
|
|
|
|
bool l = p_a.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
bool r = p_b.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(l && r);
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case OP_OR: {
|
|
|
|
bool l = p_a.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
bool r = p_b.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(l || r);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_XOR: {
|
|
|
|
bool l = p_a.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
bool r = p_b.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN((l || r) && !(l && r));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case OP_NOT: {
|
|
|
|
|
|
|
|
bool l = p_a.booleanize(r_valid);
|
|
|
|
if (!r_valid)
|
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(!l);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_IN: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
_RETURN(p_b.in(p_a, &r_valid));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case OP_MAX: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
ERR_FAIL();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Variant::set_named(const StringName &p_index, const Variant &p_value, bool *r_valid) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (type == OBJECT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null() && !ObjectDB::instance_validate(_get_obj().obj)) {
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2017-03-18 23:36:26 +00:00
|
|
|
_get_obj().obj->set(p_index, p_value, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
set(p_index.operator String(), p_value, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (type == OBJECT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return "Instance base is null.";
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null() && !ObjectDB::instance_validate(_get_obj().obj)) {
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return "Attempted use of stray pointer object.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return _get_obj().obj->get(p_index, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return get(p_index.operator String(), r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_ARRAY_CMD(m_name, m_type, skip_test, cmd) \
|
|
|
|
case m_name: { \
|
|
|
|
skip_test; \
|
|
|
|
\
|
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) { \
|
|
|
|
int index = p_index; \
|
|
|
|
m_type *arr = reinterpret_cast<m_type *>(_data._mem); \
|
|
|
|
\
|
|
|
|
if (index < 0) \
|
|
|
|
index += arr->size(); \
|
|
|
|
if (index >= 0 && index < arr->size()) { \
|
|
|
|
valid = true; \
|
|
|
|
cmd; \
|
|
|
|
} \
|
|
|
|
} \
|
2016-05-26 21:35:33 +00:00
|
|
|
} break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_DVECTOR_SET(m_name, dv_type, skip_cond) \
|
|
|
|
DEFAULT_OP_ARRAY_CMD(m_name, DVector<dv_type>, if (skip_cond) return;, arr->set(index, p_value); return )
|
2016-05-26 21:35:33 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
#define DEFAULT_OP_DVECTOR_GET(m_name, dv_type) \
|
2016-07-23 12:47:49 +00:00
|
|
|
DEFAULT_OP_ARRAY_CMD(m_name, const DVector<dv_type>, ;, return arr->get(index))
|
2016-05-26 21:35:33 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static bool _dummy = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool &valid = r_valid ? *r_valid : _dummy;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (type) {
|
|
|
|
case NIL: {
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case BOOL: {
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case INT: {
|
|
|
|
return;
|
|
|
|
} break;
|
|
|
|
case REAL: {
|
|
|
|
return;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.type != Variant::INT && p_index.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
|
|
|
String *str = reinterpret_cast<String *>(_data._mem);
|
2016-05-28 14:12:10 +00:00
|
|
|
int len = str->length();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += len;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= len)
|
2015-01-02 16:17:46 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
String chr;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type == Variant::INT || p_value.type == Variant::REAL) {
|
2015-01-02 16:17:46 +00:00
|
|
|
|
|
|
|
chr = String::chr(p_value);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_value.type == Variant::STRING) {
|
2015-01-02 16:17:46 +00:00
|
|
|
|
|
|
|
chr = p_value;
|
|
|
|
} else {
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
*str = str->substr(0, idx) + chr + str->substr(idx + 1, len);
|
|
|
|
valid = true;
|
2015-01-02 16:17:46 +00:00
|
|
|
return;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// scalar index
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 2;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector2 *v = reinterpret_cast<Vector2 *>(_data._mem);
|
|
|
|
if (*str == "x" || *str == "width") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y" || *str == "height") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 5
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Rect2 *v = reinterpret_cast<Rect2 *>(_data._mem);
|
|
|
|
if (*str == "pos") {
|
|
|
|
valid = true;
|
|
|
|
v->pos = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
v->size = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
v->size = Vector2(p_value) - v->pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case MATRIX32: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
Matrix32 *v = _data._matrix32;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->elements[index] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING && p_value.get_type() == Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Matrix32 *v = _data._matrix32;
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->elements[0] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->elements[1] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "o") {
|
|
|
|
valid = true;
|
|
|
|
v->elements[2] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar index
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
valid = true;
|
|
|
|
(*v)[idx] = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Vector3 *v = reinterpret_cast<Vector3 *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PLANE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Plane *v = reinterpret_cast<Plane *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal.z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "normal") {
|
|
|
|
if (p_value.type != Variant::VECTOR3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->normal = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "d") {
|
|
|
|
valid = true;
|
|
|
|
v->d = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Quat *v = reinterpret_cast<Quat *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->z = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "w") {
|
|
|
|
valid = true;
|
|
|
|
v->w = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case _AABB: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
AABB *v = _data._aabb;
|
|
|
|
if (*str == "pos") {
|
|
|
|
valid = true;
|
|
|
|
v->pos = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
|
|
|
v->size = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
v->size = Vector3(p_value) - v->pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break; //sorry naming convention fail :( not like it's used often // 10
|
|
|
|
case MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
Matrix3 *v = _data._matrix3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->set_axis(index, p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Matrix3 *v = _data._matrix3;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(0, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(1, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
|
|
|
v->set_axis(2, p_value);
|
2014-09-03 02:13:40 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::VECTOR3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int index = p_index;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 4;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 4) {
|
|
|
|
Transform *v = _data._transform;
|
|
|
|
valid = true;
|
|
|
|
if (index == 3)
|
|
|
|
v->origin = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
else
|
2017-03-18 23:36:26 +00:00
|
|
|
v->basis.set_axis(index, p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Transform *v = _data._transform;
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (*str == "basis") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::MATRIX3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->basis = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (*str == "origin") {
|
|
|
|
if (p_value.type != Variant::VECTOR3)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
v->origin = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
if (*str == "r") {
|
|
|
|
valid = true;
|
|
|
|
v->r = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "g") {
|
|
|
|
valid = true;
|
|
|
|
v->g = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "b") {
|
|
|
|
valid = true;
|
|
|
|
v->b = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "a") {
|
|
|
|
valid = true;
|
|
|
|
v->a = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "h") {
|
|
|
|
valid = true;
|
|
|
|
v->set_hsv(p_value, v->get_s(), v->get_v());
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "s") {
|
|
|
|
valid = true;
|
|
|
|
v->set_hsv(v->get_h(), p_value, v->get_v());
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "v") {
|
|
|
|
valid = true;
|
|
|
|
v->set_hsv(v->get_h(), v->get_s(), p_value);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "r8") {
|
|
|
|
valid = true;
|
|
|
|
v->r = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "g8") {
|
|
|
|
valid = true;
|
|
|
|
v->g = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "b8") {
|
|
|
|
valid = true;
|
|
|
|
v->b = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "a8") {
|
|
|
|
valid = true;
|
|
|
|
v->a = float(p_value) / 255.0;
|
2015-12-31 21:26:49 +00:00
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::INT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int idx = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 4;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 || idx < 4) {
|
|
|
|
Color *v = reinterpret_cast<Color *>(_data._mem);
|
|
|
|
(*v)[idx] = p_value;
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case IMAGE: {
|
|
|
|
} break;
|
|
|
|
case NODE_PATH: {
|
|
|
|
} break; // 15
|
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
//only if debugging!
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (obj) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
|
|
|
|
|
|
|
|
if (!ObjectDB::instance_validate(obj)) {
|
|
|
|
WARN_PRINT("Attempted use of stray pointer object.");
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING) {
|
|
|
|
obj->setvar(p_index, p_value, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return obj->set(p_index, p_value, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case INPUT_EVENT: {
|
|
|
|
|
|
|
|
InputEvent &ie = *_data._input_event;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "type") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int type = p_value;
|
|
|
|
if (type < 0 || type >= InputEvent::TYPE_MAX)
|
2014-02-10 01:10:30 +00:00
|
|
|
return; //fail
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.type = InputEvent::Type(type);
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "device") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.device = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "ID") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.ID = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "shift") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.mod.shift = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "alt") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.mod.alt = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "control") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.mod.control = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "meta") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.mod.meta = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "pressed") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.pressed = p_value;
|
|
|
|
return;
|
|
|
|
} else if (str == "scancode") {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.scancode = p_value;
|
|
|
|
return;
|
|
|
|
} else if (str == "unicode") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.key.unicode = p_value;
|
|
|
|
return;
|
|
|
|
} else if (str == "echo") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
valid = true;
|
|
|
|
ie.key.echo = p_value;
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_mask") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.button_mask = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "x") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "y") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pos") {
|
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
Point2 value = p_value;
|
|
|
|
ie.mouse_button.x = value.x;
|
|
|
|
ie.mouse_button.y = value.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "global_x") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.global_x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "global_y") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.global_y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "global_pos") {
|
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
Point2 value = p_value;
|
|
|
|
ie.mouse_button.global_x = value.x;
|
|
|
|
ie.mouse_button.global_y = value.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
} /*else if (str=="pointer_index") {
|
|
|
|
valid=true;
|
|
|
|
return ie.mouse_button.pointer_index;
|
|
|
|
}*/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "relative_x") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_motion.relative_x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "relative_y") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_motion.relative_y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "relative_pos") {
|
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
Point2 value = p_value;
|
|
|
|
ie.mouse_motion.relative_x = value.x;
|
|
|
|
ie.mouse_motion.relative_y = value.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "speed_x") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_motion.speed_x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "speed_y") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_motion.speed_y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "speed") {
|
|
|
|
if (p_value.type != Variant::VECTOR2)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
Point2 value = p_value;
|
|
|
|
ie.mouse_motion.speed_x = value.x;
|
|
|
|
ie.mouse_motion.speed_y = value.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_index") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.button_index = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pressed") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.pressed = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "doubleclick") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.mouse_button.doubleclick = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_index") {
|
|
|
|
if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.joy_button.button_index = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pressed") {
|
|
|
|
if (p_value.type != Variant::INT && p_value.type != Variant::REAL && p_value.type != Variant::BOOL)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.joy_button.pressed = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pressure") {
|
|
|
|
if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.joy_button.pressure = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "axis") {
|
|
|
|
if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.joy_motion.axis = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "value") {
|
|
|
|
if (p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
ie.joy_motion.axis_value = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_TOUCH) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "index") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_touch.index = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "x") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_touch.x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "y") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_touch.y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pos") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 v = p_value;
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.screen_touch.x = v.x;
|
|
|
|
ie.screen_touch.y = v.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pressed") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_touch.pressed = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_DRAG) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "index") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.index = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "x") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "y") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pos") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
Vector2 v = p_value;
|
2017-03-18 23:36:26 +00:00
|
|
|
ie.screen_drag.x = v.x;
|
|
|
|
ie.screen_drag.y = v.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "relative_x") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.relative_x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "relative_y") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.relative_y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "relative_pos") {
|
|
|
|
valid = true;
|
|
|
|
Vector2 v = p_value;
|
|
|
|
ie.screen_drag.relative_x = v.x;
|
|
|
|
ie.screen_drag.relative_y = v.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "speed_x") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.speed_x = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "speed_y") {
|
|
|
|
valid = true;
|
|
|
|
ie.screen_drag.speed_y = p_value;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "speed") {
|
|
|
|
valid = true;
|
|
|
|
Vector2 v = p_value;
|
|
|
|
ie.screen_drag.speed_x = v.x;
|
|
|
|
ie.screen_drag.speed_y = v.y;
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-01-20 12:01:02 +00:00
|
|
|
if (ie.type == InputEvent::ACTION) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "action") {
|
|
|
|
valid = true;
|
|
|
|
ie.action.action = p_value;
|
2015-01-20 12:01:02 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pressed") {
|
|
|
|
valid = true;
|
|
|
|
ie.action.pressed = p_value;
|
2015-01-20 12:01:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Dictionary *dic = reinterpret_cast<Dictionary *>(_data._mem);
|
|
|
|
dic->operator[](p_index) = p_value;
|
|
|
|
valid = true; //always valid, i guess? should this really be ok?
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 20
|
|
|
|
DEFAULT_OP_ARRAY_CMD(ARRAY, Array, ;, (*arr)[index] = p_value; return )
|
|
|
|
DEFAULT_OP_DVECTOR_SET(RAW_ARRAY, uint8_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(INT_ARRAY, int, p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(REAL_ARRAY, real_t, p_value.type != Variant::REAL && p_value.type != Variant::INT)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(STRING_ARRAY, String, p_value.type != Variant::STRING) // 25
|
|
|
|
DEFAULT_OP_DVECTOR_SET(VECTOR2_ARRAY, Vector2, p_value.type != Variant::VECTOR2)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(VECTOR3_ARRAY, Vector3, p_value.type != Variant::VECTOR3)
|
|
|
|
DEFAULT_OP_DVECTOR_SET(COLOR_ARRAY, Color, p_value.type != Variant::COLOR)
|
2014-02-10 01:10:30 +00:00
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant Variant::get(const Variant &p_index, bool *r_valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static bool _dummy = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool &valid = r_valid ? *r_valid : _dummy;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (type) {
|
|
|
|
case NIL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case BOOL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case INT: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
|
|
|
case REAL: {
|
|
|
|
return Variant();
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//string index
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += str->length();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 && idx < str->length()) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
return str->substr(idx, 1);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
// scalar index
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 2;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 && idx < 2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector2 *v = reinterpret_cast<const Vector2 *>(_data._mem);
|
|
|
|
if (*str == "x" || *str == "width") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y" || *str == "height") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 5
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Rect2 *v = reinterpret_cast<const Rect2 *>(_data._mem);
|
|
|
|
if (*str == "pos") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->pos;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->size;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
return v->size + v->pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar index
|
2017-03-18 23:36:26 +00:00
|
|
|
int idx = p_index;
|
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 && idx < 3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Vector3 *v = reinterpret_cast<const Vector3 *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case MATRIX32: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
const Matrix32 *v = _data._matrix32;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[index];
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Matrix32 *v = _data._matrix32;
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[0];
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[1];
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "o") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->elements[2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case PLANE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Plane *v = reinterpret_cast<const Plane *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal.z;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "normal") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->normal;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "d") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->d;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
|
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->z;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "w") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case _AABB: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//scalar name
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const AABB *v = _data._aabb;
|
|
|
|
if (*str == "pos") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->pos;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "size") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->size;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "end") {
|
|
|
|
valid = true;
|
|
|
|
return v->size + v->pos;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} break; //sorry naming convention fail :( not like it's used often // 10
|
|
|
|
case MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 3;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 3) {
|
|
|
|
const Matrix3 *v = _data._matrix3;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_axis(index);
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (p_index.get_type() == Variant::STRING) {
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Matrix3 *v = _data._matrix3;
|
2014-09-03 02:13:40 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (*str == "x") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(0);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "y") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(1);
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "z") {
|
|
|
|
valid = true;
|
2014-09-03 02:13:40 +00:00
|
|
|
return v->get_axis(2);
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
index += 4;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (index >= 0 && index < 4) {
|
|
|
|
const Transform *v = _data._transform;
|
|
|
|
valid = true;
|
|
|
|
return index == 3 ? v->origin : v->basis.get_axis(index);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Transform *v = _data._transform;
|
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (*str == "basis") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->basis;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (*str == "origin") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->origin;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(p_index._data._mem);
|
|
|
|
const Color *v = reinterpret_cast<const Color *>(_data._mem);
|
|
|
|
if (*str == "r") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->r;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "g") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->g;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "b") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->b;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "a") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->a;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "h") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_h();
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "s") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_s();
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "v") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return v->get_v();
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (*str == "r8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->r * 255.0);
|
|
|
|
} else if (*str == "g8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->g * 255.0);
|
|
|
|
} else if (*str == "b8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->b * 255.0);
|
|
|
|
} else if (*str == "a8") {
|
|
|
|
valid = true;
|
|
|
|
return (int)Math::round(v->a * 255.0);
|
|
|
|
}
|
|
|
|
} else if (p_index.get_type() == Variant::INT) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int idx = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0)
|
2016-05-28 14:12:10 +00:00
|
|
|
idx += 4;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= 0 || idx < 4) {
|
|
|
|
const Color *v = reinterpret_cast<const Color *>(_data._mem);
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return (*v)[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
2017-03-18 23:36:26 +00:00
|
|
|
case IMAGE: {
|
|
|
|
} break;
|
|
|
|
case NODE_PATH: {
|
|
|
|
} break; // 15
|
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
if (obj) {
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
|
|
|
|
//only if debugging!
|
|
|
|
if (!ObjectDB::instance_validate(obj)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return "Attempted get on stray pointer.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING) {
|
|
|
|
return obj->getvar(p_index, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return obj->get(p_index, r_valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case INPUT_EVENT: {
|
|
|
|
|
|
|
|
InputEvent ie = operator InputEvent();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING)
|
2014-02-10 01:10:30 +00:00
|
|
|
break;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String &str = *reinterpret_cast<const String *>(p_index._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "type") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.type;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "device") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.device;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "ID") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.ID;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "shift") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.key.mod.shift;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "alt") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.key.mod.alt;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "control") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.key.mod.control;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "meta") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.key.mod.meta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "pressed") {
|
|
|
|
valid = true;
|
|
|
|
return ie.key.pressed;
|
|
|
|
} else if (str == "scancode") {
|
|
|
|
valid = true;
|
|
|
|
return ie.key.scancode;
|
|
|
|
} else if (str == "unicode") {
|
|
|
|
valid = true;
|
|
|
|
return ie.key.unicode;
|
|
|
|
} else if (str == "echo") {
|
|
|
|
valid = true;
|
|
|
|
return ie.key.echo;
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_mask") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.button_mask;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pos") {
|
|
|
|
valid = true;
|
|
|
|
return Point2(ie.mouse_button.x, ie.mouse_button.y);
|
|
|
|
} else if (str == "global_x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.global_x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "global_y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.global_y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "global_pos") {
|
|
|
|
valid = true;
|
|
|
|
return Point2(ie.mouse_button.global_x, ie.mouse_button.global_y);
|
2014-02-10 01:10:30 +00:00
|
|
|
} /*else if (str=="pointer_index") {
|
|
|
|
valid=true;
|
|
|
|
return ie.mouse_button.pointer_index;
|
|
|
|
}*/
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "relative_x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_motion.relative_x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "relative_y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_motion.relative_y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "relative_pos") {
|
|
|
|
valid = true;
|
|
|
|
return Point2(ie.mouse_motion.relative_x, ie.mouse_motion.relative_y);
|
|
|
|
} else if (str == "speed_x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_motion.speed_x;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "speed_y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_motion.speed_y;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "speed") {
|
|
|
|
valid = true;
|
|
|
|
return Point2(ie.mouse_motion.speed_x, ie.mouse_motion.speed_y);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_index") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.button_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pressed") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.pressed;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "doubleclick") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.mouse_button.doubleclick;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "button_index") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.joy_button.button_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pressed") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.joy_button.pressed;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pressure") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.joy_button.pressure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "axis") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.joy_motion.axis;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "value") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.joy_motion.axis_value;
|
2016-03-08 23:00:52 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_TOUCH) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "index") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_touch.index;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_touch.x;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_touch.y;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pos") {
|
|
|
|
valid = true;
|
|
|
|
return Vector2(ie.screen_touch.x, ie.screen_touch.y);
|
|
|
|
}
|
|
|
|
if (str == "pressed") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_touch.pressed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_DRAG) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "index") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.index;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.x;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.y;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "pos") {
|
|
|
|
valid = true;
|
|
|
|
return Vector2(ie.screen_drag.x, ie.screen_drag.y);
|
|
|
|
}
|
|
|
|
if (str == "relative_x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.relative_x;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "relative_y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.relative_y;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "relative_pos") {
|
|
|
|
valid = true;
|
|
|
|
return Vector2(ie.screen_drag.relative_x, ie.screen_drag.relative_y);
|
|
|
|
}
|
|
|
|
if (str == "speed_x") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.speed_x;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "speed_y") {
|
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return ie.screen_drag.speed_y;
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
if (str == "speed") {
|
|
|
|
valid = true;
|
|
|
|
return Vector2(ie.screen_drag.speed_x, ie.screen_drag.speed_y);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2015-01-20 12:01:02 +00:00
|
|
|
if (ie.type == InputEvent::ACTION) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (str == "action") {
|
|
|
|
valid = true;
|
2015-01-20 12:01:02 +00:00
|
|
|
return ie.action.action;
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (str == "pressed") {
|
|
|
|
valid = true;
|
2015-05-01 13:44:08 +00:00
|
|
|
return ie.action.pressed;
|
2015-01-20 12:01:02 +00:00
|
|
|
}
|
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
|
|
|
const Variant *res = dic->getptr(p_index);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (res) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
return *res;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 20
|
|
|
|
DEFAULT_OP_ARRAY_CMD(ARRAY, const Array, ;, return (*arr)[index])
|
|
|
|
DEFAULT_OP_DVECTOR_GET(RAW_ARRAY, uint8_t)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(INT_ARRAY, int)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(REAL_ARRAY, real_t)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(STRING_ARRAY, String)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(VECTOR2_ARRAY, Vector2)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(VECTOR3_ARRAY, Vector3)
|
|
|
|
DEFAULT_OP_DVECTOR_GET(COLOR_ARRAY, Color)
|
2014-02-10 01:10:30 +00:00
|
|
|
default: return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool Variant::in(const Variant &p_index, bool *r_valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = true;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
//string index
|
2017-03-18 23:36:26 +00:00
|
|
|
String idx = p_index;
|
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
return str->find(idx) != -1;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case OBJECT: {
|
|
|
|
Object *obj = _get_obj().obj;
|
|
|
|
if (obj) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
|
|
|
|
//only if debugging!
|
|
|
|
if (!ObjectDB::instance_validate(obj)) {
|
|
|
|
if (r_valid) {
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
return "Attempted get on stray pointer.";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() != Variant::STRING) {
|
|
|
|
obj->getvar(p_index, &valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
obj->get(p_index, &valid);
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return valid;
|
|
|
|
} else {
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
return dic->has(p_index);
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 20
|
2014-02-10 01:10:30 +00:00
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
int l = arr->size();
|
|
|
|
if (l) {
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (evaluate(OP_EQUAL, (*arr)[i], p_index))
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case RAW_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<uint8_t> *arr = reinterpret_cast<const DVector<uint8_t> *>(_data._mem);
|
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<uint8_t>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case INT_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
int index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<int> *arr = reinterpret_cast<const DVector<int> *>(_data._mem);
|
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<int>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case REAL_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::INT || p_index.get_type() == Variant::REAL) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
real_t index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<real_t> *arr = reinterpret_cast<const DVector<real_t> *>(_data._mem);
|
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<real_t>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case STRING_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::STRING) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
String index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<String> *arr = reinterpret_cast<const DVector<String> *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<String>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; //25
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR2_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::VECTOR2) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector2 index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector2> *arr = reinterpret_cast<const DVector<Vector2> *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<Vector2>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR3_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::VECTOR3) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Vector3 index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector3> *arr = reinterpret_cast<const DVector<Vector3> *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<Vector3>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (p_index.get_type() == Variant::COLOR) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
Color index = p_index;
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Color> *arr = reinterpret_cast<const DVector<Color> *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
int l = arr->size();
|
2014-02-10 01:10:30 +00:00
|
|
|
if (l) {
|
|
|
|
DVector<Color>::Read r = arr->read();
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < l; i++) {
|
|
|
|
if (r[i] == index)
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_valid)
|
2017-03-18 23:36:26 +00:00
|
|
|
*r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Variant::get_property_list(List<PropertyInfo> *p_list) const {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case VECTOR2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "width"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "height"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 5
|
2014-02-10 01:10:30 +00:00
|
|
|
case RECT2: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "size"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "end"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case VECTOR3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "z"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case MATRIX32: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "o"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case PLANE: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "normal"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "z"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "d"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case QUAT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "z"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "w"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case _AABB: {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "size"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "end"));
|
2014-02-10 01:10:30 +00:00
|
|
|
} break; //sorry naming convention fail :( not like it's used often // 10
|
|
|
|
case MATRIX3: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "z"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case TRANSFORM: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::MATRIX3, "basis"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR3, "origin"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} break;
|
|
|
|
case COLOR: {
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "r"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "g"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "b"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "a"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "h"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "s"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "v"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "r8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "g8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "b8"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "a8"));
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case IMAGE: {
|
|
|
|
} break;
|
|
|
|
case NODE_PATH: {
|
|
|
|
} break; // 15
|
|
|
|
case _RID: {
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Object *obj = _get_obj().obj;
|
2014-02-10 01:10:30 +00:00
|
|
|
if (obj) {
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null()) {
|
|
|
|
//only if debugging!
|
|
|
|
if (!ObjectDB::instance_validate(obj)) {
|
|
|
|
WARN_PRINT("Attempted get_property list on stray pointer.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
obj->get_property_list(p_list);
|
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case INPUT_EVENT: {
|
|
|
|
|
|
|
|
InputEvent ie = operator InputEvent();
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "type"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "device"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "ID"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY || ie.type == InputEvent::MOUSE_BUTTON || ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-25 12:31:47 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "shift"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "alt"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "control"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "meta"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::KEY) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "echo"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "scancode"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "unicode"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION || ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "button_mask"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "global_x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "global_y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "global_pos"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::MOUSE_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "relative_x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "relative_y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
} else if (ie.type == InputEvent::MOUSE_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "doubleclick"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_BUTTON) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "button_index"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "pressure"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::JOYSTICK_MOTION) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "axis"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "value"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_TOUCH) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "index"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::BOOL, "pressed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ie.type == InputEvent::SCREEN_DRAG) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
p_list->push_back(PropertyInfo(Variant::INT, "index"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "relative_x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "relative_y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "relative_pos"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "speed_x"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::REAL, "speed_y"));
|
|
|
|
p_list->push_back(PropertyInfo(Variant::VECTOR2, "speed"));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
List<Variant> keys;
|
|
|
|
dic->get_key_list(&keys);
|
2017-03-18 23:36:26 +00:00
|
|
|
for (List<Variant>::Element *E = keys.front(); E; E = E->next()) {
|
|
|
|
if (E->get().get_type() == Variant::STRING) {
|
|
|
|
p_list->push_back(PropertyInfo(Variant::STRING, E->get()));
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
} break; // 20
|
2014-02-10 01:10:30 +00:00
|
|
|
case ARRAY:
|
|
|
|
case RAW_ARRAY:
|
|
|
|
case INT_ARRAY:
|
|
|
|
case REAL_ARRAY:
|
|
|
|
case STRING_ARRAY:
|
|
|
|
case VECTOR3_ARRAY:
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
|
|
|
|
//nothing
|
|
|
|
} break;
|
|
|
|
default: {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
bool Variant::iter_init(Variant &r_iter, bool &valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null() && !ObjectDB::instance_validate(_get_obj().obj)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Variant::CallError ce;
|
2017-03-18 23:36:26 +00:00
|
|
|
ce.error = Variant::CallError::CALL_OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
Array ref(true);
|
|
|
|
ref.push_back(r_iter);
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant vref = ref;
|
|
|
|
const Variant *refp[] = { &vref };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_init, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ref.size() != 1 || ce.error != Variant::CallError::CALL_OK) {
|
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = ref[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
return ret;
|
|
|
|
} break;
|
|
|
|
|
2016-06-26 20:03:42 +00:00
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2016-06-26 20:03:42 +00:00
|
|
|
if (str->empty())
|
|
|
|
return false;
|
|
|
|
r_iter = 0;
|
|
|
|
return true;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (dic->empty())
|
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Variant *next = dic->next(NULL);
|
|
|
|
r_iter = *next;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (arr->empty())
|
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case RAW_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<uint8_t> *arr = reinterpret_cast<const DVector<uint8_t> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case INT_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<int> *arr = reinterpret_cast<const DVector<int> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case REAL_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<real_t> *arr = reinterpret_cast<const DVector<real_t> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case STRING_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<String> *arr = reinterpret_cast<const DVector<String> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR2_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector2> *arr = reinterpret_cast<const DVector<Vector2> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR3_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector3> *arr = reinterpret_cast<const DVector<Vector3> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Color> *arr = reinterpret_cast<const DVector<Color> *>(_data._mem);
|
|
|
|
if (arr->size() == 0)
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = 0;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
bool Variant::iter_next(Variant &r_iter, bool &valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = true;
|
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
case OBJECT: {
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null() && !ObjectDB::instance_validate(_get_obj().obj)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Variant::CallError ce;
|
2017-03-18 23:36:26 +00:00
|
|
|
ce.error = Variant::CallError::CALL_OK;
|
2014-02-10 01:10:30 +00:00
|
|
|
Array ref(true);
|
|
|
|
ref.push_back(r_iter);
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant vref = ref;
|
|
|
|
const Variant *refp[] = { &vref };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_next, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ref.size() != 1 || ce.error != Variant::CallError::CALL_OK) {
|
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = ref[0];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
} break;
|
2016-06-26 20:03:42 +00:00
|
|
|
|
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
2016-06-26 20:03:42 +00:00
|
|
|
int idx = r_iter;
|
|
|
|
idx++;
|
2016-08-26 07:42:01 +00:00
|
|
|
if (idx >= str->length())
|
2016-06-26 20:03:42 +00:00
|
|
|
return false;
|
|
|
|
r_iter = idx;
|
|
|
|
return true;
|
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
|
|
|
|
const Variant *next = dic->next(&r_iter);
|
2014-02-10 01:10:30 +00:00
|
|
|
if (!next)
|
|
|
|
return false;
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = *next;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case RAW_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<uint8_t> *arr = reinterpret_cast<const DVector<uint8_t> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case INT_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<int> *arr = reinterpret_cast<const DVector<int> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case REAL_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<real_t> *arr = reinterpret_cast<const DVector<real_t> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case STRING_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<String> *arr = reinterpret_cast<const DVector<String> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR2_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector2> *arr = reinterpret_cast<const DVector<Vector2> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case VECTOR3_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector3> *arr = reinterpret_cast<const DVector<Vector3> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Color> *arr = reinterpret_cast<const DVector<Color> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
idx++;
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx >= arr->size())
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
2017-03-18 23:36:26 +00:00
|
|
|
r_iter = idx;
|
2014-02-10 01:10:30 +00:00
|
|
|
return true;
|
|
|
|
} break;
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
Variant Variant::iter_get(const Variant &r_iter, bool &r_valid) const {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = true;
|
|
|
|
switch (type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
case OBJECT: {
|
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (!_get_obj().obj) {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ScriptDebugger::get_singleton() && _get_obj().ref.is_null() && !ObjectDB::instance_validate(_get_obj().obj)) {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
Variant::CallError ce;
|
2017-03-18 23:36:26 +00:00
|
|
|
ce.error = Variant::CallError::CALL_OK;
|
|
|
|
const Variant *refp[] = { &r_iter };
|
|
|
|
Variant ret = _get_obj().obj->call(CoreStringNames::get_singleton()->_iter_get, refp, 1, ce);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (ce.error != Variant::CallError::CALL_OK) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
|
|
|
//r_iter=ref[0];
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
} break;
|
|
|
|
|
2016-06-26 20:03:42 +00:00
|
|
|
case STRING: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const String *str = reinterpret_cast<const String *>(_data._mem);
|
|
|
|
return str->substr(r_iter, 1);
|
2016-06-26 20:03:42 +00:00
|
|
|
} break;
|
2014-02-10 01:10:30 +00:00
|
|
|
case DICTIONARY: {
|
|
|
|
|
|
|
|
return r_iter; //iterator is the same as the key
|
|
|
|
|
|
|
|
} break;
|
|
|
|
case ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const Array *arr = reinterpret_cast<const Array *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case RAW_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<uint8_t> *arr = reinterpret_cast<const DVector<uint8_t> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case INT_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<int> *arr = reinterpret_cast<const DVector<int> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case REAL_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<real_t> *arr = reinterpret_cast<const DVector<real_t> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case STRING_ARRAY: {
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<String> *arr = reinterpret_cast<const DVector<String> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case VECTOR2_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector2> *arr = reinterpret_cast<const DVector<Vector2> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
#endif
|
2014-02-10 01:10:30 +00:00
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case VECTOR3_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector3> *arr = reinterpret_cast<const DVector<Vector3> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Color> *arr = reinterpret_cast<const DVector<Color> *>(_data._mem);
|
|
|
|
int idx = r_iter;
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifdef DEBUG_ENABLED
|
2017-03-18 23:36:26 +00:00
|
|
|
if (idx < 0 || idx >= arr->size()) {
|
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return arr->get(idx);
|
|
|
|
} break;
|
2016-07-23 12:47:49 +00:00
|
|
|
default: {}
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_valid = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
return Variant();
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Variant::blend(const Variant &a, const Variant &b, float c, Variant &r_dst) {
|
|
|
|
if (a.type != b.type) {
|
|
|
|
if (a.is_num() && b.is_num()) {
|
|
|
|
real_t va = a;
|
|
|
|
real_t vb = b;
|
|
|
|
r_dst = va + vb * c;
|
2016-02-18 03:34:49 +00:00
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = a;
|
2016-02-18 03:34:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (a.type) {
|
|
|
|
case NIL: {
|
|
|
|
r_dst = Variant();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INT: {
|
|
|
|
int va = a._data._int;
|
|
|
|
int vb = b._data._int;
|
|
|
|
r_dst = int(va + vb * c + 0.5);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case REAL: {
|
|
|
|
double ra = a._data._real;
|
|
|
|
double rb = b._data._real;
|
|
|
|
r_dst = ra + rb * c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR2: {
|
|
|
|
r_dst = *reinterpret_cast<const Vector2 *>(a._data._mem) + *reinterpret_cast<const Vector2 *>(b._data._mem) * c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case RECT2: {
|
|
|
|
const Rect2 *ra = reinterpret_cast<const Rect2 *>(a._data._mem);
|
|
|
|
const Rect2 *rb = reinterpret_cast<const Rect2 *>(b._data._mem);
|
|
|
|
r_dst = Rect2(ra->pos + rb->pos * c, ra->size + rb->size * c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR3: {
|
|
|
|
r_dst = *reinterpret_cast<const Vector3 *>(a._data._mem) + *reinterpret_cast<const Vector3 *>(b._data._mem) * c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case _AABB: {
|
|
|
|
const AABB *ra = reinterpret_cast<const AABB *>(a._data._mem);
|
|
|
|
const AABB *rb = reinterpret_cast<const AABB *>(b._data._mem);
|
|
|
|
r_dst = AABB(ra->pos + rb->pos * c, ra->size + rb->size * c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case QUAT: {
|
|
|
|
Quat empty_rot;
|
|
|
|
const Quat *qa = reinterpret_cast<const Quat *>(a._data._mem);
|
|
|
|
const Quat *qb = reinterpret_cast<const Quat *>(b._data._mem);
|
|
|
|
r_dst = *qa * empty_rot.slerp(*qb, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case COLOR: {
|
|
|
|
const Color *ca = reinterpret_cast<const Color *>(a._data._mem);
|
|
|
|
const Color *cb = reinterpret_cast<const Color *>(b._data._mem);
|
|
|
|
float r = ca->r + cb->r * c;
|
|
|
|
float g = ca->g + cb->g * c;
|
|
|
|
float b = ca->b + cb->b * c;
|
|
|
|
float a = ca->a + cb->a * c;
|
|
|
|
r = r > 1.0 ? 1.0 : r;
|
|
|
|
g = g > 1.0 ? 1.0 : g;
|
|
|
|
b = b > 1.0 ? 1.0 : b;
|
|
|
|
a = a > 1.0 ? 1.0 : a;
|
|
|
|
r_dst = Color(r, g, b, a);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
default: { r_dst = c < 0.5 ? a : b; }
|
|
|
|
return;
|
2016-02-18 03:34:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
void Variant::interpolate(const Variant &a, const Variant &b, float c, Variant &r_dst) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (a.type != b.type) {
|
2015-05-16 21:16:11 +00:00
|
|
|
if (a.is_num() && b.is_num()) {
|
|
|
|
//not as efficient but..
|
2017-03-18 23:36:26 +00:00
|
|
|
real_t va = a;
|
|
|
|
real_t vb = b;
|
|
|
|
r_dst = (1.0 - c) * va + vb * c;
|
2015-05-16 21:16:11 +00:00
|
|
|
|
|
|
|
} else {
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = a;
|
2015-05-16 21:16:11 +00:00
|
|
|
}
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
switch (a.type) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
case NIL: {
|
|
|
|
r_dst = Variant();
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case BOOL: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INT: {
|
|
|
|
int va = a._data._int;
|
|
|
|
int vb = b._data._int;
|
|
|
|
r_dst = int((1.0 - c) * va + vb * c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case REAL: {
|
|
|
|
real_t va = a._data._real;
|
|
|
|
real_t vb = b._data._real;
|
|
|
|
r_dst = (1.0 - c) * va + vb * c;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case STRING: {
|
2014-02-10 01:10:30 +00:00
|
|
|
//this is pretty funny and bizarre, but artists like to use it for typewritter effects
|
2017-03-18 23:36:26 +00:00
|
|
|
String sa = *reinterpret_cast<const String *>(a._data._mem);
|
|
|
|
String sb = *reinterpret_cast<const String *>(b._data._mem);
|
2014-02-10 01:10:30 +00:00
|
|
|
String dst;
|
2017-03-18 23:36:26 +00:00
|
|
|
int csize = sb.length() * c + sa.length() * (1.0 - c);
|
|
|
|
if (csize == 0) {
|
|
|
|
r_dst = "";
|
2014-02-10 01:10:30 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
dst.resize(csize + 1);
|
|
|
|
dst[csize] = 0;
|
|
|
|
int split = csize / 2;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < csize; i++) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
CharType chr = ' ';
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i < split) {
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i < sa.length())
|
|
|
|
chr = sa[i];
|
|
|
|
else if (i < sb.length())
|
|
|
|
chr = sb[i];
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
if (i < sb.length())
|
|
|
|
chr = sb[i];
|
|
|
|
else if (i < sa.length())
|
|
|
|
chr = sa[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
dst[i] = chr;
|
|
|
|
}
|
|
|
|
|
|
|
|
r_dst = dst;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR2: {
|
|
|
|
r_dst = reinterpret_cast<const Vector2 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector2 *>(b._data._mem), c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case RECT2: {
|
|
|
|
r_dst = Rect2(reinterpret_cast<const Rect2 *>(a._data._mem)->pos.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->pos, c), reinterpret_cast<const Rect2 *>(a._data._mem)->size.linear_interpolate(reinterpret_cast<const Rect2 *>(b._data._mem)->size, c));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR3: {
|
|
|
|
r_dst = reinterpret_cast<const Vector3 *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Vector3 *>(b._data._mem), c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case MATRIX32: {
|
|
|
|
r_dst = a._data._matrix32->interpolate_with(*b._data._matrix32, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case PLANE: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case QUAT: {
|
|
|
|
r_dst = reinterpret_cast<const Quat *>(a._data._mem)->slerp(*reinterpret_cast<const Quat *>(b._data._mem), c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case _AABB: {
|
|
|
|
r_dst = AABB(a._data._aabb->pos.linear_interpolate(b._data._aabb->pos, c), a._data._aabb->size.linear_interpolate(b._data._aabb->size, c));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case MATRIX3: {
|
|
|
|
r_dst = Transform(*a._data._matrix3).interpolate_with(Transform(*b._data._matrix3), c).basis;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case TRANSFORM: {
|
|
|
|
r_dst = a._data._transform->interpolate_with(*b._data._transform, c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case COLOR: {
|
|
|
|
r_dst = reinterpret_cast<const Color *>(a._data._mem)->linear_interpolate(*reinterpret_cast<const Color *>(b._data._mem), c);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case IMAGE: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case NODE_PATH: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case _RID: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case OBJECT: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INPUT_EVENT: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case DICTIONARY: {
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case RAW_ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case INT_ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case REAL_ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case STRING_ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR2_ARRAY: {
|
|
|
|
const DVector<Vector2> *arr_a = reinterpret_cast<const DVector<Vector2> *>(a._data._mem);
|
|
|
|
const DVector<Vector2> *arr_b = reinterpret_cast<const DVector<Vector2> *>(b._data._mem);
|
2014-07-07 20:44:21 +00:00
|
|
|
int sz = arr_a->size();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = a;
|
2014-07-07 20:44:21 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
DVector<Vector2> v;
|
|
|
|
v.resize(sz);
|
|
|
|
{
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<Vector2>::Write vw = v.write();
|
|
|
|
DVector<Vector2>::Read ar = arr_a->read();
|
|
|
|
DVector<Vector2>::Read br = arr_b->read();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
vw[i] = ar[i].linear_interpolate(br[i], c);
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = v;
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case VECTOR3_ARRAY: {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
const DVector<Vector3> *arr_a = reinterpret_cast<const DVector<Vector3> *>(a._data._mem);
|
|
|
|
const DVector<Vector3> *arr_b = reinterpret_cast<const DVector<Vector3> *>(b._data._mem);
|
2014-07-07 20:44:21 +00:00
|
|
|
int sz = arr_a->size();
|
2017-03-18 23:36:26 +00:00
|
|
|
if (sz == 0 || arr_b->size() != sz) {
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = a;
|
2014-07-07 20:44:21 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
DVector<Vector3> v;
|
|
|
|
v.resize(sz);
|
|
|
|
{
|
2017-03-18 23:36:26 +00:00
|
|
|
DVector<Vector3>::Write vw = v.write();
|
|
|
|
DVector<Vector3>::Read ar = arr_a->read();
|
|
|
|
DVector<Vector3>::Read br = arr_b->read();
|
2014-07-07 20:44:21 +00:00
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
for (int i = 0; i < sz; i++) {
|
|
|
|
vw[i] = ar[i].linear_interpolate(br[i], c);
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = v;
|
2014-07-07 20:44:21 +00:00
|
|
|
}
|
2017-03-18 23:36:26 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
case COLOR_ARRAY: {
|
|
|
|
r_dst = a;
|
|
|
|
}
|
|
|
|
return;
|
2014-02-10 01:10:30 +00:00
|
|
|
default: {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
r_dst = a;
|
2014-02-10 01:10:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
static const char *_op_names[Variant::OP_MAX] = {
|
2014-02-10 01:10:30 +00:00
|
|
|
"==",
|
|
|
|
"!=",
|
|
|
|
"<",
|
|
|
|
"<=",
|
|
|
|
">",
|
|
|
|
">=",
|
|
|
|
"+",
|
|
|
|
"-",
|
|
|
|
"*",
|
|
|
|
"/",
|
|
|
|
"- (negation)",
|
|
|
|
"%",
|
|
|
|
"..",
|
|
|
|
"<<",
|
|
|
|
">>",
|
|
|
|
"&",
|
|
|
|
"|",
|
|
|
|
"^",
|
|
|
|
"~",
|
|
|
|
"and",
|
|
|
|
"or",
|
|
|
|
"xor",
|
|
|
|
"not",
|
|
|
|
"in"
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
String Variant::get_operator_name(Operator p_op) {
|
|
|
|
|
2017-03-18 23:36:26 +00:00
|
|
|
ERR_FAIL_INDEX_V(p_op, OP_MAX, "");
|
2014-02-10 01:10:30 +00:00
|
|
|
return _op_names[p_op];
|
|
|
|
}
|