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

Method apply

src/actions/Choice.ts:146–230  ·  view source on GitHub ↗
({ updateLog = true } = {})

Source from the content-addressed store, hash-verified

144 }
145
146 override async apply({ updateLog = true } = {}): Promise<void> {
147 Choice.blocking = true;
148
149 // Save a reference to the choice object globally. Since the choice buttons
150 // are set a data-do property to know what the choice should do, it is
151 // limited to a string and thus object or function actions would not be
152 // able to be used in choices.
153 this.engine.global('_CurrentChoice').push(this._statement);
154
155 const promises: Promise<any>[] = [];
156
157 // Go over all the objects defined in the choice object which should be
158 // call the options to chose from or the string to show as dialog
159 for (const i in this.statement) {
160 const choice = this.statement[i];
161
162 // Check if the option is an object (a option to choose from) or
163 // if it's text (dialog to be shown)
164 if (typeof choice == 'object') {
165 if (i === 'Timer') {
166 continue;
167 }
168
169 this.statement[i]._key = i;
170
171 // Check if the current option has a condition to be shown
172 if (typeof choice.Condition !== 'undefined' && choice.Condition !== '') {
173 promises.push(
174 new Promise((resolve) => {
175 // First check if the condition is met before we add the button
176 this.engine.assertAsync(this.statement[i].Condition, this.engine).then(() => {
177 resolve(this.statement[i]);
178 }).catch(() => {
179 resolve(undefined);
180 });
181 })
182 );
183 } else {
184 promises.push(Promise.resolve(this.statement[i]));
185 }
186 }
187 }
188
189 const choices = await Promise.all(promises);
190 const element = document.createElement('choice-container');
191
192 // Check if the choice object defined a list of class names
193 const classes = typeof this.statement.Class === 'string' ? this.statement.Class.trim() : '';
194
195 (element as any).setProps({
196 choices: choices.filter(c => typeof c !== 'undefined'),
197 classes
198 });
199
200 const dialog = this.statement.Dialog;
201 const timer = this.statement.Timer;
202 const textBox = this.engine.element().find('[data-component="text-box"]').get(0);
203

Callers 1

revertMethod · 0.45

Calls 9

globalMethod · 0.80
assertAsyncMethod · 0.80
prepareActionMethod · 0.80
getMethod · 0.65
allMethod · 0.45
elementMethod · 0.45
willApplyMethod · 0.45
didApplyMethod · 0.45
contentMethod · 0.45

Tested by

no test coverage detected