forked from hereisderek/SourceMod.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSMJS_Entity.cpp
More file actions
69 lines (50 loc) · 1.66 KB
/
SMJS_Entity.cpp
File metadata and controls
69 lines (50 loc) · 1.66 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "SMJS_Entity.h"
#include "SMJS_Plugin.h"
WRAPPED_CLS_CPP(SMJS_Entity, SMJS_BaseWrapped)
SMJS_Entity::SMJS_Entity(CBaseEntity *ent){
this->ent = NULL;
datamaps.entWrapper = this;
netprops.entWrapper = this;
isEdict = false;
entIndex = -1;
SetEntity(ent);
keyvalues.entWrapper = this;
}
void SMJS_Entity::SetEntity(CBaseEntity *ent){
if(this->ent != NULL){
if(this->ent != ent){
throw "Cannot set entity twice";
}
return;
}
if(ent == NULL) return;
this->ent = ent;
IServerUnknown *pUnk = (IServerUnknown *)ent;
IServerNetworkable *pNet = pUnk->GetNetworkable();
if(pNet){
edict = pNet->GetEdict();
entIndex = gamehelpers->IndexOfEdict(edict);
}
this->valid = true;
}
Handle<Value> GetEntityIndex(Local<String> prop, const AccessorInfo& info){
Local<Value> _intfld = info.This()->GetInternalField(0); \
SMJS_Entity* self = dynamic_cast<SMJS_Entity*>((SMJS_Base*)Handle<External>::Cast(_intfld)->Value());
return v8::Int32::New(self->entIndex);
}
void SMJS_Entity::OnWrapperAttached(SMJS_Plugin *plugin, v8::Persistent<v8::Value> wrapper){
auto obj = wrapper->ToObject();
obj->SetAccessor(v8::String::New("index"), GetEntityIndex);
obj->Set(v8::String::New("netprops"), netprops.GetWrapper(plugin));
obj->Set(v8::String::New("keyvalues"), keyvalues.GetWrapper(plugin));
obj->Set(v8::String::New("datamaps"), datamaps.GetWrapper(plugin));
}
FUNCTION_M(SMJS_Entity::isValid)
GET_INTERNAL(SMJS_Entity*, self);
return v8::Boolean::New(self->valid);
END
FUNCTION_M(SMJS_Entity::getClassname)
GET_INTERNAL(SMJS_Entity*, self);
if(!self->valid) THROW("Invalid entity");
return v8::String::New(gamehelpers->GetEntityClassname(self->ent));
END