<commit_before>import { Action } from './../lib/Action';
import { Monogatari } from '../monogatari';
import Typed from 'typed.js';
import { $_ } from '@aegis-framework/artemis';

export class Dialog extends Action {

	static shouldProceed () {

		// Check if the type animation has finished and the Typed object still exists
		if (!this.engine.global ('finished_typing') && this.engine.global ('textObject') !== null) {

			// Get the string it was typing
			const str = this.engine.global ('textObject').strings [0];

			// Get the element it was typing to
			const element = this.engine.global ('textObject').el;

			this.engine.global ('textObject').destroy ();

			element.innerHTML = str;

			this.engine.global ('finished_typing', true);

			return Promise.reject ('TypeWriter effect has not finished.');
		}

		return Promise.resolve (this.engine.global ('finished_typing'));
	}

	static willProceed () {
		const centeredDialog = this.engine.element ().find ('[data-component="centered-dialog"]');
		if (centeredDialog.isVisible ()) {
			centeredDialog.remove ();
		}
		return Promise.resolve (this.engine.global ('finished_typing'));
	}

	static willRollback () {
		if (this.engine.global ('textObject') !== null) {
			this.engine.global ('textObject').destroy ();
		}

		this.engine.global ('finished_typing', true);
		this.engine.global ('_CurrentChoice', null);
		this.engine.element ().find ('[data-component="text-box"]').show ('flex');

		const dialogLog = this.engine.component ('dialog-log');

		const centeredDialog = this.engine.element ().find ('[data-component="centered-dialog"]');
		if (centeredDialog.isVisible ()) {
			centeredDialog.remove ();
			this.engine.element ().find ('[data-component="text-box"]').show ('flex');
		}

		document.querySelector ('[data-ui="who"]').innerHTML = '';

		if (typeof dialogLog !== 'undefined') {
			dialogLog.instances (instance => instance.pop ());
		}
		return Promise.resolve ();
	}

	static setup () {
		Monogatari.globals ({
			textObject: null,
			finished_typing: true,
			typedConfiguration: {
				strings: [],
				typeSpeed: Monogatari.preference ('TextSpeed'),
				fadeOut: true,
				loop: false,
				showCursor: false,
				contentType: 'html',
				preStringTyped: () => {
					Monogatari.global ('finished_typing', false);
				},
				onStringTyped: () => {
					Monogatari.global ('finished_typing', true);
				},
				onDestroy () {
					Monogatari.global ('finished_typing', true);
				}
			}
		});

		// The NVL mode has its own history so that when going back, all dialogs
		// that were shown on screen can be shown again instead of just showing
		// the last one.
		Monogatari.history ('nvl');

		return Promise.resolve ();
	}

	static bind (selector) {
		// Add listener for the text speed setting
		$_(`${selector} [data-action="set-text-speed"]`).on ('change mouseover', function () {
			const value =  this.engine.setting ('maxTextSpeed') - parseInt(this.value);
			this.engine.global ('typedConfiguration').typeSpeed = value;
			this.engine.preference ('TextSpeed', value);
		});

		// Detect scroll on the text element to remove the unread class used when
		// there's text not being shown in NVL mode.
		$_(`${selector} [data-component="text-box"]`).on ('scroll', () => {
			this.engine.element ().find ('[data-component="text-box"]').removeClass ('unread');
		});
		return Promise.resolve ();
	}

	static init (selector) {
		// Remove the Text Speed setting if the type animation was disabled
		if (this.engine.setting ('TypeAnimation') === false) {<commit_msg>Fix listener for text speed setting<commit_after>import { Action } from './../lib/Action';
import { Monogatari } from '../monogatari';
import Typed from 'typed.js';
import { $_ } from '@aegis-framework/artemis';

export class Dialog extends Action {

	static shouldProceed () {

		// Check if the type animation has finished and the Typed object still exists
		if (!this.engine.global ('finished_typing') && this.engine.global ('textObject') !== null) {

			// Get the string it was typing
			const str = this.engine.global ('textObject').strings [0];

			// Get the element it was typing to
			const element = this.engine.global ('textObject').el;

			this.engine.global ('textObject').destroy ();

			element.innerHTML = str;

			this.engine.global ('finished_typing', true);

			return Promise.reject ('TypeWriter effect has not finished.');
		}

		return Promise.resolve (this.engine.global ('finished_typing'));
	}

	static willProceed () {
		const centeredDialog = this.engine.element ().find ('[data-component="centered-dialog"]');
		if (centeredDialog.isVisible ()) {
			centeredDialog.remove ();
		}
		return Promise.resolve (this.engine.global ('finished_typing'));
	}

	static willRollback () {
		if (this.engine.global ('textObject') !== null) {
			this.engine.global ('textObject').destroy ();
		}

		this.engine.global ('finished_typing', true);
		this.engine.global ('_CurrentChoice', null);
		this.engine.element ().find ('[data-component="text-box"]').show ('flex');

		const dialogLog = this.engine.component ('dialog-log');

		const centeredDialog = this.engine.element ().find ('[data-component="centered-dialog"]');
		if (centeredDialog.isVisible ()) {
			centeredDialog.remove ();
			this.engine.element ().find ('[data-component="text-box"]').show ('flex');
		}

		document.querySelector ('[data-ui="who"]').innerHTML = '';

		if (typeof dialogLog !== 'undefined') {
			dialogLog.instances (instance => instance.pop ());
		}
		return Promise.resolve ();
	}

	static setup () {
		Monogatari.globals ({
			textObject: null,
			finished_typing: true,
			typedConfiguration: {
				strings: [],
				typeSpeed: Monogatari.preference ('TextSpeed'),
				fadeOut: true,
				loop: false,
				showCursor: false,
				contentType: 'html',
				preStringTyped: () => {
					Monogatari.global ('finished_typing', false);
				},
				onStringTyped: () => {
					Monogatari.global ('finished_typing', true);
				},
				onDestroy () {
					Monogatari.global ('finished_typing', true);
				}
			}
		});

		// The NVL mode has its own history so that when going back, all dialogs
		// that were shown on screen can be shown again instead of just showing
		// the last one.
		Monogatari.history ('nvl');

		return Promise.resolve ();
	}

	static bind (selector) {
		const self = this;

		// Add listener for the text speed setting
		$_(`${selector} [data-action="set-text-speed"]`).on ('change mouseover', function () {
			const value =  this.engine.setting ('maxTextSpeed') - parseInt(this.value);
			self.global ('typedConfiguration').typeSpeed = value;
			self.preference ('TextSpeed', value);
		});

		// Detect scroll on the text element to remove the unread class used when
		// there's text not being shown in NVL mode.
		$_(`${selector} [data-component="text-box"]`).on ('scroll', () => {
			this.engine.element ().find ('[data-component="text-box"]').removeClass ('unread');
		});
		return Promise.resolve ();
	}

	static init (selector) {
		// Remove the Text Speed setting if the type animation was disabled
		if (this.engine.setting ('TypeAnimation') === false) {
{'fraction_non_alphanumeric': 0.15955056179775282, 'fraction_numerical': 0.0002808988764044944, 'mean_word_length': 3.7505003335557037, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5660041', 'n_tokens_mistral': 2421, 'n_tokens_neox': 2098, 'n_words': 568}