Skip to content

Commit

Permalink
tiled.worlds no longer crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Jan 12, 2024
1 parent a95d295 commit 41f89d5
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/libtiled/logginginterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ SelectCustomProperty::SelectCustomProperty(QString fileName,
id = static_cast<const WangColor*>(object)->colorIndex();
break;
case Object::ProjectType:
case Object::WorldType:
break;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/libtiled/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TILEDSHARED_EXPORT Object
WangSetType = 0x040,
WangColorType = 0x080,
ProjectType = 0x100,
WorldType = 0x200,
};

explicit Object(TypeId typeId, const QString &className = QString())
Expand Down
1 change: 1 addition & 0 deletions src/tiled/editableobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ static Map *mapForObject(Object *object)
case Object::WangSetType:
case Object::WangColorType:
case Object::ProjectType:
case Object::WorldType:
break;
}
return nullptr;
Expand Down
7 changes: 4 additions & 3 deletions src/tiled/editableworld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
namespace Tiled {

ScriptWorld::ScriptWorld(World *world)
: Object(*this)
: Object(WorldType)
, world(world)
{
}

EditableWorld::EditableWorld(WorldDocument *worldDocument, QObject *parent)
: EditableAsset(worldDocument, &mWorldObject, parent),
mWorldObject(ScriptWorld(WorldManager::instance().worlds().value(worldDocument->fileName())))
: EditableAsset(worldDocument, nullptr, parent)
, mWorldObject(WorldManager::instance().worlds().value(worldDocument->fileName()))
{
setObject(&mWorldObject);
}


Expand Down
1 change: 1 addition & 0 deletions src/tiled/exporthelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ void ExportHelper::resolveProperties(Object *object) const
break;
case Object::WangColorType:
case Object::ProjectType:
case Object::WorldType:
break;
}

Expand Down
14 changes: 7 additions & 7 deletions src/tiled/propertybrowser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,7 @@ static void addAutomappingProperties(Properties &properties, const Object *objec
addRuleOptions();
break;
}
case Object::TilesetType:
case Object::TileType:
case Object::WangSetType:
case Object::WangColorType:
case Object::ProjectType:
default:
break;
}
}
Expand Down Expand Up @@ -696,7 +692,8 @@ void PropertyBrowser::valueChanged(QtProperty *property, const QVariant &val)
case Object::TileType: applyTileValue(id, val); break;
case Object::WangSetType: applyWangSetValue(id, val); break;
case Object::WangColorType: applyWangColorValue(id, val); break;
case Object::ProjectType: break;
case Object::ProjectType: break;
case Object::WorldType: break;
}
}

Expand Down Expand Up @@ -1804,7 +1801,8 @@ void PropertyBrowser::addProperties()
case Object::TileType: addTileProperties(); break;
case Object::WangSetType: addWangSetProperties(); break;
case Object::WangColorType: addWangColorProperties(); break;
case Object::ProjectType: break;
case Object::ProjectType: break;
case Object::WorldType: break;
}

// Make sure certain properties are collapsed, to save space
Expand Down Expand Up @@ -2023,6 +2021,8 @@ void PropertyBrowser::updateProperties()
}
case Object::ProjectType:
break;
case Object::WorldType:
break;
}
}

Expand Down
16 changes: 9 additions & 7 deletions src/tiled/scriptmodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,16 @@ void ScriptModule::currentDocumentChanged(Document *document)
QList<Tiled::EditableAsset*> ScriptModule::worlds() const
{
QList<Tiled::EditableAsset*> worlds;
for (const World *world : WorldManager::instance().worlds())
{
const QString worldFile = world->fileName;
WorldDocument *worldDocument = new WorldDocument(worldFile);
// TODO crashing, store references to the world document somewhere to prevent it from freeing?
EditableAsset *editableWorld = worldDocument->createEditable().get();
worlds.append(editableWorld);

auto documentManager = DocumentManager::maybeInstance();
if (!documentManager)
return worlds;

for (const World *world : WorldManager::instance().worlds()) {
WorldDocument *worldDocument = documentManager->ensureWorldDocument(world->fileName);
worlds.append(worldDocument->editable());
}

return worlds;
}

Expand Down

0 comments on commit 41f89d5

Please sign in to comment.