updated invitation link creator
This commit is contained in:
parent
9cccdca3dc
commit
c13672c9dc
@ -1,5 +1,12 @@
|
||||
<script lang="ts">
|
||||
import LL from "../../i18n/i18n-svelte";
|
||||
import { gameManager } from "../../Phaser/Game/GameManager";
|
||||
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
||||
|
||||
let entryPoint: string = $startLayerNamesStore[0];
|
||||
let walkAutomatically: boolean = false;
|
||||
const currentPlayer = gameManager.getCurrentGameScene().CurrentPlayer;
|
||||
const playerPos = { x: Math.floor(currentPlayer.x), y: Math.floor(currentPlayer.y) };
|
||||
|
||||
function copyLink() {
|
||||
const input: HTMLInputElement = document.getElementById("input-share-link") as HTMLInputElement;
|
||||
@ -8,8 +15,21 @@
|
||||
document.execCommand("copy");
|
||||
}
|
||||
|
||||
function getLink() {
|
||||
return `${location.origin}${location.pathname}#${entryPoint}${
|
||||
walkAutomatically ? `&moveTo=${playerPos.x},${playerPos.y}` : ""
|
||||
}`;
|
||||
}
|
||||
|
||||
function updateInputFieldValue() {
|
||||
const input = document.getElementById("input-share-link");
|
||||
if (input) {
|
||||
(input as HTMLInputElement).value = getLink();
|
||||
}
|
||||
}
|
||||
|
||||
async function shareLink() {
|
||||
const shareData = { url: location.toString() };
|
||||
const shareData = { url: getLink() };
|
||||
|
||||
try {
|
||||
await navigator.share(shareData);
|
||||
@ -32,6 +52,30 @@
|
||||
<input type="hidden" readonly id="input-share-link" value={location.toString()} />
|
||||
<button type="button" class="nes-btn is-primary" on:click={shareLink}>{$LL.menu.invite.share()}</button>
|
||||
</section>
|
||||
<h3>Select an entry point</h3>
|
||||
<section class="nes-select is-dark">
|
||||
<select
|
||||
bind:value={entryPoint}
|
||||
on:blur={() => {
|
||||
updateInputFieldValue();
|
||||
}}
|
||||
>
|
||||
{#each $startLayerNamesStore as entryPointName}
|
||||
<option value={entryPointName}>{entryPointName}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</section>
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
class="nes-checkbox is-dark"
|
||||
bind:checked={walkAutomatically}
|
||||
on:change={() => {
|
||||
updateInputFieldValue();
|
||||
}}
|
||||
/>
|
||||
<span>Walk automatically to my position</span>
|
||||
</label>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
@ -47,6 +91,10 @@
|
||||
margin-bottom: 50px;
|
||||
}
|
||||
|
||||
section.nes-select select:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
section.container-overflow {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
|
@ -93,6 +93,7 @@ import { followUsersColorStore } from "../../Stores/FollowStore";
|
||||
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
||||
import { locale } from "../../i18n/i18n-svelte";
|
||||
import { StringUtils } from "../../Utils/StringUtils";
|
||||
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null;
|
||||
reconnecting: boolean;
|
||||
@ -542,6 +543,8 @@ export class GameScene extends DirtyScene {
|
||||
urlManager.getStartLayerNameFromUrl()
|
||||
);
|
||||
|
||||
startLayerNamesStore.set(this.startPositionCalculator.getStartPositionNames());
|
||||
|
||||
//add entities
|
||||
this.Objects = new Array<Phaser.Physics.Arcade.Sprite>();
|
||||
|
||||
|
@ -16,32 +16,6 @@ export class StartPositionCalculator {
|
||||
) {
|
||||
this.initStartXAndStartY();
|
||||
}
|
||||
private initStartXAndStartY() {
|
||||
// If there is an init position passed
|
||||
if (this.initPosition !== null) {
|
||||
this.startPosition = this.initPosition;
|
||||
} else {
|
||||
// Now, let's find the start layer
|
||||
if (this.startLayerName) {
|
||||
this.initPositionFromLayerName(this.startLayerName, this.startLayerName);
|
||||
}
|
||||
if (this.startPosition === undefined) {
|
||||
// If we have no start layer specified or if the hash passed does not exist, let's go with the default start position.
|
||||
this.initPositionFromLayerName(defaultStartLayerName, this.startLayerName);
|
||||
}
|
||||
}
|
||||
// Still no start position? Something is wrong with the map, we need a "start" layer.
|
||||
if (this.startPosition === undefined) {
|
||||
console.warn(
|
||||
'This map is missing a layer named "start" that contains the available default start positions.'
|
||||
);
|
||||
// Let's start in the middle of the map
|
||||
this.startPosition = {
|
||||
x: this.mapFile.width * 16,
|
||||
y: this.mapFile.height * 16,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
@ -76,6 +50,47 @@ export class StartPositionCalculator {
|
||||
}
|
||||
}
|
||||
|
||||
public getStartPositionNames(): string[] {
|
||||
const names: string[] = [];
|
||||
for (const layer of this.gameMap.flatLayers) {
|
||||
if (layer.name === "start") {
|
||||
names.push(layer.name);
|
||||
continue;
|
||||
}
|
||||
if (this.isStartLayer(layer)) {
|
||||
names.push(layer.name);
|
||||
}
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private initStartXAndStartY() {
|
||||
// If there is an init position passed
|
||||
if (this.initPosition !== null) {
|
||||
this.startPosition = this.initPosition;
|
||||
} else {
|
||||
// Now, let's find the start layer
|
||||
if (this.startLayerName) {
|
||||
this.initPositionFromLayerName(this.startLayerName, this.startLayerName);
|
||||
}
|
||||
if (this.startPosition === undefined) {
|
||||
// If we have no start layer specified or if the hash passed does not exist, let's go with the default start position.
|
||||
this.initPositionFromLayerName(defaultStartLayerName, this.startLayerName);
|
||||
}
|
||||
}
|
||||
// Still no start position? Something is wrong with the map, we need a "start" layer.
|
||||
if (this.startPosition === undefined) {
|
||||
console.warn(
|
||||
'This map is missing a layer named "start" that contains the available default start positions.'
|
||||
);
|
||||
// Let's start in the middle of the map
|
||||
this.startPosition = {
|
||||
x: this.mapFile.width * 16,
|
||||
y: this.mapFile.height * 16,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private isStartLayer(layer: ITiledMapLayer): boolean {
|
||||
return this.getProperty(layer, GameMapProperties.START_LAYER) == true;
|
||||
}
|
||||
|
6
front/src/Stores/StartLayerNamesStore.ts
Normal file
6
front/src/Stores/StartLayerNamesStore.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Readable, writable } from "svelte/store";
|
||||
|
||||
/**
|
||||
* A store that contains the map starting layers names
|
||||
*/
|
||||
export const startLayerNamesStore = writable<string[]>([]);
|
Loading…
Reference in New Issue
Block a user