1
0
mirror of synced 2024-11-25 00:00:27 +01:00

pattern: add single_color attribute, fixed static array color override (#443)

This commit is contained in:
Lukas Cone 2022-02-18 13:31:44 +01:00 committed by GitHub
parent 4c8efed256
commit 6c8b75a05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -732,6 +732,8 @@ namespace hex::pl {
if (auto value = attributable->getAttributeValue("color"); value) { if (auto value = attributable->getAttributeValue("color"); value) {
u32 color = strtoul(value->c_str(), nullptr, 16); u32 color = strtoul(value->c_str(), nullptr, 16);
pattern->setColor(hex::changeEndianess(color, std::endian::big) >> 8); pattern->setColor(hex::changeEndianess(color, std::endian::big) >> 8);
} else if (auto value = attributable->hasAttribute("single_color", false); value) {
pattern->setColor(ContentRegistry::PatternLanguage::getNextColor());
} }
if (auto value = attributable->getAttributeValue("name"); value) { if (auto value = attributable->getAttributeValue("name"); value) {
@ -819,7 +821,7 @@ namespace hex::pl {
if (array == nullptr) if (array == nullptr)
LogConsole::abortEvaluation("inline_array attribute can only be applied to array types", node); LogConsole::abortEvaluation("inline_array attribute can only be applied to array types", node);
for (const auto& entry : array->getEntries()) { for (const auto &entry : array->getEntries()) {
entry->setFormatterFunction(function); entry->setFormatterFunction(function);
} }
} }
@ -1050,7 +1052,6 @@ namespace hex::pl {
outputPattern->setVariableName(this->m_name); outputPattern->setVariableName(this->m_name);
outputPattern->setEndian(templatePattern->getEndian()); outputPattern->setEndian(templatePattern->getEndian());
outputPattern->setColor(templatePattern->getColor());
outputPattern->setTypeName(templatePattern->getTypeName()); outputPattern->setTypeName(templatePattern->getTypeName());
outputPattern->setSize(templatePattern->getSize() * entryCount); outputPattern->setSize(templatePattern->getSize() * entryCount);
@ -1408,6 +1409,15 @@ namespace hex::pl {
structCleanup.release(); structCleanup.release();
if (!pattern->hasOverriddenColor()) {
if (auto value = getAttributeValue("color"); value) {
u32 color = strtoul(value->c_str(), nullptr, 16);
pattern->setColor(hex::changeEndianess(color, std::endian::big) >> 8);
} else if (auto value = hasAttribute("single_color", false); value) {
pattern->setColor(ContentRegistry::PatternLanguage::getNextColor());
}
}
return { pattern }; return { pattern };
} }

View File

@ -1019,6 +1019,7 @@ namespace hex::pl {
void setColor(u32 color) override { void setColor(u32 color) override {
PatternData::setColor(color); PatternData::setColor(color);
this->m_template->setColor(color); this->m_template->setColor(color);
this->m_highlightTemplate->setColor(color);
} }
[[nodiscard]] std::string getFormattedName() const override { [[nodiscard]] std::string getFormattedName() const override {