Themes(preset_type_select): fix 'auto-icon' display

This commit is contained in:
Pieter Vander Vennet 2025-08-29 02:11:58 +02:00
parent 152d93bf4b
commit 81f98e62ce
3 changed files with 24 additions and 3 deletions

View file

@ -120,7 +120,7 @@ export default class SubstitutingTag extends TagsFilter {
} }
isNegative(): boolean { isNegative(): boolean {
return false return this._value === ""
} }
visit(f: (tagsFilter: TagsFilter) => void) { visit(f: (tagsFilter: TagsFilter) => void) {

View file

@ -994,11 +994,31 @@ export class TagUtils {
].join("\n") ].join("\n")
} }
static fromProperties(tags: Record<string, string>): TagConfigJson | boolean { public static fromProperties(tags: Record<string, string>): TagConfigJson | boolean {
const opt = new And(Object.keys(tags).map((k) => new Tag(k, tags[k]))).optimize() const opt = new And(Object.keys(tags).map((k) => new Tag(k, tags[k]))).optimize()
if (opt === true || opt === false) { if (opt === true || opt === false) {
return opt return opt
} }
return opt.asJson() return opt.asJson()
} }
/**
* Returns a similarly structured tag, but all tags with an empty value are removed.
* Those are assumed to be all met (and thus true)
*
* new And([new Tag("a", "b"), new Tag("c", "")] // => new Tag("a","b")
* new And([new Tag("c", "")] // => true
*/
public static removeEmptyParts(tag: UploadableTag): UploadableTag | true {
if (tag["and"]) {
const tags = <UploadableTag[]>tag["and"]
const cleaned = tags.map(t => TagUtils.removeEmptyParts(t))
const filtered = <UploadableTag[]>cleaned.filter(t => t !== true)
return new And(filtered)
}
if (tag.isNegative()) {
return true
}
return tag
}
} }

View file

@ -44,8 +44,9 @@
} }
function getAutoIcon(mapping: { readonly if?: TagsFilter }): Readonly<Record<string, string>> { function getAutoIcon(mapping: { readonly if?: TagsFilter }): Readonly<Record<string, string>> {
const ifTags = TagUtils.removeEmptyParts(mapping.if)
for (const preset of layer.presets) { for (const preset of layer.presets) {
if (!new And(preset.tags).shadows(mapping.if)) { if (!new And(preset.tags).shadows(ifTags)) {
continue continue
} }