MCPcopy Create free account
hub / github.com/Monogatari/Monogatari / apply

Method apply

src/actions/HideCharacter.ts:56–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55
56 override async apply(): Promise<void> {
57 const currentPosition = this.element.data('position');
58 const position = (this._statement as string).match(/at\s(\S*)/);
59
60 const oldClasses = [...this.element.get(0).classList];
61
62 for (const oldClass of oldClasses) {
63 if (oldClass !== currentPosition || position instanceof Array) {
64 this.element.removeClass(oldClass);
65 }
66 }
67
68 if (position instanceof Array) {
69 // If it was, we'll set that position to the character
70 const [at, positionClass] = position;
71 this.element.data('position', positionClass);
72 }
73
74 this.element.addClass('animated');
75
76 // Check if there is any end-animation, here's what this matches:
77 // 'end-fadeIn'.match (/end-([A-Za-z]+)/) => [ "end-fadeIn", "fadeIn" ]
78 const endAnimation = oldClasses.find((c: string) => c.match(/end-([A-Za-z]+)/) !== null);
79
80 if (typeof endAnimation !== 'undefined') {
81 const [end, animation] = endAnimation.split('-');
82 this.element.addClass(animation);
83 }
84
85 const durationPosition = this.classes.indexOf('duration');
86
87 if (durationPosition > -1) {
88 this.element.style('animation-duration', this.classes[durationPosition + 1]);
89 } else {
90 this.element.style('animation-duration', '');
91 }
92
93 if (this.classes.length > 0 || typeof endAnimation !== 'undefined') {
94 for (const className of this.classes) {
95 if (className) {
96 this.element.addClass(className);
97 }
98 }
99 this.element.data('visibility', 'invisible');
100
101 this.element.on('animationend', (e: any) => {
102 if (e.target.dataset.visibility === 'invisible') {
103 // Remove only if the animation ends while the element is not visible
104 e.target.remove();
105 }
106 });
107 } else {
108 this.element.remove();
109 }
110 }
111
112 override async didApply(): Promise<ActionApplyResult> {
113 const characters = this.engine.state('characters').filter((item: string) => {

Callers 1

revertMethod · 0.45

Calls 4

matchMethod · 0.80
getMethod · 0.65
onMethod · 0.65
removeMethod · 0.65

Tested by

no test coverage detected