-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2116.43ed19b0c5c4834034ad.bundle.js
More file actions
377 lines (377 loc) · 23.3 KB
/
2116.43ed19b0c5c4834034ad.bundle.js
File metadata and controls
377 lines (377 loc) · 23.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
"use strict";
(self.webpackChunkmetapress = self.webpackChunkmetapress || []).push([
[2116], {
62116: (t, e, i) => {
i.r(e), i.d(e, {
default: () => p
});
const n = new class {
isValid(t) {
try {
return new URL(t), !0
} catch (t) {
return !1
}
}
};
var o = i(83674),
s = i(60516),
a = i(25108);
class r {
name = "Open Link";
icon = i(44455);
get settings() {
let t = [];
return t.push({
type: "description",
name: "Allows you to perform actions when clicking this object."
}, {
type: "select",
id: "content_type",
name: "Content Type",
placeholder: "url",
values: ["url", "post"],
labels: ["URL", "Post"],
help: "Type of Content to open when clicking the object"
}, {
type: "select",
id: "post_display_type",
name: "Display Type",
placeholder: "panel",
values: ["panel", "popup", "same-tab", "new-tab", "sidebar"],
labels: ["Open in panel", "Open in browser popup", "Open in same tab", "Open in new tab", "Open in sidebar"],
help: "Controls how the content will be displayed when the user clicks on the object."
}, {
type: "checkbox",
id: "distance_trigger",
name: "Trigger on Distance",
help: "When enabled, the click action will be triggered when the user is within the specified distance to the object."
}), this.entity.distance_trigger && (t = t.concat([{
type: "number",
id: "distance_value",
name: "Distance Value",
help: "The distance the user needs to be from the object in order to trigger its action. The default is 2 meters."
}])), t = this.entity.content_type && "url" != this.entity.content_type ? t.concat([{
type: "button",
id: "post",
name: "Select Post",
help: "Select the content to display in this slot.",
onClick: () => this.showContentPicker()
}, {
type: "text",
id: "contentSlot_source",
name: "Source ID",
placeholder: "any:0",
help: "Can either be a direct post ID or an offset in a list, ie 'posts:0' would return the first post etc."
}, {
type: "checkbox",
id: "disable_click",
name: "Disable Click Interaction",
help: "When enabled, the click action will not trigger the action."
}]) : t.concat([{
type: "text",
id: "link_url",
name: "URL",
help: "URL to open when clicking the object."
}]), t
}
onLoad() {
this.updateTimer = setInterval(this.checkDistance.bind(this), 1e3)
}
onUnload() {
this.updateTimer && clearInterval(this.updateTimer), this.updateTimer = null
}
showContentPicker() {
metapress.menubar.openReactPanel("site-content-picker", o.g, {
entityID: this.entity.id
})
}
getContent() {
if (!this.entity.content_type || "url" == this.entity.content_type) {
const t = this.entity.link_url ? this.entity.link_url.trim() : "";
return t.length < 1 ? void a.warn("[ActionScripterModifier] No URL provided.") : n.isValid(t) ? {
title: this.entity.name || "Link",
link: t
} : void a.warn("[ActionScripterModifier] Invalid URL provided.")
}
const t = metapress.siteContent.getItem(this.entity.contentSlot_source || "any:0");
if (t && t.link) return t
}
async onClick() {
this.entity.disable_click && this.entity.distance_trigger || await this.onAction()
}
async onAction(t) {
const e = this.getContent();
if (e?.link)
if (metapress.action_scripter.sendMessage({
source: "openlink",
entity: this.entity.id
}), "same-tab" == this.entity.post_display_type) metapress.close(), await new Promise((t => setTimeout(t, 500))), location.href = e.link;
else if ("new-tab" == this.entity.post_display_type) window.parent.open(e.link, "_blank");
else if ("popup" == this.entity.post_display_type) {
let t = 600,
i = 800,
n = window.screenLeft || window.screenX || 0,
o = window.screenTop || window.screenY || 0,
s = window.outerWidth || 1920,
a = window.outerHeight || 1080,
r = Math.max(n + s / 2 - t / 2, 0),
c = Math.max(o + a / 2 - i / 2, 0);
window.open(e.link, "_blank", `width=${t},height=${i},left=${r},top=${c},menubar=no,toolbar=no,location=no,personalbar=no,status=no`), metapress.input.movement.x = 0, metapress.input.movement.y = 0, metapress.input.devices.forEach((t => {
for (let e in t.activeKeys) t.activeKeys[e] = !1
}))
} else "sidebar" == this.entity.post_display_type ? metapress.menubar.openReactPanel("sidebar-iframe", s.T, {
item: e,
onClose: () => metapress.menubar.closePanel()
}) : (t && (this.popupOpen = !0), this.popup = metapress.dialogs.show({
title: e.title,
url: e.link,
width: Math.floor(.8 * window.innerWidth),
height: Math.floor(.8 * window.innerHeight)
}))
}
checkDistance() {
let t = this.entity.distance_value || 2;
if (!(this.entity.distance_trigger && this.entity && metapress.avatars && t)) return;
let e = new THREE.Vector3(metapress.avatars?.currentUserEntity.x || 0, metapress.avatars?.currentUserEntity.y || 0, metapress.avatars?.currentUserEntity.z || 0),
i = new THREE.Vector3(this.entity?.x, this.entity?.y, this.entity?.z);
e.distanceTo(i) <= t ? this.triggered || (this.triggered = !0, this.onAction(!0)) : (this.popup && this.popupOpen && (this.popup.close(), this.popup = null, this.popupOpen = !1), this.triggered = !1)
}
}
var c = i(25108);
class l {
name = "Object Interaction";
hidden = !0;
get settings() {
return [{
type: "description",
name: "Used to execute the actions from the action scripter."
}]
}
entity = null;
actionsTriggered = [];
mixer = null;
onLoad() {
this.updateTimer = setInterval(this.checkDistance.bind(this), 1e3), this.mixer = new THREE.AnimationMixer(this.renderer.object), this.triggeredActions = [], this.entity.entityActions?.forEach((t => {
"load" == t.trigger && this.onAction(t)
}))
}
onUnload() {
this.updateTimer && clearInterval(this.updateTimer), this.updateTimer = null
}
async onClick() {
this.entity.entityActions && this.entity.entityActions.length > 0 && this.entity.entityActions.forEach((t => {
"click" == t.trigger && this.onAction(t)
}))
}
async onAction(t, e) {
this.actionsTriggered.push(t), !e && t.synchronized && metapress.messaging.send("global", "actionscripter:action", {
action: t
}), 0 != t.actionLimit && null != t.actionLimit && this.actionsTriggered.filter((e => e.id == t.id))?.length > t.actionLimit || (metapress.action_scripter.sendMessage({
source: "actionscripter",
entity: this.entity.id,
action: t.action
}), "playsound" == t.action && this.playSound(t.fileURL, t.trigger), "playanimation" == t.action && this.playAnimation(t.animation, t.animationDuration), "showalert" != t.action && "showpanel" != t.action && "showsidebar" != t.action && "showpopup" != t.action || await this.openURL(t))
}
checkDistance() {
if (!this.entity.entityActions || this.entity.entityActions.length < 1) return;
let t = new THREE.Vector3(metapress.avatars?.currentUserEntity.x || 0, metapress.avatars?.currentUserEntity.y || 0, metapress.avatars?.currentUserEntity.z || 0),
e = new THREE.Vector3(this.entity?.x, this.entity?.y, this.entity?.z),
i = t.distanceTo(e);
this.entity.entityActions.forEach((t => {
let e = t.proximityRange ? parseInt(t.proximityRange) : 2;
"proximityenter" == t.trigger && (i <= e ? this.triggeredActions.find((e => e.id == t.id)) || (this.onAction(t), this.triggeredActions.push({
id: t.id
})) : (this.triggeredActions = this.triggeredActions.filter((e => e.id != t.id)), this.stopAudio())), i > e && (this.popup && "proximityenter" == this.popupTrigger && (this.popup.close(), this.popup = null, this.popupTrigger = null), "proximityenter" == this.alertTrigger && (metapress.dialogs.closeAll(), this.alertTrigger = null))
}))
}
playAnimation(t, e) {
if (t) {
if (this.entity?.["modifier:animator"] || metapress.entities.update(this.entity.id, {
"modifier:animator": !0
}), e = e ? 1e3 * parseInt(e) : 2e3, Date.now(), this.lastMoveTime, this.entity.lastAnimationTriggerDate) {
if (!(Date.now() - this.entity.lastAnimationTriggerDate > e)) return;
this.playCurrentAnimation(t)
} else this.playCurrentAnimation(t);
metapress.entities.update(this.entity.id, {
lastAnimationTriggerDate: Date.now()
}), setTimeout((() => {
this.action && (this.previousAnimation ? this.playCurrentAnimation(this.previousAnimation) : (this.action.stop(), this.action.enabled = !1, this.action = null, this.entity.animation_name = null))
}), e)
}
}
playSound(t, e) {
if (t) {
if (this.audio && (this.stopAudio(), this.lastURL == t && "click" == e && this.audio.duration > 8)) {
let t = 1e3 * this.audio.duration,
e = Date.now() - this.lastPlayDate;
if ("play" == this.lastAction && e < t) return this.lastAction = "stop", void(this.lastURL = null)
}
this.audio = new Audio(t), this.audio.play(), this.lastAction = "play", this.lastURL = t, this.lastPlayDate = Date.now()
}
}
stopAudio() {
this.audio && (this.audio.duration > 0 && !this.audio.paused && this.audio.pause(), this.audio.src = "")
}
playCurrentAnimation(t) {
let e = metapress.animation.getClip(t, this.renderer);
if (!e) return this["_notified_clipNotFound_" + t] || c.warn(`[MetaPress > Animator] Animation clip not found: ${t}`), void(this["_notified_clipNotFound_" + t] = !0);
this.previousAnimation = this.entity.animation_name;
let i = this.mixer.clipAction(e);
this.action = i, this.entity.animation_nonce = Date.now(), this.entity.animation_name = t, this.entity.animation_loop = !1
}
getContent(t) {
if (t) {
const e = t ? t.trim() : "";
return e.length < 1 ? void c.warn("[ObjectInteractionModifier] No URL provided.") : n.isValid(e) ? {
title: this.entity.name || "Link",
link: e
} : void c.warn("[ObjectInteractionModifier] Invalid URL provided.")
}
}
async openURL(t) {
const e = this.getContent(t.triggerText);
if (e?.link || "showalert" == t.action)
if ("showpopup" == t.action) {
let t = 600,
i = 800,
n = window.screenLeft || window.screenX || 0,
o = window.screenTop || window.screenY || 0,
s = window.outerWidth || 1920,
a = window.outerHeight || 1080,
r = Math.max(n + s / 2 - t / 2, 0),
c = Math.max(o + a / 2 - i / 2, 0);
window.open(e.link, "_blank", `width=${t},height=${i},left=${r},top=${c},menubar=no,toolbar=no,location=no,personalbar=no,status=no`), metapress.input.movement.x = 0, metapress.input.movement.y = 0, metapress.input.devices.forEach((t => {
for (let e in t.activeKeys) t.activeKeys[e] = !1
}))
} else "showsidebar" == t.action ? metapress.menubar.openReactPanel("sidebar-iframe", s.T, {
item: e,
onClose: () => metapress.menubar.closePanel()
}) : "showpanel" == t.action ? (this.popup && (this.popup.close(), this.popup = null, this.popupTrigger = null), this.popupTrigger = t.trigger, this.popup = await metapress.dialogs.show({
title: e.title,
url: e.link,
width: Math.floor(.8 * window.innerWidth),
height: Math.floor(.8 * window.innerHeight)
})) : "showalert" == t.action && (metapress.dialogs.closeAll(), this.alertTrigger = t.trigger, this.alert = await metapress.dialogs.alert({
icon: "info",
title: t.triggerTitle,
text: t.triggerText
}))
}
$onIncomingMessage(t) {
"actionscripter:action" == t.name && this.onAction(t.data.action, !0)
}
actionTrigger(t) {
this.onAction(t, !0)
}
}
class p {
id = "core.misc.action_scripter";
name = "Open Link";
description = "Allows the user perform actions when interacting with a object.";
requires = ["entities"];
provides = ["action_scripter", "modifier:action_scripter_click", "modifier:object_interaction"];
createModifier(t) {
return "action_scripter_click" == t ? new r : "object_interaction" == t ? new l : void 0
}
sendMessage(t) {
metapress.plugins.sendEvent("actionScripter_onObjectAction", {
entity: t.entity,
action: t.action,
source: t.source
})
}
getObjects() {
return metapress.entities.all.filter((t => t.entityActions && t.entityActions?.length > 0))
}
getClosest(t) {
let e = this.getObjects(),
i = [],
n = [];
if (t)
if ("any" == t) i = e;
else
for (let n of e) {
let e = !1;
for (let i of n.entityActions) i.action == t && (e = !0);
e && i.push(n)
}
let o = new THREE.Vector3(metapress.avatars?.currentUserEntity.x || 0, metapress.avatars?.currentUserEntity.y || 0, metapress.avatars?.currentUserEntity.z || 0);
for (let t of i) {
let e = t,
i = new THREE.Vector3(t.x, t.y, t.z),
s = o.distanceTo(i);
e.distance = s, n.push(e)
}
return n.sort(((t, e) => t.distance - e.distance)), n[0]
}
triggerActions(t) {
let e = this.getObjects();
for (let i of e)
for (let e of i.entityActions) e.action == t && metapress.entities.getModifier(i.id, "object_interaction").actionTrigger(e)
}
triggerAction(t) {
let e = this.getClosest(t);
for (let i of e.entityActions) i.action == t && metapress.entities.getModifier(e.id, "object_interaction").actionTrigger(i)
}
$ai_getKnowledgeBaseEntries = () => [{
id: `${this.id}:info`,
type: "info",
name: "Action scripter",
tags: "action scripter, scripts, logic, perform automatic actions, automate, automation, click actions, object actions, object interaction",
content: '\n The action scripter can be used to automate things within the world. For example, show a message when a user clicks an object or gets near an object, etc.\n To use it, add the "Action Scripter" modifier to an object in the Editor and configure the actions you want to perform.\n '
}, {
id: `${this.id}:triggerActionsOfTypeOnClosest`,
type: "action",
name: "Action Scripter - Trigger specific closest action",
tags: "trigger playanimation, trigger playsound, trigger showpopup, trigger showalert",
content: "\n Assistant instruction: Run this action with value 'playanimation' or 'playsound' or 'showpopup' or 'showalert' and when the user asks to trigger a type of action scripter actions.\n ",
action: t => {
if (!t.value) throw new Error("Cannot send empty message.");
return this.triggerAction(t.value), "Triggered action"
}
}, {
id: `${this.id}:triggerActionsOnClosest`,
type: "action",
name: "Action Scripter - Trigger any closest action",
tags: "trigger closest action, trigger closest action scripter action, play closest action, play closest action scripter action",
content: "\n Assistant instruction: Run this action with value 'any' when the user asks for the closest object to trigger the action scripter actions.\n ",
action: t => {
if (!t.value) throw new Error("Cannot send empty message.");
return this.triggerAction(t.value), "Triggered action"
}
}, {
id: `${this.id}:getObjectActionScripterList`,
type: "action",
name: "Action Scripter - Specific object actions list",
tags: "object animate, get object actions, get object actions list, get object action scripter actions list",
content: `\n To retrieve the list of actions that can be performed on a specific object, run the KB action '${this.id}:getObjectActionScripterList' with the value as the object name.\n\n Available objects: ${this.getObjects().map((t=>`- ${t.name}`)).join("\n")}\n `,
action: t => {
if (!t.value) throw new Error("Cannot send empty message.");
for (let e of this.getObjects())
if (e?.name?.includes(t.value) && e.entityActions.length > 0) return `The object plays ${e.entityActions.map((t=>`${t.action} ${t.triggerLabel}`)).join(", ")}.`;
return "No Action Scripter actions found for the object."
}
}, {
id: `${this.id}:triggerActionOnObject`,
type: "action",
name: "Action Scripter - Trigger specific object action",
tags: "trigger object, trigger object action, click object, play sound, trigger object action scripter action, start object",
content: `\n Assistant instruction: Run this action when the user asks to animate a specific object that has Action scripter actions. \n Run the KB action '${this.id}:triggerActionOnObject' with the value as the object name.\n Available objects: ${this.getObjects().map((t=>`- ${t.name}`)).join("\n")}\n `,
action: t => {
if (!t.value) throw new Error("Cannot send empty message.");
for (let e of this.getObjects())
if (e?.name?.includes(t.value) && e.entityActions.length > 0) {
let t = metapress.entities.getModifier(e.id, "object_interaction");
for (let i of e.entityActions) t.actionTrigger(i);
return `Triggered the object action: ${e.name}`
} return "No Action Scripter actions found for the object."
}
}]
}
},
44455: (t, e, i) => {
t.exports = i.p + "mp-core/action.091e0874ceb265e38c22.svg"
}
}
]);