Skip to content

Commit

Permalink
#5281: Visibility and active status are persisted in .mapx files
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Oct 29, 2022
1 parent c702222 commit 205835f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions radiantcore/map/format/portable/Constants.h
Expand Up @@ -20,6 +20,8 @@ const char* const TAG_MAP_LAYER = "layer";
const char* const ATTR_MAP_LAYER_ID = "id";
const char* const ATTR_MAP_LAYER_NAME = "name";
const char* const ATTR_MAP_LAYER_PARENT_ID = "parentId";
const char* const ATTR_MAP_LAYER_ACTIVE = "active";
const char* const ATTR_MAP_LAYER_HIDDEN = "hidden";

const char* const TAG_SELECTIONGROUPS = "selectionGroups";
const char* const TAG_SELECTIONGROUP = "selectionGroup";
Expand Down
12 changes: 12 additions & 0 deletions radiantcore/map/format/portable/PortableMapReader.cpp
Expand Up @@ -89,6 +89,18 @@ void PortableMapReader::readLayers(const xml::Node& mapNode)
auto name = layer.getAttributeValue(ATTR_MAP_LAYER_NAME);

layerManager.createLayer(name, id);

// Check active layer properties
if (layer.getAttributeValue(ATTR_MAP_LAYER_ACTIVE) == ATTR_VALUE_TRUE)
{
layerManager.setActiveLayer(id);
}

// Set visibility (and make sure this happens before the hierarchy is restored)
if (layer.getAttributeValue(ATTR_MAP_LAYER_HIDDEN) == ATTR_VALUE_TRUE)
{
layerManager.setLayerVisibility(id, false);
}
}

// Restore the layer hierarchy after all layers have been created
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/map/format/portable/PortableMapWriter.cpp
Expand Up @@ -68,13 +68,18 @@ void PortableMapWriter::beginWriteMap(const scene::IMapRootNodePtr& root, std::o

// Visit all layers and add a tag for each
auto& layerManager = root->getLayerManager();
auto activeLayerId = layerManager.getActiveLayer();
layerManager.foreachLayer([&](int layerId, const std::string& layerName)
{
auto layer = layers.createChild(TAG_MAP_LAYER);

layer.setAttributeValue(ATTR_MAP_LAYER_ID, string::to_string(layerId));
layer.setAttributeValue(ATTR_MAP_LAYER_NAME, layerName);
layer.setAttributeValue(ATTR_MAP_LAYER_PARENT_ID, string::to_string(layerManager.getParentLayer(layerId)));
layer.setAttributeValue(ATTR_MAP_LAYER_ACTIVE,
activeLayerId == layerId ? ATTR_VALUE_TRUE : ATTR_VALUE_FALSE);
layer.setAttributeValue(ATTR_MAP_LAYER_HIDDEN,
layerManager.layerIsVisible(layerId) ? ATTR_VALUE_FALSE : ATTR_VALUE_TRUE);
});

// Write selection groups
Expand Down

0 comments on commit 205835f

Please sign in to comment.