2020-07-12 23:19:05 +02:00
|
|
|
import {TagDependantUIElement, TagDependantUIElementConstructor} from "./UIElementConstructor";
|
2020-08-30 01:13:18 +02:00
|
|
|
import {TagsFilter, TagUtils} from "../Logic/Tags";
|
2020-07-12 23:19:05 +02:00
|
|
|
import {UIElement} from "../UI/UIElement";
|
2020-08-17 17:23:15 +02:00
|
|
|
import {UIEventSource} from "../Logic/UIEventSource";
|
2020-08-30 01:13:18 +02:00
|
|
|
import Translation from "../UI/i18n/Translation";
|
2020-07-12 23:19:05 +02:00
|
|
|
|
2020-08-30 01:13:18 +02:00
|
|
|
/**
|
|
|
|
* Wrapper around another TagDependandElement, which only shows if the filters match
|
|
|
|
*/
|
2020-07-12 23:19:05 +02:00
|
|
|
export class OnlyShowIfConstructor implements TagDependantUIElementConstructor{
|
2020-08-30 01:13:18 +02:00
|
|
|
private readonly _tagsFilter: TagsFilter;
|
|
|
|
private readonly _embedded: TagDependantUIElementConstructor;
|
|
|
|
private readonly _invert: boolean;
|
|
|
|
|
|
|
|
constructor(tagsFilter: TagsFilter, embedded: TagDependantUIElementConstructor, invert: boolean = false) {
|
2020-07-12 23:19:05 +02:00
|
|
|
this._tagsFilter = tagsFilter;
|
|
|
|
this._embedded = embedded;
|
2020-08-30 01:13:18 +02:00
|
|
|
this._invert = invert;
|
2020-07-12 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-17 14:24:31 +02:00
|
|
|
construct(dependencies): TagDependantUIElement {
|
|
|
|
return new OnlyShowIf(dependencies.tags,
|
|
|
|
this._embedded.construct(dependencies),
|
2020-08-30 01:13:18 +02:00
|
|
|
this._tagsFilter,
|
|
|
|
this._invert);
|
2020-07-12 23:19:05 +02:00
|
|
|
}
|
2020-07-13 12:10:43 +02:00
|
|
|
|
|
|
|
IsKnown(properties: any): boolean {
|
|
|
|
if(!this.Matches(properties)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this._embedded.IsKnown(properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
IsQuestioning(properties: any): boolean {
|
|
|
|
if(!this.Matches(properties)){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this._embedded.IsQuestioning(properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
Priority(): number {
|
|
|
|
return this._embedded.Priority();
|
|
|
|
}
|
2020-08-22 02:12:46 +02:00
|
|
|
|
2020-08-30 01:13:18 +02:00
|
|
|
GetContent(tags: any): Translation {
|
|
|
|
if(this.IsKnown(tags)){
|
2020-08-22 02:12:46 +02:00
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
return this._embedded.GetContent(tags);
|
|
|
|
}
|
|
|
|
|
2020-07-13 12:10:43 +02:00
|
|
|
private Matches(properties: any) : boolean{
|
2020-08-30 01:13:18 +02:00
|
|
|
return this._tagsFilter.matches(TagUtils.proprtiesToKV(properties)) != this._invert;
|
2020-07-13 12:10:43 +02:00
|
|
|
}
|
2020-07-12 23:19:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
class OnlyShowIf extends UIElement implements TagDependantUIElement {
|
2020-08-30 01:13:18 +02:00
|
|
|
private readonly _embedded: TagDependantUIElement;
|
|
|
|
private readonly _filter: TagsFilter;
|
|
|
|
private readonly _invert: boolean;
|
2020-07-12 23:19:05 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
tags: UIEventSource<any>,
|
2020-08-30 01:13:18 +02:00
|
|
|
embedded: TagDependantUIElement,
|
|
|
|
filter: TagsFilter,
|
|
|
|
invert: boolean) {
|
2020-07-12 23:19:05 +02:00
|
|
|
super(tags);
|
|
|
|
this._filter = filter;
|
|
|
|
this._embedded = embedded;
|
2020-08-30 01:13:18 +02:00
|
|
|
this._invert = invert;
|
2020-07-12 23:19:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private Matches() : boolean{
|
2020-08-30 01:13:18 +02:00
|
|
|
return this._filter.matches(TagUtils.proprtiesToKV(this._source.data)) != this._invert;
|
2020-07-12 23:19:05 +02:00
|
|
|
}
|
|
|
|
|
2020-07-25 01:07:02 +02:00
|
|
|
InnerRender(): string {
|
2020-07-12 23:19:05 +02:00
|
|
|
if (this.Matches()) {
|
|
|
|
return this._embedded.Render();
|
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Priority(): number {
|
|
|
|
return this._embedded.Priority();
|
|
|
|
}
|
|
|
|
|
|
|
|
IsKnown(): boolean {
|
|
|
|
if(!this.Matches()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this._embedded.IsKnown();
|
|
|
|
}
|
2020-07-25 01:07:02 +02:00
|
|
|
|
|
|
|
IsSkipped(): boolean {
|
|
|
|
if(!this.Matches()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this._embedded.IsSkipped();
|
|
|
|
}
|
2020-07-12 23:19:05 +02:00
|
|
|
|
|
|
|
IsQuestioning(): boolean {
|
|
|
|
if(!this.Matches()){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return this._embedded.IsQuestioning();
|
|
|
|
}
|
|
|
|
|
|
|
|
Activate(): void {
|
|
|
|
this._embedded.Activate();
|
|
|
|
}
|
|
|
|
|
|
|
|
Update(): void {
|
|
|
|
this._embedded.Update();
|
|
|
|
}
|
|
|
|
}
|