2021-06-21 17:19:27 +02:00
|
|
|
<script lang="ts">
|
|
|
|
import {ConsoleGlobalMessageManagerFocusStore, ConsoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
|
|
|
|
import {onMount} from "svelte";
|
2021-06-22 09:43:41 +02:00
|
|
|
import type {Game} from "../../Phaser/Game/Game";
|
2021-06-22 10:10:03 +02:00
|
|
|
import type {GameManager} from "../../Phaser/Game/GameManager";
|
2021-06-21 17:19:27 +02:00
|
|
|
import type {PlayGlobalMessageInterface} from "../../Connexion/ConnexionModels";
|
|
|
|
import {AdminMessageEventTypes} from "../../Connexion/AdminMessagesService";
|
2021-06-22 10:10:03 +02:00
|
|
|
import type {Quill} from "quill";
|
2021-06-22 10:22:49 +02:00
|
|
|
import {LoginSceneName} from "../../Phaser/Login/LoginScene";
|
2021-06-21 17:19:27 +02:00
|
|
|
|
|
|
|
//toolbar
|
|
|
|
export const toolbarOptions = [
|
|
|
|
['bold', 'italic', 'underline', 'strike'], // toggled buttons
|
|
|
|
['blockquote', 'code-block'],
|
|
|
|
|
|
|
|
[{'header': 1}, {'header': 2}], // custom button values
|
|
|
|
[{'list': 'ordered'}, {'list': 'bullet'}],
|
|
|
|
[{'script': 'sub'}, {'script': 'super'}], // superscript/subscript
|
|
|
|
[{'indent': '-1'}, {'indent': '+1'}], // outdent/indent
|
|
|
|
[{'direction': 'rtl'}], // text direction
|
|
|
|
|
|
|
|
[{'size': ['small', false, 'large', 'huge']}], // custom dropdown
|
|
|
|
[{'header': [1, 2, 3, 4, 5, 6, false]}],
|
|
|
|
|
|
|
|
[{'color': []}, {'background': []}], // dropdown with defaults from theme
|
|
|
|
[{'font': []}],
|
|
|
|
[{'align': []}],
|
|
|
|
|
|
|
|
['clean'],
|
|
|
|
|
|
|
|
['link', 'image', 'video']
|
|
|
|
// remove formatting button
|
|
|
|
];
|
|
|
|
|
|
|
|
export let game: Game;
|
|
|
|
export let gameManager: GameManager;
|
|
|
|
|
2021-06-22 10:22:49 +02:00
|
|
|
let gameScene = gameManager.getCurrentGameScene(game.scene.getScene(LoginSceneName));
|
2021-06-22 10:10:03 +02:00
|
|
|
let quill: Quill;
|
|
|
|
let INPUT_CONSOLE_MESSAGE: HTMLDivElement;
|
2021-06-21 17:19:27 +02:00
|
|
|
|
|
|
|
const MESSAGE_TYPE = AdminMessageEventTypes.admin;
|
|
|
|
|
|
|
|
//Quill
|
|
|
|
onMount(async () => {
|
|
|
|
|
|
|
|
// Import quill
|
|
|
|
const {default: Quill} = await import("quill"); // eslint-disable-line @typescript-eslint/no-explicit-any
|
|
|
|
|
|
|
|
quill = new Quill(INPUT_CONSOLE_MESSAGE, {
|
|
|
|
theme: 'snow',
|
|
|
|
modules: {
|
|
|
|
toolbar: toolbarOptions
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-06-22 09:43:41 +02:00
|
|
|
quill.on('selection-change', function (range, oldRange) {
|
2021-06-21 17:19:27 +02:00
|
|
|
if (range === null && oldRange !== null) {
|
|
|
|
ConsoleGlobalMessageManagerFocusStore.set(false);
|
|
|
|
} else if (range !== null && oldRange === null)
|
|
|
|
ConsoleGlobalMessageManagerFocusStore.set(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function disableConsole() {
|
|
|
|
ConsoleGlobalMessageManagerVisibleStore.set(false);
|
|
|
|
ConsoleGlobalMessageManagerFocusStore.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
function SendTextMessage() {
|
2021-06-22 10:27:54 +02:00
|
|
|
if (gameScene == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2021-06-22 09:43:41 +02:00
|
|
|
const text = quill.getText(0, quill.getLength());
|
|
|
|
|
2021-06-21 17:19:27 +02:00
|
|
|
const GlobalMessage: PlayGlobalMessageInterface = {
|
|
|
|
id: "1", // FIXME: use another ID?
|
2021-06-22 09:43:41 +02:00
|
|
|
message: text,
|
2021-06-21 17:19:27 +02:00
|
|
|
type: MESSAGE_TYPE
|
|
|
|
};
|
2021-06-22 09:43:41 +02:00
|
|
|
|
|
|
|
quill.deleteText(0, quill.getLength());
|
2021-06-22 10:43:20 +02:00
|
|
|
gameScene.connection?.emitGlobalMessage(GlobalMessage);
|
2021-06-21 17:19:27 +02:00
|
|
|
disableConsole();
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<section class="section-input-send-text">
|
|
|
|
<div class="input-send-text" bind:this={INPUT_CONSOLE_MESSAGE}></div>
|
|
|
|
<div class="btn-action">
|
|
|
|
<button class="nes-btn is-primary" on:click|preventDefault={SendTextMessage}>Send</button>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import 'https://cdn.quilljs.com/1.3.7/quill.snow.css';
|
|
|
|
</style>
|