Skip to content

Commit e137ddf

Browse files
committed
Entity Classes: Provide a data table
1 parent f2637ce commit e137ddf

File tree

12 files changed

+44
-1
lines changed

12 files changed

+44
-1
lines changed

VCMP-LUA/vcmpWrap/Classes/Bind.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ void Bind::clearAllBinds() {
1111
}
1212

1313
void Bind::Register(Bind* bind) {
14+
bind->m_LuaData = Lua.create_table();
1415
s_Binds.emplace_back(bind);
1516
}
1617

@@ -106,4 +107,7 @@ void Bind::Init(sol::state* L) {
106107

107108
/*** PROPERTIES ***/
108109
userdata["tag"] = sol::property(&Bind::getTag, &Bind::setTag);
110+
111+
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
112+
userdata["data"] = &Bind::m_LuaData;
109113
}

VCMP-LUA/vcmpWrap/Classes/Bind.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ class Bind
1616
static inline const char* getStaticType() { return "Bind"; }
1717
static void clearAllBinds();
1818

19+
/*** @Lua meta-functions & extra ***/
20+
bool operator==(const Bind& other) { return this->m_ID == other.m_ID; }
21+
int32_t operator()() { return this->m_ID; }
22+
1923
/*** CONSTRUCTORS ***/
2024
Bind(bool, int32_t, int32_t = 0, int32_t = 0);
2125

@@ -40,4 +44,5 @@ class Bind
4044
private:
4145
int32_t m_ID;
4246
std::string m_Tag = "";
47+
sol::table m_LuaData;
4348
};

VCMP-LUA/vcmpWrap/Classes/Checkpoint.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern sol::state Lua;
77
std::vector<Checkpoint*> Checkpoint::s_Checkpoints;
88

99
void Checkpoint::Register(Checkpoint* inst) {
10+
inst->m_LuaData = Lua.create_table();
1011
s_Checkpoints.emplace_back(inst);
1112
}
1213

@@ -177,5 +178,6 @@ void Checkpoint::Init(sol::state* L) {
177178
userdata["alpha"] = sol::property(&Checkpoint::getAlpha, &Checkpoint::setAlpha);
178179

179180
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
181+
userdata["data"] = &Checkpoint::m_LuaData;
180182
userdata["position"] = sol::property(&Checkpoint::getPosition, &Checkpoint::setPosition);
181183
}

VCMP-LUA/vcmpWrap/Classes/Checkpoint.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ class Checkpoint
1818
static inline const char* getStaticType() { return "Checkpoint"; }
1919
static sol::table getActive();
2020

21+
/*** @Lua meta-functions & extra ***/
22+
bool operator==(const Checkpoint& other) { return this->m_ID == other.m_ID; }
23+
int32_t operator()() { return this->m_ID; }
24+
2125
/*** CONSTRUCTORS ***/
2226
Checkpoint(Player*, int32_t, bool, sol::table, sol::table, float);
2327
Checkpoint(Player*, int32_t, bool, float, float, float, sol::table, float);
@@ -52,4 +56,5 @@ class Checkpoint
5256
void setPosition(sol::table);
5357
private:
5458
int32_t m_ID;
59+
sol::table m_LuaData;
5560
};

VCMP-LUA/vcmpWrap/Classes/Object.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern sol::state Lua;
77
std::vector<Object*> Object::s_Objects;
88

99
void Object::Register(Object* inst) {
10+
inst->m_LuaData = Lua.create_table();
1011
s_Objects.emplace_back(inst);
1112
}
1213

@@ -260,6 +261,7 @@ void Object::Init(sol::state* L) {
260261
userdata["trackTouch"] = sol::property(&Object::getBumpReports, &Object::setBumpReports);
261262

262263
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
264+
userdata["data"] = &Object::m_LuaData;
263265
userdata["position"] = sol::property(&Object::getPosition, &Object::setPosition);
264266
userdata["angle"] = sol::property(&Object::getRotation, &Object::setRotation);
265267
}

VCMP-LUA/vcmpWrap/Classes/Object.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class Object
2020
static inline const char* getStaticType() { return "Object"; }
2121
static sol::table getActive();
2222

23+
/*** @Lua meta-functions & extra ***/
24+
bool operator==(const Object& other) { return this->m_ID == other.m_ID; }
25+
int32_t operator()() { return this->m_ID; }
26+
2327
/*** CONSTRUCTORS ***/
2428
Object(int32_t, int32_t, float, float, float, int32_t = 255);
2529
Object(int32_t, int32_t, sol::table);
@@ -73,5 +77,6 @@ class Object
7377
/******/
7478
private:
7579
int32_t m_ID;
80+
sol::table m_LuaData;
7681
};
7782

VCMP-LUA/vcmpWrap/Classes/Pickup.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ extern sol::state Lua;
77
std::vector<Pickup*> Pickup::s_Pickups;
88

99
void Pickup::Register(Pickup* inst) {
10+
inst->m_LuaData = Lua.create_table();
1011
s_Pickups.emplace_back(inst);
1112
}
1213

@@ -181,5 +182,6 @@ void Pickup::Init(sol::state* L) {
181182
userdata["autoTimer"] = sol::property(&Pickup::getAutoTimer, &Pickup::setAutoTimer);
182183

183184
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
185+
userdata["data"] = &Pickup::m_LuaData;
184186
userdata["position"] = sol::property(&Pickup::getPosition, &Pickup::setPosition);
185187
}

VCMP-LUA/vcmpWrap/Classes/Pickup.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class Pickup
1717
static inline const char* getStaticType() { return "Pickup"; }
1818
static sol::table getActive();
1919

20+
/*** @Lua meta-functions & extra ***/
21+
bool operator==(const Pickup& other) { return this->m_ID == other.m_ID; }
22+
int32_t operator()() { return this->m_ID; }
23+
2024
/*** CONSTRUCTORS ***/
2125
Pickup(int32_t, int32_t, int32_t, sol::table, int32_t, bool);
2226
Pickup(int32_t, int32_t, int32_t, float, float, float, int32_t, bool);
@@ -53,4 +57,5 @@ class Pickup
5357
void setPosition(sol::table);
5458
private:
5559
int32_t m_ID;
60+
sol::table m_LuaData;
5661
};

VCMP-LUA/vcmpWrap/Classes/Player.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void Player::msgAll(const std::string& msg, sol::variadic_args args)
4646
}
4747

4848
Player::Player(int32_t id)
49-
: m_ID(id) {
49+
: m_ID(id), m_LuaData(Lua.create_table()) {
5050

5151
g_Funcs->GetPlayerName(id, m_Name, sizeof(m_Name));
5252
}
@@ -559,6 +559,7 @@ void Player::Init(sol::state* L) {
559559
userdata["aimPosition"] = sol::property(&Player::getAimPos);
560560

561561
/*** COMMON PROPERTIES AMONGST ENTITIES ***/
562+
userdata["data"] = &Player::m_LuaData;
562563
userdata["position"] = sol::property(&Player::getPosition, &Player::setPosition);
563564
userdata["angle"] = sol::property(&Player::getRotation, &Player::setRotation);
564565
}

VCMP-LUA/vcmpWrap/Classes/Player.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ class Player {
1717
static inline const char* getStaticType() { return "Player"; }
1818
static sol::table getActive(bool spawned = false);
1919
static void msgAll(const std::string& msg, sol::variadic_args args);
20+
21+
/*** @Lua meta-functions & extra ***/
22+
bool operator==(const Player& other) { return this->m_ID == other.m_ID; }
23+
int32_t operator()() { return this->m_ID; }
2024

2125
/*** CONSTRUCTORS ***/
2226
Player(int32_t id);
@@ -127,4 +131,5 @@ class Player {
127131
private:
128132
int32_t m_ID;
129133
char m_Name[24];
134+
sol::table m_LuaData;
130135
};

0 commit comments

Comments
 (0)