Skip to content

Commit

Permalink
support adding new enum and class types with tiled.project scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
dogboydog committed Jan 25, 2025
1 parent 4a697eb commit b3f333e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/tiled/editableproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,20 @@ bool EditableProject::removeTypeByName(const QString &name)
applyPropertyChanges();
return true;
}

ScriptPropertyType *EditableProject::addClassType(const QString &name)
{
SharedPropertyType newClassType = SharedPropertyType(new ClassPropertyType(name));
project()->propertyTypes()->add(newClassType);
applyPropertyChanges();
return findTypeByName(name);
}
ScriptPropertyType *EditableProject::addEnumType(const QString &name)
{
SharedPropertyType newEnumType = SharedPropertyType(new EnumPropertyType(name));
project()->propertyTypes()->add(newEnumType);
applyPropertyChanges();
return findTypeByName(name);
}
void EditableProject::applyPropertyChanges()
{
emit Preferences::instance()->propertyTypesChanged();
Expand Down
2 changes: 2 additions & 0 deletions src/tiled/editableproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class EditableProject final : public EditableAsset

Q_INVOKABLE bool removeTypeByName(const QString &name);
Q_INVOKABLE ScriptPropertyType *findTypeByName(const QString &name);
Q_INVOKABLE ScriptPropertyType *addClassType(const QString &name);
Q_INVOKABLE ScriptPropertyType *addEnumType(const QString &name);

private:
ScriptPropertyType *toScriptType(const SharedPropertyType &type) const;
Expand Down

0 comments on commit b3f333e

Please sign in to comment.