Skip to content

Commit 1c19d71

Browse files
committed
wip(objectmodelv2): GetClass -> GetType
1 parent aac0c49 commit 1c19d71

11 files changed

Lines changed: 34 additions & 34 deletions

File tree

‎client/src/main.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ int main() {
7070
}));
7171

7272
for (std::shared_ptr<Instance> inst : gWorkspace()->GetChildren()) {
73-
if (inst->GetClass()->className != "Part") continue;
73+
if (inst->GetType()->className != "Part") continue;
7474
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(inst);
7575
gWorkspace()->SyncPartPhysics(part);
7676
}

‎core/src/datatypes/ref.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static int inst_index(lua_State* L) {
196196
return 1;
197197
}
198198

199-
return luaL_error(L, "'%s' is not a valid member of %s", key.c_str(), inst->GetClass()->className.c_str());
199+
return luaL_error(L, "'%s' is not a valid member of %s", key.c_str(), inst->GetType()->className.c_str());
200200
}
201201

202202
// __newindex(t,k,v)
@@ -207,11 +207,11 @@ static int inst_newindex(lua_State* L) {
207207
// Validate property
208208
std::optional<PropertyMeta> meta = inst->GetPropertyMeta(key);
209209
if (!meta)
210-
return luaL_error(L, "'%s' is not a valid member of %s", key.c_str(), inst->GetClass()->className.c_str());
210+
return luaL_error(L, "'%s' is not a valid member of %s", key.c_str(), inst->GetType()->className.c_str());
211211
if (meta->flags & PROP_READONLY)
212-
return luaL_error(L, "'%s' of %s is read-only", key.c_str(), inst->GetClass()->className.c_str());
212+
return luaL_error(L, "'%s' of %s is read-only", key.c_str(), inst->GetType()->className.c_str());
213213
if (key == "Parent" && inst->IsParentLocked())
214-
return luaL_error(L, "Cannot set property Parent (%s) of %s, parent is locked", inst->GetParent() ? inst->GetParent()->name.c_str() : "NULL", inst->GetClass()->className.c_str());
214+
return luaL_error(L, "Cannot set property Parent (%s) of %s, parent is locked", inst->GetParent() ? inst->GetParent()->name.c_str() : "NULL", inst->GetType()->className.c_str());
215215

216216
// TODO: Make this work for enums, this is not a solution!!
217217
result<Variant, LuaCastError> value = meta->type.descriptor->fromLuaValue(L, -1);

‎core/src/error/instance.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ class AssignToReadOnlyMember : public Error {
3434

3535
class InstanceCastError : public Error {
3636
public:
37-
inline InstanceCastError(std::string sourceClass, std::string targetClass) : Error("InstanceCastError", "Attempt to cast object of type " + sourceClass + " to incompatible type " + targetClass) {}
37+
inline InstanceCastError(std::string sourceClass, std::string tarGetType) : Error("InstanceCastError", "Attempt to cast object of type " + sourceClass + " to incompatible type " + tarGetType) {}
3838
};

‎core/src/objects/annotation.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ virtual void InternalUpdateProperty(std::string name) override; \
4343
virtual std::vector<std::string> InternalGetProperties() override; \
4444
public: \
4545
const static InstanceType TYPE; \
46-
virtual const InstanceType* GetClass() override; \
46+
virtual const InstanceType* GetType() override; \
4747
private:

‎core/src/objects/base/instance.cpp‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ const InstanceType Instance::TYPE = {
3232
.flags = 0
3333
};
3434

35-
// Instance is abstract, so it should not implement GetClass directly
36-
// InstanceType* Instance::GetClass() {
35+
// Instance is abstract, so it should not implement GetType directly
36+
// InstanceType* Instance::GetType() {
3737
// return &TYPE_;
3838
// }
3939

@@ -86,8 +86,8 @@ void Instance::updateAncestry(nullable std::shared_ptr<Instance> updatedChild, n
8686

8787
// Update parent data model and workspace, if applicable
8888
if (GetParent() != nullptr) {
89-
this->_dataModel = GetParent()->GetClass() == &DataModel::TYPE ? std::dynamic_pointer_cast<DataModel>(GetParent()) : GetParent()->_dataModel;
90-
this->_workspace = GetParent()->GetClass() == &Workspace::TYPE ? std::dynamic_pointer_cast<Workspace>(GetParent()) : GetParent()->_workspace;
89+
this->_dataModel = GetParent()->GetType() == &DataModel::TYPE ? std::dynamic_pointer_cast<DataModel>(GetParent()) : GetParent()->_dataModel;
90+
this->_workspace = GetParent()->GetType() == &Workspace::TYPE ? std::dynamic_pointer_cast<Workspace>(GetParent()) : GetParent()->_workspace;
9191
} else {
9292
this->_dataModel = {};
9393
this->_workspace = {};
@@ -132,7 +132,7 @@ void Instance::Destroy() {
132132
}
133133

134134
bool Instance::IsA(std::string className) {
135-
const InstanceType* cur = GetClass();
135+
const InstanceType* cur = GetType();
136136
while (cur && cur->className != className) { cur = cur->super; }
137137
return cur != nullptr;
138138
}
@@ -203,9 +203,9 @@ result<Variant, MemberNotFound> Instance::InternalGetPropertyValue(std::string n
203203
} else if (name == "Parent") {
204204
return Variant(InstanceRef(this->parent));
205205
} else if (name == "ClassName") {
206-
return Variant(GetClass()->className);
206+
return Variant(GetType()->className);
207207
}
208-
return MemberNotFound(GetClass()->className, name);
208+
return MemberNotFound(GetType()->className, name);
209209
}
210210

211211
result<PropertyMeta, MemberNotFound> Instance::InternalGetPropertyMeta(std::string name) {
@@ -216,7 +216,7 @@ result<PropertyMeta, MemberNotFound> Instance::InternalGetPropertyMeta(std::stri
216216
} else if (name == "ClassName") {
217217
return PropertyMeta { &STRING_TYPE, PROP_NOSAVE | PROP_READONLY };
218218
}
219-
return MemberNotFound(GetClass()->className, name);
219+
return MemberNotFound(GetType()->className, name);
220220
}
221221

222222
fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyValue(std::string name, Variant value) {
@@ -226,9 +226,9 @@ fallible<MemberNotFound, AssignToReadOnlyMember> Instance::InternalSetPropertyVa
226226
std::weak_ptr<Instance> ref = value.get<InstanceRef>();
227227
SetParent(ref.expired() ? nullptr : ref.lock());
228228
} else if (name == "ClassName") {
229-
return AssignToReadOnlyMember(GetClass()->className, name);
229+
return AssignToReadOnlyMember(GetType()->className, name);
230230
} else {
231-
return MemberNotFound(GetClass()->className, name);
231+
return MemberNotFound(GetType()->className, name);
232232
}
233233
return {};
234234
}
@@ -262,7 +262,7 @@ std::vector<std::string> Instance::GetProperties() {
262262
void Instance::Serialize(pugi::xml_node parent, RefStateSerialize state) {
263263
if (state == nullptr) state = std::make_shared<__RefStateSerialize>();
264264
pugi::xml_node node = parent.append_child("Item");
265-
node.append_attribute("class").set_value(this->GetClass()->className);
265+
node.append_attribute("class").set_value(this->GetType()->className);
266266

267267
// Add properties
268268
pugi::xml_node propertiesNode = node.append_child("Properties");
@@ -339,7 +339,7 @@ result<std::shared_ptr<Instance>, NoSuchInstance> Instance::Deserialize(pugi::xm
339339
std::string propertyName = propertyNode.attribute("name").value();
340340
auto meta_ = object->GetPropertyMeta(propertyName);
341341
if (!meta_) {
342-
Logger::fatalErrorf("Attempt to set unknown property '%s' of %s", propertyName.c_str(), object->GetClass()->className.c_str());
342+
Logger::fatalErrorf("Attempt to set unknown property '%s' of %s", propertyName.c_str(), object->GetType()->className.c_str());
343343
continue;
344344
}
345345
auto meta = meta_.expect();
@@ -444,7 +444,7 @@ DescendantsIterator::self_type DescendantsIterator::operator++(int _) {
444444

445445
nullable std::shared_ptr<Instance> Instance::Clone(RefStateClone state) {
446446
if (state == nullptr) state = std::make_shared<__RefStateClone>();
447-
std::shared_ptr<Instance> newInstance = GetClass()->constructor();
447+
std::shared_ptr<Instance> newInstance = GetType()->constructor();
448448

449449
// Copy properties
450450
for (std::string property : GetProperties()) {

‎core/src/objects/base/service.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Service::Service(const InstanceType* type) : Instance(type) {}
88

99
// Fail if parented to non-datamodel, otherwise lock parent
1010
void Service::OnParentUpdated(nullable std::shared_ptr<Instance> oldParent, nullable std::shared_ptr<Instance> newParent) {
11-
if (!newParent || newParent->GetClass() != &DataModel::TYPE) {
12-
Logger::fatalErrorf("Service %s was parented to object of type %s", GetClass()->className.c_str(), newParent ? newParent->GetClass()->className.c_str() : "NULL");
11+
if (!newParent || newParent->GetType() != &DataModel::TYPE) {
12+
Logger::fatalErrorf("Service %s was parented to object of type %s", GetType()->className.c_str(), newParent ? newParent->GetType()->className.c_str() : "NULL");
1313
panic();
1414
}
1515

‎core/src/objects/datamodel.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ std::shared_ptr<DataModel> DataModel::CloneModel() {
184184
newModel->AddChild(result);
185185

186186
// Special case: Ignore instances parented to DataModel which are not services
187-
if (child->GetClass()->flags & INSTANCE_SERVICE) {
188-
newModel->services[child->GetClass()->className] = std::dynamic_pointer_cast<Service>(result);
187+
if (child->GetType()->flags & INSTANCE_SERVICE) {
188+
newModel->services[child->GetType()->className] = std::dynamic_pointer_cast<Service>(result);
189189
}
190190
}
191191

‎core/src/objects/joint/jointinstance.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void JointInstance::Update() {
4545
oldPart1 = part1;
4646

4747
// Don't build the joint if we're not part of either a workspace or JointsService
48-
if ((!GetParent() || GetParent()->GetClass() != &JointsService::TYPE) && !workspace()) return;
48+
if ((!GetParent() || GetParent()->GetType() != &JointsService::TYPE) && !workspace()) return;
4949

5050
// If either part is invalid or they are part of separate worlds, fail
5151
if (part0.expired()

‎core/src/rendering/renderer.cpp‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ void renderAABB() {
373373

374374
// Sort by nearest
375375
for (std::shared_ptr<Instance> inst : gWorkspace()->GetChildren()) {
376-
if (inst->GetClass()->className != "Part") continue;
376+
if (inst->GetType()->className != "Part") continue;
377377
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(inst);
378378
glm::mat4 model = CFrame::IDENTITY + part->cframe.Position();
379379
printf("AABB is supposedly (%f, %f, %f)\n", part->GetAABB().X(), part->GetAABB().Y(), part->GetAABB().Z());
@@ -413,7 +413,7 @@ void renderWireframe() {
413413

414414
// Sort by nearest
415415
for (std::shared_ptr<Instance> inst : gWorkspace()->GetChildren()) {
416-
if (inst->GetClass()->className != "Part") continue;
416+
if (inst->GetType()->className != "Part") continue;
417417
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(inst);
418418
glm::mat4 model = part->cframe;
419419
model = glm::scale(model, (glm::vec3)part->size);
@@ -455,7 +455,7 @@ void renderOutlines() {
455455

456456
std::shared_ptr<Selection> selection = gDataModel->GetService<Selection>();
457457
for (auto inst : selection->Get()) {
458-
if (inst->GetClass() != &BasePart::TYPE) continue;
458+
if (inst->GetType() != &BasePart::TYPE) continue;
459459
std::shared_ptr<BasePart> part = std::dynamic_pointer_cast<BasePart>(inst);
460460

461461
if (first)
@@ -640,7 +640,7 @@ void renderMessages() {
640640
float textWidth = calcTextWidth(sansSerif, message->text);
641641

642642
// Render hint
643-
if (message->GetClass() == &Hint::TYPE) {
643+
if (message->GetType() == &Hint::TYPE) {
644644
drawRect(0, 0, viewportWidth, 20, glm::vec4(0,0,0,1));
645645
drawText(sansSerif, message->text, (viewportWidth - textWidth) / 2, 0);
646646
} else {

‎docs/autogen.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ It comes with various parameters/flags:
6262
- `service` - Flag, the instance is a service. Additionally, enable the `not_creatable` flag as well (Adds both `INSTANCE_NOTCREATABLE` and `INSTANCE_SERVICE` flags)
6363
- `explorer_icon` - Option, string to pass into editor for the icon of the instance in the explorer
6464

65-
A file will be generated in `build/generated/<header>.cpp` with the `TYPE` automatically filled in, as well as an implementation for `GetClass()`
65+
A file will be generated in `build/generated/<header>.cpp` with the `TYPE` automatically filled in, as well as an implementation for `GetType()`
6666

6767
Note that it is also necessary to add `AUTOGEN_PREAMBLE` to the top of your class definition, to make sure that various functions for properties, etc. are
6868
declared such that they can later be defined in the generated source file.

0 commit comments

Comments
 (0)