Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend info file module interface and introduce MapPropertyInfoFileMo…
…dule exporting and importing the properties to the info file.
- Loading branch information
1 parent
3126a33
commit 3eae41f
Showing
19 changed files
with
274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
#include "MapPropertyInfoFileModule.h" | ||
|
||
#include "itextstream.h" | ||
#include "parser/DefTokeniser.h" | ||
#include "string/replace.h" | ||
|
||
namespace map | ||
{ | ||
|
||
namespace | ||
{ | ||
const char* const MAP_PROPERTIES = "MapProperties"; | ||
const char* const KEY_VALUE = "KeyValue"; | ||
} | ||
|
||
std::string MapPropertyInfoFileModule::getName() | ||
{ | ||
return "Map Properties"; | ||
} | ||
|
||
void MapPropertyInfoFileModule::onInfoFileSaveStart() | ||
{} | ||
|
||
void MapPropertyInfoFileModule::onBeginSaveMap(const scene::IMapRootNodePtr& root) | ||
{ | ||
// Load all the properties from the map root into a local store | ||
root->foreachProperty([this](const std::string& key, const std::string& value) | ||
{ | ||
_store.setProperty(key, value); | ||
}); | ||
} | ||
|
||
void MapPropertyInfoFileModule::onFinishSaveMap(const scene::IMapRootNodePtr& root) | ||
{} | ||
|
||
void MapPropertyInfoFileModule::onSavePrimitive(const scene::INodePtr& node, std::size_t entityNum, std::size_t primitiveNum) | ||
{} | ||
|
||
void MapPropertyInfoFileModule::onSaveEntity(const scene::INodePtr& node, std::size_t entityNum) | ||
{} | ||
|
||
void MapPropertyInfoFileModule::writeBlocks(std::ostream& stream) | ||
{ | ||
// Block output | ||
stream << "\t" << MAP_PROPERTIES << std::endl; | ||
|
||
stream << "\t{" << std::endl; | ||
|
||
_store.foreachProperty([&](const std::string& key, const std::string& value) | ||
{ | ||
stream << "\t\t" << KEY_VALUE << " { " << | ||
"\"" << string::replace_all_copy(key, "\"", """) << "\"" << | ||
" " << | ||
"\"" << string::replace_all_copy(value, "\"", """) << "\"" << | ||
" } " << std::endl; | ||
}); | ||
|
||
stream << "\t}" << std::endl; | ||
|
||
rMessage() << "Map Properties written." << std::endl; | ||
} | ||
|
||
void MapPropertyInfoFileModule::onInfoFileSaveFinished() | ||
{ | ||
_store.clearProperties(); | ||
} | ||
|
||
void MapPropertyInfoFileModule::onInfoFileLoadStart() | ||
{ | ||
_store.clearProperties(); | ||
} | ||
|
||
bool MapPropertyInfoFileModule::canParseBlock(const std::string& blockName) | ||
{ | ||
return blockName == MAP_PROPERTIES; | ||
} | ||
|
||
void MapPropertyInfoFileModule::parseBlock(const std::string& blockName, parser::DefTokeniser& tok) | ||
{ | ||
// The opening brace | ||
tok.assertNextToken("{"); | ||
|
||
int blockLevel = 1; | ||
|
||
while (tok.hasMoreTokens() && blockLevel > 0) | ||
{ | ||
std::string token = tok.nextToken(); | ||
|
||
if (token == KEY_VALUE) | ||
{ | ||
// KeyValue { "Key" "Value" } | ||
tok.assertNextToken("{"); | ||
|
||
std::string key = tok.nextToken(); | ||
std::string value = tok.nextToken(); | ||
|
||
string::replace_all(key, """, "\""); | ||
string::replace_all(value, """, "\""); | ||
|
||
tok.assertNextToken("}"); | ||
} | ||
else if (token == "{") | ||
{ | ||
blockLevel++; | ||
} | ||
else if (token == "}") | ||
{ | ||
blockLevel--; | ||
} | ||
} | ||
} | ||
|
||
void MapPropertyInfoFileModule::applyInfoToScene(const scene::IMapRootNodePtr& root, const NodeIndexMap& nodeMap) | ||
{ | ||
_store.foreachProperty([&](const std::string& key, const std::string& value) | ||
{ | ||
root->setProperty(key, value); | ||
}); | ||
} | ||
|
||
void MapPropertyInfoFileModule::onInfoFileLoadFinished() | ||
{ | ||
rMessage() << "[InfoFile]: Parsed " << _store.getPropertyCount() << " map properties." << std::endl; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#pragma once | ||
|
||
#include "imapinfofile.h" | ||
#include "KeyValueStore.h" | ||
|
||
namespace map | ||
{ | ||
|
||
/** | ||
* Info File Module to persist the map property bag to the | ||
* .darkradiant map info file. | ||
*/ | ||
class MapPropertyInfoFileModule : | ||
public IMapInfoFileModule | ||
{ | ||
private: | ||
KeyValueStore _store; | ||
|
||
public: | ||
std::string getName() override; | ||
|
||
void onInfoFileSaveStart() override; | ||
void onBeginSaveMap(const scene::IMapRootNodePtr& root) override; | ||
void onFinishSaveMap(const scene::IMapRootNodePtr& root) override; | ||
void onSavePrimitive(const scene::INodePtr& node, std::size_t entityNum, std::size_t primitiveNum) override; | ||
void onSaveEntity(const scene::INodePtr& node, std::size_t entityNum) override; | ||
void writeBlocks(std::ostream& stream) override; | ||
void onInfoFileSaveFinished() override; | ||
|
||
void onInfoFileLoadStart() override; | ||
bool canParseBlock(const std::string& blockName) override; | ||
void parseBlock(const std::string& blockName, parser::DefTokeniser& tok) override; | ||
void applyInfoToScene(const scene::IMapRootNodePtr& root, const NodeIndexMap& nodeMap) override; | ||
void onInfoFileLoadFinished() override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.