Skip to content

Commit 8d55605

Browse files
authored
Fix entity trigger message (workadventure#4079)
When we use entity we are able to define a trigger message (toaster on the top of entity object) like area.
1 parent a141791 commit 8d55605

File tree

7 files changed

+67
-39
lines changed

7 files changed

+67
-39
lines changed

docs/schema/1.0/wam.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@
132132
"volume": {
133133
"type": "number",
134134
"default": 1
135+
},
136+
"triggerMessage": {
137+
"type": "string"
135138
}
136139
},
137140
"required": [

libs/map-editor/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const PlayAudioPropertyData = PropertyBase.extend({
6363
type: z.literal("playAudio"),
6464
audioLink: z.string(),
6565
volume: z.number().default(1).optional(),
66+
triggerMessage: z.string().optional(),
6667
});
6768

6869
export const OpenWebsitePropertyData = PropertyBase.extend({

play/src/front/Components/MapEditor/AreaEditor/AreaPropertiesEditor.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@
569569
{:else if property.type === "jitsiRoomProperty"}
570570
<JitsiRoomPropertyEditor
571571
{property}
572+
isArea={true}
572573
on:close={() => {
573574
onDeleteProperty(property.id);
574575
}}
@@ -577,6 +578,7 @@
577578
{:else if property.type === "playAudio"}
578579
<PlayAudioPropertyEditor
579580
property={{ ...property, hideButtonLabel: true }}
581+
isArea={true}
580582
on:close={() => {
581583
onDeleteProperty(property.id);
582584
}}

play/src/front/Components/MapEditor/PropertyEditor/JitsiRoomPropertyEditor.svelte

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
export let property: JitsiRoomPropertyData;
99
export let triggerOnActionChoosen: boolean = property.trigger === "onaction";
1010
export let triggerOptionActivated = true;
11+
export let isArea = false;
1112
let optionAdvancedActivated = false;
1213
1314
const dispatch = createEventDispatcher();
@@ -129,18 +130,18 @@
129130
<option value="onaction">{$LL.mapEditor.properties.jitsiProperties.triggerOnAction()}</option>
130131
</select>
131132
</div>
132-
133-
{#if triggerOnActionChoosen}
134-
<div class="value-input">
135-
<label for="triggerMessage">{$LL.mapEditor.properties.jitsiProperties.triggerMessage()}</label>
136-
<input
137-
id="triggerMessage"
138-
type="text"
139-
bind:value={property.triggerMessage}
140-
on:change={onValueChange}
141-
/>
142-
</div>
143-
{/if}
133+
{/if}
134+
{#if (isArea && triggerOptionActivated && triggerOnActionChoosen) || !isArea}
135+
<div class="value-input tw-flex tw-flex-col">
136+
<label for="triggerMessage">{$LL.mapEditor.properties.linkProperties.triggerMessage()}</label>
137+
<input
138+
id="triggerMessage"
139+
type="text"
140+
placeholder={$LL.trigger.object()}
141+
bind:value={property.triggerMessage}
142+
on:change={onValueChange}
143+
/>
144+
</div>
144145
{/if}
145146
<button
146147
on:click={() => {

play/src/front/Components/MapEditor/PropertyEditor/OpenWebsitePropertyEditor.svelte

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -716,30 +716,29 @@
716716
<input id="advancedOption" type="checkbox" class="input-switch" bind:checked={optionAdvancedActivated} />
717717
</div>
718718
<div class:active={optionAdvancedActivated} class="advanced-option tw-px-2">
719-
{#if triggerOptionActivated}
720-
{#if triggerOnActionChoosen}
721-
<div class="value-input tw-flex tw-flex-col">
722-
<label for="triggerMessage">{$LL.mapEditor.properties.linkProperties.triggerMessage()}</label>
723-
<input
724-
id="triggerMessage"
725-
type="text"
726-
bind:value={property.triggerMessage}
727-
on:change={onValueChange}
728-
/>
729-
</div>
730-
{/if}
731-
<div class="value-switch">
732-
<label for="newTab">{$LL.mapEditor.properties.linkProperties.newTabLabel()}</label>
719+
{#if (isArea && triggerOptionActivated && triggerOnActionChoosen) || !isArea}
720+
<div class="value-input tw-flex tw-flex-col">
721+
<label for="triggerMessage">{$LL.mapEditor.properties.linkProperties.triggerMessage()}</label>
733722
<input
734-
id="newTab"
735-
type="checkbox"
736-
class="input-switch"
737-
bind:checked={property.newTab}
738-
on:change={onNewTabValueChange}
739-
disabled={property.forceNewTab}
723+
id="triggerMessage"
724+
type="text"
725+
placeholder={$LL.trigger.object()}
726+
bind:value={property.triggerMessage}
727+
on:change={onValueChange}
740728
/>
741729
</div>
742730
{/if}
731+
<div class="value-switch">
732+
<label for="newTab">{$LL.mapEditor.properties.linkProperties.newTabLabel()}</label>
733+
<input
734+
id="newTab"
735+
type="checkbox"
736+
class="input-switch"
737+
bind:checked={property.newTab}
738+
on:change={onNewTabValueChange}
739+
disabled={property.forceNewTab}
740+
/>
741+
</div>
743742
{#if property.forceNewTab == true}
744743
<div class="tw-mb-3">
745744
<span class="err tw-text-warning-900 tw-text-xs tw-italic">

play/src/front/Components/MapEditor/PropertyEditor/PlayAudioPropertyEditor.svelte

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import PropertyEditorBase from "./PropertyEditorBase.svelte";
77
88
export let property: PlayAudioPropertyData;
9+
export let isArea = false;
910
let optionAdvancedActivated = false;
1011
1112
const dispatch = createEventDispatcher();
@@ -102,6 +103,18 @@
102103
<input id="advancedOption" type="checkbox" class="input-switch" bind:checked={optionAdvancedActivated} />
103104
</div>
104105
<div class:active={optionAdvancedActivated} class="advanced-option tw-px-2">
106+
{#if isArea === false}
107+
<div class="value-input tw-flex tw-flex-col">
108+
<label for="triggerMessage">{$LL.mapEditor.properties.linkProperties.triggerMessage()}</label>
109+
<input
110+
id="triggerMessage"
111+
type="text"
112+
placeholder={$LL.trigger.object()}
113+
bind:value={property.triggerMessage}
114+
on:change={onValueChange}
115+
/>
116+
</div>
117+
{/if}
105118
<div class="value-input">
106119
<label for="volume">{$LL.mapEditor.properties.audioProperties.volumeLabel()}</label>
107120
<input

play/src/front/Phaser/Game/ActivatablesManager.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Player } from "../Player/Player";
55
import LL from "../../../i18n/i18n-svelte";
66
import { isMediaBreakpointUp } from "../../Utils/BreakpointsUtils";
77
import { RemotePlayer } from "../Entity/RemotePlayer";
8+
import { Entity } from "../ECS/Entity";
89
import type { ActivatableInterface } from "./ActivatableInterface";
910

1011
export class ActivatablesManager {
@@ -86,14 +87,22 @@ export class ActivatablesManager {
8687
if (isOutlineable(this.selectedActivatableObjectByDistance)) {
8788
this.selectedActivatableObjectByDistance?.characterCloseByOutline(this.outlineColor);
8889
if (this.selectedActivatableObjectByDistance instanceof RemotePlayer == false) {
89-
this.selectedActivatableObjectByDistance.playText(
90-
"object",
91-
isMediaBreakpointUp("md") ? get(LL).trigger.mobile.object() : get(LL).trigger.object(),
92-
10000,
93-
() => {
94-
this.currentPlayer.scene.userInputManager.handleActivableEntity();
90+
// TODO: improve this to show multiple trigger messages
91+
let triggerMessage: string = isMediaBreakpointUp("md")
92+
? get(LL).trigger.mobile.object()
93+
: get(LL).trigger.object();
94+
if (this.selectedActivatableObjectByDistance instanceof Entity) {
95+
for (const property of this.selectedActivatableObjectByDistance.getEntityData().properties) {
96+
if (property.type === "entityDescriptionProperties") continue;
97+
if (property.triggerMessage) {
98+
triggerMessage = property.triggerMessage;
99+
break;
100+
}
95101
}
96-
);
102+
}
103+
this.selectedActivatableObjectByDistance.playText("object", triggerMessage, 10000, () => {
104+
this.currentPlayer.scene.userInputManager.handleActivableEntity();
105+
});
97106
}
98107
}
99108
}

0 commit comments

Comments
 (0)