mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-17 10:20:12 +02:00
resolve conflicts on merge with upstream master
This commit is contained in:
commit
3c236cc60a
16 changed files with 138 additions and 111 deletions
|
@ -116,7 +116,7 @@
|
|||
"advanced": true
|
||||
},
|
||||
{
|
||||
"name": "I-print-stream-stats",
|
||||
"name": "print-stream-stats",
|
||||
"type": "checkbox",
|
||||
"label": "Print Stream Stats:",
|
||||
"help": "audio upstream and downstream stats of each agent printed to audio-mixer stdout",
|
||||
|
|
|
@ -52,6 +52,10 @@ span.port {
|
|||
color: red;
|
||||
}
|
||||
|
||||
.locked {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
.advanced-setting {
|
||||
display: none;
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ var Settings = {
|
|||
};
|
||||
|
||||
var viewHelpers = {
|
||||
getFormGroup: function(groupName, setting, values, isAdvanced) {
|
||||
getFormGroup: function(groupName, setting, values, isAdvanced, isLocked) {
|
||||
setting_id = groupName + "_" + setting.name
|
||||
|
||||
console.log(setting.name + " in " + groupName + " is " + isLocked)
|
||||
|
||||
form_group = "<div class='form-group" + (isAdvanced ? " advanced-setting" : "") + "'>"
|
||||
|
||||
if (_.has(values, groupName) && _.has(values[groupName], setting.name)) {
|
||||
|
@ -16,20 +18,26 @@ var viewHelpers = {
|
|||
setting_value = ""
|
||||
}
|
||||
|
||||
label_class = 'control-label'
|
||||
if (isLocked) {
|
||||
label_class += ' locked'
|
||||
}
|
||||
|
||||
if (setting.type === 'checkbox') {
|
||||
form_group += "<label class='control-label'>" + setting.label + "</label>"
|
||||
form_group += "<div class='checkbox'>"
|
||||
form_group += "<label class='" + label_class + "'>" + setting.label + "</label>"
|
||||
form_group += "<div class='checkbox" + (isLocked ? " disabled" : "") + "'>"
|
||||
form_group += "<label for='" + setting_id + "'>"
|
||||
form_group += "<input type='checkbox' id='" + setting_id + "' " + (setting_value ? "checked" : "") + "/>"
|
||||
form_group += "<input type='checkbox' id='" + setting_id + "' " +
|
||||
(setting_value ? "checked" : "") + (isLocked ? " disabled" : "") + "/>"
|
||||
form_group += " " + setting.help + "</label>";
|
||||
form_group += "</div>"
|
||||
} else {
|
||||
input_type = _.has(setting, 'type') ? setting.type : "text"
|
||||
|
||||
form_group += "<label for='" + setting_id + "' class='control-label'>" + setting.label + "</label>";
|
||||
form_group += "<label for='" + setting_id + "' class='" + label_class + "'>" + setting.label + "</label>";
|
||||
form_group += "<input type='" + input_type + "' class='form-control' id='" + setting_id +
|
||||
"' placeholder='" + (_.has(setting, 'placeholder') ? setting.placeholder : "") +
|
||||
"' value='" + setting_value + "'/>"
|
||||
"' value='" + setting_value + "'" + (isLocked ? " disabled" : "") + "/>"
|
||||
form_group += "<span class='help-block'>" + setting.help + "</span>"
|
||||
}
|
||||
|
||||
|
@ -101,6 +109,12 @@ function reloadSettings() {
|
|||
$('#panels').html(Settings.panelsTemplate(data))
|
||||
|
||||
Settings.initialValues = form2js('settings-form', "_", false, cleanupFormValues, true);
|
||||
|
||||
// add tooltip to locked settings
|
||||
$('label.locked').tooltip({
|
||||
placement: 'right',
|
||||
title: 'This setting is in the master config file and cannot be changed'
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,12 @@
|
|||
<div class="panel-body">
|
||||
<% split_settings = _.partition(group.settings, function(value, index) { return !value.advanced }) %>
|
||||
<% _.each(split_settings[0], function(setting) { %>
|
||||
<%= getFormGroup(group.name, setting, values, false) %>
|
||||
<%= getFormGroup(group.name, setting, values, false,
|
||||
(_.has(locked, group.name) && _.has(locked[group.name], setting.name))) %>
|
||||
<% }); %>
|
||||
<% _.each(split_settings[1], function(setting) { %>
|
||||
<%= getFormGroup(group.name, setting, values, true) %>
|
||||
<%= getFormGroup(group.name, setting, values, true,
|
||||
(_.has(locked, group.name) && _.has(locked[group.name], setting.name))) %>
|
||||
<% }); %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -57,7 +57,7 @@ DomainServer::DomainServer(int argc, char* argv[]) :
|
|||
setApplicationName("domain-server");
|
||||
QSettings::setDefaultFormat(QSettings::IniFormat);
|
||||
|
||||
_settingsManager.loadSettingsMap(arguments());
|
||||
_settingsManager.setupConfigMap(arguments());
|
||||
|
||||
installNativeEventFilter(&_shutdownEventListener);
|
||||
connect(&_shutdownEventListener, SIGNAL(receivedCloseEvent()), SLOT(quit()));
|
||||
|
|
|
@ -28,7 +28,7 @@ const QString SETTINGS_DESCRIPTION_RELATIVE_PATH = "/resources/describe-settings
|
|||
|
||||
DomainServerSettingsManager::DomainServerSettingsManager() :
|
||||
_descriptionArray(),
|
||||
_settingsMap()
|
||||
_configMap()
|
||||
{
|
||||
// load the description object from the settings description
|
||||
QFile descriptionFile(QCoreApplication::applicationDirPath() + SETTINGS_DESCRIPTION_RELATIVE_PATH);
|
||||
|
@ -37,11 +37,8 @@ DomainServerSettingsManager::DomainServerSettingsManager() :
|
|||
_descriptionArray = QJsonDocument::fromJson(descriptionFile.readAll()).array();
|
||||
}
|
||||
|
||||
void DomainServerSettingsManager::loadSettingsMap(const QStringList& argumentList) {
|
||||
_settingsMap = HifiConfigVariantMap::mergeMasterConfigWithUserConfig(argumentList);
|
||||
|
||||
// figure out where we are supposed to persist our settings to
|
||||
_settingsFilepath = HifiConfigVariantMap::userConfigFilepath(argumentList);
|
||||
void DomainServerSettingsManager::setupConfigMap(const QStringList& argumentList) {
|
||||
_configMap.loadMasterAndUserConfig(argumentList);
|
||||
}
|
||||
|
||||
const QString SETTINGS_PATH = "/settings.json";
|
||||
|
@ -76,7 +73,7 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
|
|||
QJsonObject postedObject = postedDocument.object();
|
||||
|
||||
// we recurse one level deep below each group for the appropriate setting
|
||||
recurseJSONObjectAndOverwriteSettings(postedObject, _settingsMap, _descriptionArray);
|
||||
recurseJSONObjectAndOverwriteSettings(postedObject, _configMap.getUserConfig(), _descriptionArray);
|
||||
|
||||
// store whatever the current _settingsMap is to file
|
||||
persistToFile();
|
||||
|
@ -94,10 +91,13 @@ bool DomainServerSettingsManager::handleAuthenticatedHTTPRequest(HTTPConnection
|
|||
// setup a JSON Object with descriptions and non-omitted settings
|
||||
const QString SETTINGS_RESPONSE_DESCRIPTION_KEY = "descriptions";
|
||||
const QString SETTINGS_RESPONSE_VALUE_KEY = "values";
|
||||
const QString SETTINGS_RESPONSE_LOCKED_VALUES_KEY = "locked";
|
||||
|
||||
QJsonObject rootObject;
|
||||
rootObject[SETTINGS_RESPONSE_DESCRIPTION_KEY] = _descriptionArray;
|
||||
rootObject[SETTINGS_RESPONSE_VALUE_KEY] = responseObjectForType("", true);
|
||||
rootObject[SETTINGS_RESPONSE_LOCKED_VALUES_KEY] = QJsonDocument::fromVariant(_configMap.getMasterConfig()).object();
|
||||
|
||||
|
||||
connection->respond(HTTPConnection::StatusCode200, QJsonDocument(rootObject).toJson(), "application/json");
|
||||
}
|
||||
|
@ -145,7 +145,8 @@ QJsonObject DomainServerSettingsManager::responseObjectForType(const QString& ty
|
|||
|
||||
// we need to check if the settings map has a value for this setting
|
||||
QVariant variantValue;
|
||||
QVariant settingsMapGroupValue = _settingsMap.value(groupObject[DESCRIPTION_NAME_KEY].toString());
|
||||
QVariant settingsMapGroupValue = _configMap.getMergedConfig()
|
||||
.value(groupObject[DESCRIPTION_NAME_KEY].toString());
|
||||
|
||||
if (!settingsMapGroupValue.isNull()) {
|
||||
variantValue = settingsMapGroupValue.toMap().value(settingName);
|
||||
|
@ -239,23 +240,19 @@ void DomainServerSettingsManager::recurseJSONObjectAndOverwriteSettings(const QJ
|
|||
}
|
||||
}
|
||||
|
||||
QByteArray DomainServerSettingsManager::getJSONSettingsMap() const {
|
||||
return QJsonDocument::fromVariant(_settingsMap).toJson();
|
||||
}
|
||||
|
||||
void DomainServerSettingsManager::persistToFile() {
|
||||
|
||||
// make sure we have the dir the settings file is supposed to live in
|
||||
QFileInfo settingsFileInfo(_settingsFilepath);
|
||||
QFileInfo settingsFileInfo(_configMap.getUserConfigFilename());
|
||||
|
||||
if (!settingsFileInfo.dir().exists()) {
|
||||
settingsFileInfo.dir().mkpath(".");
|
||||
}
|
||||
|
||||
QFile settingsFile(_settingsFilepath);
|
||||
QFile settingsFile(_configMap.getUserConfigFilename());
|
||||
|
||||
if (settingsFile.open(QIODevice::WriteOnly)) {
|
||||
settingsFile.write(getJSONSettingsMap());
|
||||
settingsFile.write(QJsonDocument::fromVariant(_configMap.getUserConfig()).toJson());
|
||||
} else {
|
||||
qCritical("Could not write to JSON settings file. Unable to persist settings.");
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <QtCore/QJsonArray>
|
||||
#include <QtCore/QJsonDocument>
|
||||
|
||||
#include <HifiConfigVariantMap.h>
|
||||
#include <HTTPManager.h>
|
||||
|
||||
class DomainServerSettingsManager : public QObject {
|
||||
|
@ -24,10 +25,9 @@ public:
|
|||
bool handlePublicHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
||||
bool handleAuthenticatedHTTPRequest(HTTPConnection* connection, const QUrl& url);
|
||||
|
||||
void loadSettingsMap(const QStringList& argumentList);
|
||||
void setupConfigMap(const QStringList& argumentList);
|
||||
|
||||
QByteArray getJSONSettingsMap() const;
|
||||
QVariantMap& getSettingsMap() { return _settingsMap; }
|
||||
QVariantMap& getSettingsMap() { return _configMap.getMergedConfig(); }
|
||||
private:
|
||||
QJsonObject responseObjectForType(const QString& typeValue, bool isAuthenticated = false);
|
||||
void recurseJSONObjectAndOverwriteSettings(const QJsonObject& postedObject, QVariantMap& settingsVariant,
|
||||
|
@ -35,8 +35,7 @@ private:
|
|||
void persistToFile();
|
||||
|
||||
QJsonArray _descriptionArray;
|
||||
QVariantMap _settingsMap;
|
||||
QString _settingsFilepath;
|
||||
HifiConfigVariantMap _configMap;
|
||||
};
|
||||
|
||||
#endif // hifi_DomainServerSettingsManager_h
|
|
@ -302,9 +302,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
|||
// connect to the domainChangeRequired signal on AddressManager
|
||||
connect(&addressManager, &AddressManager::possibleDomainChangeRequired,
|
||||
this, &Application::changeDomainHostname);
|
||||
|
||||
// when -url in command line, teleport to location
|
||||
addressManager.handleLookupString(getCmdOption(argc, constArgv, "-url"));
|
||||
|
||||
_settings = new QSettings(this);
|
||||
_numChangedSettings = 0;
|
||||
|
@ -1790,7 +1787,14 @@ void Application::init() {
|
|||
Menu::getInstance()->loadSettings();
|
||||
_audio.setReceivedAudioStreamSettings(Menu::getInstance()->getReceivedAudioStreamSettings());
|
||||
|
||||
qDebug("Loaded settings");
|
||||
qDebug() << "Loaded settings";
|
||||
|
||||
// when --url in command line, teleport to location
|
||||
const QString HIFI_URL_COMMAND_LINE_KEY = "--url";
|
||||
int urlIndex = arguments().indexOf(HIFI_URL_COMMAND_LINE_KEY);
|
||||
if (urlIndex != -1) {
|
||||
AddressManager::getInstance().handleLookupString(arguments().value(urlIndex + 1));
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::SixenseEnabled)) {
|
||||
|
|
|
@ -1204,7 +1204,8 @@ int PointAugmentVisitor::visit(MetavoxelInfo& info) {
|
|||
_points.swap(swapPoints);
|
||||
buffer = new PointBuffer(swapPoints);
|
||||
}
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(buffer)));
|
||||
BufferDataPointer pointer(buffer);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
|
||||
}
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
|
@ -1219,7 +1220,8 @@ bool PointAugmentVisitor::postVisit(MetavoxelInfo& info) {
|
|||
_points.swap(swapPoints);
|
||||
buffer = new PointBuffer(swapPoints);
|
||||
}
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(buffer)));
|
||||
BufferDataPointer pointer(buffer);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1446,7 +1448,8 @@ int HeightfieldRegionVisitor::visit(MetavoxelInfo& info) {
|
|||
_data->guide(_fetchVisitor);
|
||||
}
|
||||
}
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(buffer)));
|
||||
BufferDataPointer pointer(buffer);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
|
||||
|
@ -1505,7 +1508,8 @@ int HeightfieldUpdateVisitor::visit(MetavoxelInfo& info) {
|
|||
buffer->getHeight(), buffer->getColor(), buffer->getMaterial(), buffer->getMaterials());
|
||||
_fetchVisitor.init(newBuffer);
|
||||
_data->guide(_fetchVisitor);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(newBuffer)));
|
||||
BufferDataPointer pointer(newBuffer);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
|
||||
|
@ -2078,7 +2082,8 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
|
|||
|
||||
buffer = new VoxelBuffer(vertices, indices, material->getMaterials());
|
||||
}
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(BufferDataPointer(buffer)));
|
||||
BufferDataPointer pointer(buffer);
|
||||
info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));
|
||||
return STOP_RECURSION;
|
||||
}
|
||||
|
||||
|
|
|
@ -520,20 +520,18 @@ void Avatar::renderBody(RenderMode renderMode, bool postLighting, float glowLeve
|
|||
renderAttachments(renderMode);
|
||||
}
|
||||
}
|
||||
if (!postLighting) {
|
||||
getHead()->render(1.0f, modelRenderMode);
|
||||
getHead()->render(1.0f, modelRenderMode, postLighting);
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
// Render Hair
|
||||
glPushMatrix();
|
||||
glm::vec3 headPosition = getHead()->getPosition();
|
||||
glTranslatef(headPosition.x, headPosition.y, headPosition.z);
|
||||
const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
_hair.render();
|
||||
glPopMatrix();
|
||||
}
|
||||
if (!postLighting && Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
// Render Hair
|
||||
glPushMatrix();
|
||||
glm::vec3 headPosition = getHead()->getPosition();
|
||||
glTranslatef(headPosition.x, headPosition.y, headPosition.z);
|
||||
const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
_hair.render();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -211,17 +211,16 @@ void Head::relaxLean(float deltaTime) {
|
|||
_deltaLeanForward *= relaxationFactor;
|
||||
}
|
||||
|
||||
void Head::render(float alpha, Model::RenderMode mode) {
|
||||
_faceModel.render(alpha, mode);
|
||||
if (_renderLookatVectors && mode != Model::SHADOW_RENDER_MODE) {
|
||||
Application::getInstance()->getDeferredLightingEffect()->addPostLightingRenderable(this);
|
||||
void Head::render(float alpha, Model::RenderMode mode, bool postLighting) {
|
||||
if (postLighting) {
|
||||
if (_renderLookatVectors) {
|
||||
renderLookatVectors(_leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition());
|
||||
}
|
||||
} else {
|
||||
_faceModel.render(alpha, mode);
|
||||
}
|
||||
}
|
||||
|
||||
void Head::renderPostLighting() {
|
||||
renderLookatVectors(_leftEyePosition, _rightEyePosition, getCorrectedLookAtPosition());
|
||||
}
|
||||
|
||||
void Head::setScale (float scale) {
|
||||
if (_scale == scale) {
|
||||
return;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "FaceModel.h"
|
||||
#include "InterfaceConfig.h"
|
||||
#include "world.h"
|
||||
#include "renderer/DeferredLightingEffect.h"
|
||||
|
||||
enum eyeContactTargets {
|
||||
LEFT_EYE,
|
||||
|
@ -36,15 +35,14 @@ const float EYE_EAR_GAP = 0.08f;
|
|||
class Avatar;
|
||||
class ProgramObject;
|
||||
|
||||
class Head : public HeadData, public PostLightingRenderable {
|
||||
class Head : public HeadData {
|
||||
public:
|
||||
Head(Avatar* owningAvatar);
|
||||
|
||||
void init();
|
||||
void reset();
|
||||
void simulate(float deltaTime, bool isMine, bool billboard = false);
|
||||
void render(float alpha, Model::RenderMode mode);
|
||||
virtual void renderPostLighting();
|
||||
void render(float alpha, Model::RenderMode mode, bool postLighting);
|
||||
void setScale(float scale);
|
||||
void setPosition(glm::vec3 position) { _position = position; }
|
||||
void setAverageLoudness(float averageLoudness) { _averageLoudness = averageLoudness; }
|
||||
|
|
|
@ -1147,20 +1147,18 @@ void MyAvatar::renderBody(RenderMode renderMode, bool postLighting, float glowLe
|
|||
const Camera *camera = Application::getInstance()->getCamera();
|
||||
const glm::vec3 cameraPos = camera->getPosition() + (camera->getRotation() * glm::vec3(0.0f, 0.0f, 1.0f)) * camera->getDistance();
|
||||
if (shouldRenderHead(cameraPos, renderMode)) {
|
||||
if (!postLighting) {
|
||||
getHead()->render(1.0f, modelRenderMode);
|
||||
getHead()->render(1.0f, modelRenderMode, postLighting);
|
||||
|
||||
if (Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
// Render Hair
|
||||
glPushMatrix();
|
||||
glm::vec3 headPosition = getHead()->getPosition();
|
||||
glTranslatef(headPosition.x, headPosition.y, headPosition.z);
|
||||
const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
_hair.render();
|
||||
glPopMatrix();
|
||||
}
|
||||
if (!postLighting && Menu::getInstance()->isOptionChecked(MenuOption::StringHair)) {
|
||||
// Render Hair
|
||||
glPushMatrix();
|
||||
glm::vec3 headPosition = getHead()->getPosition();
|
||||
glTranslatef(headPosition.x, headPosition.y, headPosition.z);
|
||||
const glm::quat& rotation = getHead()->getFinalOrientationInWorldFrame();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
_hair.render();
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
if (postLighting) {
|
||||
|
|
|
@ -1335,11 +1335,7 @@ void Model::renderMeshes(RenderMode mode, bool translucent, float alphaThreshold
|
|||
} else {
|
||||
glm::vec4 diffuse = glm::vec4(part.diffuseColor, part.opacity);
|
||||
if (!(translucent && alphaThreshold == 0.0f)) {
|
||||
float emissive = (part.emissiveColor.r + part.emissiveColor.g + part.emissiveColor.b) / 3.0f;
|
||||
diffuse.a = qMax(Application::getInstance()->getGlowEffect()->getIntensity(), emissive);
|
||||
glAlphaFunc(GL_EQUAL, diffuse.a);
|
||||
diffuse = glm::vec4(qMax(diffuse.r, part.emissiveColor.r), qMax(diffuse.g, part.emissiveColor.g),
|
||||
qMax(diffuse.b, part.emissiveColor.b), diffuse.a);
|
||||
glAlphaFunc(GL_EQUAL, diffuse.a = Application::getInstance()->getGlowEffect()->getIntensity());
|
||||
}
|
||||
glm::vec4 specular = glm::vec4(part.specularColor, 1.0f);
|
||||
glMaterialfv(GL_FRONT, GL_AMBIENT, (const float*)&diffuse);
|
||||
|
|
|
@ -87,43 +87,48 @@ QVariantMap HifiConfigVariantMap::mergeCLParametersWithJSONConfig(const QStringL
|
|||
return mergedMap;
|
||||
}
|
||||
|
||||
QVariantMap HifiConfigVariantMap::mergeMasterConfigWithUserConfig(const QStringList& argumentList) {
|
||||
HifiConfigVariantMap::HifiConfigVariantMap() :
|
||||
_userConfigFilename(),
|
||||
_masterConfig(),
|
||||
_userConfig(),
|
||||
_mergedConfig()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void HifiConfigVariantMap::loadMasterAndUserConfig(const QStringList& argumentList) {
|
||||
// check if there is a master config file
|
||||
const QString MASTER_CONFIG_FILE_OPTION = "--master-config";
|
||||
|
||||
QVariantMap configVariantMap;
|
||||
|
||||
int masterConfigIndex = argumentList.indexOf(MASTER_CONFIG_FILE_OPTION);
|
||||
if (masterConfigIndex != -1) {
|
||||
QString masterConfigFilepath = argumentList[masterConfigIndex + 1];
|
||||
|
||||
mergeMapWithJSONFile(configVariantMap, masterConfigFilepath);
|
||||
loadMapFromJSONFile(_masterConfig, masterConfigFilepath);
|
||||
}
|
||||
|
||||
// merge the existing configVariantMap with the user config file
|
||||
mergeMapWithJSONFile(configVariantMap, userConfigFilepath(argumentList));
|
||||
|
||||
return configVariantMap;
|
||||
}
|
||||
|
||||
QString HifiConfigVariantMap::userConfigFilepath(const QStringList& argumentList) {
|
||||
// we've loaded up the master config file, now fill in anything it didn't have with the user config file
|
||||
// load the user config
|
||||
const QString USER_CONFIG_FILE_OPTION = "--user-config";
|
||||
|
||||
int userConfigIndex = argumentList.indexOf(USER_CONFIG_FILE_OPTION);
|
||||
QString userConfigFilepath;
|
||||
if (userConfigIndex != -1) {
|
||||
userConfigFilepath = argumentList[userConfigIndex + 1];
|
||||
_userConfigFilename = argumentList[userConfigIndex + 1];
|
||||
} else {
|
||||
userConfigFilepath = QString("%1/%2/%3/config.json").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation),
|
||||
QCoreApplication::organizationName(),
|
||||
QCoreApplication::applicationName());
|
||||
_userConfigFilename = QString("%1/%2/%3/config.json").arg(QStandardPaths::writableLocation(QStandardPaths::ConfigLocation),
|
||||
QCoreApplication::organizationName(),
|
||||
QCoreApplication::applicationName());
|
||||
}
|
||||
|
||||
return userConfigFilepath;
|
||||
loadMapFromJSONFile(_userConfig, _userConfigFilename);
|
||||
|
||||
// the merged config is initially matched to the master config
|
||||
_mergedConfig = _masterConfig;
|
||||
|
||||
// then we merge in anything missing from the user config
|
||||
addMissingValuesToExistingMap(_mergedConfig, _userConfig);
|
||||
}
|
||||
|
||||
void HifiConfigVariantMap::mergeMapWithJSONFile(QVariantMap& existingMap, const QString& filename) {
|
||||
void HifiConfigVariantMap::loadMapFromJSONFile(QVariantMap& existingMap, const QString& filename) {
|
||||
QFile configFile(filename);
|
||||
|
||||
if (configFile.exists()) {
|
||||
|
@ -131,12 +136,7 @@ void HifiConfigVariantMap::mergeMapWithJSONFile(QVariantMap& existingMap, const
|
|||
configFile.open(QIODevice::ReadOnly);
|
||||
|
||||
QJsonDocument configDocument = QJsonDocument::fromJson(configFile.readAll());
|
||||
|
||||
if (existingMap.isEmpty()) {
|
||||
existingMap = configDocument.toVariant().toMap();
|
||||
} else {
|
||||
addMissingValuesToExistingMap(existingMap, configDocument.toVariant().toMap());
|
||||
}
|
||||
existingMap = configDocument.toVariant().toMap();
|
||||
|
||||
} else {
|
||||
qDebug() << "Could not find JSON config file at" << filename;
|
||||
|
|
|
@ -17,11 +17,24 @@
|
|||
class HifiConfigVariantMap {
|
||||
public:
|
||||
static QVariantMap mergeCLParametersWithJSONConfig(const QStringList& argumentList);
|
||||
static QVariantMap mergeMasterConfigWithUserConfig(const QStringList& argumentList);
|
||||
static QString userConfigFilepath(const QStringList& argumentList);
|
||||
|
||||
HifiConfigVariantMap();
|
||||
void loadMasterAndUserConfig(const QStringList& argumentList);
|
||||
|
||||
const QVariantMap& getMasterConfig() const { return _masterConfig; }
|
||||
QVariantMap& getUserConfig() { return _userConfig; }
|
||||
QVariantMap& getMergedConfig() { return _mergedConfig; }
|
||||
|
||||
const QString& getUserConfigFilename() const { return _userConfigFilename; }
|
||||
private:
|
||||
static void mergeMapWithJSONFile(QVariantMap& existingMap, const QString& filename);
|
||||
static void addMissingValuesToExistingMap(QVariantMap& existingMap, const QVariantMap& newMap);
|
||||
QString _userConfigFilename;
|
||||
|
||||
QVariantMap _masterConfig;
|
||||
QVariantMap _userConfig;
|
||||
QVariantMap _mergedConfig;
|
||||
|
||||
void loadMapFromJSONFile(QVariantMap& existingMap, const QString& filename);
|
||||
void addMissingValuesToExistingMap(QVariantMap& existingMap, const QVariantMap& newMap);
|
||||
};
|
||||
|
||||
const QVariant* valueForKeyPath(QVariantMap& variantMap, const QString& keyPath);
|
||||
|
|
Loading…
Reference in a new issue