Skip to content

Commit

Permalink
Multiple ents keyvalue editor. Part1
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealKaraulov committed Dec 10, 2023
1 parent 3feab98 commit 5fb32a0
Show file tree
Hide file tree
Showing 6 changed files with 233 additions and 146 deletions.
47 changes: 46 additions & 1 deletion src/bsp/Entity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ void Entity::addKeyvalue(const std::string key, const std::string value, bool mu

void Entity::setOrAddKeyvalue(const std::string key, const std::string value)
{
if (!key.size())
return;
if (key == "origin")
originInited = false;
cachedModelIdx = -2;
targetsCached = false;

Expand All @@ -70,8 +74,12 @@ void Entity::setOrAddKeyvalue(const std::string key, const std::string value)

void Entity::removeKeyvalue(const std::string key)
{
if (!strlen(key))
if (!key.size())
return;

if (key == "origin")
originInited = false;

if (std::find(keyOrder.begin(), keyOrder.end(), key) != keyOrder.end())
keyOrder.erase(std::find(keyOrder.begin(), keyOrder.end(), key));

Expand All @@ -93,6 +101,9 @@ bool Entity::renameKey(int idx, const std::string& newName)
}
if (keyOrder[idx].starts_with("render"))
updateRenderModes();
if (keyOrder[idx] == "origin" || newName == "origin")
originInited = false;

for (int i = 0; i < keyOrder.size(); i++)
{
if (keyOrder[i] == newName)
Expand All @@ -101,6 +112,40 @@ bool Entity::renameKey(int idx, const std::string& newName)
}
}


keyvalues[newName] = keyvalues[keyOrder[idx]];
keyvalues.erase(keyOrder[idx]);
keyOrder[idx] = newName;
cachedModelIdx = -2;
targetsCached = false;
return true;
}

bool Entity::renameKey(const std::string& oldName, const std::string& newName)
{
if (oldName.empty() || newName.empty())
{
return false;
}
if (oldName == "origin" || newName == "origin")
originInited = false;

if (oldName.starts_with("render") || newName.starts_with("render"))
updateRenderModes();
int idx = -1;
for (int i = 0; i < keyOrder.size(); i++)
{
if (keyOrder[i] == newName)
{
return false;
}
else if (keyOrder[i] == oldName)
{
idx = i;
}
}
if (idx == -1)
return false;
keyvalues[newName] = keyvalues[keyOrder[idx]];
keyvalues.erase(keyOrder[idx]);
keyOrder[idx] = newName;
Expand Down
1 change: 1 addition & 0 deletions src/bsp/Entity.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Entity
void addKeyvalue(const std::string key, const std::string value, bool multisupport = false);
void removeKeyvalue(const std::string key);
bool renameKey(int idx, const std::string& newName);
bool renameKey(const std::string& oldName, const std::string& newName);
void clearAllKeyvalues();
void clearEmptyKeyvalues();

Expand Down
Loading

0 comments on commit 5fb32a0

Please sign in to comment.