2021-06-21 17:19:27 +02:00
|
|
|
<script lang="ts">
|
2021-07-19 09:22:47 +02:00
|
|
|
import { consoleGlobalMessageManagerFocusStore, consoleGlobalMessageManagerVisibleStore } from "../../Stores/ConsoleGlobalMessageManagerStore";
|
2021-07-23 16:17:53 +02:00
|
|
|
import {onDestroy, onMount} from "svelte";
|
2021-07-19 09:22:47 +02:00
|
|
|
import type { GameManager } from "../../Phaser/Game/GameManager";
|
|
|
|
import { AdminMessageEventTypes } from "../../Connexion/AdminMessagesService";
|
|
|
|
import type { Quill } from "quill";
|
2021-07-22 16:14:27 +02:00
|
|
|
import type { PlayGlobalMessageInterface } from "../../Connexion/ConnexionModels";
|
2021-06-21 17:19:27 +02:00
|
|
|
|
|
|
|
//toolbar
|
2021-07-19 09:22:47 +02:00
|
|
|
const toolbarOptions = [
|
2021-06-21 17:19:27 +02:00
|
|
|
['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 gameManager: GameManager;
|
|
|
|
|
2021-08-03 17:19:47 +02:00
|
|
|
const gameScene = gameManager.getCurrentGameScene();
|
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;
|
|
|
|
|
2021-07-19 09:22:47 +02:00
|
|
|
export const handleSending = {
|
2021-07-20 15:16:51 +02:00
|
|
|
sendTextMessage(broadcastToWorld: boolean) {
|
2021-07-19 09:22:47 +02:00
|
|
|
if (gameScene == undefined) {
|
|
|
|
return;
|
|
|
|
}
|
2021-07-23 11:07:17 +02:00
|
|
|
const text = JSON.stringify(quill.getContents(0, quill.getLength()));
|
2021-07-22 16:14:27 +02:00
|
|
|
|
|
|
|
const textGlobalMessage: PlayGlobalMessageInterface = {
|
2021-07-20 15:16:51 +02:00
|
|
|
type: MESSAGE_TYPE,
|
|
|
|
content: text,
|
|
|
|
broadcastToWorld: broadcastToWorld
|
2021-07-19 09:22:47 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
quill.deleteText(0, quill.getLength());
|
2021-07-22 16:14:27 +02:00
|
|
|
gameScene.connection?.emitGlobalMessage(textGlobalMessage);
|
2021-07-19 09:22:47 +02:00
|
|
|
disableConsole();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-21 17:19:27 +02:00
|
|
|
//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, {
|
2021-07-15 15:09:35 +02:00
|
|
|
placeholder: 'Enter your message here...',
|
2021-06-21 17:19:27 +02:00
|
|
|
theme: 'snow',
|
|
|
|
modules: {
|
|
|
|
toolbar: toolbarOptions
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-07-23 16:17:53 +02:00
|
|
|
consoleGlobalMessageManagerFocusStore.set(true);
|
2021-06-21 17:19:27 +02:00
|
|
|
});
|
|
|
|
|
2021-07-23 16:17:53 +02:00
|
|
|
onDestroy(() => {
|
|
|
|
consoleGlobalMessageManagerFocusStore.set(false);
|
|
|
|
})
|
|
|
|
|
2021-06-21 17:19:27 +02:00
|
|
|
function disableConsole() {
|
2021-06-22 16:12:53 +02:00
|
|
|
consoleGlobalMessageManagerVisibleStore.set(false);
|
|
|
|
consoleGlobalMessageManagerFocusStore.set(false);
|
2021-06-21 17:19:27 +02:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<section class="section-input-send-text">
|
|
|
|
<div class="input-send-text" bind:this={INPUT_CONSOLE_MESSAGE}></div>
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@import 'https://cdn.quilljs.com/1.3.7/quill.snow.css';
|
|
|
|
</style>
|