-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathScriptTarget.cpp
54 lines (45 loc) · 1.65 KB
/
ScriptTarget.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "JuceHeader.h"
ScriptTarget::ScriptTarget(const String& name, void* ptr, const String& targetType) :
thisPtr((int64)ptr),
scriptTargetName(name)
{
scriptObject = new DynamicObject();
scriptObject.getDynamicObject()->setProperty(scriptPtrIdentifier, thisPtr);
scriptObject.getDynamicObject()->setProperty(scriptTargetTypeIdentifier, targetType);
scriptObject.getDynamicObject()->setMethod(ptrCompareIdentifier, ScriptTarget::checkTargetsAreTheSameFromScript);
scriptObjectIsDirty = true;
}
ScriptTarget::~ScriptTarget()
{
}
var ScriptTarget::getScriptObject()
{
if (scriptObjectIsDirty) updateScriptObject();
return scriptObject;
}
void ScriptTarget::updateScriptObject(var parent)
{
scriptObjectLock.enter();
//liveScriptObject = scriptObject.clone(); //is there a bettery way to deal with updating without recreating an object each time ?
updateScriptObjectInternal(parent);
scriptObjectLock.exit();
scriptObjectIsDirty = false;
scriptTargetListeners.call(&ScriptTargetListener::scriptObjectUpdated, this);
}
var ScriptTarget::checkTargetsAreTheSameFromScript(const var::NativeFunctionArgs& args)
{
if (args.numArguments == 0) return false;
if (!args.arguments[0].isObject()) return false;
DynamicObject* o = args.arguments[0].getDynamicObject();
if (o == nullptr) return false;
if (!o->hasProperty(scriptPtrIdentifier)) return false;
DynamicObject* d = args.thisObject.getDynamicObject();
if (d == nullptr) return false;
int64 oId = (int64)o->getProperty(scriptPtrIdentifier);
int64 thisId = (int64)d->getProperty(scriptPtrIdentifier);
return oId == thisId;
}
String ScriptTarget::getScriptTargetString()
{
return "[" + scriptTargetName + "]";
}